Search posts, tags, users, and pages
I would like the tokens to be distributed at the end of the ico, how can we do this?
Instead of transferring the tokens to the users immediately, you can maintain a mapping which stores the pending token balance of each user. Once the ICO is over, you can make the actual transfer via a function call.
Hi, trying to add a transfer test like this but it is failing.
it('Token transfer', async () => { const contractInstance = await HashnodeCrowdsale.deployed() let ecoSystemBalance = await web3.eth.getBalance(accounts[9])
const tokenAddress = await contractInstance.token.call()
const hashToken = HashnodeToken.at(tokenAddress)
const owner = await hashToken.owner.call()
console.log(owner)
await hashToken.approve(accounts[4], 4)
console.log(await hashToken.allowance(owner, accounts[4]))
await hashToken.transferFrom(owner, accounts[4], 3)
let receiverBalance = await web3.eth.getBalance(accounts[4])
receiverBalance = receiverBalance.toNumber()
assert.equal(receiverBalance, 3, 'Transfer failed')
})
getting this error. Any idea how to get that working? Tried with other from addresses like accounts[9] but getting the same error.
== output of the test run ===
0x85d22c38d2b791a5803fc3f15267fda1b0473c3b BigNumber { s: 1, e: 0, c: [ 0 ] }
Events emitted during test:
---------------------------
Approval(owner: <indexed>, spender: <indexed>, value: 4)
---------------------------
Error: VM Exception while processing transaction: revert at Object.InvalidResponse (node_modules/truffle-contract/node_modules/web3/lib/web3/errors.js:38:16) at node_modules/truffle-contract/node_modules/web3/lib/web3/requestmanager.js:86:36 at node_modules/truffle-provider/wrapper.js:134:9 at XMLHttpRequest.request.onreadystatechange (node_modules/truffle-provider/node_modules/web3/lib/web3/httpprovider.js:128:7) at XMLHttpRequestEventTarget.dispatchEvent (node_modules/xhr2/lib/xhr2.js:64:18) at XMLHttpRequest._setReadyState (node_modules/xhr2/lib/xhr2.js:354:12) at XMLHttpRequest._onHttpResponseEnd (node_modules/xhr2/lib/xhr2.js:509:12) at IncomingMessage.<anonymous> (node_modules/xhr2/lib/xhr2.js:469:24) at endReadableNT (_stream_readable.js:1055:12) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9)
Here is the fixed/working code, thanks to advice from github.com/OpenZeppelin/zeppelin-solidity/issues/…
it('Token transfer', async () => {
const fromAccount = accounts[1]
const toAccount = accounts[4]
const transferLimit = 4000000000000000000
const transferAmount = 3000000000000000000
let ecoSystemBalance = await tokenInstance.balanceOf(fromAccount)
assert.isAtLeast(ecoSystemBalance, transferLimit, 'From account balance should be atleast 4')
await tokenInstance.approve(toAccount, transferLimit, {from: fromAccount})
assert.equal(await tokenInstance.allowance(fromAccount, toAccount), transferLimit, 'Allowance from->to should be 4')
console.log(`Attempting a transfer with ecoSystem balance of ${ecoSystemBalance}`)
await tokenInstance.transferFrom(fromAccount, toAccount, transferAmount, {from: toAccount})
assert.equal(await tokenInstance.balanceOf(toAccount), transferAmount, 'To account should have 3')
})