Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix / Kujira / New tendermint changes #218

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"test:scripts": "jest -i --verbose ./test-scripts/*.test.ts"
},
"dependencies": {
"@cosmjs/proto-signing": "^0.30.1",
"@cosmjs/stargate": "^0.30.1",
"@cosmjs/proto-signing": "^0.31.1",
"@cosmjs/stargate": "^0.31.1",
"@crocswap/sdk": "^2.4.5",
"@ethersproject/abstract-provider": "5.7.0",
"@ethersproject/address": "5.7.0",
Expand Down Expand Up @@ -76,7 +76,7 @@
"http-status-codes": "2.2.0",
"immutable": "^4.2.4",
"js-yaml": "^4.1.0",
"kujira.js": "^0.8.145",
"kujira.js": "0.9.6",
"level": "^8.0.0",
"lodash": "^4.17.21",
"lru-cache": "^7.14.1",
Expand Down
4 changes: 3 additions & 1 deletion src/clob/clob.validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export const validateOrderId: Validator = mkValidator(
export const validateOrderType: Validator = mkValidator(
'orderType',
invalidOrderTypeError,
(val) => typeof val === 'string' && (val === 'LIMIT' || val === 'LIMIT_MAKER')
(val) =>
typeof val === 'string' &&
(val === 'LIMIT' || val === 'LIMIT_MAKER' || val === 'MARKET')
);

const NETWORK_VALIDATIONS = [validateConnector, validateChain, validateNetwork];
Expand Down
16 changes: 8 additions & 8 deletions src/connectors/kujira/kujira.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ import {
DirectSecp256k1HdWallet,
EncodeObject,
} from '@cosmjs/proto-signing';
import { HttpBatchClient, Tendermint34Client } from '@cosmjs/tendermint-rpc';
import { HttpBatchClient, Tendermint37Client } from '@cosmjs/tendermint-rpc';
import { StdFee } from '@cosmjs/amino';
import { IndexedTx } from '@cosmjs/stargate/build/stargateclient';
import { BigNumber } from 'bignumber.js';
Expand Down Expand Up @@ -245,7 +245,7 @@ export class KujiraModel {
*/
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
private tendermint34Client: Tendermint34Client;
private tendermint37Client: Tendermint37Client;

/**
*
Expand Down Expand Up @@ -385,7 +385,7 @@ export class KujiraModel {

this.kujiraGetHttpBatchClient(rpcEndpoint);

await this.kujiraGetTendermint34Client();
await this.kujiraGetTendermint37Client();

this.kujiraGetKujiraQueryClient();

Expand All @@ -411,12 +411,12 @@ export class KujiraModel {

private kujiraGetKujiraQueryClient() {
this.kujiraQueryClient = kujiraQueryClient({
client: this.tendermint34Client,
client: this.tendermint37Client,
});
}

private async kujiraGetTendermint34Client() {
this.tendermint34Client = await Tendermint34Client.create(
private async kujiraGetTendermint37Client() {
this.tendermint37Client = await Tendermint37Client.create(
this.httpBatchClient
);
}
Expand Down Expand Up @@ -1960,8 +1960,8 @@ export class KujiraModel {
return JSON.parse(decryptedString);
}

async toClient(endpoint: string): Promise<[Tendermint34Client, string]> {
const client = await Tendermint34Client.create(
async toClient(endpoint: string): Promise<[Tendermint37Client, string]> {
const client = await Tendermint37Client.create(
new HttpBatchClient(endpoint, {
dispatchInterval: 100,
batchSizeLimit: 200,
Expand Down
4 changes: 2 additions & 2 deletions test-bronze/connectors/kujira/fixtures/patches/data.ts

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions test-bronze/connectors/kujira/fixtures/patches/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ export const createPatches = (
);

patches.setIn(
['kujira', 'kujiraGetTendermint34Client'],
['kujira', 'kujiraGetTendermint37Client'],
async (testTitle: string) => {
if (!usePatches) return;

patch(kujira, 'kujiraGetTendermint34Client', async (...any: any[]) => {
patch(kujira, 'kujiraGetTendermint37Client', async (...any: any[]) => {
const inputArguments = any;

if (!ordinalMap.has(testTitle)) {
Expand All @@ -191,7 +191,7 @@ export const createPatches = (

const dataKey = [
'kujira',
'kujiraGetTendermint34Client',
'kujiraGetTendermint37Client',
testTitle,
ordinal,
];
Expand All @@ -202,7 +202,7 @@ export const createPatches = (
return await inputOutputWrapper<any>(
dataKey,
kujira,
'kujiraGetTendermint34Client',
'kujiraGetTendermint37Client',
inputArguments
);
}
Expand Down
99 changes: 98 additions & 1 deletion test-bronze/connectors/kujira/kujira.controllers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
Market,
MarketId,
MarketName,
MarketNotFoundError,
MarketsWithdrawsFundsResponse,
MarketsWithdrawsRequest,
MarketWithdrawRequest,
Expand Down Expand Up @@ -290,7 +291,7 @@ beforeAll(async () => {
// await getPatch(['global', 'fetch'])('beforeAll');
await getPatch(['kujira', 'getFastestRpc'])('beforeAll');
await getPatch(['kujira', 'kujiraGetHttpBatchClient'])('beforeAll');
await getPatch(['kujira', 'kujiraGetTendermint34Client'])('beforeAll');
await getPatch(['kujira', 'kujiraGetTendermint37Client'])('beforeAll');
await getPatch(['kujira', 'kujiraGetKujiraQueryClient'])('beforeAll');
await getPatch(['kujira', 'kujiraGetStargateClient'])('beforeAll');
await getPatch(['kujira', 'kujiraGetBasicMarkets'])('beforeAll');
Expand Down Expand Up @@ -4819,4 +4820,100 @@ describe('Kujira', () => {
}
});
});

describe('Exceptions', () => {
it.skip('Generate TokenNotFound Exception (token)', async () => {
const requestBody = {
name: 'KUJ',
} as GetTokenRequest;

const request = {
...commonRequestBody,
...requestBody,
};

logRequest(request);

try {
sendRequest<GetTokenResponse>({
RESTMethod: RESTfulMethod.GET,
RESTRoute: '/token',
RESTRequest: request,
controllerFunction: KujiraController.getToken,
});
} catch (e) {
expect(true).toBeTrue();
}
});

it.skip('Generate MarketNotFoundError Exception', async () => {
const requestBody = {
ownerAddress: ownerAddress,
} as MarketsWithdrawsRequest;

const request = {
...commonRequestBody,
...requestBody,
};

logRequest(request);
try {
await sendRequest<MarketsWithdrawsFundsResponse>({
RESTMethod: RESTfulMethod.POST,
RESTRoute: '/market/withdraws',
RESTRequest: request,
controllerFunction: KujiraController.withdrawFromMarkets,
});
} catch (e) {
expect(e).toEqual(new MarketNotFoundError('No market informed.'));
}
});

it.skip('Generate TokenNotFoundError Exception (tokens)', async () => {
const requestBody = {
names: ['KUJ', tokensIds[3]],
} as GetTokensRequest;

const request = {
...commonRequestBody,
...requestBody,
};

logRequest(request);
try {
await sendRequest<GetTokensResponse>({
RESTMethod: RESTfulMethod.GET,
RESTRoute: '/tokens',
RESTRequest: request,
controllerFunction: KujiraController.getTokens,
});
} catch (exception) {
expect(true).toBeTrue();
}
});

it('Generate Exception in getMarket', async () => {
const requestBody = {
name: 'KUJX/USK',
} as GetMarketRequest;

const request = {
...commonRequestBody,
...requestBody,
};

logRequest(request);

try {
await sendRequest<GetMarketResponse>({
RESTMethod: RESTfulMethod.GET,
RESTRoute: '/market',
RESTRequest: request,
controllerFunction: KujiraController.getMarket,
});
} catch (exception) {
expect(true).toBeTrue();
}
});
});
});
Loading
Loading