diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/integration/index.html | 2 | ||||
-rw-r--r-- | test/integration/index.js | 21 | ||||
-rw-r--r-- | test/integration/lib/encryptor-test.js | 44 | ||||
-rw-r--r-- | test/integration/lib/first-time.js (renamed from test/integration/tests.js) | 3 | ||||
-rw-r--r-- | test/unit/actions/restore_vault_test.js | 2 | ||||
-rw-r--r-- | test/unit/actions/tx_test.js | 8 | ||||
-rw-r--r-- | test/unit/keyring-controller-test.js | 141 |
7 files changed, 214 insertions, 7 deletions
diff --git a/test/integration/index.html b/test/integration/index.html index 6de40b046..ad4b4eb14 100644 --- a/test/integration/index.html +++ b/test/integration/index.html @@ -12,7 +12,7 @@ <script src="https://code.jquery.com/qunit/qunit-2.0.0.js"></script> <script src="./jquery-3.1.0.min.js"></script> <script src="helpers.js"></script> - <script src="tests.js"></script> + <script src="bundle.js"></script> <script src="/testem.js"></script> <iframe src="/development/index.html" height="500px" width="360px"> diff --git a/test/integration/index.js b/test/integration/index.js new file mode 100644 index 000000000..ff6d1baf8 --- /dev/null +++ b/test/integration/index.js @@ -0,0 +1,21 @@ +var fs = require('fs') +var path = require('path') +var browserify = require('browserify'); +var tests = fs.readdirSync(path.join(__dirname, 'lib')) +var bundlePath = path.join(__dirname, 'bundle.js') + +var b = browserify(); + +// Remove old bundle +try { + fs.unlinkSync(bundlePath) +} catch (e) {} + +var writeStream = fs.createWriteStream(bundlePath) + +tests.forEach(function(fileName) { + b.add(path.join(__dirname, 'lib', fileName)) +}) + +b.bundle().pipe(writeStream); + diff --git a/test/integration/lib/encryptor-test.js b/test/integration/lib/encryptor-test.js new file mode 100644 index 000000000..88ebed51b --- /dev/null +++ b/test/integration/lib/encryptor-test.js @@ -0,0 +1,44 @@ +var encryptor = require('../../../app/scripts/lib/encryptor') + +QUnit.test('encryptor:serializeBufferForStorage', function (assert) { + assert.expect(1) + var buf = new Buffer(2) + buf[0] = 16 + buf[1] = 1 + + var output = encryptor.serializeBufferForStorage(buf) + + var expect = '0x1001' + assert.equal(expect, output) +}) + +QUnit.test('encryptor:serializeBufferFromStorage', function (assert) { + assert.expect(2) + var input = '0x1001' + var output = encryptor.serializeBufferFromStorage(input) + + assert.equal(output[0], 16) + assert.equal(output[1], 1) +}) + +QUnit.test('encryptor:encrypt & decrypt', function(assert) { + var done = assert.async(); + var password, data, encrypted + + password = 'a sample passw0rd' + data = { foo: 'data to encrypt' } + + encryptor.encrypt(password, data) + .then(function(encryptedStr) { + assert.equal(typeof encryptedStr, 'string', 'returns a string') + return encryptor.decrypt(password, encryptedStr) + }) + .then(function (decryptedObj) { + assert.deepEqual(decryptedObj, data, 'decrypted what was encrypted') + done() + }) + .catch(function(reason) { + assert.ifError(reason, 'threw an error') + }) + +}) diff --git a/test/integration/tests.js b/test/integration/lib/first-time.js index 92111b05b..af9b94e24 100644 --- a/test/integration/tests.js +++ b/test/integration/lib/first-time.js @@ -15,10 +15,11 @@ QUnit.test('agree to terms', function (assert) { assert.equal(title, 'MetaMask', 'title screen') var buttons = app.find('button') - assert.equal(buttons.length, 2, 'two buttons: create and restore') + assert.equal(buttons.length, 1, 'one button: create new vault') done() }) // Wait for view to transition: }) + diff --git a/test/unit/actions/restore_vault_test.js b/test/unit/actions/restore_vault_test.js index 609f5429e..7202abb70 100644 --- a/test/unit/actions/restore_vault_test.js +++ b/test/unit/actions/restore_vault_test.js @@ -20,7 +20,7 @@ describe('#recoverFromSeed(password, seed)', function() { }) // stub out account manager - actions._setAccountManager({ + actions._setKeyringController({ recoverFromSeed(pw, seed, cb) { cb(null, { identities: { diff --git a/test/unit/actions/tx_test.js b/test/unit/actions/tx_test.js index c08a8aa26..e365ee3a3 100644 --- a/test/unit/actions/tx_test.js +++ b/test/unit/actions/tx_test.js @@ -46,7 +46,7 @@ describe('tx confirmation screen', function() { describe('cancelTx', function() { before(function(done) { - actions._setAccountManager({ + actions._setKeyringController({ approveTransaction(txId, cb) { cb('An error!') }, cancelTransaction(txId) { /* noop */ }, clearSeedWordCache(cb) { cb() }, @@ -75,7 +75,7 @@ describe('tx confirmation screen', function() { before(function(done) { alert = () => {/* noop */} - actions._setAccountManager({ + actions._setKeyringController({ approveTransaction(txId, cb) { cb({message: 'An error!'}) }, }) @@ -96,7 +96,7 @@ describe('tx confirmation screen', function() { describe('when there is success', function() { it('should complete tx and go home', function() { - actions._setAccountManager({ + actions._setKeyringController({ approveTransaction(txId, cb) { cb() }, }) @@ -135,7 +135,7 @@ describe('tx confirmation screen', function() { } freeze(initialState) - actions._setAccountManager({ + actions._setKeyringController({ approveTransaction(txId, cb) { cb() }, }) diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js new file mode 100644 index 000000000..854ac5212 --- /dev/null +++ b/test/unit/keyring-controller-test.js @@ -0,0 +1,141 @@ +var assert = require('assert') +var KeyringController = require('../../app/scripts/keyring-controller') +var configManagerGen = require('../lib/mock-config-manager') +const ethUtil = require('ethereumjs-util') +const async = require('async') + +describe('KeyringController', function() { + + describe('#createNewVault', function () { + let keyringController + let password = 'password123' + let entropy = 'entripppppyy duuude' + let seedWords + let accounts = [] + let originalKeystore + + before(function(done) { + window.localStorage = {} // Hacking localStorage support into JSDom + + keyringController = new KeyringController({ + configManager: configManagerGen(), + ethStore: { + addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, + }, + }) + + keyringController.createNewVault(password, entropy, (err, seeds) => { + assert.ifError(err, 'createNewVault threw error') + seedWords = seeds + originalKeystore = keyringController._idmgmt.keyStore + done() + }) + }) + + describe('#recoverFromSeed', function() { + let newAccounts = [] + + before(function() { + window.localStorage = {} // Hacking localStorage support into JSDom + + keyringController = new KeyringController({ + configManager: configManagerGen(), + ethStore: { + addAccount(acct) { newAccounts.push(ethUtil.addHexPrefix(acct)) }, + }, + }) + }) + + it('should return the expected keystore', function (done) { + + keyringController.recoverFromSeed(password, seedWords, (err) => { + assert.ifError(err) + + let newKeystore = keyringController._idmgmt.keyStore + assert.equal(newAccounts[0], accounts[0]) + done() + }) + }) + }) + }) + + describe('#recoverFromSeed BIP44 compliance', function() { + const salt = 'lightwalletSalt' + + let password = 'secret!' + let accounts = {} + let keyringController + + 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 + + keyringController = new KeyringController({ + 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) { + + keyringController.recoverFromSeed(password, assertion.seed, (err) => { + assert.ifError(err) + + var expected = assertion.account.toLowerCase() + var received = accounts[expected].toLowerCase() + assert.equal(received, expected) + + keyringController.tryPassword(password, function (err) { + + assert.ok(keyringController._isUnlocked(), 'should unlock the id store') + + keyringController.submitPassword(password, function(err, account) { + assert.ifError(err) + assert.equal(account, expected) + assert.equal(Object.keys(keyringController._getAddresses()).length, 1, 'only one account on restore') + cb() + }) + }) + }) + } + }) + + async.series(tests, function(err, results) { + assert.ifError(err) + done() + }) + }) + }) +}) |