mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-27 21:00:46 +00:00
fix(@embark/core): Fix contract testing with remix_tests
Remix_test-injected contract files were not correctly being tested due to an update in the `remix-tests` signature. I'm really not sure how tests were not completely bombing out during testing. This PR introduces a few changes: 1. Ensure all contract files have been compiled before skipping compilation. This can occur if contract files have been added after a compilation round has already completed (ie in the tests). 2. Update solc tests to support latest `remix_tests.runTests` signature and include `userdoc` in compiled contracts. 3. Ensure `EmbarkJS` is reset before executing solc tests - like in the js tests, this is required for built EmbarkJS contract objects to behave correctly when it's functions are executed against the chain. 4. Refactor “all files already compiled” function. BLOCKER: base branch `feat/replace-node-vm` must be merged in https://github.com/embark-framework/embark/pull/1234 before this can be merged.
This commit is contained in:
parent
c1a5bfee3c
commit
02305fa4e5
@ -291,9 +291,21 @@ class ContractsManager {
|
|||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function compileContracts(callback) {
|
function allContractsCompiled(callback) {
|
||||||
|
const allContractsCompiled =
|
||||||
|
self.compiledContracts &&
|
||||||
|
self.contractsFiles &&
|
||||||
|
self.contractsFiles.every(contractFile =>
|
||||||
|
Object.values(self.compiledContracts).find(contract =>
|
||||||
|
contract.originalFilename === contractFile.filename
|
||||||
|
)
|
||||||
|
);
|
||||||
|
callback(null, allContractsCompiled);
|
||||||
|
},
|
||||||
|
function compileContracts(allContractsCompiled, callback) {
|
||||||
self.events.emit("status", __("Compiling..."));
|
self.events.emit("status", __("Compiling..."));
|
||||||
if (self.compileOnceOnly && self.compiledContracts && Object.keys(self.compiledContracts).length) {
|
const hasCompiledContracts = self.compiledContracts && Object.keys(self.compiledContracts).length;
|
||||||
|
if (self.compileOnceOnly && hasCompiledContracts && allContractsCompiled) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
self.events.request("compiler:contracts", self.contractsFiles, compilerOptions, function (err, compiledObject) {
|
self.events.request("compiler:contracts", self.contractsFiles, compilerOptions, function (err, compiledObject) {
|
||||||
|
@ -143,6 +143,7 @@ class Solidity {
|
|||||||
compiled_object[className].gasEstimates = contract.evm.gasEstimates;
|
compiled_object[className].gasEstimates = contract.evm.gasEstimates;
|
||||||
compiled_object[className].functionHashes = contract.evm.methodIdentifiers;
|
compiled_object[className].functionHashes = contract.evm.methodIdentifiers;
|
||||||
compiled_object[className].abiDefinition = contract.abi;
|
compiled_object[className].abiDefinition = contract.abi;
|
||||||
|
compiled_object[className].userdoc = contract.userdoc;
|
||||||
compiled_object[className].filename = filename;
|
compiled_object[className].filename = filename;
|
||||||
compiled_object[className].originalFilename = originalFilepaths[filename];
|
compiled_object[className].originalFilename = originalFilepaths[filename];
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,11 @@ class SolcTest extends Test {
|
|||||||
fns.push(fn);
|
fns.push(fn);
|
||||||
});
|
});
|
||||||
async.series(fns, next);
|
async.series(fns, next);
|
||||||
|
},
|
||||||
|
function resetEmbarkJs(file, next) {
|
||||||
|
self.resetEmbarkJS((err) => {
|
||||||
|
next(err, file);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
], cb);
|
], cb);
|
||||||
}
|
}
|
||||||
@ -97,13 +102,25 @@ class SolcTest extends Test {
|
|||||||
next(null, contracts, web3);
|
next(null, contracts, web3);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function run(contracts, web3, next) {
|
function getAccounts(contracts, web3, next) {
|
||||||
|
self.events.request('blockchain:getAccounts', (err, accounts) => {
|
||||||
|
if (err) return next(err);
|
||||||
|
next(null, contracts, web3, accounts);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function run(contracts, web3, accounts, next) {
|
||||||
let fns = [];
|
let fns = [];
|
||||||
contracts.forEach((contract) => {
|
contracts.forEach((contract) => {
|
||||||
let fn = (_callback) => {
|
let fn = (_callback) => {
|
||||||
// TODO: web3 is not injected into the function. Issue has been raised on remixTests.
|
// TODO: web3 is not injected into the function. Issue has been raised on remixTests.
|
||||||
// To fix once web3 has been made injectable.
|
// To fix once web3 has been made injectable.
|
||||||
remixTests.runTest(contract.className, Test.getWeb3Contract(contract, web3),
|
const contractDetails = {
|
||||||
|
userdoc: (contract.userdoc || { methods: [] }),
|
||||||
|
evm: {
|
||||||
|
methodIdentifiers: contract.functionHashes
|
||||||
|
}
|
||||||
|
};
|
||||||
|
remixTests.runTest(contract.className, Test.getWeb3Contract(contract, web3), contractDetails, {accounts},
|
||||||
self._prettyPrint.bind(self), _callback);
|
self._prettyPrint.bind(self), _callback);
|
||||||
};
|
};
|
||||||
fns.push(fn);
|
fns.push(fn);
|
||||||
|
@ -219,27 +219,9 @@ class Test {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
function changeGlobalWeb3(accounts, next) {
|
function changeGlobalWeb3(accounts, next) {
|
||||||
self.events.request('blockchain:get', (web3) => {
|
self.resetEmbarkJS((err) => {
|
||||||
global.web3 = web3;
|
|
||||||
self.vm = new VM({
|
|
||||||
sandbox: {
|
|
||||||
EmbarkJS,
|
|
||||||
web3: web3,
|
|
||||||
Web3: Web3,
|
|
||||||
IpfsApi
|
|
||||||
}
|
|
||||||
});
|
|
||||||
self.events.request("code-generator:embarkjs:provider-code", (code) => {
|
|
||||||
self.vm.doEval(code, false, (err, _result) => {
|
|
||||||
if(err) return next(err);
|
|
||||||
self.events.request("code-generator:embarkjs:init-provider-code", (code) => {
|
|
||||||
self.vm.doEval(code, false, (err, _result) => {
|
|
||||||
next(err, accounts);
|
next(err, accounts);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
], (err, accounts) => {
|
], (err, accounts) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -250,6 +232,30 @@ class Test {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetEmbarkJS(cb) {
|
||||||
|
this.events.request('blockchain:get', (web3) => {
|
||||||
|
global.web3 = web3;
|
||||||
|
this.vm = new VM({
|
||||||
|
sandbox: {
|
||||||
|
EmbarkJS,
|
||||||
|
web3: web3,
|
||||||
|
Web3: Web3,
|
||||||
|
IpfsApi
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.events.request("code-generator:embarkjs:provider-code", (code) => {
|
||||||
|
this.vm.doEval(code, false, (err, _result) => {
|
||||||
|
if(err) return cb(err);
|
||||||
|
this.events.request("code-generator:embarkjs:init-provider-code", (code) => {
|
||||||
|
this.vm.doEval(code, false, (err, _result) => {
|
||||||
|
cb(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async deploy(contract, deployArgs = {}, sendArgs = {}) {
|
async deploy(contract, deployArgs = {}, sendArgs = {}) {
|
||||||
const instance = await contract.deploy(deployArgs).send(sendArgs);
|
const instance = await contract.deploy(deployArgs).send(sendArgs);
|
||||||
this.events.emit("tests:manualDeploy", instance);
|
this.events.emit("tests:manualDeploy", instance);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user