fix: use right accounts for contract deployment

This commit is contained in:
Andre Medeiros 2019-02-14 13:57:11 -05:00 committed by Iuri Matias
parent b5a3897795
commit 576836df87
6 changed files with 27 additions and 14 deletions

View File

@ -165,7 +165,8 @@ class BlockchainConnector {
logger: this.logger,
isDev: this.isDev,
type: type,
web3Endpoint: self.web3Endpoint
web3Endpoint: self.web3Endpoint,
events: this.events
};
this.provider = new Provider(providerOptions);

View File

@ -14,7 +14,13 @@ class Provider {
this.web3Endpoint = options.web3Endpoint;
this.logger = options.logger;
this.isDev = options.isDev;
this.events = options.events;
this.nonceCache = {};
this.events.setCommandHandler("blockchain:provider:contract:accounts:get", cb => {
const accounts = this.accounts.map(a => a.address);
cb(accounts);
});
}
getNonce(address, callback) {
@ -123,7 +129,7 @@ class Provider {
return cb(err);
}
if (self.accounts.length) {
result.result = self.addresses; // Send our addresses
result.result = self.blockchainAccounts.map(a => a.address);
}
cb(null, result);
});

View File

@ -113,10 +113,7 @@ class ContractDeployer {
// TODO: can potentially go to a beforeDeploy plugin
function getAccounts(next) {
deploymentAccount = self.blockchain.defaultAccount();
self.blockchain.getAccounts(function (err, _accounts) {
if (err) {
return next(new Error(err));
}
self.events.request('blockchain:provider:contract:accounts:get', _accounts => {
accounts = _accounts;
// applying deployer account configuration, if any

View File

@ -26,6 +26,10 @@ class Test {
this.provider = null;
this.accounts = [];
this.embarkjs = {};
this.events.setCommandHandler("blockchain:provider:contract:accounts:get", cb => {
cb(this.accounts);
});
}
init(callback) {

View File

@ -65,10 +65,12 @@ class AccountParser {
logger.warn(`Private key ending with ${accountConfig.privateKey.substr(accountConfig.privateKey.length - 5)} is not a HEX string`);
return null;
}
const key = Buffer.from(accountConfig.privateKey.substr(2), 'hex');
if (returnAddress) {
return ethereumjsWallet.fromPrivateKey(accountConfig.privateKey).getChecksumAddressString();
return ethereumjsWallet.fromPrivateKey(key).getChecksumAddressString();
}
return Object.assign(web3.eth.accounts.privateKeyToAccount(accountConfig.privateKey), {hexBalance});
return Object.assign(web3.eth.accounts.privateKeyToAccount(key), {hexBalance});
}
if (accountConfig.privateKeyFile) {
@ -103,6 +105,9 @@ class AccountParser {
logger.warn(`Private key is not a HEX string in file ${accountConfig.privateKeyFile} at index ${index}`);
return null;
}
key = Buffer.from(key.substr(2), 'hex');
if (returnAddress) {
return ethereumjsWallet.fromPrivateKey(key).getChecksumAddressString();
}

View File

@ -38,7 +38,7 @@ describe('embark.AccountParser', function () {
privateKey: 'myKey'
}, web3, testLogger);
assert.deepEqual(account, {key: '0xmyKey', hexBalance: null});
assert.deepEqual(account, {key: Buffer.from('myKey', 'hex'), hexBalance: null});
});
it('should return two accounts from the keys in the file', function () {
@ -47,8 +47,8 @@ describe('embark.AccountParser', function () {
}, web3, testLogger);
assert.deepEqual(account, [
{key: '0xkey1', hexBalance: null},
{key: '0xkey2', hexBalance: null}
{key: Buffer.from('key1', 'hex'), hexBalance: null},
{key: Buffer.from('key2', 'hex'), hexBalance: null}
]);
});