Skip to content

Commit

Permalink
new keystore test
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Apr 12, 2024
1 parent a2045e5 commit 7be4725
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
40 changes: 32 additions & 8 deletions yarn-project/key-store/src/new_test_key_store.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
import { Fr } from "@aztec/circuits.js";
import { NewTestKeyStore } from "./new_test_key_store.js";
import { openTmpStore } from "@aztec/kv-store/utils";
import { Grumpkin } from "@aztec/circuits.js/barretenberg";
import { Fr } from '@aztec/circuits.js';
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
import { openTmpStore } from '@aztec/kv-store/utils';

import { NewTestKeyStore } from './new_test_key_store.js';

describe('NewTestKeyStore', () => {
it('Adds account and returns keys', () => {
it('Adds account and returns keys', async () => {
const db = openTmpStore();
const keyStore = new NewTestKeyStore(new Grumpkin(), db);

// Arbitrary fixed values
const sk = new Fr(8923n);
const partialAddress = new Fr(243523n);

const accountAddress = keyStore.addAccount(sk, partialAddress);
expect(accountAddress).toMatchInlineSnapshot(`"0071f7630d28ce02cc1ca8b15c44953f84a39e1478445395247ae04dfa213c0e"`);

const accountAddress = await keyStore.addAccount(sk, partialAddress);
expect(accountAddress.toString()).toMatchInlineSnapshot(
`"0x2ae5eeea29e4059842653d97864456c28fa53e4a823a8df65802090de1e85baa"`,
);

// TODO(#5714): The keys are currently the same here because separator is currently ignored in poseidon
const masterNullifierPublicKey = await keyStore.getMasterNullifierPublicKey(accountAddress);
expect(masterNullifierPublicKey.toString()).toMatchInlineSnapshot(
`"0x1b0b998b70b295ed14912584c64abfd402ee13511d0dcf05badef38e8c10acd00fce0a5909d612c9a2d2c9172ff3cf5ba6be3e314d66b05edd74f3d5d259110f"`,
);

const masterIncomingViewingPublicKey = await keyStore.getMasterIncomingViewingPublicKey(accountAddress);
expect(masterIncomingViewingPublicKey.toString()).toMatchInlineSnapshot(
`"0x1b0b998b70b295ed14912584c64abfd402ee13511d0dcf05badef38e8c10acd00fce0a5909d612c9a2d2c9172ff3cf5ba6be3e314d66b05edd74f3d5d259110f"`,
);

const masterOutgoingViewingPublicKey = await keyStore.getMasterOutgoingViewingPublicKey(accountAddress);
expect(masterOutgoingViewingPublicKey.toString()).toMatchInlineSnapshot(
`"0x1b0b998b70b295ed14912584c64abfd402ee13511d0dcf05badef38e8c10acd00fce0a5909d612c9a2d2c9172ff3cf5ba6be3e314d66b05edd74f3d5d259110f"`,
);

const masterTaggingPublicKey = await keyStore.getMasterTaggingPublicKey(accountAddress);
expect(masterTaggingPublicKey.toString()).toMatchInlineSnapshot(
`"0x1b0b998b70b295ed14912584c64abfd402ee13511d0dcf05badef38e8c10acd00fce0a5909d612c9a2d2c9172ff3cf5ba6be3e314d66b05edd74f3d5d259110f"`,
);
});
});
1 change: 0 additions & 1 deletion yarn-project/key-store/src/new_test_key_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { type AztecKVStore, type AztecMap } from '@aztec/kv-store';
/**
* TestKeyStore is an implementation of the KeyStore interface, used for managing key pairs in a testing environment.
* It should be utilized in testing scenarios where secure key management is not required, and ease-of-use is prioritized.
* TODO: Potentially rename to not include 'Test' in the name.
*/
export class NewTestKeyStore implements NewKeyStore {
#keys: AztecMap<string, Buffer>;
Expand Down

0 comments on commit 7be4725

Please sign in to comment.