enable using accounts and balances

This commit is contained in:
Jonathan Rainville 2018-06-06 15:33:48 -04:00
parent ac631f90dc
commit 30a8263569
2 changed files with 38 additions and 8 deletions

View File

@ -6,6 +6,7 @@ const utils = require('../utils/utils');
const constants = require('../constants'); const constants = require('../constants');
const Events = require('../core/events'); const Events = require('../core/events');
const cloneDeep = require('clone-deep'); const cloneDeep = require('clone-deep');
const AccountParser = require('../contracts/accountParser');
function getSimulator() { function getSimulator() {
try { try {
@ -36,12 +37,7 @@ class Test {
this.compiledContracts = {}; this.compiledContracts = {};
this.web3 = new Web3(); this.web3 = new Web3();
if (this.simOptions.node) { this.initWeb3Provider();
this.web3.setProvider(new this.web3.providers.HttpProvider(this.simOptions.node));
} else {
this.sim = getSimulator();
this.web3.setProvider(this.sim.provider(this.simOptions));
}
this.engine = new Engine({ this.engine = new Engine({
env: this.options.env || 'test', env: this.options.env || 'test',
@ -55,11 +51,32 @@ class Test {
}); });
this.versions_default = this.engine.config.contractsConfig.versions; this.versions_default = this.engine.config.contractsConfig.versions;
const deploymentConfig = this.engine.config.contractsConfig.versions;
// Reset contract config to nothing to make sure we deploy only what we want // Reset contract config to nothing to make sure we deploy only what we want
this.engine.config.contractsConfig = {contracts: {}, versions: this.versions_default}; this.engine.config.contractsConfig = {contracts: {}, versions: this.versions_default, deployment: deploymentConfig};
this.engine.startService("libraryManager"); this.engine.startService("libraryManager");
this.engine.startService("codeRunner"); this.engine.startService("codeRunner");
this.initDeployServices();
this.engine.startService("codeGenerator");
}
initWeb3Provider() {
if (this.simOptions.node) {
this.web3.setProvider(new this.web3.providers.HttpProvider(this.simOptions.node));
} else {
if (this.simOptions.accounts) {
this.simOptions.accounts = this.simOptions.accounts.map((account, index) => {
return {balance: this.options.deployment.accounts[index].balance || 0xFFFFFFFFFFFFFFFFFF,
secretKey: account.privateKey};
});
}
this.sim = getSimulator();
this.web3.setProvider(this.sim.provider(this.simOptions));
}
}
initDeployServices() {
this.engine.startService("web3", { this.engine.startService("web3", {
web3: this.web3 web3: this.web3
}); });
@ -67,7 +84,6 @@ class Test {
trackContracts: false, trackContracts: false,
ipcRole: 'client' ipcRole: 'client'
}); });
this.engine.startService("codeGenerator");
} }
init(callback) { init(callback) {
@ -100,6 +116,13 @@ class Test {
this.simOptions = this.options.simulatorOptions || {}; this.simOptions = this.options.simulatorOptions || {};
this.ready = false; this.ready = false;
if (this.options.deployment && this.options.deployment.accounts) {
// Account setup
this.simOptions.accounts = AccountParser.parseAccountsConfig(this.options.deployment.accounts, this.web3);
this.initWeb3Provider();
this.initDeployServices();
}
// Reset contracts // Reset contracts
this.engine.contractsManager.contracts = cloneDeep(this.builtContracts); this.engine.contractsManager.contracts = cloneDeep(this.builtContracts);
this.engine.contractsManager.compiledContracts = cloneDeep(this.compiledContracts); this.engine.contractsManager.compiledContracts = cloneDeep(this.compiledContracts);

View File

@ -4,6 +4,13 @@ const AnotherStorage = embark.require('Embark/contracts/AnotherStorage');
const SimpleStorage = embark.require('Embark/contracts/SimpleStorage'); const SimpleStorage = embark.require('Embark/contracts/SimpleStorage');
config({ config({
deployment: {
"accounts": [
{
"mnemonic": "example exile argue silk regular smile grass bomb merge arm assist farm"
}
]
},
contracts: { contracts: {
"SimpleStorage": { "SimpleStorage": {
args: [100] args: [100]