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

Commit

Permalink
add test comparing new implementation with old to ensure account deri…
Browse files Browse the repository at this point in the history
…vation is consistent
  • Loading branch information
adonesky1 committed Sep 16, 2022
1 parent 3e3862d commit 91ee4c8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@metamask/eslint-config": "^8.0.0",
"@metamask/eslint-config-jest": "^9.0.0",
"@metamask/eslint-config-nodejs": "^8.0.0",
"@metamask/eth-hd-keyring": "4.0.2",
"@types/jest": "^27.4.1",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
Expand Down
23 changes: 23 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
const { wordlist } = require('@metamask/scure-bip39/dist/wordlists/english');
const oldMMForkBIP39 = require('@metamask/bip39');
const { isValidAddress } = require('@ethereumjs/util');
const OldHdKeyring = require('@metamask/eth-hd-keyring');
const HdKeyring = require('..');

// Sample account:
Expand All @@ -26,6 +27,28 @@ describe('hd-keyring', () => {
keyring = new HdKeyring();
});

describe('compare old bip39 implementation with new', () => {
it('should derive the same accounts from the same mnemonics', () => {
const mnemonics = [];
for (let i = 0; i < 99; i++) {
mnemonics.push(oldMMForkBIP39.generateMnemonic());
}

mnemonics.forEach(async (mnemonic) => {
const newHDKeyring = new HdKeyring({ mnemonic, numberOfAccounts: 3 });
const oldHDKeyring = new OldHdKeyring({
mnemonic,
numberOfAccounts: 3,
});
const newAccounts = await newHDKeyring.getAccounts();
const oldAccounts = await oldHDKeyring.getAccounts();
expect(newAccounts[0]).toStrictEqual(oldAccounts[0]);
expect(newAccounts[1]).toStrictEqual(oldAccounts[1]);
expect(newAccounts[2]).toStrictEqual(oldAccounts[2]);
});
});
});

describe('constructor', () => {
it('constructs with a typeof string mnemonic', async () => {
keyring = new HdKeyring({
Expand Down
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,17 @@
resolved "https://registry.yarnpkg.com/@metamask/eslint-config/-/eslint-config-8.0.0.tgz#f4e3bcd6b37ec135b5a72902b0526cba2a6b5a4d"
integrity sha512-ZO9B3ohNhjomrufNAkxnDXV46Kut7NKzri7itDxUzHJncNtI1of7ewWh6fKPl/hr6Al6Gd7WgjPdJZGFpzKPQw==

"@metamask/eth-hd-keyring@4.0.2":
version "4.0.2"
resolved "https://registry.yarnpkg.com/@metamask/eth-hd-keyring/-/eth-hd-keyring-4.0.2.tgz#0a81556a556b361755c8d6fb5aced1ce5be0331c"
integrity sha512-v47VOTCCmZUZ6uxM5tQNoasQjLdrZADmgph2fhk4m7zKVUxDvYFU7FJT3Rm55fk8mg+dKSbEObDriqbdWeBbcA==
dependencies:
"@metamask/bip39" "^4.0.0"
"@metamask/eth-sig-util" "^4.0.0"
eth-simple-keyring "^4.2.0"
ethereumjs-util "^7.0.9"
ethereumjs-wallet "^1.0.1"

"@metamask/eth-sig-util@^4.0.0":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@metamask/eth-sig-util/-/eth-sig-util-4.0.1.tgz#3ad61f6ea9ad73ba5b19db780d40d9aae5157088"
Expand Down

0 comments on commit 91ee4c8

Please sign in to comment.