Skip to content

Commit 034f682

Browse files
committed
Add viem predicates examples to the readme
1 parent 9f89015 commit 034f682

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

.changeset/kind-bags-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nomicfoundation/hardhat-viem-assertions": patch
3+
---
4+
5+
Add viem predicates examples to the readme

v-next/hardhat-viem-assertions/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@ await viem.assertions.revertWithCustomErrorWithArgs(
106106
);
107107
```
108108

109+
This assertion can take predicate functions to match some of the arguments:
110+
111+
```ts
112+
await viem.assertions.revertWithCustomErrorWithArgs(
113+
contract.read.revertWithCustomErrorWithUintAndString([1n, "test"]),
114+
contract,
115+
"CustomErrorWithUintAndString",
116+
[(arg: bigint) => arg === 1n, "test"],
117+
);
118+
119+
import { anyValue } from "@nomicfoundation/hardhat-toolbox-viem/predicates";
120+
121+
await viem.assertions.revertWithCustomErrorWithArgs(
122+
contract.read.revertWithCustomErrorWithUintAndString([1n, "test"]),
123+
contract,
124+
"CustomErrorWithUintAndString",
125+
[1n, anyValue],
126+
);
127+
```
128+
109129
### Events
110130

111131
#### `.emit`
@@ -133,6 +153,26 @@ await viem.assertions.emitWithArgs(
133153
);
134154
```
135155

156+
This assertion can take predicate functions to match some of the arguments:
157+
158+
```ts
159+
await viem.assertions.emitWithArgs(
160+
contract.write.emitTwoUints([1n, 2n]),
161+
contract,
162+
"WithTwoUintArgs",
163+
[1n, (arg: bigint) => arg >= 2],
164+
);
165+
166+
import { anyValue } from "@nomicfoundation/hardhat-toolbox-viem/predicates";
167+
168+
await viem.assertions.emitWithArgs(
169+
contract.write.emitTwoUints([1n, 2n]),
170+
contract,
171+
"WithTwoUintArgs",
172+
[anyValue, 2n],
173+
);
174+
```
175+
136176
### Balance change
137177

138178
These assertions can be used to check how a given transaction affects the ether balance of a specific address.

0 commit comments

Comments
 (0)