2018-05-17 17:52:09 +00:00
|
|
|
/*global describe, it*/
|
2018-05-14 18:04:26 +00:00
|
|
|
const assert = require('assert');
|
|
|
|
const sinon = require('sinon');
|
2018-05-17 17:52:09 +00:00
|
|
|
const AccountParser = require('../lib/contracts/accountParser');
|
2018-05-14 18:04:26 +00:00
|
|
|
let TestLogger = require('../lib/tests/test_logger.js');
|
|
|
|
|
2018-05-17 17:52:09 +00:00
|
|
|
describe('embark.AccountParser', function () {
|
2018-05-14 18:04:26 +00:00
|
|
|
describe('#getAccount', function () {
|
2018-05-17 17:52:09 +00:00
|
|
|
const web3 = {
|
|
|
|
eth: {
|
|
|
|
accounts: {
|
|
|
|
privateKeyToAccount: sinon.stub().callsFake((key) => {
|
|
|
|
return {key};
|
|
|
|
})
|
2018-05-14 18:04:26 +00:00
|
|
|
}
|
2018-05-18 17:44:03 +00:00
|
|
|
},
|
|
|
|
utils: {
|
|
|
|
isHexStrict: sinon.stub().returns(true)
|
2018-05-17 17:52:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
const testLogger = new TestLogger({});
|
2018-05-14 18:04:26 +00:00
|
|
|
|
|
|
|
it('should return one account with the key', function () {
|
2018-05-17 17:52:09 +00:00
|
|
|
const account = AccountParser.getAccount({
|
2018-05-14 18:04:26 +00:00
|
|
|
privateKey: 'myKey'
|
2018-05-17 17:52:09 +00:00
|
|
|
}, web3, testLogger);
|
2018-05-14 18:04:26 +00:00
|
|
|
|
2018-05-14 21:03:39 +00:00
|
|
|
assert.deepEqual(account, {key: '0xmyKey'});
|
2018-05-14 18:04:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return two accounts from the keys in the file', function () {
|
2018-05-17 17:52:09 +00:00
|
|
|
const account = AccountParser.getAccount({
|
2018-05-14 18:04:26 +00:00
|
|
|
privateKeyFile: 'test/keyFiles/twoKeys'
|
2018-05-17 17:52:09 +00:00
|
|
|
}, web3, testLogger);
|
2018-05-14 18:04:26 +00:00
|
|
|
|
|
|
|
assert.deepEqual(account, [
|
2018-05-14 21:03:39 +00:00
|
|
|
{key: '0xkey1'},
|
|
|
|
{key: '0xkey2'}
|
2018-05-14 18:04:26 +00:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return one account from the mnemonic', function () {
|
2018-05-17 17:52:09 +00:00
|
|
|
const account = AccountParser.getAccount({
|
2018-05-14 18:04:26 +00:00
|
|
|
mnemonic: 'example exile argue silk regular smile grass bomb merge arm assist farm'
|
2018-05-17 17:52:09 +00:00
|
|
|
}, web3, testLogger);
|
2018-05-14 18:04:26 +00:00
|
|
|
|
|
|
|
assert.deepEqual(account,
|
2018-05-15 15:40:35 +00:00
|
|
|
[{key: "0xf942d5d524ec07158df4354402bfba8d928c99d0ab34d0799a6158d56156d986"}]);
|
2018-05-14 18:04:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return two accounts from the mnemonic using numAddresses', function () {
|
2018-05-17 17:52:09 +00:00
|
|
|
const account = AccountParser.getAccount({
|
2018-05-14 18:04:26 +00:00
|
|
|
mnemonic: 'example exile argue silk regular smile grass bomb merge arm assist farm',
|
|
|
|
numAddresses: 2
|
2018-05-17 17:52:09 +00:00
|
|
|
}, web3, testLogger);
|
2018-05-14 18:04:26 +00:00
|
|
|
|
|
|
|
assert.deepEqual(account,
|
|
|
|
[
|
2018-05-15 15:40:35 +00:00
|
|
|
{key: "0xf942d5d524ec07158df4354402bfba8d928c99d0ab34d0799a6158d56156d986"},
|
|
|
|
{key: "0x88f37cfbaed8c0c515c62a17a3a1ce2f397d08bbf20dcc788b69f11b5a5c9791"}
|
2018-05-14 18:04:26 +00:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return nothing with bad config', function () {
|
2018-05-17 17:52:09 +00:00
|
|
|
const account = AccountParser.getAccount({
|
2018-05-14 18:04:26 +00:00
|
|
|
badConfig: 'not working'
|
2018-05-17 17:52:09 +00:00
|
|
|
}, web3, testLogger);
|
2018-05-14 18:04:26 +00:00
|
|
|
|
|
|
|
assert.strictEqual(account, null);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|