diff options
Merge branch 'dev' into i831-AddRopsten-Dev
Diffstat (limited to 'test/integration')
-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 | 67 | ||||
-rw-r--r-- | test/integration/lib/first-time.js | 15 | ||||
-rw-r--r-- | test/integration/lib/keyring-controller-test.js | 46 | ||||
-rw-r--r-- | test/integration/mocks/oldVault.json | 21 | ||||
-rw-r--r-- | test/integration/tests.js | 24 |
7 files changed, 171 insertions, 25 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..d42608152 --- /dev/null +++ b/test/integration/lib/encryptor-test.js @@ -0,0 +1,67 @@ +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') + done(reason) + }) + +}) + +QUnit.test('encryptor:encrypt & decrypt with wrong password', function(assert) { + var done = assert.async(); + var password, data, encrypted, wrongPassword + + password = 'a sample passw0rd' + wrongPassword = 'a wrong password' + data = { foo: 'data to encrypt' } + + encryptor.encrypt(password, data) + .then(function(encryptedStr) { + assert.equal(typeof encryptedStr, 'string', 'returns a string') + return encryptor.decrypt(wrongPassword, encryptedStr) + }) + .then(function (decryptedObj) { + assert.equal(!decryptedObj, true, 'Wrong password should not decrypt') + done() + }) + .catch(function(reason) { + done() + }) +}) diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js new file mode 100644 index 000000000..a73b0cba3 --- /dev/null +++ b/test/integration/lib/first-time.js @@ -0,0 +1,15 @@ +QUnit.test('agree to terms', function (assert) { + var done = assert.async() + let app + + wait().then(function() { + app = $('iframe').contents().find('#app-content .mock-app-root') + app.find('.markdown').prop('scrollTop', 100000000) + return wait() + }).then(function() { + var title = app.find('h1').text() + assert.equal(title, 'MetaMask', 'title screen') + + done() + }) +}) diff --git a/test/integration/lib/keyring-controller-test.js b/test/integration/lib/keyring-controller-test.js new file mode 100644 index 000000000..bea485270 --- /dev/null +++ b/test/integration/lib/keyring-controller-test.js @@ -0,0 +1,46 @@ +var KeyringController = require('../../../app/scripts/keyring-controller') +var ConfigManager = require('../../../app/scripts/lib/config-manager') + +var oldStyleVault = require('../mocks/oldVault.json') + +var STORAGE_KEY = 'metamask-config' +var PASSWORD = '12345678' +var FIRST_ADDRESS = '0x4dd5d356c5A016A220bCD69e82e5AF680a430d00'.toLowerCase() + + +QUnit.module('Old Style Vaults', { + beforeEach: function () { + window.localStorage[STORAGE_KEY] = JSON.stringify(oldStyleVault) + + this.configManager = new ConfigManager({ + loadData: () => { return JSON.parse(window.localStorage[STORAGE_KEY]) }, + setData: (data) => { window.localStorage[STORAGE_KEY] = JSON.stringify(data) }, + }) + + this.keyringController = new KeyringController({ + configManager: this.configManager, + getNetwork: () => { return '2' }, + }) + + this.ethStore = { + addAccount: () => {}, + removeAccount: () => {}, + } + + this.keyringController.setStore(this.ethStore) + } +}) + +QUnit.test('keyringController:isInitialized', function (assert) { + assert.ok(this.keyringController.getState().isInitialized) +}) + +QUnit.test('keyringController:submitPassword', function (assert) { + var done = assert.async() + + this.keyringController.submitPassword(PASSWORD, (err, state) => { + assert.notOk(err) + assert.ok(state.identities[FIRST_ADDRESS]) + done() + }) +}) diff --git a/test/integration/mocks/oldVault.json b/test/integration/mocks/oldVault.json new file mode 100644 index 000000000..5861c41d7 --- /dev/null +++ b/test/integration/mocks/oldVault.json @@ -0,0 +1,21 @@ +{ + "meta": { + "version": 4 + }, + "data": { + "fiatCurrency": "USD", + "isConfirmed": true, + "TOSHash": "a4f4e23f823a7ac51783e7ffba7914a911b09acdb97263296b7e14b527f80c5b", + "conversionRate": 9.47316629, + "conversionDate": 1479510994, + "wallet": "{\"encSeed\":{\"encStr\":\"a5tjKtDGlHkua+6Ta5s3wMFWPmsBqaPdMKGmqeI2z1kMbNs3V03HBaCptU7NtMra1DjHKbSNsUToxFUrmrvWBmUejamN16+l1CviwqASsv7kKzpot00/dfyyJgtZwwFP5Je+TAB1V231nRbPidOfeE1cDec5V8KTF8epl6qzsbA25pjeW76Dfw==\",\"nonce\":\"RzID6bAhWfGTSR74xdIh3RaT1+1sLk6F\"},\"ksData\":{\"m/44'/60'/0'/0\":{\"info\":{\"curve\":\"secp256k1\",\"purpose\":\"sign\"},\"encHdPathPriv\":{\"encStr\":\"6nlYAopRbmGcqerRZO08XwgeYaCJg9XRhh4oiYiVVdQtyNPdxvOI9TcE/mqvBiatMwBwA+TmsqTV6eZZe/VDZKYIGajKulQbScd0xQ71JhYfqqmzSG6EH2Pnzwa+aSAsfARgN1JJSaff2+p6wV6Zg5BUDtl72OGEIEfXhcUGwg==\",\"nonce\":\"Ee1KiDqtx7NvYToQUFvjEhKNinNQcXlK\"},\"hdIndex\":1,\"encPrivKeys\":{\"4dd5d356c5a016a220bcd69e82e5af680a430d00\":{\"key\":\"htGRGAH10lGF4M+fvioznmYVIUSWAzwp/yWSIo85psgZZwmCdJY72oyGanYsrFO8\",\"nonce\":\"PkP8XeZ+ok215rzEorvJu9nYTWzkOVr0\"}},\"addresses\":[\"4dd5d356c5a016a220bcd69e82e5af680a430d00\"]}},\"encHdRootPriv\":{\"encStr\":\"TAZAo71a+4IlAaoA66f0w4ts2f+V7ArTSUHRIrMltfAPXz7GfJBmKXNtHPORUYAjRiKqWK6FZnhKLf7Vcng2LG7VnDQwC4xPxzSRZzSEilnoY3V+zRY0HD7Wb/pndb4FliA/buZQmjohO4vezeX0hl70rJlPJEZTyYoWgxbxFA==\",\"nonce\":\"FlJOaLyBEHMaH5fEnYjdHc6nn18+WkRj\"},\"salt\":\"CmuCcWpbqpKUUv+1aE2ZwvQl7EIQ731uFibSq++vwtY=\",\"version\":2}", + "config": { + "provider": { + "type": "testnet" + }, + "selectedAccount": "0x4dd5d356c5a016a220bcd69e82e5af680a430d00" + }, + "showSeedWords": false, + "isEthConfirmed": true + } +} diff --git a/test/integration/tests.js b/test/integration/tests.js deleted file mode 100644 index 92111b05b..000000000 --- a/test/integration/tests.js +++ /dev/null @@ -1,24 +0,0 @@ -QUnit.test('agree to terms', function (assert) { - var done = assert.async() - - // Select the mock app root - var app = $('iframe').contents().find('#app-content .mock-app-root') - - app.find('.markdown').prop('scrollTop', 100000000) - - wait().then(function() { - app.find('button').click() - }).then(function() { - return wait() - }).then(function() { - var title = app.find('h1').text() - assert.equal(title, 'MetaMask', 'title screen') - - var buttons = app.find('button') - assert.equal(buttons.length, 2, 'two buttons: create and restore') - - done() - }) - - // Wait for view to transition: -}) |