Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 21 additions & 24 deletions packages/keyring-eth-hd/src/hd-keyring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ const sampleMnemonicSeed = mnemonicToSeedSync(sampleMnemonic);

const notKeyringAddress = '0xbD20F6F5F1616947a39E11926E78ec94817B3931';

const getAddressAtIndex = async (
keyring: HdKeyring,
index: number,
): Promise<Hex> => {
const accounts = await keyring.getAccounts();
const getAddressAtIndex = (keyring: HdKeyring, index: number): Hex => {
const accounts = keyring.getAccounts();
assert(accounts[index], `Account not found at index ${index}`);
return accounts[index];
};
Expand Down Expand Up @@ -78,7 +75,7 @@ describe('hd-keyring', () => {
mnemonic,
numberOfAccounts: 3,
});
const newAccounts = await newHDKeyring.getAccounts();
const newAccounts = newHDKeyring.getAccounts();
const oldAccounts = await oldHDKeyring.getAccounts();
expect(newAccounts[0]).toStrictEqual(oldAccounts[0]);

Expand Down Expand Up @@ -181,7 +178,7 @@ describe('hd-keyring', () => {
numberOfAccounts: 2,
});

const accounts = await keyring.getAccounts();
const accounts = keyring.getAccounts();
expect(accounts[0]).toStrictEqual(firstAcct);
expect(accounts[1]).toStrictEqual(secondAcct);
expect(keyring.mnemonic).toStrictEqual(sampleMnemonicBytes);
Expand All @@ -196,7 +193,7 @@ describe('hd-keyring', () => {
numberOfAccounts: 2,
});

const accounts = await keyring.getAccounts();
const accounts = keyring.getAccounts();
expect(accounts[0]).toStrictEqual(firstAcct);
expect(accounts[1]).toStrictEqual(secondAcct);
expect(keyring.mnemonic).toStrictEqual(sampleMnemonicBytes);
Expand Down Expand Up @@ -242,7 +239,7 @@ describe('hd-keyring', () => {
numberOfAccounts: 2,
});

const accounts = await keyring.getAccounts();
const accounts = keyring.getAccounts();
expect(accounts[0]).toStrictEqual(firstAcct);
expect(accounts[1]).toStrictEqual(secondAcct);
expect(keyring.mnemonic).toStrictEqual(sampleMnemonicBytes);
Expand Down Expand Up @@ -281,11 +278,11 @@ describe('hd-keyring', () => {
mnemonic: sampleMnemonic,
numberOfAccounts: 1,
});
const accountsFirstCheck = await keyring.getAccounts();
const accountsFirstCheck = keyring.getAccounts();

expect(accountsFirstCheck).toHaveLength(1);
await keyring.addAccounts(1);
const accountsSecondCheck = await keyring.getAccounts();
const accountsSecondCheck = keyring.getAccounts();
expect(accountsSecondCheck[0]).toStrictEqual(firstAcct);
expect(accountsSecondCheck[1]).toStrictEqual(secondAcct);
expect(accountsSecondCheck).toHaveLength(2);
Expand All @@ -303,7 +300,7 @@ describe('hd-keyring', () => {
await keyring.deserialize({});
await keyring.generateRandomMnemonic();
await keyring.addAccounts();
const accounts = await keyring.getAccounts();
const accounts = keyring.getAccounts();
expect(accounts).toHaveLength(1);
});

Expand All @@ -321,7 +318,7 @@ describe('hd-keyring', () => {
await keyring.deserialize({});
await keyring.generateRandomMnemonic();
await keyring.addAccounts(3);
const accounts = await keyring.getAccounts();
const accounts = keyring.getAccounts();
expect(accounts).toHaveLength(3);
});
});
Expand Down Expand Up @@ -364,7 +361,7 @@ describe('hd-keyring', () => {
await keyring.deserialize({});
await keyring.generateRandomMnemonic();
await keyring.addAccounts(1);
const address = await getAddressAtIndex(keyring, 0);
const address = getAddressAtIndex(keyring, 0);
const signature = await keyring.signTypedData(address, typedData);
const restored = recoverTypedSignature({
data: typedData,
Expand All @@ -389,7 +386,7 @@ describe('hd-keyring', () => {
await keyring.deserialize({});
await keyring.generateRandomMnemonic();
await keyring.addAccounts(1);
const address = await getAddressAtIndex(keyring, 0);
const address = getAddressAtIndex(keyring, 0);
const signature = await keyring.signTypedData(address, typedData, {
version: SignTypedDataVersion.V1,
});
Expand Down Expand Up @@ -418,7 +415,7 @@ describe('hd-keyring', () => {
mnemonic: sampleMnemonic,
numberOfAccounts: 1,
});
const address = await getAddressAtIndex(keyring, 0);
const address = getAddressAtIndex(keyring, 0);
const signature = await keyring.signTypedData(address, typedData, {
version: SignTypedDataVersion.V3,
});
Expand Down Expand Up @@ -475,7 +472,7 @@ describe('hd-keyring', () => {
await keyring.deserialize({});
await keyring.generateRandomMnemonic();
await keyring.addAccounts(1);
const address = await getAddressAtIndex(keyring, 0);
const address = getAddressAtIndex(keyring, 0);
const signature = await keyring.signTypedData(address, typedData, {
version: SignTypedDataVersion.V3,
});
Expand All @@ -497,7 +494,7 @@ describe('hd-keyring', () => {
numberOfAccounts: 1,
hdPath: hdPathString,
});
const addresses = await keyring.getAccounts();
const addresses = keyring.getAccounts();
expect(addresses[0]).toStrictEqual(firstAcct);
const serialized = await keyring.serialize();
expect(serialized.hdPath).toStrictEqual(hdPathString);
Expand All @@ -511,7 +508,7 @@ describe('hd-keyring', () => {
numberOfAccounts: 1,
hdPath: hdPathString,
});
const addresses = await keyring.getAccounts();
const addresses = keyring.getAccounts();
expect(addresses[0]).not.toBe(firstAcct);
const serialized = await keyring.serialize();
expect(serialized.hdPath).toStrictEqual(hdPathString);
Expand Down Expand Up @@ -640,7 +637,7 @@ describe('hd-keyring', () => {
Buffer.from(keccak256(Buffer.from(localMessage))),
);
await keyring.addAccounts(9);
const addresses = await keyring.getAccounts();
const addresses = keyring.getAccounts();
const signatures = await Promise.all(
addresses.map(async (accountAddress) => {
return await keyring.signMessage(accountAddress, msgHashHex);
Expand Down Expand Up @@ -767,10 +764,10 @@ describe('hd-keyring', () => {

describe('if the account exists', function () {
it('should remove that account', async function () {
const addresses = await keyring.getAccounts();
const addresses = keyring.getAccounts();
expect(addresses).toHaveLength(1);
keyring.removeAccount(await getAddressAtIndex(keyring, 0));
const addressesAfterRemoval = await keyring.getAccounts();
keyring.removeAccount(getAddressAtIndex(keyring, 0));
const addressesAfterRemoval = keyring.getAccounts();
expect(addressesAfterRemoval).toHaveLength(0);
});
});
Expand Down Expand Up @@ -979,7 +976,7 @@ describe('hd-keyring', () => {
},
};

const address = await getAddressAtIndex(keyring, 0);
const address = getAddressAtIndex(keyring, 0);

const signature = await keyring.signTypedData(address, typedData, {
version: SignTypedDataVersion.V4,
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-eth-hd/src/hd-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export class HdKeyring implements Keyring {
*
* @returns The addresses of all accounts in the keyring.
*/
async getAccounts(): Promise<Hex[]> {
getAccounts(): Hex[] {
return Array.from(this.#walletMap.keys());
}

Expand Down
10 changes: 5 additions & 5 deletions packages/keyring-eth-ledger-bridge/src/ledger-keyring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('LedgerKeyring', function () {
});
expect(typeof ledgerKeyring).toBe('object');

const accounts = await ledgerKeyring.getAccounts();
const accounts = ledgerKeyring.getAccounts();
expect(Array.isArray(accounts)).toBe(true);
});

Expand Down Expand Up @@ -441,7 +441,7 @@ describe('LedgerKeyring', function () {
keyring.setAccountToUnlock(1);
const secondBatch = await keyring.addAccounts(1);

expect(await keyring.getAccounts()).toHaveLength(2);
expect(keyring.getAccounts()).toHaveLength(2);
expect(firstBatch).toStrictEqual([fakeAccounts[0]]);
expect(secondBatch).toStrictEqual([fakeAccounts[1]]);
});
Expand All @@ -455,7 +455,7 @@ describe('LedgerKeyring', function () {
const accounts = await keyring.addAccounts(1);
expect(accounts).toHaveLength(1);
keyring.removeAccount(fakeAccounts[0]);
const accountsAfterRemoval = await keyring.getAccounts();
const accountsAfterRemoval = keyring.getAccounts();
expect(accountsAfterRemoval).toHaveLength(0);
});
});
Expand Down Expand Up @@ -546,7 +546,7 @@ describe('LedgerKeyring', function () {
beforeEach(async function () {
keyring.setAccountToUnlock(accountIndex);
await keyring.addAccounts(1);
accounts = await keyring.getAccounts();
accounts = keyring.getAccounts();
});

it('returns an array of accounts', function () {
Expand All @@ -569,7 +569,7 @@ describe('LedgerKeyring', function () {
// Wipe the keyring
keyring.forgetDevice();

const accounts = await keyring.getAccounts();
const accounts = keyring.getAccounts();

expect(keyring.isUnlocked()).toBe(false);
expect(accounts).toHaveLength(0);
Expand Down
4 changes: 2 additions & 2 deletions packages/keyring-eth-ledger-bridge/src/ledger-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ export class LedgerKeyring implements Keyring {
return this.#getPage(-1);
}

async getAccounts(): Promise<Hex[]> {
return Promise.resolve(this.accounts.slice());
getAccounts(): Hex[] {
return this.accounts.slice();
}

removeAccount(address: string): void {
Expand Down
22 changes: 11 additions & 11 deletions packages/keyring-eth-qr/src/qr-keyring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('QrKeyring', () => {

await keyring.deserialize({});

expect(await keyring.getAccounts()).toStrictEqual([]);
expect(keyring.getAccounts()).toStrictEqual([]);
expect(await getXPUBFromKeyring(keyring)).toBeUndefined();
});
});
Expand All @@ -208,7 +208,7 @@ describe('QrKeyring', () => {

await keyring.deserialize(HDKEY_SERIALIZED_KEYRING_WITH_NO_ACCOUNTS);

expect(await keyring.getAccounts()).toStrictEqual([]);
expect(keyring.getAccounts()).toStrictEqual([]);
expect(await getXPUBFromKeyring(keyring)).toStrictEqual(
HDKEY_SERIALIZED_KEYRING_WITH_NO_ACCOUNTS.xpub,
);
Expand All @@ -226,7 +226,7 @@ describe('QrKeyring', () => {
await keyring.deserialize(await keystoneKeyring.serialize());

expect(await keystoneKeyring.getAccounts()).toStrictEqual(
await keystoneKeyring.getAccounts(),
keyring.getAccounts(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suspect that the original tests were incorrect.

);
expect(await getXPUBFromKeyring(keyring)).toStrictEqual(
await getXPUBFromKeyring(keystoneKeyring),
Expand Down Expand Up @@ -270,7 +270,7 @@ describe('QrKeyring', () => {

expect(firstAddition).toStrictEqual(expectedAccounts.slice(0, 1));
expect(secondAddition).toStrictEqual([]);
expect(await keyring.getAccounts()).toStrictEqual(
expect(keyring.getAccounts()).toStrictEqual(
expectedAccounts.slice(0, 1),
);
});
Expand Down Expand Up @@ -328,7 +328,7 @@ describe('QrKeyring', () => {
bridge: getMockBridge(),
ur: KNOWN_HDKEY_UR,
});
expect(await keyring.getAccounts()).toStrictEqual([]);
expect(keyring.getAccounts()).toStrictEqual([]);
});
});

Expand All @@ -342,7 +342,7 @@ describe('QrKeyring', () => {

const accounts = await keyring.addAccounts(numberOfAccountsToAdd);

expect(await keyring.getAccounts()).toStrictEqual(
expect(keyring.getAccounts()).toStrictEqual(
EXPECTED_ACCOUNTS.slice(0, numberOfAccountsToAdd),
);
expect(accounts).toStrictEqual(
Expand All @@ -362,7 +362,7 @@ describe('QrKeyring', () => {

keyring.removeAccount(EXPECTED_ACCOUNTS[1]);

expect(await keyring.getAccounts()).toStrictEqual([
expect(keyring.getAccounts()).toStrictEqual([
EXPECTED_ACCOUNTS[0],
EXPECTED_ACCOUNTS[2],
]);
Expand All @@ -374,12 +374,12 @@ describe('QrKeyring', () => {
ur: KNOWN_HDKEY_UR,
});
await keyring.addAccounts(1);
const initialAccounts = await keyring.getAccounts();
const initialAccounts = keyring.getAccounts();

expect(() =>
keyring.removeAccount('0x0000000000000000000000000000000000000000'),
).not.toThrow();
expect(await keyring.getAccounts()).toStrictEqual(initialAccounts);
expect(keyring.getAccounts()).toStrictEqual(initialAccounts);
});
});

Expand Down Expand Up @@ -617,7 +617,7 @@ describe('QrKeyring', () => {
});
await keyring.deserialize(HDKEY_SERIALIZED_KEYRING_WITH_ACCOUNTS);
// let's make sure we have an xpub set
expect(await keyring.getAccounts()).toStrictEqual(
expect(keyring.getAccounts()).toStrictEqual(
HDKEY_SERIALIZED_KEYRING_WITH_ACCOUNTS.accounts,
);
expect(await getXPUBFromKeyring(keyring)).toStrictEqual(
Expand All @@ -626,7 +626,7 @@ describe('QrKeyring', () => {

await keyring.forgetDevice();

expect(await keyring.getAccounts()).toStrictEqual([]);
expect(keyring.getAccounts()).toStrictEqual([]);
expect(await getXPUBFromKeyring(keyring)).toBeUndefined();
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-eth-qr/src/qr-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class QrKeyring implements Keyring {
*
* @returns The accounts in the QrKeyring
*/
async getAccounts(): Promise<Hex[]> {
getAccounts(): Hex[] {
return this.#accounts.slice();
}

Expand Down
14 changes: 7 additions & 7 deletions packages/keyring-eth-simple/src/simple-keyring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('simple-keyring', function () {
describe('#constructor with a private key', function () {
it('has the correct addresses', async function () {
const newKeyring = new SimpleKeyring([testAccount.key]);
const accounts = await newKeyring.getAccounts();
const accounts = newKeyring.getAccounts();
expect(accounts).toStrictEqual([testAccount.address]);
});
});
Expand Down Expand Up @@ -181,7 +181,7 @@ describe('simple-keyring', function () {
const msgHashHex = bytesToHex(keccak256(Buffer.from(localMessage)));

await keyring.addAccounts(9);
const addresses = await keyring.getAccounts();
const addresses = keyring.getAccounts();
const signatures = await Promise.all(
addresses.map(async (accountAddress: Hex) => {
return await keyring.signMessage(accountAddress, msgHashHex);
Expand Down Expand Up @@ -261,7 +261,7 @@ describe('simple-keyring', function () {
// Push a mock wallet
await keyring.deserialize([testAccount.key]);

const output = await keyring.getAccounts();
const output = keyring.getAccounts();
expect(output).toHaveLength(1);
expect(output[0]).toBe(testAccount.address);
});
Expand All @@ -271,10 +271,10 @@ describe('simple-keyring', function () {
describe('if the account exists', function () {
it('should remove that account', async function () {
await keyring.addAccounts();
const address = (await keyring.getAccounts())[0];
const address = keyring.getAccounts()[0];
assert(address, 'address is undefined');
keyring.removeAccount(address);
const addressesAfterRemoval = await keyring.getAccounts();
const addressesAfterRemoval = keyring.getAccounts();
expect(addressesAfterRemoval).toHaveLength(0);
});
});
Expand Down Expand Up @@ -503,7 +503,7 @@ describe('simple-keyring', function () {
};

await keyring.deserialize([privKeyHex]);
const address = (await keyring.getAccounts())[0];
const address = keyring.getAccounts()[0];
assert(address, 'address is undefined');
const signature = await keyring.signTypedData(address, typedData, {
version: SignTypedDataVersion.V3,
Expand Down Expand Up @@ -723,7 +723,7 @@ describe('simple-keyring', function () {

await keyring.deserialize([privKeyHex]);

const address = (await keyring.getAccounts())[0];
const address = keyring.getAccounts()[0];
assert(address, 'address is undefined');
const signature = await keyring.signTypedData(address, typedData, {
version: SignTypedDataVersion.V4,
Expand Down
Loading
Loading