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

Commit

Permalink
fix: treat undefined/null as [] in deserialize
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed Oct 19, 2023
1 parent 22d42a2 commit 317e8bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/simple-keyring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ describe('simple-keyring', function () {
});
});

describe('#deserialize an empty value', function () {
it('resets wallets', async function () {
await keyring.deserialize([testAccount.key]);
const serialized = await keyring.serialize();
expect(serialized).toHaveLength(1);
await keyring.deserialize(undefined);
const serialized2 = await keyring.serialize();
expect(serialized2).toHaveLength(0);
});
});

describe('#constructor with a private key', function () {
it('has the correct addresses', async function () {
const newKeyring = new SimpleKeyring([testAccount.key]);
Expand Down
2 changes: 1 addition & 1 deletion src/simple-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class SimpleKeyring implements Keyring<string[]> {
return this.#wallets.map((a) => a.privateKey.toString('hex'));
}

async deserialize(privateKeys: string[]) {
async deserialize(privateKeys: string[] = []) {
this.#wallets = privateKeys.map((hexPrivateKey) => {
const strippedHexPrivateKey = stripHexPrefix(hexPrivateKey);
const privateKey = Buffer.from(strippedHexPrivateKey, 'hex');
Expand Down

0 comments on commit 317e8bd

Please sign in to comment.