@@ -86,7 +86,7 @@ function shouldBehaveLikeNoncesKeyed() {
86
86
87
87
await expect ( this . mock . $_useNonce ( sender , ethers . Typed . uint192 ( 0n ) ) )
88
88
. to . emit ( this . mock , 'return$_useNonce_address_uint192' )
89
- . withArgs ( 1n ) ;
89
+ . withArgs ( keyOffset ( 0n ) + 1n ) ;
90
90
91
91
expect ( this . mock . nonces ( sender , ethers . Typed . uint192 ( 0n ) ) ) . to . eventually . equal ( keyOffset ( 0n ) + 2n ) ;
92
92
expect ( this . mock . nonces ( sender , ethers . Typed . uint192 ( 17n ) ) ) . to . eventually . equal ( keyOffset ( 17n ) + 0n ) ;
@@ -98,18 +98,18 @@ function shouldBehaveLikeNoncesKeyed() {
98
98
99
99
await expect ( this . mock . $_useNonce ( sender , ethers . Typed . uint192 ( 17n ) ) )
100
100
. to . emit ( this . mock , 'return$_useNonce_address_uint192' )
101
- . withArgs ( 0n ) ;
101
+ . withArgs ( keyOffset ( 17n ) + 0n ) ;
102
102
103
103
await expect ( this . mock . $_useNonce ( sender , ethers . Typed . uint192 ( 17n ) ) )
104
104
. to . emit ( this . mock , 'return$_useNonce_address_uint192' )
105
- . withArgs ( 1n ) ;
105
+ . withArgs ( keyOffset ( 17n ) + 1n ) ;
106
106
107
107
expect ( this . mock . nonces ( sender , ethers . Typed . uint192 ( 0n ) ) ) . to . eventually . equal ( keyOffset ( 0n ) + 0n ) ;
108
108
expect ( this . mock . nonces ( sender , ethers . Typed . uint192 ( 17n ) ) ) . to . eventually . equal ( keyOffset ( 17n ) + 2n ) ;
109
109
} ) ;
110
110
} ) ;
111
111
112
- describe ( '_useCheckedNonce' , function ( ) {
112
+ describe ( '_useCheckedNonce(address, uint256) ' , function ( ) {
113
113
it ( 'default variant uses key 0' , async function ( ) {
114
114
const currentNonce = await this . mock . nonces ( sender , ethers . Typed . uint192 ( 0n ) ) ;
115
115
@@ -135,12 +135,49 @@ function shouldBehaveLikeNoncesKeyed() {
135
135
// reuse same nonce
136
136
await expect ( this . mock . $_useCheckedNonce ( sender , currentNonce ) )
137
137
. to . be . revertedWithCustomError ( this . mock , 'InvalidAccountNonce' )
138
- . withArgs ( sender , 1 ) ;
138
+ . withArgs ( sender , currentNonce + 1n ) ;
139
139
140
140
// use "future" nonce too early
141
141
await expect ( this . mock . $_useCheckedNonce ( sender , currentNonce + 10n ) )
142
142
. to . be . revertedWithCustomError ( this . mock , 'InvalidAccountNonce' )
143
- . withArgs ( sender , 1 ) ;
143
+ . withArgs ( sender , currentNonce + 1n ) ;
144
+ } ) ;
145
+ } ) ;
146
+
147
+ describe ( '_useCheckedNonce(address, uint192, uint64)' , function ( ) {
148
+ const MASK = 0xffffffffffffffffn ;
149
+
150
+ it ( 'default variant uses key 0' , async function ( ) {
151
+ const currentNonce = await this . mock . nonces ( sender , ethers . Typed . uint192 ( 0n ) ) ;
152
+
153
+ await this . mock . $_useCheckedNonce ( sender , ethers . Typed . uint192 ( 0n ) , currentNonce ) ;
154
+
155
+ expect ( this . mock . nonces ( sender , ethers . Typed . uint192 ( 0n ) ) ) . to . eventually . equal ( currentNonce + 1n ) ;
156
+ } ) ;
157
+
158
+ it ( 'use nonce at another key' , async function ( ) {
159
+ const currentNonce = await this . mock . nonces ( sender , ethers . Typed . uint192 ( 17n ) ) ;
160
+
161
+ await this . mock . $_useCheckedNonce ( sender , ethers . Typed . uint192 ( 17n ) , currentNonce & MASK ) ;
162
+
163
+ expect ( this . mock . nonces ( sender , ethers . Typed . uint192 ( 17n ) ) ) . to . eventually . equal ( currentNonce + 1n ) ;
164
+ } ) ;
165
+
166
+ it ( 'reverts when nonce is not the expected' , async function ( ) {
167
+ const currentNonce = await this . mock . nonces ( sender , ethers . Typed . uint192 ( 42n ) ) ;
168
+
169
+ // use and increment
170
+ await this . mock . $_useCheckedNonce ( sender , ethers . Typed . uint192 ( 42n ) , currentNonce & MASK ) ;
171
+
172
+ // reuse same nonce
173
+ await expect ( this . mock . $_useCheckedNonce ( sender , ethers . Typed . uint192 ( 42n ) , currentNonce & MASK ) )
174
+ . to . be . revertedWithCustomError ( this . mock , 'InvalidAccountNonce' )
175
+ . withArgs ( sender , currentNonce + 1n ) ;
176
+
177
+ // use "future" nonce too early
178
+ await expect ( this . mock . $_useCheckedNonce ( sender , ethers . Typed . uint192 ( 42n ) , ( currentNonce & MASK ) + 10n ) )
179
+ . to . be . revertedWithCustomError ( this . mock , 'InvalidAccountNonce' )
180
+ . withArgs ( sender , currentNonce + 1n ) ;
144
181
} ) ;
145
182
} ) ;
146
183
} ) ;
0 commit comments