support constructor arguments in specs

This commit is contained in:
Iuri Matias 2015-06-14 21:38:00 -04:00
parent 55cdf4c878
commit 1e5d704061
3 changed files with 23 additions and 7 deletions

View File

@ -1,9 +1,12 @@
var Tests = require('embark-framework').Tests;
SimpleStorage = Tests.request("SimpleStorage");
SimpleStorage = Tests.request("SimpleStorage", 150);
SimpleStorage.set(100);
a = SimpleStorage.get()
console.log(a)
a = SimpleStorage.foo()
console.log(a)

View File

@ -1,4 +1,10 @@
contract SimpleStorage {
uint public foo;
function SimpleStorage(uint y) {
foo = y;
}
uint storedData;
function set(uint x) {
storedData = x;

View File

@ -16,9 +16,10 @@ web3.setProvider(new web3.providers.HttpProvider('http://localhost:8101'));
web3.eth.defaultAccount = web3.eth.accounts[0];
TestContractWrapper = (function() {
function TestContractWrapper(contract, className) {
function TestContractWrapper(contract, className, args) {
this.contract = contract;
this.className = className;
this.args = args;
this.initializeContract();
}
@ -30,7 +31,13 @@ TestContractWrapper = (function() {
py_exec("example_abi")
py_exec("example_binary = '" + example_binary + "'.decode('hex')")
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"
};
@ -51,8 +58,8 @@ TestContractWrapper = (function() {
})();
TestContract = function(contract, className) {
var wrapper = new TestContractWrapper(contract, className);
TestContract = function(contract, className, args) {
var wrapper = new TestContractWrapper(contract, className, args);
var Obj = mm(wrapper, function (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];
return TestContract(contract, className)
return TestContract(contract, className, args)
}
Test = {