3

This question already has an answer here:

I am testing a contract with Truffle, which code is :

Contribution[] public contributions;

struct Contribution {
    address participantAddress;
    string name;
    uint timestamp;
    uint amount;
    bool refunded;
}

function() {
    contributions.push(Contribution({
            participantAddress: tx.origin,
            name: "anonymous",
            timestamp: block.timestamp,
            amount: msg.value,
            refunded: false
        })
    );
    NewContribution(tx.origin);
}

My test code is :

it.only('should contribute to the pot', function (done) {
  var pot = Pot.deployed()
  var event = pot.NewContribution()

  web3.eth.sendTransaction({from: owner, to: pot.address, value: web3.toWei(1, 'ether')}).then(new Promise(function (resolve, reject) {
    event.watch(function (error, log) {
      if (error) {
        return reject(error)
      }
      console.log(log)
      return resolve(log)
    })
  }).then((log) => {
    assert.equal(log.args.contributor, owner, 'contributor address is wrong')
  }).then(done).catch(done))
})

With this code, I get no events in my test, but if I comment the push like this, I get the expected event :

function() {
    /*contributions.push(Contribution({
            participantAddress: tx.origin,
            name: "anonymous",
            timestamp: block.timestamp,
            amount: msg.value,
            refunded: false
        })
    );*/
    NewContribution(tx.origin);
}

Note that it compile, and both codes are working fine on testrpc, but the first one is failing with a private network or with the testnet network.

Any idea ?

Thank you

marked as duplicate by Waqar Lim Jun 3 '16 at 8:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Have you tried more gas like {from: owner, gas:2000000... ? – eth Jun 3 '16 at 7:47