Skip to content

Commit

Permalink
feat: fo-516: update negative tests to match with what polkadot uses …
Browse files Browse the repository at this point in the history
…for json responses (#79)
  • Loading branch information
okovalov authored Nov 2, 2021
1 parent 119f276 commit 37676eb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 69 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"test:emv:integration:rpc:negative:devnet": "RPC_ENV_NAME=dev yarn test:emv:integration:rpc:negative",
"test:emv:integration:rpc:negative:mocknet": "RPC_ENV_NAME=mocknet yarn test:emv:integration:rpc:negative",
"test:emv:integration:rpc:negative:rinkeby": "RPC_ENV_NAME=rinkeby yarn test:emv:integration:rpc:negative",
"test:emv:integration:rpc:negative:moonbeam": "RPC_ENV_NAME=moonbeam yarn test:emv:integration:rpc:negative",
"test:emv:integration:rpc:no_tx": "jest --detectOpenHandles --watch -t 'rpc test' rpc.integration.no_tx.spec.ts ",
"test:emv:integration:rpc:no_tx:local": "RPC_ENV_NAME=local yarn test:emv:integration:rpc:no_tx",
"test:emv:integration:rpc:no_tx:devnet": "RPC_ENV_NAME=dev yarn test:emv:integration:rpc:no_tx",
Expand Down
127 changes: 58 additions & 69 deletions src/evm/rpc.integration.negative.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const extendedExecutionTimeout = 20000;

const { rpcUrl = 'http://127.0.0.1:8545' } = rpcParams;

//Rinkeby compatible
//moonbeam (polkadot) compatible
const ERROR_INVALID_REQUEST = -32600;
const ERROR_METHOD_NOT_FOUND = -32601;
const ERROR_INVALID_PARAMS = -32602;
Expand All @@ -24,12 +24,7 @@ const assertResultResponse = (result: NetworkTypes.NetworkAxiosDataResult) => {
expect(result).not.toHaveProperty('error');
};

const assertResultError = (result: NetworkTypes.NetworkAxiosDataResult) => {
expect(result).not.toHaveProperty('response');
expect(result).toHaveProperty('error');
};

describe('Api Endpoint (rpc test negative)', () => {
describe(`Api Endpoint (rpc test negative) for "${rpcUrl}"`, () => {
const msgId = 2;

const payload = {
Expand Down Expand Up @@ -101,11 +96,11 @@ describe('Api Endpoint (rpc test negative)', () => {
params: 'foo',
});

assertResultError(result);
assertResultResponse(result);

const { error } = result;
const code = result?.response?.error?.code;

expect(error?.message).toEqual('Request failed with status code 400');
expect(code).toEqual(ERROR_INVALID_REQUEST);
},
extendedExecutionTimeout,
);
Expand Down Expand Up @@ -146,11 +141,11 @@ describe('Api Endpoint (rpc test negative)', () => {
params: [...extraParams, '0x0'],
});

assertResultError(result);
assertResultResponse(result);

const message = result?.error?.message;
const code = result?.response?.error?.code;

expect(message).toEqual('Request failed with status code 403');
expect(code).toEqual(ERROR_INVALID_PARAMS);
},
extendedExecutionTimeout,
);
Expand All @@ -165,11 +160,11 @@ describe('Api Endpoint (rpc test negative)', () => {
params: extraParams,
});

assertResultError(result);
assertResultResponse(result);

const message = result?.error?.message;
const code = result?.response?.error?.code;

expect(message).toEqual('Request failed with status code 400');
expect(code).toEqual(ERROR_INVALID_REQUEST);
},
extendedExecutionTimeout,
);
Expand Down Expand Up @@ -261,11 +256,11 @@ describe('Api Endpoint (rpc test negative)', () => {
params: 'aaaa',
});

assertResultError(result);
assertResultResponse(result);

const message = result?.error?.message;
const code = result?.response?.error?.code;

expect(message).toEqual('Request failed with status code 400');
expect(code).toEqual(ERROR_INVALID_REQUEST);
},
extendedExecutionTimeout,
);
Expand Down Expand Up @@ -332,11 +327,11 @@ describe('Api Endpoint (rpc test negative)', () => {
params: 'aaa',
});

assertResultError(result);
assertResultResponse(result);

const message = result?.error?.message;
const code = result?.response?.error?.code;

expect(message).toEqual('Request failed with status code 400');
expect(code).toEqual(ERROR_INVALID_REQUEST);
},
extendedExecutionTimeout,
);
Expand Down Expand Up @@ -369,11 +364,11 @@ describe('Api Endpoint (rpc test negative)', () => {
{ ...payload, method: 'eth_getBlockTransactionCountByHash', params: 'aaa' },
);

assertResultError(result);
assertResultResponse(result);

const message = result?.error?.message;
const code = result?.response?.error?.code;

expect(message).toEqual('Request failed with status code 400');
expect(code).toEqual(ERROR_INVALID_REQUEST);
},
extendedExecutionTimeout,
);
Expand Down Expand Up @@ -433,11 +428,11 @@ describe('Api Endpoint (rpc test negative)', () => {
},
);

assertResultError(result);
assertResultResponse(result);

const message = result?.error?.message;
const code = result?.response?.error?.code;

expect(message).toEqual('Request failed with status code 400');
expect(code).toEqual(ERROR_INVALID_REQUEST);
},
extendedExecutionTimeout,
);
Expand Down Expand Up @@ -488,11 +483,11 @@ describe('Api Endpoint (rpc test negative)', () => {
params: 'aaaa',
});

assertResultError(result);
assertResultResponse(result);

const message = result?.error?.message;
const code = result?.response?.error?.code;

expect(message).toEqual('Request failed with status code 400');
expect(code).toEqual(ERROR_INVALID_REQUEST);
},
extendedExecutionTimeout,
);
Expand Down Expand Up @@ -543,11 +538,11 @@ describe('Api Endpoint (rpc test negative)', () => {
params: 'aaaa',
});

assertResultError(result);
assertResultResponse(result);

const message = result?.error?.message;
const code = result?.response?.error?.code;

expect(message).toEqual('Request failed with status code 400');
expect(code).toEqual(ERROR_INVALID_REQUEST);
},
extendedExecutionTimeout,
);
Expand Down Expand Up @@ -598,11 +593,11 @@ describe('Api Endpoint (rpc test negative)', () => {
params: 'aaaa',
});

assertResultError(result);
assertResultResponse(result);

const message = result?.error?.message;
const code = result?.response?.error?.code;

expect(message).toEqual('Request failed with status code 400');
expect(code).toEqual(ERROR_INVALID_REQUEST);
},
extendedExecutionTimeout,
);
Expand Down Expand Up @@ -653,11 +648,11 @@ describe('Api Endpoint (rpc test negative)', () => {
params: 'aaaa',
});

assertResultError(result);
assertResultResponse(result);

const message = result?.error?.message;
const code = result?.response?.error?.code;

expect(message).toEqual('Request failed with status code 400');
expect(code).toEqual(ERROR_INVALID_REQUEST);
},
extendedExecutionTimeout,
);
Expand Down Expand Up @@ -717,11 +712,11 @@ describe('Api Endpoint (rpc test negative)', () => {
},
);

assertResultError(result);
assertResultResponse(result);

const message = result?.error?.message;
const code = result?.response?.error?.code;

expect(message).toEqual('Request failed with status code 400');
expect(code).toEqual(ERROR_INVALID_REQUEST);
},
extendedExecutionTimeout,
);
Expand All @@ -733,14 +728,12 @@ describe('Api Endpoint (rpc test negative)', () => {
async () => {
const extraParams = ['aaa'];

const result = await Network.sendRpcCall<NetworkTypes.EthGetTransactionByBlockNumberAndIndexRpcResult>(
rpcUrl,
{
const result =
await Network.sendRpcCall<NetworkTypes.EthGetTransactionByBlockNumberAndIndexRpcResult>(rpcUrl, {
...payload,
method: 'eth_getTransactionByBlockNumberAndIndex',
params: extraParams,
},
);
});

assertResultResponse(result);

Expand All @@ -753,13 +746,11 @@ describe('Api Endpoint (rpc test negative)', () => {
it(
'Returns a proper error code for a missing payload',
async () => {
const result = await Network.sendRpcCall<NetworkTypes.EthGetTransactionByBlockNumberAndIndexRpcResult>(
rpcUrl,
{
const result =
await Network.sendRpcCall<NetworkTypes.EthGetTransactionByBlockNumberAndIndexRpcResult>(rpcUrl, {
...payload,
method: 'eth_getTransactionByBlockNumberAndIndex',
},
);
});

assertResultResponse(result);

Expand All @@ -772,20 +763,18 @@ describe('Api Endpoint (rpc test negative)', () => {
it(
'Returns an error when payload format is incorrect',
async () => {
const result = await Network.sendRpcCall<NetworkTypes.EthGetTransactionByBlockNumberAndIndexRpcResult>(
rpcUrl,
{
const result =
await Network.sendRpcCall<NetworkTypes.EthGetTransactionByBlockNumberAndIndexRpcResult>(rpcUrl, {
...payload,
method: 'eth_getTransactionByBlockNumberAndIndex',
params: 'aaaa',
},
);
});

assertResultError(result);
assertResultResponse(result);

const message = result?.error?.message;
const code = result?.response?.error?.code;

expect(message).toEqual('Request failed with status code 400');
expect(code).toEqual(ERROR_INVALID_REQUEST);
},
extendedExecutionTimeout,
);
Expand Down Expand Up @@ -836,11 +825,11 @@ describe('Api Endpoint (rpc test negative)', () => {
params: 'aaaa',
});

assertResultError(result);
assertResultResponse(result);

const message = result?.error?.message;
const code = result?.response?.error?.code;

expect(message).toEqual('Request failed with status code 400');
expect(code).toEqual(ERROR_INVALID_REQUEST);
},
extendedExecutionTimeout,
);
Expand All @@ -862,7 +851,7 @@ describe('Api Endpoint (rpc test negative)', () => {

const code = result?.response?.error?.code;

expect(code).toEqual(ERROR_INVALID_REQUEST);
expect(code).toEqual(ERROR_INVALID_PARAMS);
},
extendedExecutionTimeout,
);
Expand All @@ -885,7 +874,7 @@ describe('Api Endpoint (rpc test negative)', () => {

const code = result?.response?.error?.code;

expect(code).toEqual(ERROR_INVALID_REQUEST);
expect(code).toEqual(ERROR_INVALID_PARAMS);
},
extendedExecutionTimeout,
);
Expand All @@ -898,11 +887,11 @@ describe('Api Endpoint (rpc test negative)', () => {
params: 'aaaa',
});

assertResultError(result);
assertResultResponse(result);

const message = result?.error?.message;
const code = result?.response?.error?.code;

expect(message).toEqual('Request failed with status code 400');
expect(code).toEqual(ERROR_INVALID_REQUEST);
},
extendedExecutionTimeout,
);
Expand Down

0 comments on commit 37676eb

Please sign in to comment.