Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

fix _initFromMnemonic bug + get test coverage to 100% #62

Merged
merged 2 commits into from
Apr 18, 2022

Conversation

adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented Apr 18, 2022

  • Fix bug where we are passing the unbuffered mnemonic to bip39.mnemonicToSeedSync when _initFromMnemonic is passed a typeof string mnemonic

  • Bump unit test coverage to 100%

@adonesky1 adonesky1 requested a review from a team as a code owner April 18, 2022 17:31
@adonesky1 adonesky1 requested review from Gudahtt and mcmire April 18, 2022 17:31
@@ -36,6 +43,17 @@ describe('hd-keyring', () => {
expect(accounts[1]).toStrictEqual(secondAcct);
});

it('constructs with a typeof array mnemonic', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a third type accepted: Buffer.

keyring.generateRandomMnemonic();
const output = await keyring.serialize();
expect(output.numberOfAccounts).toBe(0);
expect(Array.isArray(output.mnemonic)).toBe(true);
});

it('serializes mnemonic stored as a string in a class variable into a buffer array and does not add accounts', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I suppose this test is useful because the mnemonic field isn't marked as private, but I really was thinking of it as private 🤔 Maybe we should have noted the type change of this field in the changelog as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can note the change when we push a patch release?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can amend the v4 changelog in that same PR.

Gudahtt
Gudahtt previously approved these changes Apr 18, 2022
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Though I left one suggestion for an additional test case

@adonesky1
Copy link
Contributor Author

@Gudahtt added a test to cover the case you noted.

@adonesky1 adonesky1 merged commit 7ce5c14 into main Apr 18, 2022
@adonesky1 adonesky1 deleted the test-coverage-100 branch April 18, 2022 19:32
@mcmire
Copy link

mcmire commented Apr 18, 2022

Thank you @adonesky1 for stepping in to fix the bugs that I must have missed in the original patch 😣

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants