fix linking issue

pull/7/head
Iuri Matias 7 years ago
parent a23965a270
commit 8a0697dc73
  1. 8
      examples/simple_storage_test.sol
  2. 10
      sol/tests.sol
  3. 5
      src/compiler.js
  4. 56
      src/deployer.js

@ -10,13 +10,13 @@ contract MyTest {
} }
function initialValueShouldBe100() public constant returns (bool) { function initialValueShouldBe100() public constant returns (bool) {
//return Assert.equal(foo.get(), 100, "initial value is not correct"); return Assert.equal(foo.get(), 100, "initial value is not correct");
return foo.get() == 100; //return foo.get() == 100;
} }
function initialValueShouldBe200() public constant returns (bool) { function initialValueShouldBe200() public constant returns (bool) {
//return Assert.equal(foo.get(), 200, "initial value is not correct"); return Assert.equal(foo.get(), 200, "initial value is not correct");
return foo.get() == 200; //return foo.get() == 200;
} }
} }

@ -2,8 +2,14 @@ pragma solidity ^0.4.7;
library Assert { library Assert {
function equal(uint a, uint b, string text) { event AssertionEvent(
//return a == b; bool indexed passed,
string message
);
function equal(uint a, uint b, string message) public returns (bool result) {
result = (a == b);
AssertionEvent(result, message);
} }
} }

@ -36,6 +36,11 @@ function compileFileOrFiles (filename, isDirectory, cb) {
compiler.compile(sources, filepath) compiler.compile(sources, filepath)
} }
], function (err, result) { ], function (err, result) {
let errors = result.errors.filter((e) => e.type === 'Error');
if (errors.length > 0) {
console.dir(errors);
return cb("errors compiling");
}
cb(err, result.contracts) cb(err, result.contracts)
}) })
} }

@ -30,12 +30,32 @@ function deployAll (compileResult, web3, callback) {
compiledObject[className].code = code compiledObject[className].code = code
compiledObject[className].filename = filename compiledObject[className].filename = filename
compiledObject[className].className = className compiledObject[className].className = className
if (contractFile.indexOf("_test.sol") >=0 ) {
compiledObject[className].isTest = true
}
} }
} }
next() next()
}, },
function deployContracts (next) { function determineContractsToDeploy (next) {
async.eachOfLimit(compiledObject, 1, function (contract, contractName, nextEach) { let contractsToDeploy = ['Assert'];
let allContracts = Object.keys(compiledObject);
for (let contractName of allContracts) {
if (contractName === 'Assert') {
continue;
}
if (compiledObject[contractName].isTest) {
contractsToDeploy.push(contractName)
}
}
next(null, contractsToDeploy);
},
function deployContracts (contractsToDeploy, next) {
async.eachOfLimit(contractsToDeploy, 1, function (contractName, index, nextEach) {
let contract = compiledObject[contractName];
console.dir('deploying... ' + contractName);
let contractObject = new web3.eth.Contract(contract.abi) let contractObject = new web3.eth.Contract(contract.abi)
let contractCode = '0x' + contract.code let contractCode = '0x' + contract.code
@ -54,22 +74,32 @@ function deployAll (compileResult, web3, callback) {
throw new Error('linking not found for ' + name + ' when deploying ' + contractName) throw new Error('linking not found for ' + name + ' when deploying ' + contractName)
} }
contractCode = contractCode.replace(new RegExp(toReplace, 'g'), contractObj.deployedAddress) console.dir("replacing " + toReplace + " with " + contractObj.deployedAddress);
contractCode = contractCode.replace(new RegExp(toReplace, 'g'), contractObj.deployedAddress.slice(2))
} }
contractObject.deploy({arguments: [], data: contractCode}).send({ console.dir(contractCode);
from: accounts[0],
gas: 4000 * 1000 let deployObject = contractObject.deploy({arguments: [], data: contractCode});
}).on('receipt', function (receipt) {
contractObject.options.address = receipt.contractAddress
contractObject.options.from = accounts[0]
contractObject.options.gas = 4000 * 1000
compiledObject[contractName].deployedAddress = receipt.contractAddress
contracts[contractName] = contractObject console.dir("estimating gas...");
deployObject.estimateGas().then((gasValue) => {
console.dir("gas value is " + gasValue);
deployObject.send({
from: accounts[0],
gas: 5000 * 1000
}).on('receipt', function (receipt) {
contractObject.options.address = receipt.contractAddress
contractObject.options.from = accounts[0]
contractObject.options.gas = 5000 * 1000
compiledObject[contractName].deployedAddress = receipt.contractAddress
nextEach() contracts[contractName] = contractObject
nextEach()
})
}) })
}, function () { }, function () {
next(null, contracts) next(null, contracts)
}) })

Loading…
Cancel
Save