Skip to content

Commit 0fd77d4

Browse files
authored
Remove test dependency on expectRevert (chiru-labs#14)
Fixed tests in GitHub actions
1 parent 34529dc commit 0fd77d4

File tree

4 files changed

+58
-59
lines changed

4 files changed

+58
-59
lines changed

.eslintrc

+8
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,13 @@
1111
},
1212
"globals": {
1313
"ethers": "readonly"
14+
},
15+
"rules": {
16+
"max-len": [
17+
"error",
18+
{
19+
"code": 120
20+
}
21+
]
1422
}
1523
}

.github/workflows/run_tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ jobs:
2424
run: npm ci
2525
- name: Run linter
2626
run: npm run lint
27-
# - name: Run tests
28-
# run: npm test
27+
- name: Run tests
28+
run: npm test

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ contract Azuki is ERC721A {
5656

5757
## Roadmap
5858

59-
- [] Setup CI pipeline to run tests on every PR
6059
- [] Add burn function
6160
- [] Add flexibility for the first token id to not start at 0
6261
- [] Move `_setOwnersExplicit` to an extension

test/ERC721A.test.js

+48-56
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { expect } = require('chai');
2-
const { constants, expectRevert } = require('@openzeppelin/test-helpers');
2+
const { constants } = require('@openzeppelin/test-helpers');
33
const { ZERO_ADDRESS } = constants;
44

55
const RECEIVER_MAGIC_VALUE = '0x150b7a02';
@@ -10,7 +10,7 @@ describe('ERC721A', function () {
1010
beforeEach(async function () {
1111
this.ERC721A = await ethers.getContractFactory('ERC721AMock');
1212
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);
1414
await this.erc721a.deployed();
1515
});
1616

@@ -36,7 +36,7 @@ describe('ERC721A', function () {
3636
describe('exists', async function () {
3737
it('verifies valid tokens', async function () {
3838
for (let tokenId = 0; tokenId < 6; tokenId++) {
39-
let exists = await this.erc721a.exists(tokenId);
39+
const exists = await this.erc721a.exists(tokenId);
4040
expect(exists).to.be.true;
4141
}
4242
});
@@ -56,9 +56,9 @@ describe('ERC721A', function () {
5656
});
5757

5858
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');
6262
});
6363
});
6464

@@ -79,9 +79,7 @@ describe('ERC721A', function () {
7979
});
8080

8181
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');
8583
});
8684
});
8785

@@ -96,38 +94,35 @@ describe('ERC721A', function () {
9694
});
9795

9896
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');
102100
});
103101

104102
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');
108106
});
109107

110108
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');
114110
});
115111
});
116112

117113
describe('setApprovalForAll', async function () {
118114
it('sets approval for all properly', async function () {
119115
const approvalTx = await this.erc721a.setApprovalForAll(this.addr1.address, true);
120116
await expect(approvalTx)
121-
.to.emit(this.erc721a, "ApprovalForAll")
117+
.to.emit(this.erc721a, 'ApprovalForAll')
122118
.withArgs(this.owner.address, this.addr1.address, true);
123119
expect(await this.erc721a.isApprovedForAll(this.owner.address, this.addr1.address)).to.be.true;
124120
});
125121

126122
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');
131126
});
132127
});
133128

@@ -152,7 +147,7 @@ describe('ERC721A', function () {
152147

153148
it('emits a Transfer event', async function () {
154149
await expect(this.transferTx)
155-
.to.emit(this.erc721a, "Transfer")
150+
.to.emit(this.erc721a, 'Transfer')
156151
.withArgs(from, to, tokenId);
157152
});
158153

@@ -162,7 +157,7 @@ describe('ERC721A', function () {
162157

163158
it('emits an Approval event', async function () {
164159
await expect(this.transferTx)
165-
.to.emit(this.erc721a, "Approval")
160+
.to.emit(this.erc721a, 'Approval')
166161
.withArgs(from, ZERO_ADDRESS, tokenId);
167162
});
168163

@@ -180,30 +175,27 @@ describe('ERC721A', function () {
180175
const tokenId = 1;
181176

182177
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');
187181
});
188182

189183
it('rejects transfer from incorrect owner', async function () {
190184
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');
195188
});
196189

197190
it('rejects transfer to zero address', async function () {
198191
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');
203195
});
204-
}
196+
};
205197

206-
context("successful transfers", function () {
198+
context('successful transfers', function () {
207199
describe('transferFrom', function () {
208200
testSuccessfulTransfer('transferFrom');
209201
});
@@ -213,13 +205,13 @@ describe('ERC721A', function () {
213205

214206
it('validates ERC721Received', async function () {
215207
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);
218210
});
219211
});
220212
});
221213

222-
context("unsuccessful transfers", function () {
214+
context('unsuccessful transfers', function () {
223215
describe('transferFrom', function () {
224216
testUnsuccessfulTransfer('transferFrom');
225217
});
@@ -240,42 +232,42 @@ describe('ERC721A', function () {
240232
this.receiver = await this.ERC721Receiver.deploy(RECEIVER_MAGIC_VALUE);
241233
});
242234

243-
describe("safeMint", function () {
235+
describe('safeMint', function () {
244236
it('successfully mints a single token', async function () {
245237
const mintTx = await this.erc721a['safeMint(address,uint256)'](this.receiver.address, 1);
246238
await expect(mintTx)
247-
.to.emit(this.erc721a, "Transfer")
239+
.to.emit(this.erc721a, 'Transfer')
248240
.withArgs(ZERO_ADDRESS, this.receiver.address, 0);
249241
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);
252244
expect(await this.erc721a.ownerOf(0)).to.equal(this.receiver.address);
253245
});
254246

255247
it('successfully mints multiple tokens', async function () {
256248
const mintTx = await this.erc721a['safeMint(address,uint256)'](this.receiver.address, 5);
257249
for (let tokenId = 0; tokenId < 5; tokenId++) {
258250
await expect(mintTx)
259-
.to.emit(this.erc721a, "Transfer")
251+
.to.emit(this.erc721a, 'Transfer')
260252
.withArgs(ZERO_ADDRESS, this.receiver.address, tokenId);
261253
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);
264256
expect(await this.erc721a.ownerOf(tokenId)).to.equal(this.receiver.address);
265257
}
266258
});
267259

268260
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');
272264
});
273265

274266
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');
278270
});
279271
});
280272
});
281-
});
273+
});

0 commit comments

Comments
 (0)