-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert error should not be retried (#254)
- Loading branch information
Showing
4 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { errorCodes } from '@metamask/rpc-errors'; | ||
|
||
import { isExecutionRevertedError } from './error'; | ||
|
||
const executionRevertedError = { | ||
code: errorCodes.rpc.invalidInput, | ||
message: 'execution reverted', | ||
}; | ||
|
||
describe('isExecutionRevertedError', () => { | ||
it('return false if object is not valid JSON RPC error', async () => { | ||
const result = isExecutionRevertedError({ test: 'dummy' }); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('return false if error code is not same as errorCodes.rpc.invalidInput', async () => { | ||
const result = isExecutionRevertedError({ | ||
...executionRevertedError, | ||
code: 123, | ||
}); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('return false if error message is not "execution reverted"', async () => { | ||
const result = isExecutionRevertedError({ | ||
...executionRevertedError, | ||
message: 'test', | ||
}); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('return true for correct executionRevertedError', async () => { | ||
const result = isExecutionRevertedError(executionRevertedError); | ||
expect(result).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { errorCodes } from '@metamask/rpc-errors'; | ||
import { isJsonRpcError } from '@metamask/utils'; | ||
import type { JsonRpcError } from '@metamask/utils'; | ||
|
||
export function isExecutionRevertedError( | ||
error: unknown, | ||
): error is JsonRpcError { | ||
return ( | ||
isJsonRpcError(error) && | ||
error.code === errorCodes.rpc.invalidInput && | ||
error.message === 'execution reverted' | ||
); | ||
} |