Skip to content

Commit

Permalink
feat: support Panic & custom contract errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Feb 8, 2023
1 parent b6186bb commit c01964a
Show file tree
Hide file tree
Showing 30 changed files with 1,432 additions and 628 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ bench
.env.production.local
.envrc

# @wagmi/cli
generated.ts

actions/**
chains/**
clients/**
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "contracts/lib/forge-std"]
path = contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
2 changes: 2 additions & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cache/
out/
2 changes: 2 additions & 0 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[profile.ci.fuzz]
runs = 10_000
1 change: 1 addition & 0 deletions contracts/lib/forge-std
Submodule forge-std added at 662ae0
50 changes: 50 additions & 0 deletions contracts/src/ErrorsExample.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.13;

contract ErrorsExample {
struct Foo {
address sender;
uint256 bar;
}

error SimpleError(string message);
error ComplexError(Foo foo, string message, uint256 number);

function revertExample() public pure {
revert("This is a revert message");
}

function assertExample() public pure {
assert(false);
}

function overflowExample() public pure returns (uint256) {
uint256 a = 2**256 - 1;
uint256 b = 1;
uint256 c = a + b;
return c;
}

function divideByZeroExample() public pure returns (uint256) {
uint256 a = 69;
uint256 b = 0;
uint256 c = a / b;
return c;
}

function requireExample() public pure {
require(false);
}

function simpleCustomError() public pure {
revert SimpleError("bugger");
}

function complexCustomError() public pure {
revert ComplexError(
Foo({sender: 0x0000000000000000000000000000000000000000, bar: 69}),
"bugger",
69
);
}
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"changeset": "changeset",
"changeset:release": "pnpm build && changeset publish",
"changeset:version": "changeset version && pnpm install --lockfile-only",
"contracts:build": "wagmi generate",
"dev": "DEV=true tsup",
"dev:docs": "pnpm -r --filter site dev",
"format": "rome format src/ test/ --write",
Expand All @@ -18,12 +19,12 @@
"playground": "pnpm --filter playground-dev dev",
"playground:benchmark": "pnpm --filter playground-benchmark dev",
"postinstall": "pnpm dev",
"preinstall": "npx only-allow pnpm",
"preinstall": "npx only-allow pnpm && pnpm contracts:build",
"prepublishOnly": "pnpm ts-node scripts/generate-package-json.ts",
"prepare": "npx simple-git-hooks",
"test": "vitest dev --no-threads",
"test:ci": "CI=true vitest --coverage --no-threads",
"test:ui": "vitest dev --ui --no-threads",
"test": "pnpm contracts:build && vitest dev --no-threads",
"test:ci": "pnpm contracts:build && CI=true vitest --coverage --no-threads",
"test:ui": "pnpm contracts:build && vitest dev --ui --no-threads",
"ts-node": "node --loader esbuild-register/loader -r esbuild-register",
"typecheck": "tsc --noEmit"
},
Expand Down Expand Up @@ -107,6 +108,7 @@
"@types/node": "^17.0.45",
"@vitest/coverage-c8": "^0.24.3",
"@vitest/ui": "^0.19.1",
"@wagmi/cli": "^0.1.5",
"bundlewatch": "^0.3.3",
"dedent": "^0.7.0",
"esbuild": "^0.16.12",
Expand Down
Loading

0 comments on commit c01964a

Please sign in to comment.