I'm testing my contracts using Truffle, but my functions are not returning the correct uint, despite doing so when testing in Remix. This is my Test.js code:
var EventContract = artifacts.require("./EventContract.sol");
contract ('EventContract', function (accounts){
it("account1 purchases 4 tickets from ticketContract, which had 10 tickets to start with at a cost of 2", function(){
var event;
var account1 = accounts[0];
return EventContract.deployed()
.then(function(instance){
event = instance;
return event.buyTicketsFromContract.call(account1, 2, {from: account1, value: 4});
})
.then (function (success){
console.log("purchased from contract with success: " + success);
assert.equal(true, success, "bought 2 tickets for 4 ether");
return event.getContractTicketBalance.call();
})
.then (function(contractBalance){
console.log(contractBalance.toNumber());
// Fails here
assert.equal(8, contractBalance.toNumber(), "contract ticket balance is not 8");
return event.getTicketBalance.call(account1);
})
.then (function(accountBalance){
assert.equal(2, accountBalance.toNumber(), "account balance is not 2");
})
;
})
;
It fails because the contract ticket balance is 10 (initial amount), not 8. When using the same functions on Remix, the values returned are correct.