1
1
const { expect } = require ( 'chai' ) ;
2
- const { constants, expectRevert } = require ( '@openzeppelin/test-helpers' ) ;
2
+ const { constants } = require ( '@openzeppelin/test-helpers' ) ;
3
3
const { ZERO_ADDRESS } = constants ;
4
4
5
5
const RECEIVER_MAGIC_VALUE = '0x150b7a02' ;
@@ -10,7 +10,7 @@ describe('ERC721A', function () {
10
10
beforeEach ( async function ( ) {
11
11
this . ERC721A = await ethers . getContractFactory ( 'ERC721AMock' ) ;
12
12
this . ERC721Receiver = await ethers . getContractFactory ( 'ERC721ReceiverMock' ) ;
13
- this . erc721a = await this . ERC721A . deploy ( " Azuki" , " AZUKI" , 5 ) ;
13
+ this . erc721a = await this . ERC721A . deploy ( ' Azuki' , ' AZUKI' , 5 ) ;
14
14
await this . erc721a . deployed ( ) ;
15
15
} ) ;
16
16
@@ -36,7 +36,7 @@ describe('ERC721A', function () {
36
36
describe ( 'exists' , async function ( ) {
37
37
it ( 'verifies valid tokens' , async function ( ) {
38
38
for ( let tokenId = 0 ; tokenId < 6 ; tokenId ++ ) {
39
- let exists = await this . erc721a . exists ( tokenId ) ;
39
+ const exists = await this . erc721a . exists ( tokenId ) ;
40
40
expect ( exists ) . to . be . true ;
41
41
}
42
42
} ) ;
@@ -56,9 +56,9 @@ describe('ERC721A', function () {
56
56
} ) ;
57
57
58
58
it ( 'throws an exception for the 0 address' , async function ( ) {
59
- await expectRevert (
60
- this . erc721a . balanceOf ( ZERO_ADDRESS ) , 'ERC721A: balance query for the zero address' ,
61
- ) ;
59
+ await expect (
60
+ this . erc721a . balanceOf ( ZERO_ADDRESS )
61
+ ) . to . be . revertedWith ( 'ERC721A: balance query for the zero address' ) ;
62
62
} ) ;
63
63
} ) ;
64
64
@@ -79,9 +79,7 @@ describe('ERC721A', function () {
79
79
} ) ;
80
80
81
81
it ( 'reverts for an invalid token' , async function ( ) {
82
- await expectRevert (
83
- this . erc721a . ownerOf ( 10 ) , 'ERC721A: owner query for nonexistent token' ,
84
- ) ;
82
+ await expect ( this . erc721a . ownerOf ( 10 ) ) . to . be . revertedWith ( 'ERC721A: owner query for nonexistent token' ) ;
85
83
} ) ;
86
84
} ) ;
87
85
@@ -96,38 +94,35 @@ describe('ERC721A', function () {
96
94
} ) ;
97
95
98
96
it ( 'rejects an invalid token owner' , async function ( ) {
99
- await expectRevert (
100
- this . erc721a . connect ( this . addr1 ) . approve ( this . addr2 . address , tokenId2 ) , 'ERC721A: approval to current owner'
101
- ) ;
97
+ await expect (
98
+ this . erc721a . connect ( this . addr1 ) . approve ( this . addr2 . address , tokenId2 )
99
+ ) . to . be . revertedWith ( 'ERC721A: approval to current owner' ) ;
102
100
} ) ;
103
101
104
102
it ( 'rejects an unapproved caller' , async function ( ) {
105
- await expectRevert (
106
- this . erc721a . approve ( this . addr2 . address , tokenId ) , 'ERC721A: approve caller is not owner nor approved for all'
107
- ) ;
103
+ await expect (
104
+ this . erc721a . approve ( this . addr2 . address , tokenId )
105
+ ) . to . be . revertedWith ( 'ERC721A: approve caller is not owner nor approved for all' ) ;
108
106
} ) ;
109
107
110
108
it ( 'does not get approved for invalid tokens' , async function ( ) {
111
- await expectRevert (
112
- this . erc721a . getApproved ( 10 ) , 'ERC721A: approved query for nonexistent token'
113
- ) ;
109
+ await expect ( this . erc721a . getApproved ( 10 ) ) . to . be . revertedWith ( 'ERC721A: approved query for nonexistent token' ) ;
114
110
} ) ;
115
111
} ) ;
116
112
117
113
describe ( 'setApprovalForAll' , async function ( ) {
118
114
it ( 'sets approval for all properly' , async function ( ) {
119
115
const approvalTx = await this . erc721a . setApprovalForAll ( this . addr1 . address , true ) ;
120
116
await expect ( approvalTx )
121
- . to . emit ( this . erc721a , " ApprovalForAll" )
117
+ . to . emit ( this . erc721a , ' ApprovalForAll' )
122
118
. withArgs ( this . owner . address , this . addr1 . address , true ) ;
123
119
expect ( await this . erc721a . isApprovedForAll ( this . owner . address , this . addr1 . address ) ) . to . be . true ;
124
120
} ) ;
125
121
126
122
it ( 'sets rejects approvals for non msg senders' , async function ( ) {
127
- await expectRevert (
128
- this . erc721a . connect ( this . addr1 ) . setApprovalForAll ( this . addr1 . address , true ) ,
129
- 'ERC721A: approve to caller'
130
- ) ;
123
+ await expect (
124
+ this . erc721a . connect ( this . addr1 ) . setApprovalForAll ( this . addr1 . address , true )
125
+ ) . to . be . revertedWith ( 'ERC721A: approve to caller' ) ;
131
126
} ) ;
132
127
} ) ;
133
128
@@ -152,7 +147,7 @@ describe('ERC721A', function () {
152
147
153
148
it ( 'emits a Transfer event' , async function ( ) {
154
149
await expect ( this . transferTx )
155
- . to . emit ( this . erc721a , " Transfer" )
150
+ . to . emit ( this . erc721a , ' Transfer' )
156
151
. withArgs ( from , to , tokenId ) ;
157
152
} ) ;
158
153
@@ -162,7 +157,7 @@ describe('ERC721A', function () {
162
157
163
158
it ( 'emits an Approval event' , async function ( ) {
164
159
await expect ( this . transferTx )
165
- . to . emit ( this . erc721a , " Approval" )
160
+ . to . emit ( this . erc721a , ' Approval' )
166
161
. withArgs ( from , ZERO_ADDRESS , tokenId ) ;
167
162
} ) ;
168
163
@@ -180,30 +175,27 @@ describe('ERC721A', function () {
180
175
const tokenId = 1 ;
181
176
182
177
it ( 'rejects unapproved transfer' , async function ( ) {
183
- await expectRevert (
184
- this . erc721a . connect ( this . addr1 ) [ transferFn ] ( this . addr2 . address , this . addr1 . address , tokenId ) ,
185
- 'ERC721A: transfer caller is not owner nor approved' ,
186
- )
178
+ await expect (
179
+ this . erc721a . connect ( this . addr1 ) [ transferFn ] ( this . addr2 . address , this . addr1 . address , tokenId )
180
+ ) . to . be . revertedWith ( 'ERC721A: transfer caller is not owner nor approved' ) ;
187
181
} ) ;
188
182
189
183
it ( 'rejects transfer from incorrect owner' , async function ( ) {
190
184
await this . erc721a . connect ( this . addr2 ) . setApprovalForAll ( this . addr1 . address , true ) ;
191
- await expectRevert (
192
- this . erc721a . connect ( this . addr1 ) [ transferFn ] ( this . addr3 . address , this . addr1 . address , tokenId ) ,
193
- 'ERC721A: transfer from incorrect owner' ,
194
- )
185
+ await expect (
186
+ this . erc721a . connect ( this . addr1 ) [ transferFn ] ( this . addr3 . address , this . addr1 . address , tokenId )
187
+ ) . to . be . revertedWith ( 'ERC721A: transfer from incorrect owner' ) ;
195
188
} ) ;
196
189
197
190
it ( 'rejects transfer to zero address' , async function ( ) {
198
191
await this . erc721a . connect ( this . addr2 ) . setApprovalForAll ( this . addr1 . address , true ) ;
199
- await expectRevert (
200
- this . erc721a . connect ( this . addr1 ) [ transferFn ] ( this . addr2 . address , ZERO_ADDRESS , tokenId ) ,
201
- 'ERC721A: transfer to the zero address' ,
202
- )
192
+ await expect (
193
+ this . erc721a . connect ( this . addr1 ) [ transferFn ] ( this . addr2 . address , ZERO_ADDRESS , tokenId )
194
+ ) . to . be . revertedWith ( 'ERC721A: transfer to the zero address' ) ;
203
195
} ) ;
204
- }
196
+ } ;
205
197
206
- context ( " successful transfers" , function ( ) {
198
+ context ( ' successful transfers' , function ( ) {
207
199
describe ( 'transferFrom' , function ( ) {
208
200
testSuccessfulTransfer ( 'transferFrom' ) ;
209
201
} ) ;
@@ -213,13 +205,13 @@ describe('ERC721A', function () {
213
205
214
206
it ( 'validates ERC721Received' , async function ( ) {
215
207
await expect ( this . transferTx )
216
- . to . emit ( this . receiver , " Received" )
217
- . withArgs ( this . addr2 . address , this . addr2 . address , 1 , "0x" , GAS_MAGIC_VALUE ) ;
208
+ . to . emit ( this . receiver , ' Received' )
209
+ . withArgs ( this . addr2 . address , this . addr2 . address , 1 , '0x' , GAS_MAGIC_VALUE ) ;
218
210
} ) ;
219
211
} ) ;
220
212
} ) ;
221
213
222
- context ( " unsuccessful transfers" , function ( ) {
214
+ context ( ' unsuccessful transfers' , function ( ) {
223
215
describe ( 'transferFrom' , function ( ) {
224
216
testUnsuccessfulTransfer ( 'transferFrom' ) ;
225
217
} ) ;
@@ -240,42 +232,42 @@ describe('ERC721A', function () {
240
232
this . receiver = await this . ERC721Receiver . deploy ( RECEIVER_MAGIC_VALUE ) ;
241
233
} ) ;
242
234
243
- describe ( " safeMint" , function ( ) {
235
+ describe ( ' safeMint' , function ( ) {
244
236
it ( 'successfully mints a single token' , async function ( ) {
245
237
const mintTx = await this . erc721a [ 'safeMint(address,uint256)' ] ( this . receiver . address , 1 ) ;
246
238
await expect ( mintTx )
247
- . to . emit ( this . erc721a , " Transfer" )
239
+ . to . emit ( this . erc721a , ' Transfer' )
248
240
. withArgs ( ZERO_ADDRESS , this . receiver . address , 0 ) ;
249
241
await expect ( mintTx )
250
- . to . emit ( this . receiver , " Received" )
251
- . withArgs ( this . owner . address , ZERO_ADDRESS , 0 , "0x" , GAS_MAGIC_VALUE ) ;
242
+ . to . emit ( this . receiver , ' Received' )
243
+ . withArgs ( this . owner . address , ZERO_ADDRESS , 0 , '0x' , GAS_MAGIC_VALUE ) ;
252
244
expect ( await this . erc721a . ownerOf ( 0 ) ) . to . equal ( this . receiver . address ) ;
253
245
} ) ;
254
246
255
247
it ( 'successfully mints multiple tokens' , async function ( ) {
256
248
const mintTx = await this . erc721a [ 'safeMint(address,uint256)' ] ( this . receiver . address , 5 ) ;
257
249
for ( let tokenId = 0 ; tokenId < 5 ; tokenId ++ ) {
258
250
await expect ( mintTx )
259
- . to . emit ( this . erc721a , " Transfer" )
251
+ . to . emit ( this . erc721a , ' Transfer' )
260
252
. withArgs ( ZERO_ADDRESS , this . receiver . address , tokenId ) ;
261
253
await expect ( mintTx )
262
- . to . emit ( this . receiver , " Received" )
263
- . withArgs ( this . owner . address , ZERO_ADDRESS , 0 , "0x" , GAS_MAGIC_VALUE ) ;
254
+ . to . emit ( this . receiver , ' Received' )
255
+ . withArgs ( this . owner . address , ZERO_ADDRESS , 0 , '0x' , GAS_MAGIC_VALUE ) ;
264
256
expect ( await this . erc721a . ownerOf ( tokenId ) ) . to . equal ( this . receiver . address ) ;
265
257
}
266
258
} ) ;
267
259
268
260
it ( 'rejects mints to the zero address' , async function ( ) {
269
- await expectRevert (
270
- this . erc721a [ 'safeMint(address,uint256)' ] ( ZERO_ADDRESS , 1 ) , 'ERC721A: mint to the zero address'
271
- ) ;
261
+ await expect (
262
+ this . erc721a [ 'safeMint(address,uint256)' ] ( ZERO_ADDRESS , 1 )
263
+ ) . to . be . revertedWith ( 'ERC721A: mint to the zero address' ) ;
272
264
} ) ;
273
265
274
266
it ( 'rejects quantity > maxBatchSize' , async function ( ) {
275
- await expectRevert (
276
- this . erc721a [ 'safeMint(address,uint256)' ] ( this . receiver . address , 6 ) , 'ERC721A: quantity to mint too high'
277
- ) ;
267
+ await expect (
268
+ this . erc721a [ 'safeMint(address,uint256)' ] ( this . receiver . address , 6 )
269
+ ) . to . be . revertedWith ( 'ERC721A: quantity to mint too high' ) ;
278
270
} ) ;
279
271
} ) ;
280
272
} ) ;
281
- } ) ;
273
+ } ) ;
0 commit comments