Skip to content

Instantly share code, notes, and snippets.

@PhyrexTsai
Created July 17, 2017 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PhyrexTsai/eaecfff6a6ea7aa915cb104824fea998 to your computer and use it in GitHub Desktop.
Save PhyrexTsai/eaecfff6a6ea7aa915cb104824fea998 to your computer and use it in GitHub Desktop.
var Caller = artifacts.require("Caller.sol");
var Callee = artifacts.require("Callee.sol");
var abi = require("ethereumjs-abi");
contract("Caller and Callee", function(accounts) {
it("invoke callee via caller", function() {
var caller;
var callee;
return Caller.deployed().then(function(callerInstance) {
caller = callerInstance;
return Callee.deployed().then(function(calleeInstance) {
callee = calleeInstance;
var encoded = abi.methodID("addOne", []).toString("hex");
return caller.invoke(callee.address, 0, "0x" + encoded);
}).then(function() {
return callee.counter.call();
}).then(function(counter) {
assert.equal(counter.toNumber(), 1, "count wasn't correctly");
}).then(function() {
var encoded = abi.methodID("addNum", [ "uint256" ]).toString("hex") +
abi.rawEncode([ "uint256" ], [ 10 ]).toString("hex");
return caller.invoke(callee.address, 0, "0x" + encoded);
}).then(function() {
return callee.counter.call();
}).then(function(counter) {
assert.equal(counter.toNumber(), 11, "count wasn't correctly");
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment