Skip to content

Commit

Permalink
Merge pull request #276 from oasisprotocol/CedarMist/ethersv6-tests
Browse files Browse the repository at this point in the history
examples: added require() reversion message check to ethers v6 client
  • Loading branch information
CedarMist authored Feb 19, 2024
2 parents 94dd75b + e3f7086 commit b932662
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/ethersv6-ts-esm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ async function testTheContract(contract:BaseContract, signerAddr?:string)
assert( addr === ZeroAddress );
}

// Verifies that calling a function which does require(false,"ThisIsAnError")
// Will return the correct error message in the exception to Ethers
try {
await contract.getFunction("testViewRevert()").staticCall();
assert(false);
}
catch(e:any) {
assert(e.code == 'CALL_EXCEPTION');
assert(e.reason == 'ThisIsAnError');
}

// Verifies that calling a function which does revert CustomError(someInteger)
// Will return the correctly encoded custom error type to Ethers
try {
await contract.getFunction("testCustomRevert()").staticCall();
assert(false);
Expand Down

0 comments on commit b932662

Please sign in to comment.