add test poc to attempt to replicate/fix tx issue

pull/3094/head
Iuri Matias 7 years ago
parent 9d419856e8
commit 23a35cf746
  1. 17
      examples2/simple_storage.sol
  2. 26
      examples2/simple_storage2_test.sol
  3. 44
      examples2/simple_storage_test.sol
  4. 20
      mytest.sol
  5. 76
      sol/tests.sol
  6. 6
      src/compiler.js
  7. 3
      src/txProcess.js
  8. 62
      test.js
  9. 22
      test.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;
}
}

@ -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");
//}
}

@ -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");
//}
}

@ -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");
}
}

@ -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);
// //}
}

@ -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'))

@ -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) {

@ -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);
});

@ -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;
}
}
Loading…
Cancel
Save