With the erc20 token and crowdsale contracts created, I am using truffle framework doing testing, and 1 testcase failed: after crowdsale.buyToken(investor1) successfully fulfilled, I expect token.balanceOf(investor1) return non-zero, but it returns 0:
Environment
Truffle
Details
testcase:
beforeEach(async function() {
await this.crowdsale.buyTokens(investor1, { value: ether(1), from: investor1 });
});
describe('during crowdsale', function() {
it('check investor1 should have the tokens purchaged', async function() {
let tb = await this.token.balanceOf(investor1);
console.log(" investor1 tokens: " + tb + " @ " + investor1);
expect(tb).to.be.equal(500);
});
}):
Even the events correctly generated:
IERC20.Transfer(
from: <indexed> 0x0000000000000000000000000000000000000000 (type: address),
to: <indexed> 0xBf449E4c98361630005ADf5cfb129707d7B0714d (type: address),
value: 500000000000000000000 (type: uint256)
)
Crowdsale.TokensPurchased(
purchaser: <indexed> 0x46F5862A84Cd5138BE62530AE6a563D4F110DB3e (type: address),
beneficiary: <indexed> 0x46F5862A84Cd5138BE62530AE6a563D4F110DB3e (type: address),
value: 1000000000000000000 (type: uint256),
amount: 500000000000000000000 (type: uint256)
)
1 failing
1) Contract: WJWNpmTokenCrowdsale
refundable crowdsale
during crowdsale
check investor1 should have the tokens purchaged:
AssertionError: expected <BN: 0> to equal 500
at Context._callee14$ (test/WJWNpmTokenCrowdsale.test.js:416:34)
at tryCatch (node_modules/regenerator-runtime/runtime.js:65:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:303:22)
at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:117:21)
at step (test/WJWNpmTokenCrowdsale.test.js:21:191)
at /home/james/workspace/ico_wjw/test/WJWNpmTokenCrowdsale.test.js:21:361
at process._tickCallback (internal/process/next_tick.js:68:7)
Code to reproduce
beforeEach(async function() {
await this.crowdsale.buyTokens(investor1, { value: ether(1), from: investor1 });
});
describe('during crowdsale', function() {
it('check investor1 should have the tokens purchaged', async function() {
let tb = await this.token.balanceOf(investor1);
console.log(" investor1 tokens: " + tb + " @ " + investor1);
expect(tb).to.be.equal(500);
});
}):
the rate of the crowdsale is 500.