-
-
Notifications
You must be signed in to change notification settings - Fork 821
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
feat: support Panic
& custom contract errors
#57
Conversation
🦋 Changeset detectedLatest commit: bf0ee4d The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Socket Security Pull Request ReportDependency issues detected. If you merge this pull request, you will not be alerted to the instances of these issues again. 📜 Install scriptsInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts. Packages should not be running non-essential scripts during install and there are often solutions to problems people solve with install scripts that can be run at publish time instead.
Pull request report summary
Bot CommandsTo ignore an alert, reply with a comment starting with
Powered by socket.dev |
c01964a
to
810230a
Compare
@@ -0,0 +1,50 @@ | |||
// SPDX-License-Identifier: Unlicense |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This contract is to test contract errors.
}) | ||
} | ||
|
||
export async function deployErrorExample() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can deploy the bytecode generated from @wagmi/cli
to use in our tests.
const abiItem = getAbiItem({ abi, args, name: functionName }) | ||
const formattedArgs = abiItem | ||
? formatAbiItemWithArgs({ | ||
abiItem, | ||
args, | ||
includeFunctionName: false, | ||
includeName: false, | ||
}) | ||
: undefined | ||
const functionWithParams = abiItem | ||
? formatAbiItem(abiItem, { includeName: true }) | ||
: undefined | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just moved this logic into ContractFunctionRevertedError
.
const { abiItem, errorName, args: errorArgs } = decodedData | ||
if (errorName === 'Error') { | ||
reason = (errorArgs as [string])[0] | ||
} else if (errorName === 'Panic') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support Panic
& retrieve corresponding reason.
} else if (errorName === 'Panic') { | ||
const [firstArg] = errorArgs as [number] | ||
reason = panicReasons[firstArg as keyof typeof panicReasons] | ||
} else if (errorArgs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support custom errors.
@@ -156,6 +152,159 @@ describe('bayc', () => { | |||
}) | |||
}) | |||
|
|||
describe('contract errors', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E2E examples of contract errors can be seen here!
1a10d19
to
c1f2734
Compare
@@ -0,0 +1,52 @@ | |||
name: 'Setup' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel like we use these steps in a lot of actions. Might make sense to create a composite action for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea
.github/workflows/release.yml
Outdated
run: pnpm i | ||
env: | ||
SKIP_WAGMI_CLI: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we do pnpm i --ignore-scripts
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea lol
src/constants/index.test.ts
Outdated
"panicReasons": { | ||
"1": "An \`assert\` condition failed.", | ||
"17": "Arithmic operation resulted in underflow or overflow.", | ||
"18": "Division or modulo by zero (e.g. \`5 / 0\` or \`23 % 0\`).", | ||
"33": "Attempted to convert to an invalid type.", | ||
"34": "Attempted to access a storage byte array that is incorrectly encoded.", | ||
"49": "Performed \`.pop()\` on an empty array", | ||
"50": "Array index is out of bounds.", | ||
"65": "Allocated too much memory or created an array which is too large.", | ||
"81": "Attempted to call a zero-initialized variable of internal function type.", | ||
}, | ||
"solidityError": { | ||
"inputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "message", | ||
"type": "string", | ||
}, | ||
], | ||
"name": "Error", | ||
"type": "error", | ||
}, | ||
"solidityPanic": { | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "reason", | ||
"type": "uint256", | ||
}, | ||
], | ||
"name": "Panic", | ||
"type": "error", | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some duplication here from other tests. in my mind, index.test.ts
tests are for locking down exports. could switch to expect(Object.keys(exports)).toMatchInlineSnapshot()
instead.
import { AbiError } from 'abitype' | ||
|
||
// https://docs.soliditylang.org/en/v0.8.16/control-structures.html#panic-via-assert-and-error-via-require | ||
export const panicReasons = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥🔥🔥
src/constants/solidity.ts
Outdated
export const solidityPanic: AbiError = { | ||
inputs: [ | ||
{ | ||
internalType: 'uint256', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could drop internalType
from here (and other ABIs that are around in the codebase).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool use of cli
01e3fe5
to
a3f9f6a
Compare
Panic
& custom contract errors thrown from contracts@wagmi/cli
so we can build contract bytecode, generate abis, and then deploy them in tests