Skip to content

Commit ea17532

Browse files
committed
fix: test cleanup
1 parent daad8cb commit ea17532

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

test/DATAv2-test.js

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
const { parseEther } = require("@ethersproject/units")
2-
const { formatBytes32String, toUtf8Bytes } = require("@ethersproject/strings")
32
const { id } = require("@ethersproject/hash")
43
const { expect } = require("chai")
54
const { ethers } = require("hardhat")
65

6+
// "err" as bytes, induces a simulated error in MockRecipient.sol and MockRecipientReturnBool.sol
7+
const errData = "0x657272"
8+
79
describe("DATAv2", () => {
810
it("transferAndCall triggers ERC677 callback", async () => {
911
const [signer, minter] = await ethers.getSigners()
@@ -13,47 +15,39 @@ describe("DATAv2", () => {
1315
await recipient.deployed()
1416

1517
const MockRecipientNotERC677Receiver = await ethers.getContractFactory("MockRecipientNotERC677Receiver")
16-
const recipient2 = await MockRecipientNotERC677Receiver.deploy()
17-
await recipient2.deployed()
18+
const nonReceiverRecipient = await MockRecipientNotERC677Receiver.deploy()
19+
await nonReceiverRecipient.deployed()
1820

1921
const MockRecipientReturnBool = await ethers.getContractFactory("MockRecipientReturnBool")
20-
const recipient3 = await MockRecipientReturnBool.deploy()
21-
await recipient3.deployed()
22-
22+
const returnBoolRecipient = await MockRecipientReturnBool.deploy()
23+
await returnBoolRecipient.deployed()
2324

2425
const DATAv2 = await ethers.getContractFactory("DATAv2")
2526
const token = await DATAv2.deploy()
2627
await token.deployed()
2728

2829
await expect(token.grantRole(id("MINTER_ROLE"), minter.address)).to.emit(token, "RoleGranted")
29-
await expect(token.connect(minter).mint(signer.address, parseEther("10"))).to.emit(token, "Transfer(address,address,uint256)")
30+
await expect(token.connect(minter).mint(signer.address, parseEther("10"))).to.emit(token, "Transfer(address,address,uint256)")
3031

31-
//"err" as bytes
32-
const errData = "0x657272"
33-
//revert in callback should revert transferAndCall
32+
// revert in callback => should revert transferAndCall
3433
await expect(token.transferAndCall(recipient.address, parseEther("1"), errData)).to.be.reverted
35-
//no callback should revert transferAndCall
36-
await expect(token.transferAndCall(recipient2.address, parseEther("1"), "0x")).to.be.reverted
37-
38-
//call to contract that implements ERC677Receiver reverts if onTokensReceived = false
39-
//await expect().to.be.reverted
40-
41-
//call to contract that implements ERC677Receiver calls callback
42-
let before = await recipient.txCount()
43-
await token.transferAndCall(recipient.address, parseEther("1"), "0x6c6f6c")
44-
let after = await recipient.txCount()
45-
expect(after).to.equal(before.add(1))
4634

35+
// no callback => should revert transferAndCall
36+
await expect(token.transferAndCall(nonReceiverRecipient.address, parseEther("1"), "0x")).to.be.reverted
4737

48-
before = await recipient3.txCount()
38+
// contract that implements ERC677Receiver executes the callback
39+
const txsBefore = await recipient.txCount()
40+
await token.transferAndCall(recipient.address, parseEther("1"), "0x6c6f6c")
41+
const txsAfter = await recipient.txCount()
4942

50-
//if callback returns true or false, shouldnt revert
51-
await token.transferAndCall(recipient3.address, parseEther("1"), errData)
52-
await token.transferAndCall(recipient3.address, parseEther("1"), "0x")
43+
// callback returns true or false but doesn't revert => should NOT revert
44+
const txsBeforeBool = await returnBoolRecipient.txCount()
45+
await token.transferAndCall(returnBoolRecipient.address, parseEther("1"), errData)
46+
await token.transferAndCall(returnBoolRecipient.address, parseEther("1"), "0x")
47+
const txsAfterBool = await returnBoolRecipient.txCount()
5348

54-
after = await recipient3.txCount()
55-
expect(after).to.equal(before.add(2))
56-
49+
expect(txsAfter).to.equal(txsBefore.add(1))
50+
expect(txsAfterBool).to.equal(txsBeforeBool.add(2))
5751
})
5852

5953
it("transferAndCall just does normal transfer for non-contract accounts", async () => {

0 commit comments

Comments
 (0)