Hi,
I got the code from the following link:
quick guide
it("Test balance after deposit", function() {
return SimpleBank.deployed().then(function(instance) {
sb = instance;
return sb.deposit({ from: accounts[0], value: web3.utils.toWei('10', 'ether') });
}).then(function(tx_receipt) {
return sb.getBalance({ from: accounts[0] });
}).then(function(x) {
assert.equal(web3.utils.toWei('10', 'ether'), x, "Wrong balance");
}).then(function() {
return sb.getBalance({ from: accounts[1] });
}).then(function(x) {
assert.equal(0, x, "Wrong balance");
});
});
});
==
Somebody please provide me line by line explanation of above code, I would highly appreciate it. I have problem with the keyword ‘function()’, it is used with different arguments and sometimes with no arguments. deposit() is defined in the contract with no arguments, but in the above code deposit() is used i.e. its arguments as called in other language are very strange , I have not seen it in any other language. What is the purpose of tx_receipt? We have ‘return’ statement at the start of the first bracket which then starts another block then sb is initialized, then again a ‘return’ statement but this time hooked to toWei(…)which is connected to ‘then’ and then we have another block and so on . Each time the block starts with 'then function() ’ but argument of ‘function’ can be different, two times, it is ‘x’, please guide me.
Zulfi.
Environment
Details
Code to reproduce