---
title: "Comment by Martin Blanco on \"The 2018 guide to writing (and testing) real world crowdsale contracts\" | Hashnode"
description: "I would like the tokens to be distributed at the end of the ico, how can we do this?"
url: "https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a9f1e750430f87244d401be"
---

[Discussion](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9)

Comment [The 2018 guide to writing (and testing) real world crowdsale contracts](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9)

[Martin Blanco](https://hashnode.com/@kaptincho)

[Mar 6, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a9f1e750430f87244d401be)

I would like the tokens to be distributed at the end of the ico, how can we do this?

[Sandeep Panda](https://hashnode.com/@sandeep)

[Mar 7, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a9f1e750430f87244d401be#reply-5a9fbbe60430f87244d408ce)

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.

[Vamsee](https://hashnode.com/@vamsee)

[Mar 25, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a9f1e750430f87244d401be#reply-5ab7f80a17ffdb93140852ed)

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)

[Vamsee](https://hashnode.com/@vamsee)

[Mar 26, 2018](https://hashnode.com/posts/the-2018-guide-to-writing-and-testing-real-world-crowdsale-contracts/5a67bb65357c012503a334c9/comment/5a9f1e750430f87244d401be#reply-5ab886bc17ffdb9314085414)

Here is the fixed/working code, thanks to advice from [github.com/OpenZeppelin/zeppelin-solidity/issues/…](https://github.com/OpenZeppelin/zeppelin-solidity/issues/584#issuecomment-376042522)

```
  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')
  })
```
