From 3aeb8c546aaa177955d2e3d2ac6205ba697d9c4f Mon Sep 17 00:00:00 2001 From: Den Date: Sun, 21 Jan 2024 15:07:15 +0200 Subject: [PATCH] test: fix rpc-errors test suites --- packages/utils/test/rpc-errors.test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/utils/test/rpc-errors.test.js b/packages/utils/test/rpc-errors.test.js index 2039324529..5a62d79b6c 100644 --- a/packages/utils/test/rpc-errors.test.js +++ b/packages/utils/test/rpc-errors.test.js @@ -52,9 +52,8 @@ describe('rpc-errors', () => { } }; let error = parseRpcError(rpc_error); - expect(error.type === 'InvalidIteratorIndex').toBe(true); - expect(error.iterator_index).toBe(42); - expect(formatError(error.type, error)).toBe('Iterator index 42 does not exist'); + expect(error.type).toBe('ActionError'); + expect(error.message).toBe('{"kind":{"FunctionCallError":{"HostError":{"InvalidIteratorIndex":{"iterator_index":42}}}}}'); }); test('test ActionError::FunctionCallError::GasLimitExceeded error', async () => { @@ -69,28 +68,29 @@ describe('rpc-errors', () => { } }; let error = parseRpcError(rpc_error); - expect(error.type === 'GasLimitExceeded').toBe(true); - - expect(formatError(error.type, error)).toBe('Exceeded the maximum amount of gas allowed to burn per contract'); + expect(error.type).toBe('ActionError'); + expect(error.message).toBe('{"index":0,"kind":{"index":0,"kind":{"FunctionCallError":{"HostError":"GasLimitExceeded"}}}}'); }); test('test parse error object', async () => { const errorStr = '{"status":{"Failure":{"ActionError":{"index":0,"kind":{"FunctionCallError":{"EvmError":"ArgumentParseError"}}}}},"transaction":{"signer_id":"test.near","public_key":"ed25519:D5HVgBE8KgXkSirDE4UQ8qwieaLAR4wDDEgrPRtbbNep","nonce":110,"receiver_id":"evm","actions":[{"FunctionCall":{"method_name":"transfer","args":"888ZO7SvECKvfSCJ832LrnFXuF/QKrSGztwAAA==","gas":300000000000000,"deposit":"0"}}],"signature":"ed25519:7JtWQ2Ux63ixaKy7bTDJuRTWnv6XtgE84ejFMMjYGKdv2mLqPiCfkMqbAPt5xwLWwFdKjJniTcxWZe7FdiRWpWv","hash":"E1QorKKEh1WLJwRQSQ1pdzQN3f8yeFsQQ8CbJjnz1ZQe"},"transaction_outcome":{"proof":[],"block_hash":"HXXBPjGp65KaFtam7Xr67B8pZVGujZMZvTmVW6Fy9tXf","id":"E1QorKKEh1WLJwRQSQ1pdzQN3f8yeFsQQ8CbJjnz1ZQe","outcome":{"logs":[],"receipt_ids":["ZsKetkrZQGVTtmXr2jALgNjzcRqpoQQsk9HdLmFafeL"],"gas_burnt":2428001493624,"tokens_burnt":"2428001493624000000000","executor_id":"test.near","status":{"SuccessReceiptId":"ZsKetkrZQGVTtmXr2jALgNjzcRqpoQQsk9HdLmFafeL"}}},"receipts_outcome":[{"proof":[],"block_hash":"H6fQCVpxBDv9y2QtmTVHoxHibJvamVsHau7fDi7AmFa2","id":"ZsKetkrZQGVTtmXr2jALgNjzcRqpoQQsk9HdLmFafeL","outcome":{"logs":[],"receipt_ids":["DgRyf1Wv3ZYLFvM8b67k2yZjdmnyUUJtRkTxAwoFi3qD"],"gas_burnt":2428001493624,"tokens_burnt":"2428001493624000000000","executor_id":"evm","status":{"Failure":{"ActionError":{"index":0,"kind":{"FunctionCallError":{"EvmError":"ArgumentParseError"}}}}}}},{"proof":[],"block_hash":"9qNVA235L9XdZ8rZLBAPRNBbiGPyNnMUfpbi9WxbRdbB","id":"DgRyf1Wv3ZYLFvM8b67k2yZjdmnyUUJtRkTxAwoFi3qD","outcome":{"logs":[],"receipt_ids":[],"gas_burnt":0,"tokens_burnt":"0","executor_id":"test.near","status":{"SuccessValue":""}}}]}'; const error = parseRpcError(JSON.parse(errorStr).status.Failure); - expect(error).toEqual(new ServerError('{"index":0,"kind":{"EvmError":"ArgumentParseError"}}')); + expect(error).toEqual(new ServerError('{"index":0,"kind":{"index":0,"kind":{"FunctionCallError":{"EvmError":"ArgumentParseError"}}}}')); }); test('test getErrorTypeFromErrorMessage', () => { const err1 = 'account random.near does not exist while viewing'; const err2 = 'Account random2.testnet doesn\'t exist'; const err3 = 'access key ed25519:DvXowCpBHKdbD2qutgfhG6jvBMaXyUh7DxrDSjkLxMHp does not exist while viewing'; - const err4 = 'wasm execution failed with error: FunctionCallError(CompilationError(CodeDoesNotExist { account_id: "random.testnet" }))'; + const err4 = 'wasm execution failed with error: CompilationError(CodeDoesNotExist { account_id: "random.testnet" })'; const err5 = '[-32000] Server error: Invalid transaction: Transaction nonce 1 must be larger than nonce of the used access key 1'; + const err6 = 'wasm execution failed with error: MethodResolveError(MethodNotFound)'; expect(getErrorTypeFromErrorMessage(err1)).toEqual('AccountDoesNotExist'); expect(getErrorTypeFromErrorMessage(err2)).toEqual('AccountDoesNotExist'); expect(getErrorTypeFromErrorMessage(err3)).toEqual('AccessKeyDoesNotExist'); expect(getErrorTypeFromErrorMessage(err4)).toEqual('CodeDoesNotExist'); expect(getErrorTypeFromErrorMessage(err5)).toEqual('InvalidNonce'); + expect(getErrorTypeFromErrorMessage(err6)).toEqual('MethodNotFound'); }); test('test NotEnoughBalance message uses human readable values', () => {