I am creating a crowdsale that is a WhitelistedCrowdsale, PostDeliveryCrowdsale, CappedCrowdsale.
My tests all pass (See attached)
TravelkoinCrowdsale.js.zip
However, when deploying this code and running the crowdsale, everything works except withdrawToken() method on PostDeliveryCrowdsale. You can see me trying to withdraw tokens here:
https://rinkeby.etherscan.io/address/0xa74b909b7ea62d280b64c4465c5c8e5b7a9c5ac6
It fails with a revert in Mist and Metamask. Now I know the sale is over and have a balance in PostDeliveryCrowdsale. The only thing I have to go by is a message from Mist (see attached).

I can see that the integration test works by calling the exact same functions at the right time. However, they don't work when actually running a sale.
Unfortunately, I don't know enough about where the error is happening. I tried to override the withdrawToken method in my own contract to fire off some events with the values of "balances" and to make sure the sale was over (in case the require methods in PostDeliveryCrowdsale would fail) and then call super. No events were fired.
Next, we need to know what your environment looks like.
Which version of OpenZeppelin are you using?
1.7.0
What network are you deploying to? testrpc? Ganache? Ropsten?
Ganache & Rinkeby
How are you deploying your OpenZeppelin-backed contracts? truffle? Remix? Let us know!
Truffle
My setup is almost identical to PostDeliveryCrowdsaleImpl. Attaching crowdsale and token contract. There is nothing interfering with the withdrawToken method.
Archive.zip
Sorry to not be able to provide something more concrete. I have been struggling with this for over a week.
Please advise,
Bjorn
@bjornharvold, I'm checking your issue, is it possible that you are calling withdrawTokens() from an account with 0 balance (0xbb13e514578afd3c0031c7a8bb54132981317675)?.. Could you please check this?
Hi @fiiiu. I did some further investigation. It is not the PostDeliveryCrowdsale that's the issue. I removed it and I still get the same error without it. The account you mention there has 18 ETH. It must have something to do with actually transferring the tokens over to the beneficiary. Thoughts?
I am trying to simplify the token contract to see if I suddenly strike gold. Right now, my crowdsale contract extends WhitelistedCrowdsale, TimedCrowdsale and CappedCrowdsale. My token only extends StandardToken and DetailedERC20. My test account has 100 ETH and I am still getting the same error when I call buyTokens now. All tests are passing.
We really need assert, require and revert to come with messages. This guess work will not make for easy adoption.
State of the EVM as of right now:

FYI. I do get a slightly different error locally vs when testing on Rinkeby. Here is my local error:
Error: Error: Error: [ethjs-rpc] rpc error with payload {"id":3189152973203,"jsonrpc":"2.0","params":["0xf8928084ee6b280083030d40948f0483125fcb9aaaefa9209d8e9d7b9c8b9fb90f8803311fc80a570000a4ec8ac4d8000000000000000000000000f17f52151ebef6c7334fad080c5704d77216b7328222e1a0f976a09e97998ab1ecaa197b2197f49e0d8e1253b6c348b810c7cb9b230c0375a0343c09d2ab37ad4bfe7987f3f5e2cacf76728098fdbc8ac679afaa9260eab616"],"method":"eth_sendRawTransaction"} Error: VM Exception while processing transaction: revert
I'm not sure about your last found error, but be aware that I'm not referring to the balance in ETH (retrieved with balanceOf(address)) but to the _token_ balance (retrieved with balances(address)). Be sure to transfer tokens to the address before you call the withdrawal method.
Hi @fiiiu. I looked at the transaction log and could see that the token balance I had assigned the owner account was way too low. Instead of being 85 million if was 0.000000000085.
I redeployed the crowd sale onto Rinkeby.
Token: 0xee272c3572b17b66461b6ab965494e41750e5b9d
Crowdsale: 0xb18d04699934f74882e5e77317feee32c6399e8d
Owner: 0xbb13e514578afd3c0031c7a8bb54132981317675. You can see that the owner now owns 85 million tokens that were giving to him when the contract was deployed.
https://rinkeby.etherscan.io/address/0xbb13e514578afd3c0031c7a8bb54132981317675#tokentxns.
I successfully whitelisted account: 0x88783faC668A501B9376527F5fCC6eF42789F1A7 and tried to "buyTokens()". It fails with the same error.
It fails like this in MetaMask:
{message: "Transaction: 0x5fa47aa404857fb07813a63ae7a5a3e5282… does not trigger a Solidity revert statement.↵", stack: "Error: Transaction: 0x5fa47aa404857fb07813a63ae7a5…ogaeaoehlefnkodbefgpgknn/scripts/inpage.js:1:6725", name: "StatusError", tx: "0x5fa47aa404857fb07813a63ae7a5a3e5282e839cf31b435acadb8a9175ae64ae", receipt: {…}}message: "Transaction: 0x5fa47aa404857fb07813a63ae7a5a3e5282e839cf31b435acadb8a9175ae64ae exited with an error (status 0).↵Please check that the transaction:↵ - satisfies all conditions set by Solidity require statements.↵ - does not trigger a Solidity revert statement.↵"name: "StatusError"receipt: {blockHash: "0x2f003c197d33eda81530814ba3c7da7f7c32bcd9e17c138981760d0dbd3f41ea", blockNumber: 1905798, contractAddress: null, cumulativeGasUsed: 1454517, from: "0x88783fac668a501b9376527f5fcc6ef42789f1a7", …}stack: "Error: Transaction: 0x5fa47aa404857fb07813a63ae7a5a3e5282e839cf31b435acadb8a9175ae64ae exited with an error (status 0).↵Please check that the transaction:↵ - satisfies all conditions set by Solidity require statements.↵ - does not trigger a Solidity revert statement.↵↵ at StatusError.ExtendableError (webpack-internal:///./node_modules/truffle-error/index.js:10:17)↵ at new StatusError (webpack-internal:///./node_modules/truffle-contract/statuserror.js:29:22)↵ at Object.eval [as callback] (webpack-internal:///./node_modules/truffle-contract/contract.js:181:41)↵ at eval (webpack-internal:///./node_modules/truffle-contract/node_modules/web3/lib/web3/method.js:142:25)↵ at eval (webpack-internal:///./node_modules/truffle-contract/node_modules/web3/lib/web3/requestmanager.js:89:9)↵ at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:1:84195↵ at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:1:6725↵ at o (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:1:24956)↵ at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:1:9555↵ at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:1:6725"tx: "0x5fa47aa404857fb07813a63ae7a5a3e5282e839cf31b435acadb8a9175ae64ae"__proto__: ExtendableError
And the transaction never finishes with Mist. It just hangs after I confirm payment:

Sounds like the rate or decimals or similar might be off in your code. Unfortunately, I don't want to download your zip file — can you upload it to a github repository so we can take a look?
Hi @Shrugs
Thank you for your feedback. I moved the contract code out of our private repo to Github: https://github.com/bjornharvold/travelkoin-contracts.
I did look at the decimals. I updated my application to take the amount of ether I received from the form page (E.g. 0.45) and convert to actual Ether => new BigNumber(amount * Math.pow(10, 18)). MetaMask asks me if I want to send 0.45 ETH but it still fails when I execute the transaction.
Cheers
Note: One thing I am having issues with is calling the estimateGas on buyTokens. It just fails with this error:
{"id":116,"jsonrpc":"2.0","error":{"code":-32603}}
Can this be related?
Just another stupid developer mistake. Please ignore me completely. I failed to transfer the funds from the token to the crowdsale so there was nothing to buy. #argh
Most helpful comment
Just another stupid developer mistake. Please ignore me completely. I failed to transfer the funds from the token to the crowdsale so there was nothing to buy. #argh