From 1e5d70406169e9c776712dce9b65c431a0c5ad14 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 14 Jun 2015 21:38:00 -0400 Subject: [PATCH] support constructor arguments in specs --- boilerplate/spec/test.js | 5 ++++- demo/contracts/simple_storage.sol | 6 ++++++ lib/test.js | 19 +++++++++++++------ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/boilerplate/spec/test.js b/boilerplate/spec/test.js index 178bd429..42ad1773 100644 --- a/boilerplate/spec/test.js +++ b/boilerplate/spec/test.js @@ -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) + diff --git a/demo/contracts/simple_storage.sol b/demo/contracts/simple_storage.sol index efc52495..a27bd3b1 100644 --- a/demo/contracts/simple_storage.sol +++ b/demo/contracts/simple_storage.sol @@ -1,4 +1,10 @@ contract SimpleStorage { + uint public foo; + + function SimpleStorage(uint y) { + foo = y; + } + uint storedData; function set(uint x) { storedData = x; diff --git a/lib/test.js b/lib/test.js index 23a7847f..ea2da333 100644 --- a/lib/test.js +++ b/lib/test.js @@ -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 = {