From 3f09d5d3f06516358a009548d46f5f88f9fdb2cd Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 14 May 2018 14:04:26 -0400 Subject: [PATCH] add tests for getContract --- lib/core/provider.js | 1 + lib/i18n/locales/en.json | 5 ++- test/keyFiles/twoKeys | 1 + test/provider.js | 81 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 test/keyFiles/twoKeys create mode 100644 test/provider.js diff --git a/lib/core/provider.js b/lib/core/provider.js index 19503ab2..f4544cca 100644 --- a/lib/core/provider.js +++ b/lib/core/provider.js @@ -83,6 +83,7 @@ class Provider { this.logger.warn('Unsupported account configuration: ' + JSON.stringify(accountConfig)); this.logger.warn('Try using one of those: ' + '{ "privateKey": "your-private-key", "privateKeyFile": "path/to/file/containing/key", "mnemonic": "12 word mnemonic" }'); + return null; } eth_accounts(payload, cb) { diff --git a/lib/i18n/locales/en.json b/lib/i18n/locales/en.json index b2788aed..6d5b161e 100644 --- a/lib/i18n/locales/en.json +++ b/lib/i18n/locales/en.json @@ -85,5 +85,8 @@ "Init complete": "Init complete", "App ready at ": "App ready at ", "already initialized": "already initialized", - "deployed at": "deployed at" + "deployed at": "deployed at", + "executing onDeploy commands": "executing onDeploy commands", + "executing: ": "executing: ", + "no config file found at %s using default config": "no config file found at %s using default config" } \ No newline at end of file diff --git a/test/keyFiles/twoKeys b/test/keyFiles/twoKeys new file mode 100644 index 00000000..e500e8b9 --- /dev/null +++ b/test/keyFiles/twoKeys @@ -0,0 +1 @@ +key1;key2 diff --git a/test/provider.js b/test/provider.js new file mode 100644 index 00000000..47a37924 --- /dev/null +++ b/test/provider.js @@ -0,0 +1,81 @@ +/*global describe, it, before*/ +const assert = require('assert'); +const sinon = require('sinon'); +const Provider = require('../lib/core/provider'); +let TestLogger = require('../lib/tests/test_logger.js'); + +describe('embark.provider', function () { + describe('#getAccount', function () { + let provider; + + before(() => { + const web3 = { + eth: { + accounts: { + privateKeyToAccount: sinon.stub().callsFake((key) => { + return {key}; + }) + } + } + }; + + provider = new Provider({ + accountsConfig: [], + logger: new TestLogger({}), + web3Endpoint: 'http:localhost:555', + web3 + }); + }); + + it('should return one account with the key', function () { + const account = provider.getAccount({ + privateKey: 'myKey' + }); + + assert.deepEqual(account, {key: 'myKey'}); + }); + + it('should return two accounts from the keys in the file', function () { + const account = provider.getAccount({ + privateKeyFile: 'test/keyFiles/twoKeys' + }); + + assert.deepEqual(account, [ + {key: 'key1'}, + {key: 'key2'} + ]); + }); + + it('should return one account from the mnemonic', function () { + const account = provider.getAccount({ + mnemonic: 'example exile argue silk regular smile grass bomb merge arm assist farm' + }); + + + assert.deepEqual(account, + [{key: Buffer.from('f942d5d524ec07158df4354402bfba8d928c99d0ab34d0799a6158d56156d986', 'hex')}]); + }); + + it('should return two accounts from the mnemonic using numAddresses', function () { + const account = provider.getAccount({ + mnemonic: 'example exile argue silk regular smile grass bomb merge arm assist farm', + numAddresses: 2 + }); + + assert.deepEqual(account, + [ + {key: Buffer.from('f942d5d524ec07158df4354402bfba8d928c99d0ab34d0799a6158d56156d986', 'hex')}, + {key: Buffer.from('88f37cfbaed8c0c515c62a17a3a1ce2f397d08bbf20dcc788b69f11b5a5c9791', 'hex')} + ]); + }); + + it('should return nothing with bad config', function () { + const account = provider.getAccount({ + badConfig: 'not working' + }); + + assert.strictEqual(account, null); + }); + + }); +});