Skip to content

Commit 1f39fa9

Browse files
authored
Merge pull request #7095 from NomicFoundation/viem-predicates-readme
Add viem predicates examples to the readme
2 parents 9f89015 + b5613c6 commit 1f39fa9

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,28 @@ 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+
120+
```ts
121+
import { anyValue } from "@nomicfoundation/hardhat-toolbox-viem/predicates";
122+
123+
await viem.assertions.revertWithCustomErrorWithArgs(
124+
contract.read.revertWithCustomErrorWithUintAndString([1n, "test"]),
125+
contract,
126+
"CustomErrorWithUintAndString",
127+
[1n, anyValue],
128+
);
129+
```
130+
109131
### Events
110132

111133
#### `.emit`
@@ -133,6 +155,28 @@ await viem.assertions.emitWithArgs(
133155
);
134156
```
135157

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

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

0 commit comments

Comments
 (0)