support constructor arguments in specs
This commit is contained in:
parent
55cdf4c878
commit
1e5d704061
|
@ -1,9 +1,12 @@
|
||||||
var Tests = require('embark-framework').Tests;
|
var Tests = require('embark-framework').Tests;
|
||||||
|
|
||||||
SimpleStorage = Tests.request("SimpleStorage");
|
SimpleStorage = Tests.request("SimpleStorage", 150);
|
||||||
|
|
||||||
SimpleStorage.set(100);
|
SimpleStorage.set(100);
|
||||||
|
|
||||||
a = SimpleStorage.get()
|
a = SimpleStorage.get()
|
||||||
console.log(a)
|
console.log(a)
|
||||||
|
|
||||||
|
a = SimpleStorage.foo()
|
||||||
|
console.log(a)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
contract SimpleStorage {
|
contract SimpleStorage {
|
||||||
|
uint public foo;
|
||||||
|
|
||||||
|
function SimpleStorage(uint y) {
|
||||||
|
foo = y;
|
||||||
|
}
|
||||||
|
|
||||||
uint storedData;
|
uint storedData;
|
||||||
function set(uint x) {
|
function set(uint x) {
|
||||||
storedData = x;
|
storedData = x;
|
||||||
|
|
19
lib/test.js
19
lib/test.js
|
@ -16,9 +16,10 @@ web3.setProvider(new web3.providers.HttpProvider('http://localhost:8101'));
|
||||||
web3.eth.defaultAccount = web3.eth.accounts[0];
|
web3.eth.defaultAccount = web3.eth.accounts[0];
|
||||||
|
|
||||||
TestContractWrapper = (function() {
|
TestContractWrapper = (function() {
|
||||||
function TestContractWrapper(contract, className) {
|
function TestContractWrapper(contract, className, args) {
|
||||||
this.contract = contract;
|
this.contract = contract;
|
||||||
this.className = className;
|
this.className = className;
|
||||||
|
this.args = args;
|
||||||
this.initializeContract();
|
this.initializeContract();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +31,13 @@ TestContractWrapper = (function() {
|
||||||
py_exec("example_abi")
|
py_exec("example_abi")
|
||||||
py_exec("example_binary = '" + example_binary + "'.decode('hex')")
|
py_exec("example_binary = '" + example_binary + "'.decode('hex')")
|
||||||
py_exec("example_binary")
|
py_exec("example_binary")
|
||||||
py_exec(this.className + "_contract = EvmContract(example_abi, example_binary)")
|
|
||||||
|
if (this.args == undefined) {
|
||||||
|
py_exec(this.className + "_contract = EvmContract(example_abi, example_binary, '" + this.className + "')")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
py_exec(this.className + "_contract = EvmContract(example_abi, example_binary, '" + this.className + "', [" + this.args.join(",") + "])")
|
||||||
|
}
|
||||||
|
|
||||||
this.contractVariable = this.className + "_contract"
|
this.contractVariable = this.className + "_contract"
|
||||||
};
|
};
|
||||||
|
@ -51,8 +58,8 @@ TestContractWrapper = (function() {
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
TestContract = function(contract, className) {
|
TestContract = function(contract, className, args) {
|
||||||
var wrapper = new TestContractWrapper(contract, className);
|
var wrapper = new TestContractWrapper(contract, className, args);
|
||||||
var Obj = mm(wrapper, function (key, args) {
|
var Obj = mm(wrapper, function (key, args) {
|
||||||
return wrapper.execCmd(key, args);
|
return wrapper.execCmd(key, args);
|
||||||
});
|
});
|
||||||
|
@ -75,9 +82,9 @@ for (i = 0, len = contractFiles.length; i < len; i++) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
request = function(className) {
|
request = function(className, args) {
|
||||||
var contract = contractDB[className];
|
var contract = contractDB[className];
|
||||||
return TestContract(contract, className)
|
return TestContract(contract, className, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
Test = {
|
Test = {
|
||||||
|
|
Loading…
Reference in New Issue