diff --git a/examples2/simple_storage.sol b/examples2/simple_storage.sol new file mode 100644 index 0000000000..4f8a84a5b1 --- /dev/null +++ b/examples2/simple_storage.sol @@ -0,0 +1,17 @@ +pragma solidity ^0.4.7; +contract SimpleStorage { + uint public storedData; + + function SimpleStorage() public { + storedData = 100; + } + + function set(uint x) public { + storedData = x; + } + + function get() public view returns (uint retVal) { + return storedData; + } + +} diff --git a/examples2/simple_storage2_test.sol b/examples2/simple_storage2_test.sol new file mode 100644 index 0000000000..f1095bb0d1 --- /dev/null +++ b/examples2/simple_storage2_test.sol @@ -0,0 +1,26 @@ +pragma solidity ^0.4.7; +import "./tests.sol"; +import "./simple_storage.sol"; + +contract MyTest2 { + SimpleStorage foo; + uint i = 0; + + function beforeEach() { + foo = new SimpleStorage(); + //if (i == 1) { + // foo.set(200); + //} + //i += 1; + } + + function initialValueShouldBe100() public constant returns (bool) { + return Assert.equal(foo.get(), 100, "initial value is not correct"); + //return foo.get() == 100; + } + + //function initialValueShouldBe200() public constant returns (bool) { + // return Assert.equal(foo.get(), 200, "initial value is not correct"); + //} + +} diff --git a/examples2/simple_storage_test.sol b/examples2/simple_storage_test.sol new file mode 100644 index 0000000000..e6900d7d0f --- /dev/null +++ b/examples2/simple_storage_test.sol @@ -0,0 +1,44 @@ +pragma solidity ^0.4.7; +import "./tests.sol"; +import "./simple_storage.sol"; + +//contract MyTest { +// SimpleStorage foo; +// +// function beforeAll() { +// foo = new SimpleStorage(); +// } +// +// function initialValueShouldBe100() public { +// Assert.equal(foo.get(), 100, "initial value is not correct"); +// } +// +// function initialValueShouldBe200() public { +// Assert.equal(foo.get(), 200, "initial value is not correct"); +// } +// +//} + +contract MyTest { + SimpleStorage foo; + uint i = 0; + + function beforeEach() { + foo = new SimpleStorage(); + //if (i == 1) { + // foo.set(200); + //} + //i += 1; + } + + function initialValueShouldBe100() public constant returns (bool) { + return Assert.equal(foo.get(), 100, "initial value is not correct"); + } + + //function initialValueShouldBe200() public constant returns (bool) { + // return Assert.equal(foo.get(), 200, "initial value is not correct"); + //} + +} + + diff --git a/mytest.sol b/mytest.sol new file mode 100644 index 0000000000..3b1c4fb2fe --- /dev/null +++ b/mytest.sol @@ -0,0 +1,20 @@ +pragma solidity ^0.4.7; +import "./tests.sol"; + +contract MyTest { + SimpleStorage foo; + + function beforeAll() { + foo = new SimpleStorage(); + } + + function initialValueShouldBe100() public { + Assert.equal(foo.get(), 100, "initial value is not correct"); + } + + function initialValueShouldBe200() public { + Assert.equal(foo.get(), 200, "initial value is not correct"); + } + +} + diff --git a/sol/tests.sol b/sol/tests.sol index d4a3975b8a..c439054b12 100644 --- a/sol/tests.sol +++ b/sol/tests.sol @@ -15,6 +15,8 @@ library Assert { function equal(uint a, uint b, string message) public returns (bool result) { result = (a == b); AssertionEvent(result, message); + //result = true; + //return true; } function equal(int a, int b, string message) public returns (bool result) { @@ -60,43 +62,43 @@ library Assert { AssertionEvent(result, message); } - function notEqual(int a, int b, string message) public returns (bool result) { - result = (a != b); - AssertionEvent(result, message); - } - - function notEqual(bool a, bool b, string message) public returns (bool result) { - result = (a != b); - AssertionEvent(result, message); - } - - // TODO: only for certain versions of solc - //function notEqual(fixed a, fixed b, string message) public returns (bool result) { - // result = (a != b); - // AssertionEvent(result, message); - //} - - // TODO: only for certain versions of solc - //function notEqual(ufixed a, ufixed b, string message) public returns (bool result) { - // result = (a != b); - // AssertionEvent(result, message); - //} - - function notEqual(address a, address b, string message) public returns (bool result) { - result = (a != b); - AssertionEvent(result, message); - } - - function notEqual(bytes32 a, bytes32 b, string message) public returns (bool result) { - result = (a != b); - AssertionEvent(result, message); - } - - // TODO: needs to be convert to bytes first to be comparable - //function notEqual(string a, string b, string message) public returns (bool result) { - // result = (a != b); - // AssertionEvent(result, message); - //} +// function notEqual(int a, int b, string message) public returns (bool result) { +// result = (a != b); +// AssertionEvent(result, message); +// } + +// function notEqual(bool a, bool b, string message) public returns (bool result) { +// result = (a != b); +// AssertionEvent(result, message); +// } +// +// // TODO: only for certain versions of solc +// //function notEqual(fixed a, fixed b, string message) public returns (bool result) { +// // result = (a != b); +// // AssertionEvent(result, message); +// //} +// +// // TODO: only for certain versions of solc +// //function notEqual(ufixed a, ufixed b, string message) public returns (bool result) { +// // result = (a != b); +// // AssertionEvent(result, message); +// //} +// +// function notEqual(address a, address b, string message) public returns (bool result) { +// result = (a != b); +// AssertionEvent(result, message); +// } +// +// function notEqual(bytes32 a, bytes32 b, string message) public returns (bool result) { +// result = (a != b); +// AssertionEvent(result, message); +// } +// +// // TODO: needs to be convert to bytes first to be comparable +// //function notEqual(string a, string b, string message) public returns (bool result) { +// // result = (a != b); +// // AssertionEvent(result, message); +// //} } diff --git a/src/compiler.js b/src/compiler.js index dc74d2d1a4..b3c73008b0 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -17,6 +17,8 @@ function compileFileOrFiles (filename, isDirectory, cb) { // should be replaced with remix's & browser solidity compiler code filepath = (isDirectory ? filename : path.dirname(filename)) + //sources[filename] = {content: fs.readFileSync(path.join(filepath, filename)).toString()} + //console.dir(sources); fs.readdirSync(filepath).forEach(file => { sources[file] = {content: fs.readFileSync(path.join(filepath, file)).toString()} }) @@ -36,7 +38,9 @@ function compileFileOrFiles (filename, isDirectory, cb) { compiler.compile(sources, filepath) } ], function (err, result) { - let errors = result.errors.filter((e) => e.type === 'Error') + console.dir(err); + console.dir(result); + let errors = (result.errors || []).filter((e) => e.type === 'Error') if (errors.length > 0) { console.dir(errors) return cb(new Error('errors compiling')) diff --git a/src/txProcess.js b/src/txProcess.js index 89a421f277..b7bb1ab21f 100644 --- a/src/txProcess.js +++ b/src/txProcess.js @@ -12,6 +12,7 @@ function runTx(payload, from, to, data, value, gasLimit, txRunner, callbacks, is let finalCallback = function(err, result) { let toReturn; if (isCall) { + console.dir('---- result is '); console.dir(result.result.vm.return); console.dir(result.result.vm); toReturn = "0x" + result.result.vm.return.toString('hex') @@ -25,7 +26,7 @@ function runTx(payload, from, to, data, value, gasLimit, txRunner, callbacks, is callback(null, jsonRPCResponse(payload.id, toReturn)) } - TxExecution.callFunction(from, to, data, value, gasLimit, null, txRunner, callbacks, finalCallback) + TxExecution.callFunction(from, to, data, value, gasLimit, null, txRunner, callbacks, finalCallback, isCall) } function createContract(payload, from, data, value, gasLimit, txRunner, callbacks, callback) { diff --git a/test.js b/test.js new file mode 100644 index 0000000000..4dcdc56680 --- /dev/null +++ b/test.js @@ -0,0 +1,62 @@ +var async = require('async') +const Web3 = require('web3') +const Provider = require('./src/provider.js') +const Compiler = require('./src/compiler.js') + +let web3 = new Web3() +web3.setProvider(new Provider()) +let accounts = []; + +async.waterfall([ + function compileContract(next) { + Compiler.compileFileOrFiles('test.sol', false, next); + }, + function getAccounts(contracts, next) { + web3.eth.getAccounts((err, _accounts) => { + accounts = _accounts; + next(null, contracts); + }); + }, + function deployContract(contracts, next) { + let contract = contracts['test.sol'].SimpleStorage; + let abi = contract.abi; + let code = contract.evm.bytecode.object; + + console.dir(contracts); + + let contractObject = new web3.eth.Contract(abi) + let deployObject = contractObject.deploy({arguments: [], data: code}) + + deployObject.send({ + from: accounts[0], + gas: 1200000 + }).on('receipt', function (receipt) { + console.dir("==== got the receipt"); + console.dir(receipt); + + contractObject.options.address = receipt.contractAddress + contractObject.options.from = accounts[0] + contractObject.options.gas = 5000 * 1000 + //next(null, receipt.contractAddress); + next(null, contractObject); + }) + }, + function callContract(contract, next) { + console.dir('=============='); + console.dir(contract); + + //contract.methods.storedData().call(console.dir); + //contract.methods.get().call(console.dir); + contract.methods.set(50).send({from: accounts[0]}).then(() => { + console.dir('value was set'); + next(null, contract); + }); + }, + function callContract2(contract, next) { + contract.methods.get2().call(console.dir); + next(null, contract); + } +], function(err, results) { + //console.dir(arguments); +}); + diff --git a/test.sol b/test.sol new file mode 100644 index 0000000000..807ecdecd4 --- /dev/null +++ b/test.sol @@ -0,0 +1,22 @@ +pragma solidity ^0.4.7; +contract SimpleStorage { + uint public storedData; + + function SimpleStorage() public { + storedData = 100; + } + + function set(uint x) public { + storedData = x; + } + + function get() public view returns (uint retVal) { + return storedData; + } + + function get2() public constant returns (bool) { + return storedData != 2; + } + +} +