}
-
contractInstance[testFunction]({
from: that.web3.eth.defaultAccount,
gas: DEFAULT_GAS
diff --git a/lib/streams/test.js b/lib/streams/test.js
index 75aa04c..870edd6 100644
--- a/lib/streams/test.js
+++ b/lib/streams/test.js
@@ -20,52 +20,53 @@ module.exports = function (opts) {
return through.obj(function (file, enc, cb) {
var that = this;
var classes = JSON.parse(String(file.contents));
-
+
// Skip if Test contract isn't found
if( !("Test" in classes) ) return cb()
-
+
// Load the Test contract
try {
var testContract = new Contract(classes['Test']);
} catch (err) {
return cb(err);
}
-
+
+ var web3;
+ if (opts.web3 == 'internal') {
+ web3 = Web3Factory.EVM();
+ } else {
+ try {
+ web3 = Web3Factory.JSONRPC(opts.web3);
+ } catch (e) {
+ this.push(new File({
+ path: "JSON-RPC Connection/Can't connect.stderr",
+ contents: new Buffer(String(e))
+ }));
+ cb();
+ return;
+ }
+ }
+
for (var className in classes) {
-
+
// Filter classNames if a filter is present if a filter is present
if ( opts.nameFilter && !opts.nameFilter.test( className ) ) {
continue;
}
-
+
try {
var contract = new Contract(classes[className]);
} catch(err) {
return cb(err);
}
-
+
// way to determine if the class is a test,
// iff it has implemented the Test interface
- if (_.intersection( contract.signatures, testContract.signatures ).length != testContract.signatures.length) {
+ if (_.intersection(contract.signatures, testContract.signatures)
+ .length != testContract.signatures.length) {
continue;
}
- var web3;
- if (opts.web3 == 'internal') {
- web3 = Web3Factory.EVM();
- } else {
- try {
- web3 = Web3Factory.JSONRPC(opts.web3);
- } catch (e) {
- this.push(new File({
- path: "JSON-RPC Connection/Can't connect.stderr",
- contents: new Buffer(String(e))
- }));
- cb();
- return;
- }
- }
-
// **TODO**: Run all tests in chain forks at the same height.
var remaining = -1;
var logTranslator = new LogTranslator(contract.abi);
@@ -75,7 +76,7 @@ module.exports = function (opts) {
var errored = false;
var logTestResult = function(err, result) {
- if (errored) return;
+ if (errored || that.isPaused()) return;
if (err) {
that.push(new File({
@@ -118,6 +119,7 @@ module.exports = function (opts) {
contents: new Buffer(output)
});
that.push(file);
+
remaining = remaining - 1;
errored = result.failed;
};
diff --git a/lib/vmtest.js b/lib/vmtest.js
index 3c1ba80..76714d4 100644
--- a/lib/vmtest.js
+++ b/lib/vmtest.js
@@ -70,15 +70,67 @@ module.exports = class VMTest {
var contractClass = that.web3.eth.contract(that.contract.abi);
- that.deploy(function (err, receipt) {
+ var runTestOn = function (contract) {
+ that.runInstanceTestByName(contract, that.tests[testIndex], cb);
+ };
+
+ var setUpHandlerFor = function (contract) {
+ return function (err, txHash) {
+ if (err) {
+ return cb(err);
+ }
+
+ that.web3.eth.getTransactionReceipt(txHash, function(err, receipt) {
+ if( receipt === null && err === null) {
+ err = "setUp failed - exception thrown";
+ }
+
+ if (err) {
+ var testResult = {
+ title: "setUp failed",
+ message: err,
+ logs: [],
+ failed: true
+ };
+ cb(err, testResult);
+ return;
+ }
+
+ runTestOn(contract);
+ });
+ };
+ };
+
+ var getCodeHandlerFor = function(address) {
+ return function (err, code) {
+ if (err) {
+ return cb(err);
+ }
+
+ if (code === '0x') {
+ return cb("Contract failed to deploy.");
+ }
+
+ var contract = contractClass.at(address);
+
+ if( contract.setUp !== undefined ) {
+ contract.setUp(setUpHandlerFor(contract));
+ }
+ else {
+ runTestOn(contract);
+ }
+ };
+ };
+
+ var deployHandler = function (err, receipt) {
if (err) {
return cb(err);
}
+ that.web3.eth.getCode(receipt.contractAddress,
+ getCodeHandlerFor(receipt.contractAddress));
+ };
- that.runInstanceTestByName(
- contractClass.at(receipt.contractAddress),
- that.tests[testIndex], cb);
- });
+ that.deploy(deployHandler);
}
testCount() {
@@ -126,7 +178,7 @@ module.exports = class VMTest {
if( receipt == null ) {
failed = true;
logs = [];
- message = "Transaction failed - no logs available.";
+ message = "test failed - exception thrown";
} else {
failed = failed || Boolean(err);
message = err ? err : (failed ? "Failed!" : "Passed!");
@@ -148,14 +200,6 @@ module.exports = class VMTest {
});
};
- if( contractInstance.setUp !== undefined ) {
- contractInstance.setUp(function () {}); // No-op function is
- // a workaround for a
- // bug that needs to
- // be properly handled.
- // (TODO)
- }
-
contractInstance[testFunction]({
from: that.web3.eth.defaultAccount,
gas: DEFAULT_GAS
a workaround for a -bug that needs to -be properly handled. -(TODO)