Skip to content
Merged
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
68 changes: 68 additions & 0 deletions packages/e2e/src/test-helpers/executeJs/wrappedKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ namespace TestHelper {
export const randomHash = (input: string) =>
createHash('sha256').update(input).digest('hex');

export const createEvmContractConditions = () =>
JSON.stringify([
{
contractAddress: ZERO_ADDRESS,
standardContractType: 'ERC20',
chain: EVM_CHAIN,
method: 'balanceOf',
parameters: [':userAddress'],
returnValueTest: {
comparator: '>=',
value: '0',
},
},
]);

export const createStorePayload = (memo = randomMemo('store')) => {
const ciphertext = randomCiphertext();
return {
Expand Down Expand Up @@ -391,6 +406,59 @@ export const registerWrappedKeysTests = () => {
expect(fetched.versions?.[0].memo).toBe(initialPayload.memo);
});

test('updateEncryptedKey with evmContractConditions stores conditions in version history', async () => {
const pkpSessionSigs = await TestHelper.createPkpSessionSigs({
testEnv,
alice,
delegationAuthSig: aliceDelegationAuthSig,
});

const initialPayload = TestHelper.createStorePayload(
TestHelper.randomMemo('update-evm-before')
);

const { id } = await wrappedKeysApi.storeEncryptedKey({
pkpSessionSigs,
litClient: testEnv.litClient,
...initialPayload,
});

const newCiphertext = TestHelper.randomCiphertext();
const newMemo = TestHelper.randomMemo('update-evm-after');
const evmContractConditions = TestHelper.createEvmContractConditions();

const updateResult = await wrappedKeysApi.updateEncryptedKey({
pkpSessionSigs,
litClient: testEnv.litClient,
id,
ciphertext: newCiphertext,
memo: newMemo,
evmContractConditions,
});

expect(updateResult.id).toBe(id);
expect(updateResult.pkpAddress).toBe(alice.pkp!.ethAddress);
expect(updateResult.updatedAt).toBeTruthy();

const fetched = await wrappedKeysApi.getEncryptedKey({
pkpSessionSigs,
litClient: testEnv.litClient,
id,
includeVersions: true,
});

expect(fetched.ciphertext).toBe(newCiphertext);
expect(fetched.memo).toBe(newMemo);
expect(fetched.updatedAt).toBeTruthy();
expect(fetched.versions).toBeDefined();
expect(fetched.versions?.length).toBe(1);
expect(fetched.versions?.[0].ciphertext).toBe(
initialPayload.ciphertext
);
expect(fetched.versions?.[0].memo).toBe(initialPayload.memo);
expect(fetched.versions?.[0].evmContractConditions).toBeUndefined();
});
Comment on lines +409 to +460
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

This test doesn't actually verify that evmContractConditions were stored. The assertion at line 459 only confirms the initial version (before the update) doesn't have conditions, which is expected since they weren't provided initially.

To properly test that evmContractConditions are stored in version history, the test should perform a second update and verify that versions[0] (the state from the first update) contains the evmContractConditions that were provided. For example:

// After line 437, add another update:
const secondUpdateResult = await wrappedKeysApi.updateEncryptedKey({
  pkpSessionSigs,
  litClient: testEnv.litClient,
  id,
  ciphertext: TestHelper.randomCiphertext(),
  memo: TestHelper.randomMemo('update-evm-final'),
  // No evmContractConditions this time
});

const fetchedAfterSecond = await wrappedKeysApi.getEncryptedKey({
  pkpSessionSigs,
  litClient: testEnv.litClient,
  id,
  includeVersions: true,
});

// Now versions[0] should be the state from the first update with evmContractConditions
expect(fetchedAfterSecond.versions?.[0].evmContractConditions).toBe(evmContractConditions);
// And versions[1] should be the initial state without them
expect(fetchedAfterSecond.versions?.[1].evmContractConditions).toBeUndefined();

Copilot uses AI. Check for mistakes.

test('importPrivateKey persists an externally generated key', async () => {
const pkpSessionSigs = await TestHelper.createPkpSessionSigs({
testEnv,
Expand Down