I am implementing an airdrop function as follows:
--- SNIP ---
event Airdrop(address[] recipients, uint256[] values);
--- SNIP ---
function airdrop(address[] memory recipients, uint256[] memory values)
public
{
for (uint256 i = 0; i < recipients.length; i++) {
transfer(recipients[i], values[i]);
}
emit Airdrop(recipients, values);
}
--- SNIP ---
And trying to test this function as follows:
contract("Miscellanous", async (accounts) => {
const [sender] = accounts;
it("should airdrop x% of minted tokens", async () => {
const senderBalance = await this.token.balanceOf(sender);
const recipients = accounts.slice(1, 6);
const totalAmount = BigNumber(2.5)
.dividedBy(100)
.multipliedBy(senderBalance.toString())
.toFixed();
const amounts = Array(recipients.length).fill(
new BN(totalAmount).div(new BN(recipients.length))
);
const receipt = await this.token.airdrop(recipients, amounts, {
from: sender,
});
await expectEvent(receipt, "Airdrop", {
recipients: recipients,
values: amounts,
});
recipients.forEach(async (i, recipient) => {
await expectEvent(receipt, "Transfer", {
from: sender,
to: recipient,
value: amounts[i],
});
const recipientBalance = await this.token.balanceOf(recipient[i]);
expect(recipientBalance).to.be.bignumber.equal(amounts[i]);
});
const senderBalanceAfterTx = await this.token.balanceOf(sender);
expect(senderBalanceAfterTx).to.be.bignumber.equal(
senderBalance.sub(new BN(totalAmount))
);
});
});
I am not sure how expectEvent
deals with Arrays
but I am getting the following stacktrace:
2) Contract: Miscellanous
should airdrop x% of minted tokens:
expected event argument 'values' to have value 5000000000000000000000000000000,5000000000000000000000000000000,5000000000000000000000000000000,5000000000000000000000000000000,5000000000000000000000000000000 but got 5000000000000000000000000000000,5000000000000000000000000000000,5000000000000000000000000000000,5000000000000000000000000000000,5000000000000000000000000000000
+ expected - actual
0
36267216
16848388
16543612
+ 0
]
}
{
"length": 4
--
0
36267216
16848388
16543612
+ 0
]
}
{
"length": 4
--
0
36267216
16848388
16543612
+ 0
]
}
{
"length": 4
--
0
36267216
16848388
16543612
+ 0
]
}
{
"length": 4
--
0
36267216
16848388
16543612
+ 0
]
}
]
at contains (node_modules\@openzeppelin\test-helpers\src\expectEvent.js:158:34)
at C:\Users\ateyar\Documents\GitHub\erc20-deflationary\node_modules\@openzeppelin\test-helpers\src\expectEvent.js:57:9
at Array.find (<anonymous>)
at inLogs (node_modules\@openzeppelin\test-helpers\src\expectEvent.js:54:24)
at expectEvent (node_modules\@openzeppelin\test-helpers\src\expectEvent.js:29:12)
at Context.<anonymous> (test\ERC20Deflationary.test.js:433:11)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
What am I missing there?