2

Testing with Truffle and solidity on localhost ganache network:

Works:

function dosomething(string a) {
    //do nothing
}

testing with:

TokenFactory tf = TokenFactory(TokenFactoryAddress);
function testDeployed() public {
  TokenFactory tf = TokenFactory(TokenFactoryAddress);
  tf.dosomething("lala"); //works!
  tf.dosomething.value(1000); //works!
  //assertions here
}

fails:

function dosomething(string a) payable {
   //do nothing
}

testing with:

TokenFactory tf = TokenFactory(TokenFactoryAddress);
function testDeployed() public {
  TokenFactory tf = TokenFactory(TokenFactoryAddress);
  tf.dosomething.value(100000)("lala"); //fails!
  tf.dosomething.value(100000).gas(1000000)("lala"); //fails!
  //assertions here
}

error:

Error: VM Exception while processing transaction: revert

  • revert errors usually mean contract received bad input and requre/assert statements triggered the REVERT opcode. check what values your constructor is receiving – Nulik Sep 6 '18 at 23:41
  • there is only one arg that is the same in the test and without payable it works perfectly. also i don't have any assert/requirement in the code. it must be something about how i send ether or gas problem but not sure what – arisalexis Sep 7 '18 at 9:17
  • either your contract doesn't have enough ether for that transaction or the gas that you are passing is not enough to create the contract. – Jaime Sep 7 '18 at 10:32
  • I am passing 2M gas in the call and the first call where the contract is not payable executes with normal gas so it's not it I think. Also my contract has 20ETH which is more than enough. Does the TokenFactory contract also need ETH? I think not. – arisalexis Sep 7 '18 at 10:44
  • post constructor's code – Nulik Sep 7 '18 at 13:13
1

At the start of the TestContract according to the docs: https://truffleframework.com/docs/truffle/testing/writing-tests-in-solidity#in-beta-testing-ether-transactions

there should be a line giving initial Ether to the contract:

 uint public initialBalance = 1 ether;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.