Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtenz committed Nov 27, 2024
1 parent 98fe1d6 commit 85882ea
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/snaps-controllers/coverage.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"branches": 92.89,
"functions": 96.71,
"lines": 98,
"lines": 98.01,
"statements": 97.71
}
2 changes: 1 addition & 1 deletion packages/snaps-rpc-methods/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = deepmerge(baseConfig, {
],
coverageThreshold: {
global: {
branches: 92.88,
branches: 92.91,
functions: 97.26,
lines: 97.84,
statements: 97.36,
Expand Down
42 changes: 34 additions & 8 deletions packages/snaps-rpc-methods/src/restricted/getBip32Entropy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ describe('getBip32EntropyImplementation', () => {
const getMnemonic = jest
.fn()
.mockResolvedValue(TEST_SECRET_RECOVERY_PHRASE_BYTES);
const getClientCryptography = jest.fn().mockReturnValue({});

expect(
// @ts-expect-error Missing other required properties.
await getBip32EntropyImplementation({ getUnlockPromise, getMnemonic })({
await getBip32EntropyImplementation({
getUnlockPromise,
getMnemonic,
getClientCryptography,
// @ts-expect-error Missing other required properties.
})({
params: { path: ['m', "44'", "1'"], curve: 'secp256k1' },
}),
).toMatchInlineSnapshot(`
Expand All @@ -76,6 +81,7 @@ describe('getBip32EntropyImplementation', () => {
"depth": 2,
"index": 2147483649,
"masterFingerprint": 1404659567,
"network": "mainnet",
"parentFingerprint": 1829122711,
"privateKey": "0xc73cedb996e7294f032766853a8b7ba11ab4ce9755fc052f2f7b9000044c99af",
"publicKey": "0x048e129862c1de5ca86468add43b001d32fd34b8113de716ecd63fa355b7f1165f0e76f5dc6095100f9fdaa76ddf28aa3f21406ac5fda7c71ffbedb45634fe2ceb",
Expand All @@ -88,10 +94,15 @@ describe('getBip32EntropyImplementation', () => {
const getMnemonic = jest
.fn()
.mockResolvedValue(TEST_SECRET_RECOVERY_PHRASE_BYTES);
const getClientCryptography = jest.fn().mockReturnValue({});

expect(
// @ts-expect-error Missing other required properties.
await getBip32EntropyImplementation({ getUnlockPromise, getMnemonic })({
await getBip32EntropyImplementation({
getUnlockPromise,
getMnemonic,
getClientCryptography,
// @ts-expect-error Missing other required properties.
})({
params: {
path: ['m', "44'", "1'", "0'", '0', '1'],
curve: 'secp256k1',
Expand All @@ -104,6 +115,7 @@ describe('getBip32EntropyImplementation', () => {
"depth": 5,
"index": 1,
"masterFingerprint": 1404659567,
"network": "mainnet",
"parentFingerprint": 3495658567,
"privateKey": "0x43a9353dfebf7209c3feb1843510299e2b0f4fa09151dccc3824df88451be37c",
"publicKey": "0x0467f3cac111f47782b6c2d8d0984d51e22c128d24ec3eaca044509a386771d17206c740c7337c399d8ade8f52a60029340f288e11de82fffd3b69c5b863f6a515",
Expand All @@ -117,9 +129,15 @@ describe('getBip32EntropyImplementation', () => {
.fn()
.mockResolvedValue(TEST_SECRET_RECOVERY_PHRASE_BYTES);

const getClientCryptography = jest.fn().mockReturnValue({});

expect(
// @ts-expect-error Missing other required properties.
await getBip32EntropyImplementation({ getUnlockPromise, getMnemonic })({
await getBip32EntropyImplementation({
getUnlockPromise,
getMnemonic,
getClientCryptography,
// @ts-expect-error Missing other required properties.
})({
params: {
path: ['m', "44'", "1'", "0'", "0'", "1'"],
curve: 'ed25519',
Expand All @@ -132,6 +150,7 @@ describe('getBip32EntropyImplementation', () => {
"depth": 5,
"index": 2147483649,
"masterFingerprint": 650419359,
"network": "mainnet",
"parentFingerprint": 660188756,
"privateKey": "0x5e6ebe8f5c33833e6c86f8769da173daa206b9dfd1956efcd2b115d82376bb5e",
"publicKey": "0x0012affaf55babdfb59b76adcf00f69442f019974124639108470409d47e25e19f",
Expand All @@ -145,9 +164,15 @@ describe('getBip32EntropyImplementation', () => {
.fn()
.mockResolvedValue(TEST_SECRET_RECOVERY_PHRASE_BYTES);

const getClientCryptography = jest.fn().mockReturnValue({});

expect(
// @ts-expect-error Missing other required properties.
await getBip32EntropyImplementation({ getUnlockPromise, getMnemonic })({
await getBip32EntropyImplementation({
getUnlockPromise,
getMnemonic,
getClientCryptography,
// @ts-expect-error Missing other required properties.
})({
params: {
path: ['m', "44'", "1'", "0'", "0'", "1'"],
curve: 'ed25519Bip32',
Expand All @@ -160,6 +185,7 @@ describe('getBip32EntropyImplementation', () => {
"depth": 5,
"index": 2147483649,
"masterFingerprint": 1587894111,
"network": "mainnet",
"parentFingerprint": 3236688876,
"privateKey": "0x88a59d7aa9fe82d8f98843ef474195178eb71956dee597252e7a5fbeebbc734e9b5bfdd17f82144a2bea78c8ab19bef26dc93f36e96eaa41453b65cb3daa1817",
"publicKey": "0xd91d18b4540a2f30341e8463d5f9b25b14fae9a236dcbea338b668a318bb0867",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ describe('getBip44EntropyImplementation', () => {
const getMnemonic = jest
.fn()
.mockResolvedValue(TEST_SECRET_RECOVERY_PHRASE_BYTES);
const getClientCryptography = jest.fn().mockReturnValue({});

expect(
// @ts-expect-error Missing other required properties.
await getBip44EntropyImplementation({ getUnlockPromise, getMnemonic })({
await getBip44EntropyImplementation({
getUnlockPromise,
getMnemonic,
getClientCryptography,
// @ts-expect-error Missing other required properties.
})({
params: { coinType: 1 },
}),
).toMatchInlineSnapshot(`
Expand All @@ -76,6 +81,7 @@ describe('getBip44EntropyImplementation', () => {
"depth": 2,
"index": 2147483649,
"masterFingerprint": 1404659567,
"network": "mainnet",
"parentFingerprint": 1829122711,
"path": "m / bip32:44' / bip32:1'",
"privateKey": "0xc73cedb996e7294f032766853a8b7ba11ab4ce9755fc052f2f7b9000044c99af",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('getEntropyBuilder', () => {
methodHooks: {
getMnemonic: true,
getUnlockPromise: true,
getClientCryptography: jest.fn(),
getClientCryptography: true,
},
});
});
Expand Down
9 changes: 9 additions & 0 deletions packages/snaps-rpc-methods/src/restricted/manageState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ const ENCRYPTION_KEY =

describe('getEncryptionEntropy', () => {
it('returns the encryption entropy for the snap ID', async () => {
const result = await getEncryptionEntropy({
mnemonicPhrase: TEST_SECRET_RECOVERY_PHRASE_BYTES,
snapId: MOCK_SNAP_ID,
});

expect(result).toBe(ENCRYPTION_KEY);
});

it('accepts custom cryptographic functions', async () => {
const result = await getEncryptionEntropy({
mnemonicPhrase: TEST_SECRET_RECOVERY_PHRASE_BYTES,
snapId: MOCK_SNAP_ID,
Expand Down
4 changes: 2 additions & 2 deletions packages/snaps-rpc-methods/src/restricted/manageState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const STORAGE_SIZE_LIMIT = 104857600; // In bytes (100MB)
type GetEncryptionKeyArgs = {
snapId: string;
mnemonicPhrase: Uint8Array;
cryptographicFunctions: CryptographicFunctions;
cryptographicFunctions?: CryptographicFunctions;
};

/**
Expand All @@ -133,7 +133,7 @@ type GetEncryptionKeyArgs = {
export async function getEncryptionEntropy({
mnemonicPhrase,
snapId,
cryptographicFunctions,
cryptographicFunctions = {},
}: GetEncryptionKeyArgs) {
return await deriveEntropy({
mnemonicPhrase,
Expand Down
2 changes: 2 additions & 0 deletions packages/snaps-rpc-methods/src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('getNode', () => {
"depth": 2,
"index": 2147483649,
"masterFingerprint": 1404659567,
"network": "mainnet",
"parentFingerprint": 1829122711,
"privateKey": "0xc73cedb996e7294f032766853a8b7ba11ab4ce9755fc052f2f7b9000044c99af",
"publicKey": "0x048e129862c1de5ca86468add43b001d32fd34b8113de716ecd63fa355b7f1165f0e76f5dc6095100f9fdaa76ddf28aa3f21406ac5fda7c71ffbedb45634fe2ceb",
Expand All @@ -77,6 +78,7 @@ describe('getNode', () => {
"depth": 2,
"index": 2147483649,
"masterFingerprint": 650419359,
"network": "mainnet",
"parentFingerprint": 4080844380,
"privateKey": "0x9dee85af06f9b94d2451549f5a9b0a3bbba9e2513daebc793ca5c9a13e80cafa",
"publicKey": "0x00c9aaf347832dc3b1dbb7aab4f41e5e04c64446b819c0761571c27b9f90eacb27",
Expand Down

0 comments on commit 85882ea

Please sign in to comment.