From dc2d614da68ca851c3b1c0c108e7c2f22185751c Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Fri, 10 Mar 2017 09:52:05 -0800 Subject: Add basic tests. --- test/unit/address-book-controller.js | 28 ++++++++++++++++++++++++++++ test/unit/currency-controller-test.js | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/unit/address-book-controller.js (limited to 'test') diff --git a/test/unit/address-book-controller.js b/test/unit/address-book-controller.js new file mode 100644 index 000000000..f00547167 --- /dev/null +++ b/test/unit/address-book-controller.js @@ -0,0 +1,28 @@ +const assert = require('assert') +const extend = require('xtend') +const AddressBookController = require('../../app/scripts/controllers/address-book') + +describe('address-book-controller', function() { + var addressBookController + + beforeEach(function() { + addressBookController = new AddressBookController() + }) + + describe('addres book management', function () { + describe('#_getAddressBook', function () { + it('should be empty by default.', function () { + assert.equal(addressBookController._getAddressBook().length, 0) + }) + }) + describe('#setAddressBook', function () { + it('should properly set a new address.', function () { + addressBookController.setAddressBook('0x01234', 'test') + var addressBook = addressBookController._getAddressBook() + assert.equal(addressBook.length, 1, 'incorrect address book length.') + assert.equal(addressBook[0].address, '0x01234', 'incorrect addresss') + assert.equal(addressBook[0].name, 'test', 'incorrect nickname') + }) + }) + }) +}) diff --git a/test/unit/currency-controller-test.js b/test/unit/currency-controller-test.js index dd7fa91e0..079f8b488 100644 --- a/test/unit/currency-controller-test.js +++ b/test/unit/currency-controller-test.js @@ -7,7 +7,7 @@ const rp = require('request-promise') const nock = require('nock') const CurrencyController = require('../../app/scripts/controllers/currency') -describe('config-manager', function() { +describe('currency-controller', function() { var currencyController beforeEach(function() { -- cgit From c47f7f6a765e748c33ffde6ff38e881199251eda Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Fri, 10 Mar 2017 10:34:18 -0800 Subject: Add another test for duplicates. --- test/unit/address-book-controller.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/unit/address-book-controller.js b/test/unit/address-book-controller.js index f00547167..51dc898b8 100644 --- a/test/unit/address-book-controller.js +++ b/test/unit/address-book-controller.js @@ -23,6 +23,13 @@ describe('address-book-controller', function() { assert.equal(addressBook[0].address, '0x01234', 'incorrect addresss') assert.equal(addressBook[0].name, 'test', 'incorrect nickname') }) + + it('should reject duplicates.', function () { + addressBookController.setAddressBook('0x01234', 'test') + addressBookController.setAddressBook('0x01234', 'test') + var addressBook = addressBookController._getAddressBook() + assert.equal(addressBook.length, 1, 'incorrect address book length.') + }) }) }) }) -- cgit From d85cc7ec4ef4e93d424ef4debbca1bb27b952a4e Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Fri, 10 Mar 2017 10:48:07 -0800 Subject: Add test to account for prevention of identities duplication. --- test/unit/address-book-controller.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/address-book-controller.js b/test/unit/address-book-controller.js index 51dc898b8..f345b0328 100644 --- a/test/unit/address-book-controller.js +++ b/test/unit/address-book-controller.js @@ -2,11 +2,27 @@ const assert = require('assert') const extend = require('xtend') const AddressBookController = require('../../app/scripts/controllers/address-book') +const mockKeyringController = { + memStore: { + getState: function () { + return { + identities: { + '0x0aaa' : { + address: '0x0aaa', + name: 'owned', + } + } + } + } + } +} + + describe('address-book-controller', function() { var addressBookController beforeEach(function() { - addressBookController = new AddressBookController() + addressBookController = new AddressBookController({}, mockKeyringController) }) describe('addres book management', function () { @@ -30,6 +46,11 @@ describe('address-book-controller', function() { var addressBook = addressBookController._getAddressBook() assert.equal(addressBook.length, 1, 'incorrect address book length.') }) + it('should not add any identities that are under user control', function () { + addressBookController.setAddressBook('0x0aaa', ' ') + var addressBook = addressBookController._getAddressBook() + assert.equal(addressBook.length, 0, 'incorrect address book length.') + }) }) }) }) -- cgit From b6e2eaf7b1d14fcca8ed614791937a5ccbfc00dd Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 16 Mar 2017 11:16:03 -0700 Subject: Remove eth-lightwallet --- test/integration/lib/idStore-migrator-test.js | 92 ----------------- test/unit/id-management-test.js | 35 ------- test/unit/idStore-migration-test.js | 83 --------------- test/unit/idStore-test.js | 142 -------------------------- 4 files changed, 352 deletions(-) delete mode 100644 test/integration/lib/idStore-migrator-test.js delete mode 100644 test/unit/id-management-test.js delete mode 100644 test/unit/idStore-migration-test.js delete mode 100644 test/unit/idStore-test.js (limited to 'test') diff --git a/test/integration/lib/idStore-migrator-test.js b/test/integration/lib/idStore-migrator-test.js deleted file mode 100644 index 290216ae8..000000000 --- a/test/integration/lib/idStore-migrator-test.js +++ /dev/null @@ -1,92 +0,0 @@ -const ObservableStore = require('obs-store') -const ConfigManager = require('../../../app/scripts/lib/config-manager') -const IdStoreMigrator = require('../../../app/scripts/lib/idStore-migrator') -const SimpleKeyring = require('eth-simple-keyring') -const normalize = require('eth-sig-util').normalize - -const oldStyleVault = require('../mocks/oldVault.json').data -const badStyleVault = require('../mocks/badVault.json').data - -const PASSWORD = '12345678' -const FIRST_ADDRESS = '0x4dd5d356c5A016A220bCD69e82e5AF680a430d00'.toLowerCase() -const BAD_STYLE_FIRST_ADDRESS = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' -const SEED = 'fringe damage bounce extend tunnel afraid alert sound all soldier all dinner' - -QUnit.module('Old Style Vaults', { - beforeEach: function () { - let managers = managersFromInitState(oldStyleVault) - - this.configManager = managers.configManager - this.migrator = managers.migrator - } -}) - -QUnit.test('migrator:isInitialized', function (assert) { - assert.ok(this.migrator) -}) - -QUnit.test('migrator:migratedVaultForPassword', function (assert) { - var done = assert.async() - - this.migrator.migratedVaultForPassword(PASSWORD) - .then((result) => { - assert.ok(result, 'migratedVaultForPassword returned result') - const { serialized, lostAccounts } = result - assert.equal(serialized.data.mnemonic, SEED, 'seed phrase recovered') - assert.equal(lostAccounts.length, 0, 'no lost accounts') - done() - }) -}) - -QUnit.module('Old Style Vaults with bad HD seed', { - beforeEach: function () { - let managers = managersFromInitState(badStyleVault) - - this.configManager = managers.configManager - this.migrator = managers.migrator - } -}) - -QUnit.test('migrator:migratedVaultForPassword', function (assert) { - var done = assert.async() - - this.migrator.migratedVaultForPassword(PASSWORD) - .then((result) => { - assert.ok(result, 'migratedVaultForPassword returned result') - const { serialized, lostAccounts } = result - - assert.equal(lostAccounts.length, 1, 'one lost account') - assert.equal(lostAccounts[0].address, '0xe15D894BeCB0354c501AE69429B05143679F39e0'.toLowerCase()) - assert.ok(lostAccounts[0].privateKey, 'private key exported') - - var lostAccount = lostAccounts[0] - var privateKey = lostAccount.privateKey - - var simple = new SimpleKeyring() - simple.deserialize([privateKey]) - .then(() => { - return simple.getAccounts() - }) - .then((accounts) => { - assert.equal(normalize(accounts[0]), lostAccount.address, 'recovered address.') - done() - }) - .catch((reason) => { - assert.ifError(reason) - done(reason) - }) - }) -}) - -function managersFromInitState(initState){ - - let configManager = new ConfigManager({ - store: new ObservableStore(initState), - }) - - let migrator = new IdStoreMigrator({ - configManager: configManager, - }) - - return { configManager, migrator } -} diff --git a/test/unit/id-management-test.js b/test/unit/id-management-test.js deleted file mode 100644 index cbc6403bc..000000000 --- a/test/unit/id-management-test.js +++ /dev/null @@ -1,35 +0,0 @@ -var assert = require('assert') -var IdManagement = require('../../app/scripts/lib/id-management') -var sinon = require('sinon') - -describe('IdManagement', function() { - - beforeEach(function() { - // sinon allows stubbing methods that are easily verified - this.sinon = sinon.sandbox.create() - window.localStorage = {} // Hacking localStorage support into JSDom - }) - - afterEach(function() { - // sinon requires cleanup otherwise it will overwrite context - this.sinon.restore() - }) - - describe('#signMsg', function () { - it('passes the dennis test', function() { - const address = '0x9858e7d8b79fc3e6d989636721584498926da38a' - const message = '0x879a053d4800c6354e76c7985a865d2922c82fb5b3f4577b2fe08b998954f2e0' - const privateKey = '0x7dd98753d7b4394095de7d176c58128e2ed6ee600abe97c9f6d9fd65015d9b18' - const expectedResult = '0x28fcb6768e5110144a55b2e6ce9d1ea5a58103033632d272d2b5cf506906f7941a00b539383fd872109633d8c71c404e13dba87bc84166ee31b0e36061a69e161c' - - const idManagement = new IdManagement() - const exportKeyStub = sinon.stub(idManagement, 'exportPrivateKey', (addr) => { - assert.equal(addr, address) - return privateKey - }) - - const result = idManagement.signMsg(address, message) - assert.equal(result, expectedResult) - }) - }) -}) diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js deleted file mode 100644 index 81a99ef63..000000000 --- a/test/unit/idStore-migration-test.js +++ /dev/null @@ -1,83 +0,0 @@ -const async = require('async') -const assert = require('assert') -const ObservableStore = require('obs-store') -const ethUtil = require('ethereumjs-util') -const BN = ethUtil.BN -const ConfigManager = require('../../app/scripts/lib/config-manager') -const firstTimeState = require('../../app/scripts/first-time-state') -const delegateCallCode = require('../lib/example-code.json').delegateCallCode -const clone = require('clone') - -// The old way: -const IdentityStore = require('../../app/scripts/lib/idStore') -const STORAGE_KEY = 'metamask-config' - -// The new ways: -var KeyringController = require('../../app/scripts/keyring-controller') -const mockEncryptor = require('../lib/mock-encryptor') -const MockSimpleKeychain = require('../lib/mock-simple-keychain') -const sinon = require('sinon') - -const mockVault = { - seed: 'picnic injury awful upper eagle junk alert toss flower renew silly vague', - account: '0x5d8de92c205279c10e5669f797b853ccef4f739a', -} - -const badVault = { - seed: 'radar blur cabbage chef fix engine embark joy scheme fiction master release', -} - -describe('IdentityStore to KeyringController migration', function() { - - // The stars of the show: - let idStore, keyringController, seedWords, configManager - - let password = 'password123' - let entropy = 'entripppppyy duuude' - let accounts = [] - let newAccounts = [] - let originalKeystore - - // This is a lot of setup, I know! - // We have to create an old style vault, populate it, - // and THEN create a new one, before we can run tests on it. - beforeEach(function(done) { - this.sinon = sinon.sandbox.create() - let store = new ObservableStore(clone(firstTimeState)) - configManager = new ConfigManager({ store }) - - idStore = new IdentityStore({ - configManager: configManager, - ethStore: { - addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, - del(acct) { delete accounts[acct] }, - }, - }) - - idStore._createVault(password, mockVault.seed, (err) => { - assert.ifError(err, 'createNewVault threw error') - originalKeystore = idStore._idmgmt.keyStore - - idStore.setLocked((err) => { - assert.ifError(err, 'createNewVault threw error') - keyringController = new KeyringController({ - configManager, - ethStore: { - addAccount(acct) { newAccounts.push(ethUtil.addHexPrefix(acct)) }, - del(acct) { delete newAccounts[acct] }, - }, - txManager: { - getTxList: () => [], - getUnapprovedTxList: () => [] - }, - }) - - // Stub out the browser crypto for a mock encryptor. - // Browser crypto is tested in the integration test suite. - keyringController.encryptor = mockEncryptor - done() - }) - }) - }) - -}) diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js deleted file mode 100644 index 000c58a82..000000000 --- a/test/unit/idStore-test.js +++ /dev/null @@ -1,142 +0,0 @@ -const async = require('async') -const assert = require('assert') -const ethUtil = require('ethereumjs-util') -const BN = ethUtil.BN -const configManagerGen = require('../lib/mock-config-manager') -const delegateCallCode = require('../lib/example-code.json').delegateCallCode -const IdentityStore = require('../../app/scripts/lib/idStore') - -describe('IdentityStore', function() { - - describe('#createNewVault', function () { - let idStore - let password = 'password123' - let seedWords - let accounts = [] - let originalKeystore - - before(function(done) { - window.localStorage = {} // Hacking localStorage support into JSDom - - idStore = new IdentityStore({ - configManager: configManagerGen(), - ethStore: { - addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, - }, - }) - - idStore.createNewVault(password, (err, seeds) => { - assert.ifError(err, 'createNewVault threw error') - seedWords = seeds - originalKeystore = idStore._idmgmt.keyStore - done() - }) - }) - - describe('#recoverFromSeed', function() { - let newAccounts = [] - - before(function() { - window.localStorage = {} // Hacking localStorage support into JSDom - - idStore = new IdentityStore({ - configManager: configManagerGen(), - ethStore: { - addAccount(acct) { newAccounts.push(ethUtil.addHexPrefix(acct)) }, - }, - }) - }) - - it('should return the expected keystore', function (done) { - - idStore.recoverFromSeed(password, seedWords, (err) => { - assert.ifError(err) - - let newKeystore = idStore._idmgmt.keyStore - assert.equal(newAccounts[0], accounts[0]) - done() - }) - }) - }) - }) - - describe('#recoverFromSeed BIP44 compliance', function() { - const salt = 'lightwalletSalt' - - let password = 'secret!' - let accounts = {} - let idStore - - var assertions = [ - { - seed: 'picnic injury awful upper eagle junk alert toss flower renew silly vague', - account: '0x5d8de92c205279c10e5669f797b853ccef4f739a', - }, - { - seed: 'radar blur cabbage chef fix engine embark joy scheme fiction master release', - account: '0xe15d894becb0354c501ae69429b05143679f39e0', - }, - { - seed: 'phone coyote caught pattern found table wedding list tumble broccoli chief swing', - account: '0xb0e868f24bc7fec2bce2efc2b1c344d7569cd9d2', - }, - { - seed: 'recycle tag bird palace blue village anxiety census cook soldier example music', - account: '0xab34a45920afe4af212b96ec51232aaa6a33f663', - }, - { - seed: 'half glimpse tape cute harvest sweet bike voyage actual floor poet lazy', - account: '0x28e9044597b625ac4beda7250011670223de43b2', - }, - { - seed: 'flavor tiger carpet motor angry hungry document inquiry large critic usage liar', - account: '0xb571be96558940c4e9292e1999461aa7499fb6cd', - }, - ] - - before(function() { - window.localStorage = {} // Hacking localStorage support into JSDom - - idStore = new IdentityStore({ - configManager: configManagerGen(), - ethStore: { - addAccount(acct) { accounts[acct] = acct}, - del(acct) { delete accounts[acct] }, - }, - }) - }) - - it('should enforce seed compliance with TestRPC', function (done) { - this.timeout(10000) - const tests = assertions.map((assertion) => { - return function (cb) { - - idStore.recoverFromSeed(password, assertion.seed, (err) => { - assert.ifError(err) - - var expected = assertion.account.toLowerCase() - var received = accounts[expected].toLowerCase() - assert.equal(received, expected) - - idStore.tryPassword(password, function (err) { - - assert.ok(idStore._isUnlocked(), 'should unlock the id store') - - idStore.submitPassword(password, function(err, account) { - assert.ifError(err) - assert.equal(account, expected) - assert.equal(Object.keys(idStore._getAddresses()).length, 1, 'only one account on restore') - cb() - }) - }) - }) - } - }) - - async.series(tests, function(err, results) { - assert.ifError(err) - done() - }) - }) - }) -}) -- cgit