From c009fba302a66a93202f46b45623a66cb8e164c7 Mon Sep 17 00:00:00 2001 From: Jamie M Date: Thu, 12 Jan 2023 18:25:50 +0800 Subject: [PATCH 1/5] leave unlocked when adding account --- main/signers/hot/RingSigner/index.js | 4 +-- main/signers/hot/SeedSigner/index.js | 3 +-- .../main/signers/hot/RingSigner/index.test.js | 20 +++----------- .../main/signers/hot/SeedSigner/index.test.js | 26 +++++++++---------- 4 files changed, 20 insertions(+), 33 deletions(-) diff --git a/main/signers/hot/RingSigner/index.js b/main/signers/hot/RingSigner/index.js index 9d88387b7..bc322629c 100644 --- a/main/signers/hot/RingSigner/index.js +++ b/main/signers/hot/RingSigner/index.js @@ -55,7 +55,7 @@ class RingSigner extends HotSigner { this.update() // If signer was unlock -> update keys in worker - if (this.status === 'ok') this.unlock(password, cb) + if (this.status === 'locked') this.unlock(password, cb) else cb(null) }) } @@ -78,7 +78,7 @@ class RingSigner extends HotSigner { this.update() // If signer was unlock -> update keys in worker - if (this.status === 'ok') this.unlock(password, cb) + if (this.status === 'ok') this.lock(cb) else cb(null) }) } diff --git a/main/signers/hot/SeedSigner/index.js b/main/signers/hot/SeedSigner/index.js index 671e398c6..d3f9c371f 100644 --- a/main/signers/hot/SeedSigner/index.js +++ b/main/signers/hot/SeedSigner/index.js @@ -35,8 +35,7 @@ class SeedSigner extends HotSigner { this.encryptedSeed = encryptedSeed this.addresses = addresses this.update() - - cb(null) + if (this.status === 'locked') this.unlock(password, cb) }) } diff --git a/test/main/signers/hot/RingSigner/index.test.js b/test/main/signers/hot/RingSigner/index.test.js index 23bab7bb5..8871d5038 100644 --- a/test/main/signers/hot/RingSigner/index.test.js +++ b/test/main/signers/hot/RingSigner/index.test.js @@ -82,7 +82,7 @@ describe('Ring signer', () => { signer = result expect(err).toBe(null) - expect(signer.status).toBe('locked') + expect(signer.status).toBe('ok') expect(signer.id).not.toBe(undefined) expect(store(`main.signers.${signer.id}.id`)).toBe(signer.id) done() @@ -132,14 +132,14 @@ describe('Ring signer', () => { hot.createFromKeystore(signers, keystore, 'test', PASSWORD, (err, result) => { signer = result expect(err).toBe(null) - expect(signer.status).toBe('locked') + expect(signer.status).toBe('ok') expect(signer.id).not.toBe(undefined) done() }) } catch (e) { done(e) } - }, 2000) + }, 5000) test('Add private key', (done) => { try { @@ -177,7 +177,7 @@ describe('Ring signer', () => { } catch (e) { done(e) } - }, 1000) + }, 6000) test('Add private key from keystore', (done) => { try { @@ -277,18 +277,6 @@ describe('Ring signer', () => { } }, 500) - test('Lock', (done) => { - try { - signer.lock((err) => { - expect(err).toBe(null) - expect(signer.status).toBe('locked') - done() - }) - } catch (e) { - done(e) - } - }, 2000) - test('Sign message when locked', (done) => { try { signer.signMessage(0, 'test', (err) => { diff --git a/test/main/signers/hot/SeedSigner/index.test.js b/test/main/signers/hot/SeedSigner/index.test.js index 7c13cb480..ffdfc14df 100644 --- a/test/main/signers/hot/SeedSigner/index.test.js +++ b/test/main/signers/hot/SeedSigner/index.test.js @@ -65,7 +65,7 @@ describe('Seed signer', () => { hot.createFromPhrase(signers, mnemonic, PASSWORD, (err, result) => { signer = result expect(err).toBe(null) - expect(signer.status).toBe('locked') + expect(signer.status).toBe('ok') expect(signer.addresses.length).toBe(100) expect(store(`main.signers.${signer.id}.id`)).toBe(signer.id) done() @@ -75,6 +75,18 @@ describe('Seed signer', () => { } }, 2000) + test('Lock', (done) => { + try { + signer.lock((err) => { + expect(err).toBe(null) + expect(signer.status).toBe('locked') + done() + }) + } catch (e) { + done(e) + } + }, 2000) + test('Scan for signers', (done) => { jest.useFakeTimers() @@ -177,18 +189,6 @@ describe('Seed signer', () => { } }, 500) - test('Lock', (done) => { - try { - signer.lock((err) => { - expect(err).toBe(null) - expect(signer.status).toBe('locked') - done() - }) - } catch (e) { - done(e) - } - }, 2000) - test('Sign message when locked', (done) => { try { signer.signMessage(0, 'test', (err) => { From 28b05c7e33a342c35abb3b551c61201ef2794a0b Mon Sep 17 00:00:00 2001 From: Jamie M Date: Fri, 13 Jan 2023 09:58:57 +0800 Subject: [PATCH 2/5] address PR comments --- main/signers/hot/RingSigner/index.js | 3 +-- main/signers/hot/SeedSigner/index.js | 2 +- test/main/signers/hot/RingSigner/index.test.js | 12 ++++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/main/signers/hot/RingSigner/index.js b/main/signers/hot/RingSigner/index.js index bc322629c..cee514ce6 100644 --- a/main/signers/hot/RingSigner/index.js +++ b/main/signers/hot/RingSigner/index.js @@ -55,8 +55,7 @@ class RingSigner extends HotSigner { this.update() // If signer was unlock -> update keys in worker - if (this.status === 'locked') this.unlock(password, cb) - else cb(null) + this.unlock(password, cb) }) } diff --git a/main/signers/hot/SeedSigner/index.js b/main/signers/hot/SeedSigner/index.js index d3f9c371f..b110ddc42 100644 --- a/main/signers/hot/SeedSigner/index.js +++ b/main/signers/hot/SeedSigner/index.js @@ -35,7 +35,7 @@ class SeedSigner extends HotSigner { this.encryptedSeed = encryptedSeed this.addresses = addresses this.update() - if (this.status === 'locked') this.unlock(password, cb) + this.unlock(password, cb) }) } diff --git a/test/main/signers/hot/RingSigner/index.test.js b/test/main/signers/hot/RingSigner/index.test.js index 8871d5038..0b92e0358 100644 --- a/test/main/signers/hot/RingSigner/index.test.js +++ b/test/main/signers/hot/RingSigner/index.test.js @@ -206,6 +206,18 @@ describe('Ring signer', () => { } }, 600) + test('Lock', (done) => { + try { + signer.lock((err) => { + expect(err).toBe(null) + expect(signer.status).toBe('locked') + done() + }) + } catch (e) { + done(e) + } + }, 2000) + test('Unlock', (done) => { try { signer.unlock(PASSWORD, (err) => { From 5e1c4ae456af30582a947e8518d6529b6a9af2cc Mon Sep 17 00:00:00 2001 From: Jamie M Date: Fri, 13 Jan 2023 12:22:14 +0800 Subject: [PATCH 3/5] reduce timeouts again --- test/main/signers/hot/RingSigner/index.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/main/signers/hot/RingSigner/index.test.js b/test/main/signers/hot/RingSigner/index.test.js index 0b92e0358..120098a9c 100644 --- a/test/main/signers/hot/RingSigner/index.test.js +++ b/test/main/signers/hot/RingSigner/index.test.js @@ -139,7 +139,7 @@ describe('Ring signer', () => { } catch (e) { done(e) } - }, 5000) + }, 2000) test('Add private key', (done) => { try { @@ -177,7 +177,7 @@ describe('Ring signer', () => { } catch (e) { done(e) } - }, 6000) + }, 2000) test('Add private key from keystore', (done) => { try { From 1949a79bf46e22f7e6aae7e14df78ec837bdac66 Mon Sep 17 00:00:00 2001 From: Jamie M Date: Mon, 16 Jan 2023 17:01:41 +0800 Subject: [PATCH 4/5] correct order of tests, increase timeout for creating the account, close the signer afterAll if not done yet --- .../main/signers/hot/RingSigner/index.test.js | 24 ++++++++++--------- .../main/signers/hot/SeedSigner/index.test.js | 6 +++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/test/main/signers/hot/RingSigner/index.test.js b/test/main/signers/hot/RingSigner/index.test.js index 120098a9c..58e3998d9 100644 --- a/test/main/signers/hot/RingSigner/index.test.js +++ b/test/main/signers/hot/RingSigner/index.test.js @@ -43,7 +43,9 @@ describe('Ring signer', () => { afterAll(() => { clean() - + if (signer.status !== 'locked') { + signer.close() + } log.transports.console.level = 'debug' }) @@ -90,7 +92,7 @@ describe('Ring signer', () => { } catch (e) { done(e) } - }, 2000) + }, 10_000) test('Scan for signers', (done) => { jest.useFakeTimers() @@ -195,28 +197,28 @@ describe('Ring signer', () => { } }, 2000) - test('Unlock with wrong password', (done) => { + test('Lock', (done) => { try { - signer.unlock('Wrong password', (err) => { - expect(err).toBeTruthy() + signer.lock((err) => { + expect(err).toBe(null) + expect(signer.status).toBe('locked') done() }) } catch (e) { done(e) } - }, 600) + }, 2000) - test('Lock', (done) => { + test('Unlock with wrong password', (done) => { try { - signer.lock((err) => { - expect(err).toBe(null) - expect(signer.status).toBe('locked') + signer.unlock('Wrong password', (err) => { + expect(err).toBeTruthy() done() }) } catch (e) { done(e) } - }, 2000) + }, 600) test('Unlock', (done) => { try { diff --git a/test/main/signers/hot/SeedSigner/index.test.js b/test/main/signers/hot/SeedSigner/index.test.js index ffdfc14df..73c259913 100644 --- a/test/main/signers/hot/SeedSigner/index.test.js +++ b/test/main/signers/hot/SeedSigner/index.test.js @@ -41,7 +41,9 @@ describe('Seed signer', () => { afterAll(() => { clean() - + if (signer.status !== 'locked') { + signer.close() + } log.transports.console.level = 'debug' }) @@ -73,7 +75,7 @@ describe('Seed signer', () => { } catch (e) { done(e) } - }, 2000) + }, 10_000) test('Lock', (done) => { try { From f6cf9278a261223b7415a6f6212e1262bd48f88b Mon Sep 17 00:00:00 2001 From: Jamie M Date: Mon, 16 Jan 2023 19:32:24 +0800 Subject: [PATCH 5/5] reduce tests to 7500ms --- test/main/signers/hot/RingSigner/index.test.js | 2 +- test/main/signers/hot/SeedSigner/index.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/main/signers/hot/RingSigner/index.test.js b/test/main/signers/hot/RingSigner/index.test.js index 58e3998d9..b3025b3db 100644 --- a/test/main/signers/hot/RingSigner/index.test.js +++ b/test/main/signers/hot/RingSigner/index.test.js @@ -92,7 +92,7 @@ describe('Ring signer', () => { } catch (e) { done(e) } - }, 10_000) + }, 7_500) test('Scan for signers', (done) => { jest.useFakeTimers() diff --git a/test/main/signers/hot/SeedSigner/index.test.js b/test/main/signers/hot/SeedSigner/index.test.js index 73c259913..38a317dbe 100644 --- a/test/main/signers/hot/SeedSigner/index.test.js +++ b/test/main/signers/hot/SeedSigner/index.test.js @@ -75,7 +75,7 @@ describe('Seed signer', () => { } catch (e) { done(e) } - }, 10_000) + }, 7_500) test('Lock', (done) => { try {