I have the following javascript
test for a simple ERC 20 token. Which on the call return token.balanceOf.call(accounts[2]);
will fetch some old data and fail from a previous test transaction writting similar, but in another contract() scope on the same contract. Using TestRpc
contract('ERC Allowance', function (accounts) {
it("should be able to lend money and that user spend it", function () {
var token;
return Token.deployed().then(function (instance) {
token= instance;
return instance.approve(accounts[1], 5555, {from: accounts[0]});
})
.then(function (approveTransaction) {
return chftoken .allowance.call(accounts[0], accounts[1]);
})
.then(function (allowance) {
assert.equal(allowance, 5555, "allowance should be increased");
return token.transferFrom.call(accounts[0], accounts[2], 55555, {from: accounts[1]});
})
.then(function (failedTransaction) {
return token.balanceOf.call(accounts[2]);
})
.then(function (balance) {
assert.equal(balance.valueOf(), 0, "transfer should not go through");
return token.transferFrom.call(accounts[0], accounts[9], 10000, {from: accounts[1]});
})
.then(function (transactionCompleted) {
return token.balanceOf.call(accounts[2])
})
.then(function (balance) {
assert.equal(balance, 5555, "the balance should be transferred")
});
});
});