From 36dc63bc048e62b5ef0d1b0385e530afdad3fefa Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 9 Sep 2016 19:42:18 -0700 Subject: Add new eth-lightwallet salting to vault. eth-lightwallet was previously not salting vault passwords, potentially making it easier to crack them once obtained. This branch incorporates the API changes to allow us to take advantage of the new salting logic. This is still throwing deprecation warnings, but that's actually a bug in eth-lightwallet I wrote, [I've submitted a PR for that here](https://github.com/ConsenSys/eth-lightwallet/pull/116). Fixes #555 --- test/unit/idStore-test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index ee4613236..cbbec43b5 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -23,6 +23,7 @@ describe('IdentityStore', function() { }) idStore.createNewVault(password, entropy, (err, seeds) => { + assert.ifError(err, 'createNewVault threw error') seedWords = seeds originalKeystore = idStore._idmgmt.keyStore done() @@ -59,6 +60,7 @@ describe('IdentityStore', function() { describe('#recoverFromSeed BIP44 compliance', function() { let seedWords = 'picnic injury awful upper eagle junk alert toss flower renew silly vague' let firstAccount = '0x5d8de92c205279c10e5669f797b853ccef4f739a' + const salt = 'lightwalletSalt' let password = 'secret!' let accounts = [] @@ -70,7 +72,7 @@ describe('IdentityStore', function() { idStore = new IdentityStore({ configManager: configManagerGen(), ethStore: { - addAccount(acct) { accounts.push(acct) }, + addAccount(acct) { accounts.push('0x' + acct) }, }, }) }) -- cgit From 6763871c416001e19c224b90a99ed7d9ece69158 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 11:46:50 -0700 Subject: Captured #640 in failing test --- test/unit/idStore-test.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index cbbec43b5..3d28ddf90 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -83,8 +83,19 @@ describe('IdentityStore', function() { assert.ifError(err) let newKeystore = idStore._idmgmt.keyStore + assert.equal(accounts[0], firstAccount) - done() + + accounts = [] + const secondSeed = 'radar blur cabbage chef fix engine embark joy scheme fiction master release' + const secondAcct = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' + + idStore.recoverFromSeed(password, secondSeed, (err) => { + + let accounts = idStore._getAddresses() + assert.equal(accounts[0], secondAcct) + done() + }) }) }) }) -- cgit From 59fd86383fbf379724c3bcca6da9d5a6192bbcf2 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 12:08:27 -0700 Subject: Correctly clear ethStore cache on new vault restore --- test/unit/idStore-test.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 3d28ddf90..422db6f7b 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -1,6 +1,7 @@ var assert = require('assert') var IdentityStore = require('../../app/scripts/lib/idStore') var configManagerGen = require('../lib/mock-config-manager') +const ethUtil = require('ethereumjs-util') describe('IdentityStore', function() { @@ -18,7 +19,7 @@ describe('IdentityStore', function() { idStore = new IdentityStore({ configManager: configManagerGen(), ethStore: { - addAccount(acct) { accounts.push(acct) }, + addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, }, }) @@ -39,7 +40,7 @@ describe('IdentityStore', function() { idStore = new IdentityStore({ configManager: configManagerGen(), ethStore: { - addAccount(acct) { newAccounts.push(acct) }, + addAccount(acct) { newAccounts.push(ethUtil.addHexPrefix(acct)) }, }, }) }) @@ -62,6 +63,9 @@ describe('IdentityStore', function() { let firstAccount = '0x5d8de92c205279c10e5669f797b853ccef4f739a' const salt = 'lightwalletSalt' + const secondSeed = 'radar blur cabbage chef fix engine embark joy scheme fiction master release' + const secondAcct = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' + let password = 'secret!' let accounts = [] let idStore @@ -72,11 +76,15 @@ describe('IdentityStore', function() { idStore = new IdentityStore({ configManager: configManagerGen(), ethStore: { - addAccount(acct) { accounts.push('0x' + acct) }, + addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, }, }) }) + beforeEach(function() { + accounts = [] + }) + it('should return the expected first account', function (done) { idStore.recoverFromSeed(password, seedWords, (err) => { @@ -87,9 +95,6 @@ describe('IdentityStore', function() { assert.equal(accounts[0], firstAccount) accounts = [] - const secondSeed = 'radar blur cabbage chef fix engine embark joy scheme fiction master release' - const secondAcct = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' - idStore.recoverFromSeed(password, secondSeed, (err) => { let accounts = idStore._getAddresses() @@ -98,5 +103,16 @@ describe('IdentityStore', function() { }) }) }) + + it('should return the expected second account', function (done) { + idStore.recoverFromSeed(password, secondSeed, (err) => { + assert.ifError(err) + + let newKeystore = idStore._idmgmt.keyStore + + assert.equal(accounts[0], firstAccount) + done() + }) + }) }) }) -- cgit From 1b77d5300b1ace16f96cf626d69925a26b5f0d29 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 12:15:05 -0700 Subject: Clean up tests --- test/unit/idStore-test.js | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 422db6f7b..1028e35ea 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -59,12 +59,7 @@ describe('IdentityStore', function() { }) describe('#recoverFromSeed BIP44 compliance', function() { - let seedWords = 'picnic injury awful upper eagle junk alert toss flower renew silly vague' - let firstAccount = '0x5d8de92c205279c10e5669f797b853ccef4f739a' - const salt = 'lightwalletSalt' - - const secondSeed = 'radar blur cabbage chef fix engine embark joy scheme fiction master release' - const secondAcct = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' + const salt = 'lightwalletSalt' let password = 'secret!' let accounts = [] @@ -86,31 +81,35 @@ describe('IdentityStore', function() { }) it('should return the expected first account', function (done) { + let seedWords = 'picnic injury awful upper eagle junk alert toss flower renew silly vague' + let firstAccount = '0x5d8de92c205279c10e5669f797b853ccef4f739a' idStore.recoverFromSeed(password, seedWords, (err) => { assert.ifError(err) - let newKeystore = idStore._idmgmt.keyStore - assert.equal(accounts[0], firstAccount) - - accounts = [] - idStore.recoverFromSeed(password, secondSeed, (err) => { - - let accounts = idStore._getAddresses() - assert.equal(accounts[0], secondAcct) - done() - }) + done() }) }) it('should return the expected second account', function (done) { + const secondSeed = 'radar blur cabbage chef fix engine embark joy scheme fiction master release' + const secondAcct = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' + idStore.recoverFromSeed(password, secondSeed, (err) => { assert.ifError(err) + assert.equal(accounts[0], secondAcct) + done() + }) + }) - let newKeystore = idStore._idmgmt.keyStore + it('should return the expected third account', function (done) { + const thirdSeed = 'phone coyote caught pattern found table wedding list tumble broccoli chief swing' + const thirdAcct = '0xb0e868f24bc7fec2bce2efc2b1c344d7569cd9d2' - assert.equal(accounts[0], firstAccount) + idStore.recoverFromSeed(password, thirdSeed, (err) => { + assert.ifError(err) + assert.equal(accounts[0], thirdAcct) done() }) }) -- cgit From 8922ae1a55d3c5bf743c85aec5e454cf189f94f1 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 12:35:52 -0700 Subject: Made bip44 assertions easier to add to --- test/unit/idStore-test.js | 63 +++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 27 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 1028e35ea..09d8f1b8f 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -2,6 +2,7 @@ var assert = require('assert') var IdentityStore = require('../../app/scripts/lib/idStore') var configManagerGen = require('../lib/mock-config-manager') const ethUtil = require('ethereumjs-util') +const async = require('async') describe('IdentityStore', function() { @@ -65,6 +66,29 @@ describe('IdentityStore', function() { 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: '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9', + }, + { + 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', + } + ] + before(function() { window.localStorage = {} // Hacking localStorage support into JSDom @@ -80,36 +104,21 @@ describe('IdentityStore', function() { accounts = [] }) - it('should return the expected first account', function (done) { - let seedWords = 'picnic injury awful upper eagle junk alert toss flower renew silly vague' - let firstAccount = '0x5d8de92c205279c10e5669f797b853ccef4f739a' - - idStore.recoverFromSeed(password, seedWords, (err) => { - assert.ifError(err) - - assert.equal(accounts[0], firstAccount) - done() + it('should enforce seed compliance with TestRPC', function (done) { + const tests = assertions.map((assertion) => { + return function (cb) { + idStore.recoverFromSeed(password, assertion.seed, (err) => { + assert.ifError(err) + + console.log('comparing %s to %s', accounts[0], assertion.account) + assert.equal(accounts[0], assertion.account) + cb() + }) + } }) - }) - - it('should return the expected second account', function (done) { - const secondSeed = 'radar blur cabbage chef fix engine embark joy scheme fiction master release' - const secondAcct = '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9' - - idStore.recoverFromSeed(password, secondSeed, (err) => { - assert.ifError(err) - assert.equal(accounts[0], secondAcct) - done() - }) - }) - - it('should return the expected third account', function (done) { - const thirdSeed = 'phone coyote caught pattern found table wedding list tumble broccoli chief swing' - const thirdAcct = '0xb0e868f24bc7fec2bce2efc2b1c344d7569cd9d2' - idStore.recoverFromSeed(password, thirdSeed, (err) => { + async.series(tests, function(err, results) { assert.ifError(err) - assert.equal(accounts[0], thirdAcct) done() }) }) -- cgit From cdd367dc3989d89092c322279972ce5ee18c276e Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 12:38:04 -0700 Subject: Add more bip44 assertions --- test/unit/idStore-test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 09d8f1b8f..4327013b3 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -86,7 +86,15 @@ describe('IdentityStore', function() { { 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', + }, + { + seed: 'this is a twelve word phrase seven eight nine ten eleven twelve', + account: '0x814e8ec0c3647e140b8e09228fc374b2a867fe48', + }, ] before(function() { -- cgit From b1590f179e77d80193cc5e82d430c789c6fd816f Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 12:39:50 -0700 Subject: Remove log --- test/unit/idStore-test.js | 1 - 1 file changed, 1 deletion(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 4327013b3..28111a85e 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -118,7 +118,6 @@ describe('IdentityStore', function() { idStore.recoverFromSeed(password, assertion.seed, (err) => { assert.ifError(err) - console.log('comparing %s to %s', accounts[0], assertion.account) assert.equal(accounts[0], assertion.account) cb() }) -- cgit From 5e60b2f0c4c1a88839a87cc93d867c9c40d1090d Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 12:57:11 -0700 Subject: Correct assertion for BIP32 compliance According to [axic's work here](https://github.com/MetaMask/metamask-plugin/issues/640#issuecomment-246133672), MetaMask is generating the correct address, so I've corrected that assertion accordingly. --- test/unit/idStore-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 28111a85e..b3bb1a49c 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -73,7 +73,7 @@ describe('IdentityStore', function() { }, { seed: 'radar blur cabbage chef fix engine embark joy scheme fiction master release', - account: '0xac39b311dceb2a4b2f5d8461c1cdaf756f4f7ae9', + account: '0xe15D894BeCB0354c501AE69429B05143679F39e0', }, { seed: 'phone coyote caught pattern found table wedding list tumble broccoli chief swing', -- cgit From 9b861b6687d5b079560a67b35e4a4890da643b03 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 10 Sep 2016 15:45:34 -0700 Subject: Fixed caching bug Fixed bug where the second new vault created in an IdStore would initially return the accounts from the original store. Also fixed some tests that were incorrect. --- test/unit/idStore-test.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index b3bb1a49c..a763eb0e7 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -73,7 +73,7 @@ describe('IdentityStore', function() { }, { seed: 'radar blur cabbage chef fix engine embark joy scheme fiction master release', - account: '0xe15D894BeCB0354c501AE69429B05143679F39e0', + account: '0xe15d894becb0354c501ae69429b05143679f39e0', }, { seed: 'phone coyote caught pattern found table wedding list tumble broccoli chief swing', @@ -91,10 +91,6 @@ describe('IdentityStore', function() { seed: 'flavor tiger carpet motor angry hungry document inquiry large critic usage liar', account: '0xb571be96558940c4e9292e1999461aa7499fb6cd', }, - { - seed: 'this is a twelve word phrase seven eight nine ten eleven twelve', - account: '0x814e8ec0c3647e140b8e09228fc374b2a867fe48', - }, ] before(function() { @@ -115,10 +111,13 @@ describe('IdentityStore', function() { it('should enforce seed compliance with TestRPC', function (done) { const tests = assertions.map((assertion) => { return function (cb) { + accounts = [] idStore.recoverFromSeed(password, assertion.seed, (err) => { assert.ifError(err) - assert.equal(accounts[0], assertion.account) + var received = accounts[0].toLowerCase() + var expected = assertion.account.toLowerCase() + assert.equal(received, expected) cb() }) } -- cgit From 5c1d8e299e68be6a74935f4eff56f68a9ccf5b72 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 12 Sep 2016 08:50:42 -0700 Subject: Select first address when restoring vault Fixes #642 --- test/unit/idStore-test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index a763eb0e7..1ed1bf9a7 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -128,5 +128,23 @@ describe('IdentityStore', function() { done() }) }) + + it('should allow restoring and unlocking again', function (done) { + const assertion = assertions[0] + idStore.recoverFromSeed(password, assertion.seed, (err) => { + assert.ifError(err) + + var received = accounts[0].toLowerCase() + var expected = assertion.account.toLowerCase() + assert.equal(received, expected) + + + idStore.submitPassword(password, function(err, account) { + assert.ifError(err) + assert.equal(account, expected) + done() + }) + }) + }) }) }) -- cgit From 363c2a0939aba5fa73e08ff8e6d65581031242d5 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 12 Sep 2016 11:07:25 -0700 Subject: Fix account unlocking SubmitPassword was not creating a new id-management This is because I broke up the old "createIdmgmt" method to not perform as much conditional logic. Now the pieces are reusable and do what they should do. --- test/unit/idStore-test.js | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 1ed1bf9a7..ac416e5cd 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -109,6 +109,7 @@ describe('IdentityStore', function() { }) it('should enforce seed compliance with TestRPC', function (done) { + this.timeout(5000) const tests = assertions.map((assertion) => { return function (cb) { accounts = [] @@ -118,7 +119,17 @@ describe('IdentityStore', function() { var received = accounts[0].toLowerCase() var expected = assertion.account.toLowerCase() assert.equal(received, expected) - cb() + + 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) + cb() + }) + }) }) } }) @@ -128,23 +139,5 @@ describe('IdentityStore', function() { done() }) }) - - it('should allow restoring and unlocking again', function (done) { - const assertion = assertions[0] - idStore.recoverFromSeed(password, assertion.seed, (err) => { - assert.ifError(err) - - var received = accounts[0].toLowerCase() - var expected = assertion.account.toLowerCase() - assert.equal(received, expected) - - - idStore.submitPassword(password, function(err, account) { - assert.ifError(err) - assert.equal(account, expected) - done() - }) - }) - }) }) }) -- cgit From e0e38b879f4d8ea367a0ea77be633d0b4d6762fa Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 12 Sep 2016 11:21:27 -0700 Subject: Fix some references --- test/unit/idStore-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index ac416e5cd..03b1d3b41 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -109,7 +109,7 @@ describe('IdentityStore', function() { }) it('should enforce seed compliance with TestRPC', function (done) { - this.timeout(5000) + this.timeout(10000) const tests = assertions.map((assertion) => { return function (cb) { accounts = [] @@ -122,7 +122,7 @@ describe('IdentityStore', function() { idStore.tryPassword(password, function (err) { - assert.ok(idStore.isUnlocked(), 'should unlock the id store') + assert.ok(idStore._isUnlocked(), 'should unlock the id store') idStore.submitPassword(password, function(err, account) { assert.ifError(err) -- cgit From c3d1404e72f4978db5b4522cb793ffd22653d9ff Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 12 Sep 2016 15:18:32 -0700 Subject: Fix clearing of account cache on vault restore --- test/unit/idStore-test.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 03b1d3b41..31da2cd3d 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -63,7 +63,7 @@ describe('IdentityStore', function() { const salt = 'lightwalletSalt' let password = 'secret!' - let accounts = [] + let accounts = {} let idStore var assertions = [ @@ -99,25 +99,22 @@ describe('IdentityStore', function() { idStore = new IdentityStore({ configManager: configManagerGen(), ethStore: { - addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, + addAccount(acct) { accounts[acct] = acct}, + del(acct) { delete accounts[acct] }, }, }) }) - beforeEach(function() { - accounts = [] - }) - it('should enforce seed compliance with TestRPC', function (done) { this.timeout(10000) const tests = assertions.map((assertion) => { return function (cb) { - accounts = [] + idStore.recoverFromSeed(password, assertion.seed, (err) => { assert.ifError(err) - var received = accounts[0].toLowerCase() var expected = assertion.account.toLowerCase() + var received = accounts[expected].toLowerCase() assert.equal(received, expected) idStore.tryPassword(password, function (err) { @@ -127,6 +124,7 @@ describe('IdentityStore', function() { 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() }) }) -- cgit From 91f43fa2130e84a32ebecf902696a0b897cdd095 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 17 Oct 2016 12:47:37 -0700 Subject: Increase gas estimate by 100000 wei To prevent minor gas estimation errors, probably usually related to operating on dynamic state. Fixes #738. --- test/unit/idStore-test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 31da2cd3d..7f6324645 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -2,6 +2,7 @@ var assert = require('assert') var IdentityStore = require('../../app/scripts/lib/idStore') var configManagerGen = require('../lib/mock-config-manager') const ethUtil = require('ethereumjs-util') +const BN = ethUtil.BN const async = require('async') describe('IdentityStore', function() { @@ -138,4 +139,20 @@ describe('IdentityStore', function() { }) }) }) + + describe('#addGasBuffer', function() { + const idStore = new IdentityStore({ + configManager: configManagerGen(), + ethStore: { + addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, + }, + }) + + const gas = '0x01' + const bnGas = new BN(gas, 16) + const result = idStore.addGasBuffer(gas) + const bnResult = new BN(result, 16) + + assert.ok(bnResult.gt(gas), 'added more gas as buffer.') + }) }) -- cgit From 827d7553fc843a75b7a4306c7549505f799609d7 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 17 Oct 2016 13:05:45 -0700 Subject: Restore hex prefix to gas price --- test/unit/idStore-test.js | 1 + 1 file changed, 1 insertion(+) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 7f6324645..0a57d2121 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -154,5 +154,6 @@ describe('IdentityStore', function() { const bnResult = new BN(result, 16) assert.ok(bnResult.gt(gas), 'added more gas as buffer.') + assert.equal(result.indexOf('0x'), 0, 'include hex prefix') }) }) -- cgit From 049705004f306bb83ad1bc0b7315d322becf8263 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 17 Oct 2016 14:48:25 -0700 Subject: Reproduced issue 743 in test case This contract hex does include the value `f4`, but it was compiled from a contract with no instance of `.delegatecall`. I believe `f4` in this case is part of some other value or contract address, and `ethBinToOps` has some error in how it skips pushed data. @kumavis --- test/unit/idStore-test.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 0a57d2121..c3f79b088 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -1,10 +1,15 @@ -var assert = require('assert') -var IdentityStore = require('../../app/scripts/lib/idStore') -var configManagerGen = require('../lib/mock-config-manager') +const assert = require('assert') +const IdentityStore = require('../../app/scripts/lib/idStore') +const configManagerGen = require('../lib/mock-config-manager') +const fs = require('fs') +const path = require('path') const ethUtil = require('ethereumjs-util') const BN = ethUtil.BN const async = require('async') +const nonDelegatePath = path.join(__dirname, '..', 'lib', 'non-delegate-code.txt') +const nonDelegateCode = fs.readFileSync(nonDelegatePath).toString() + describe('IdentityStore', function() { describe('#createNewVault', function () { @@ -156,4 +161,16 @@ describe('IdentityStore', function() { assert.ok(bnResult.gt(gas), 'added more gas as buffer.') assert.equal(result.indexOf('0x'), 0, 'include hex prefix') }) + + describe('#checkForDelegateCall', function() { + const idStore = new IdentityStore({ + configManager: configManagerGen(), + ethStore: { + addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, + }, + }) + + var result = idStore.checkForDelegateCall(nonDelegateCode) + assert.equal(result, false, 'no delegate call in provided code') + }) }) -- cgit From 3af3565000e4952d95c50c1c25a9367ba8caec90 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 24 Oct 2016 16:12:44 -0700 Subject: test - fix delegate-call test --- test/unit/idStore-test.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index c3f79b088..da465f511 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -1,14 +1,10 @@ +const async = require('async') const assert = require('assert') -const IdentityStore = require('../../app/scripts/lib/idStore') -const configManagerGen = require('../lib/mock-config-manager') -const fs = require('fs') -const path = require('path') const ethUtil = require('ethereumjs-util') const BN = ethUtil.BN -const async = require('async') - -const nonDelegatePath = path.join(__dirname, '..', 'lib', 'non-delegate-code.txt') -const nonDelegateCode = fs.readFileSync(nonDelegatePath).toString() +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() { @@ -170,7 +166,7 @@ describe('IdentityStore', function() { }, }) - var result = idStore.checkForDelegateCall(nonDelegateCode) - assert.equal(result, false, 'no delegate call in provided code') + var result = idStore.checkForDelegateCall(delegateCallCode) + assert.equal(result, true, 'no delegate call in provided code') }) }) -- cgit From fff5a6765ecc586bd855aa263c0fdfc3f957e8d7 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 7 Nov 2016 11:25:23 -0800 Subject: Added failing test for #787 --- test/unit/idStore-test.js | 52 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 11 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index da465f511..34b0c992e 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -142,20 +142,49 @@ describe('IdentityStore', function() { }) describe('#addGasBuffer', function() { - const idStore = new IdentityStore({ - configManager: configManagerGen(), - ethStore: { - addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, - }, + it('formats the result correctly', function() { + const idStore = new IdentityStore({ + configManager: configManagerGen(), + ethStore: { + addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, + }, + }) + + const gas = '0x01' + const bnGas = new BN(gas, 16) + const result = idStore.addGasBuffer(gas) + const bnResult = new BN(result, 16) + + assert.ok(bnResult.gt(gas), 'added more gas as buffer.') + assert.equal(result.indexOf('0x'), 0, 'include hex prefix') }) - const gas = '0x01' - const bnGas = new BN(gas, 16) - const result = idStore.addGasBuffer(gas) - const bnResult = new BN(result, 16) + it('buffers reasonably', function() { + const idStore = new IdentityStore({ + configManager: configManagerGen(), + ethStore: { + addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, + }, + }) - assert.ok(bnResult.gt(gas), 'added more gas as buffer.') - assert.equal(result.indexOf('0x'), 0, 'include hex prefix') + const gas = '0x04ee59' // Actual estimated gas example + const tooBigOutput = '0x80674f9' // Actual bad output + const bnGas = new BN(gas, 16) + const correctBuffer = new BN('100000', 10) + const correct = bnGas.add(correctBuffer) + + const tooBig = new BN(tooBigOutput, 16) + console.log(`Pure estimate is ${bnGas.toString(10)}`) + console.log(`Too big is ${tooBig.toString(10)}`) + console.log(`Buffer should be ${correctBuffer.toString(10)}`) + console.log(`correct should be ${correct.toString(10)}`) + const result = idStore.addGasBuffer(gas) + const bnResult = new BN(result, 16) + + console.log(`Result was ${bnResult.toString(10)}`) + assert.equal(result, correct.toString(16), 'add the right amount') + assert.notEqual(result, tooBigOutput, 'not that bad estimate') + }) }) describe('#checkForDelegateCall', function() { @@ -169,4 +198,5 @@ describe('IdentityStore', function() { var result = idStore.checkForDelegateCall(delegateCallCode) assert.equal(result, true, 'no delegate call in provided code') }) + }) -- cgit From 1896928562c728612caa7498ed82559a82a09aeb Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 7 Nov 2016 11:55:17 -0800 Subject: Fix gas price buffering Our gas price buffering logic had a bug, because bn.js has inconsistent behavior when using hex-prefixed output. The issue has been opened with them here: https://github.com/indutny/bn.js/issues/151 We've corrected our usage in the mean time. --- test/unit/idStore-test.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 34b0c992e..46b3d4809 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -169,20 +169,18 @@ describe('IdentityStore', function() { const gas = '0x04ee59' // Actual estimated gas example const tooBigOutput = '0x80674f9' // Actual bad output - const bnGas = new BN(gas, 16) + const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16) const correctBuffer = new BN('100000', 10) const correct = bnGas.add(correctBuffer) const tooBig = new BN(tooBigOutput, 16) - console.log(`Pure estimate is ${bnGas.toString(10)}`) - console.log(`Too big is ${tooBig.toString(10)}`) - console.log(`Buffer should be ${correctBuffer.toString(10)}`) - console.log(`correct should be ${correct.toString(10)}`) const result = idStore.addGasBuffer(gas) - const bnResult = new BN(result, 16) + const bnResult = new BN(ethUtil.stripHexPrefix(result), 16) - console.log(`Result was ${bnResult.toString(10)}`) - assert.equal(result, correct.toString(16), 'add the right amount') + assert.equal(result.indexOf('0x'), 0, 'included hex prefix') + assert(bnResult.gt(bnGas), 'Estimate increased in value.') + assert.equal(bnResult.sub(bnGas).toString(10), '100000', 'added 100k gas') + assert.equal(result, '0x' + correct.toString(16), 'Added the right amount') assert.notEqual(result, tooBigOutput, 'not that bad estimate') }) }) -- cgit From 6f39924e60545ca8ac19995a799c16d0dea11b04 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 8 Nov 2016 08:32:34 -0800 Subject: Increase gas buffer Fixes #795 --- test/unit/idStore-test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 46b3d4809..b0940d2fa 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -168,9 +168,8 @@ describe('IdentityStore', function() { }) const gas = '0x04ee59' // Actual estimated gas example - const tooBigOutput = '0x80674f9' // Actual bad output const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16) - const correctBuffer = new BN('100000', 10) + const correctBuffer = new BN('200000', 10) const correct = bnGas.add(correctBuffer) const tooBig = new BN(tooBigOutput, 16) -- cgit From 7068d2e71c6d1ddb68095916dc16f3ff1f283590 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 8 Nov 2016 08:39:41 -0800 Subject: Adjust gas buffer to be 20% over estimate --- test/unit/idStore-test.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index b0940d2fa..064483ba0 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -159,7 +159,7 @@ describe('IdentityStore', function() { assert.equal(result.indexOf('0x'), 0, 'include hex prefix') }) - it('buffers reasonably', function() { + it('buffers 20%', function() { const idStore = new IdentityStore({ configManager: configManagerGen(), ethStore: { @@ -169,18 +169,17 @@ describe('IdentityStore', function() { const gas = '0x04ee59' // Actual estimated gas example const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16) - const correctBuffer = new BN('200000', 10) + const five = new BN('5', 10) + const correctBuffer = bnGas.div(five) const correct = bnGas.add(correctBuffer) - const tooBig = new BN(tooBigOutput, 16) const result = idStore.addGasBuffer(gas) const bnResult = new BN(ethUtil.stripHexPrefix(result), 16) assert.equal(result.indexOf('0x'), 0, 'included hex prefix') assert(bnResult.gt(bnGas), 'Estimate increased in value.') - assert.equal(bnResult.sub(bnGas).toString(10), '100000', 'added 100k gas') + assert.equal(bnResult.sub(bnGas).toString(10), correctBuffer.toString(10), 'added 20% gas') assert.equal(result, '0x' + correct.toString(16), 'Added the right amount') - assert.notEqual(result, tooBigOutput, 'not that bad estimate') }) }) -- cgit From 9123e70434fcd35dcb79a587e6d5c00734cb99e4 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Mon, 21 Nov 2016 15:49:03 -0800 Subject: Remove entropy from encryption and project. --- test/unit/idStore-test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 064483ba0..72ecf34d5 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -11,7 +11,6 @@ describe('IdentityStore', function() { describe('#createNewVault', function () { let idStore let password = 'password123' - let entropy = 'entripppppyy duuude' let seedWords let accounts = [] let originalKeystore @@ -26,7 +25,7 @@ describe('IdentityStore', function() { }, }) - idStore.createNewVault(password, entropy, (err, seeds) => { + idStore.createNewVault(password, (err, seeds) => { assert.ifError(err, 'createNewVault threw error') seedWords = seeds originalKeystore = idStore._idmgmt.keyStore -- cgit From fa2f0dee285d4a9032f8a756ee8711a7fe767b76 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 22 Nov 2016 12:10:49 -0800 Subject: idStore - fix estimateGas calculation --- test/unit/idStore-test.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 064483ba0..bf8270540 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -152,11 +152,9 @@ describe('IdentityStore', function() { const gas = '0x01' const bnGas = new BN(gas, 16) - const result = idStore.addGasBuffer(gas) - const bnResult = new BN(result, 16) + const bnResult = idStore.addGasBuffer(bnGas) assert.ok(bnResult.gt(gas), 'added more gas as buffer.') - assert.equal(result.indexOf('0x'), 0, 'include hex prefix') }) it('buffers 20%', function() { @@ -173,13 +171,10 @@ describe('IdentityStore', function() { const correctBuffer = bnGas.div(five) const correct = bnGas.add(correctBuffer) - const result = idStore.addGasBuffer(gas) - const bnResult = new BN(ethUtil.stripHexPrefix(result), 16) + const bnResult = idStore.addGasBuffer(bnGas) - assert.equal(result.indexOf('0x'), 0, 'included hex prefix') assert(bnResult.gt(bnGas), 'Estimate increased in value.') assert.equal(bnResult.sub(bnGas).toString(10), correctBuffer.toString(10), 'added 20% gas') - assert.equal(result, '0x' + correct.toString(16), 'Added the right amount') }) }) -- cgit From 6e78494846c9032fbf1264a0225c0df4df0867cb Mon Sep 17 00:00:00 2001 From: Frances Pangilinan Date: Fri, 16 Dec 2016 10:33:36 -0800 Subject: First pass at revision requests --- test/unit/idStore-test.js | 50 ----------------------------------------------- 1 file changed, 50 deletions(-) (limited to 'test/unit/idStore-test.js') diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js index 3ca89cd38..000c58a82 100644 --- a/test/unit/idStore-test.js +++ b/test/unit/idStore-test.js @@ -139,54 +139,4 @@ describe('IdentityStore', function() { }) }) }) - - describe('#addGasBuffer', function() { - it('formats the result correctly', function() { - const idStore = new IdentityStore({ - configManager: configManagerGen(), - ethStore: { - addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, - }, - }) - - const gas = '0x01' - const bnGas = new BN(gas, 16) - const bnResult = idStore.addGasBuffer(bnGas) - - assert.ok(bnResult.gt(gas), 'added more gas as buffer.') - }) - - it('buffers 20%', function() { - const idStore = new IdentityStore({ - configManager: configManagerGen(), - ethStore: { - addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, - }, - }) - - const gas = '0x04ee59' // Actual estimated gas example - const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16) - const five = new BN('5', 10) - const correctBuffer = bnGas.div(five) - const correct = bnGas.add(correctBuffer) - - const bnResult = idStore.addGasBuffer(bnGas) - - assert(bnResult.gt(bnGas), 'Estimate increased in value.') - assert.equal(bnResult.sub(bnGas).toString(10), correctBuffer.toString(10), 'added 20% gas') - }) - }) - - describe('#checkForDelegateCall', function() { - const idStore = new IdentityStore({ - configManager: configManagerGen(), - ethStore: { - addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) }, - }, - }) - - var result = idStore.checkForDelegateCall(delegateCallCode) - assert.equal(result, true, 'no delegate call in provided code') - }) - }) -- cgit