Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7e260fe
feat: introduce CaveatType enum and normalize caveat type handling in…
mj-kiwi Feb 24, 2026
9368578
feat: implement validateCaveatType function for robust caveat type va…
mj-kiwi Feb 24, 2026
7f1699b
refactor: simplify caveat type validation and improve error messaging
mj-kiwi Feb 25, 2026
d6c499f
refactor: enhance type handling in ConvertCaveatConfigsToInputs for b…
mj-kiwi Feb 25, 2026
ce1aa47
- Change validateCaveatType to use 'asserts type is CaveatType' inste…
mj-kiwi Feb 26, 2026
3c3953d
refactor: update CoreCaveatMap to use CaveatType enum for improved ty…
mj-kiwi Feb 26, 2026
755b3e0
refactor: remove duplicate entry for NativeTokenStreaming in CoreCave…
mj-kiwi Feb 26, 2026
8cfe0a7
refactor: replace string literals with CaveatType enums in caveat bui…
mj-kiwi Feb 27, 2026
540f649
refactor: export CaveatType from caveatBuilder for improved type access
mj-kiwi Feb 27, 2026
e688a14
refactor: unify config conversion utilities by using ConvertEnumConfi…
mj-kiwi Feb 27, 2026
cd25cb8
refactor: import CaveatType in test files for improved type safety
mj-kiwi Feb 27, 2026
6b91508
refactor: enhance CaveatType integration to support both enum and str…
mj-kiwi Mar 3, 2026
e4fe6ac
refactor: replace ConvertEnumConfigToInputs with ConvertCaveatConfigT…
mj-kiwi Mar 3, 2026
3121c91
refactor: update addCaveat to accept string literals for improved fle…
mj-kiwi Mar 3, 2026
c54863a
refactor: add tests for string literal caveat names in createCaveatBu…
mj-kiwi Mar 4, 2026
8c8b766
refactor: add string literal test cases for AllowedCalldata caveat ha…
mj-kiwi Mar 4, 2026
9296e17
refactor: update addCaveat method to enforce registered enforcer name…
mj-kiwi Mar 4, 2026
0c71b08
refactor: enhance type safety for addCaveat method with string litera…
mj-kiwi Mar 4, 2026
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
72 changes: 70 additions & 2 deletions packages/delegator-e2e/test/caveats/allowedCalldata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@metamask/smart-accounts-kit';
import {
createCaveatBuilder,
CaveatType,
encodeExecutionCalldatas,
encodeDelegations,
} from '@metamask/smart-accounts-kit/utils';
Expand Down Expand Up @@ -77,6 +78,13 @@ test('maincase: Bob redeems the delegation with the exact calldata', async () =>
await runTest_expectSuccess(newCount, [{ from: 4, calldata }]);
});

test('maincase (string literal): Bob redeems the delegation with the exact calldata', async () => {
const calldata = randomBytes(32);
const newCount = hexToBigInt(calldata);

await runTest_expectSuccess(newCount, [{ from: 4, calldata }], 'allowedCalldata');
});

test('Bob redeems the delegation where the delegation requires a substring of the calldata', async () => {
const calldata = randomBytes(32);
const newCount = hexToBigInt(calldata);
Expand All @@ -88,6 +96,19 @@ test('Bob redeems the delegation where the delegation requires a substring of th
]);
});

test('Bob redeems the delegation where the delegation requires a substring of the calldata (string literal)', async () => {
const calldata = randomBytes(32);
const newCount = hexToBigInt(calldata);

const requiredCalldata = slice(calldata, 0, 34);

await runTest_expectSuccess(
newCount,
[{ from: 4, calldata: requiredCalldata }],
'allowedCalldata',
);
});

test('Bob redeems the delegation where the calldata matches multiple caveats', async () => {
const calldata = randomBytes(32);
const newCount = hexToBigInt(calldata);
Expand All @@ -101,6 +122,23 @@ test('Bob redeems the delegation where the calldata matches multiple caveats', a
]);
});

test('Bob redeems the delegation where the calldata matches multiple caveats (string literal)', async () => {
const calldata = randomBytes(32);
const newCount = hexToBigInt(calldata);

const firstSlice = slice(calldata, 0, 34);
const secondSlice = slice(calldata, 20);

await runTest_expectSuccess(
newCount,
[
{ from: 4, calldata: firstSlice },
{ from: 24, calldata: secondSlice },
],
'allowedCalldata',
);
});

test('Bob attempts to redeem the delegation with incorrect calldata', async () => {
const newCount = 1n;

Expand All @@ -117,6 +155,23 @@ test('Bob attempts to redeem the delegation with incorrect calldata', async () =
);
});

test('Bob attempts to redeem the delegation with incorrect calldata (string literal)', async () => {
const newCount = 1n;

const executedCalldata = encodeFunctionData({
abi: aliceCounter.abi,
functionName: 'setCount',
args: [newCount],
});

await runTest_expectFailure(
executedCalldata,
[{ from: 0, calldata: randomBytes(32) }],
'AllowedCalldataEnforcer:invalid-calldata',
'allowedCalldata',
);
});

test('Bob attempts to redeem the delegation with no calldata', async () => {
const executedCalldata = '0x';

Expand All @@ -127,9 +182,21 @@ test('Bob attempts to redeem the delegation with no calldata', async () => {
);
});

test('Bob attempts to redeem the delegation with no calldata (string literal)', async () => {
const executedCalldata = '0x';

await runTest_expectFailure(
executedCalldata,
[{ from: 0, calldata: randomBytes(32) }],
'AllowedCalldataEnforcer:invalid-calldata',
'allowedCalldata',
);
});

const runTest_expectSuccess = async (
newCount: bigint,
caveats: { from: number; calldata: Hex }[],
caveatForm: typeof CaveatType.AllowedCalldata | 'allowedCalldata' = CaveatType.AllowedCalldata,
) => {
const { environment } = aliceSmartAccount;

Expand All @@ -140,7 +207,7 @@ const runTest_expectSuccess = async (
salt: '0x0',
caveats: caveats
.reduce((builder, caveat) => {
builder.addCaveat('allowedCalldata', {
builder.addCaveat(caveatForm, {
startIndex: caveat.from,
value: caveat.calldata,
});
Expand Down Expand Up @@ -208,6 +275,7 @@ const runTest_expectFailure = async (
executedCalldata: Hex,
caveats: { from: number; calldata: Hex }[],
expectedError: string,
caveatForm: typeof CaveatType.AllowedCalldata | 'allowedCalldata' = CaveatType.AllowedCalldata,
) => {
const { environment } = aliceSmartAccount;

Expand All @@ -218,7 +286,7 @@ const runTest_expectFailure = async (
salt: '0x0',
caveats: caveats
.reduce((builder, caveat) => {
builder.addCaveat('allowedCalldata', {
builder.addCaveat(caveatForm, {
startIndex: caveat.from,
value: caveat.calldata,
});
Expand Down
6 changes: 3 additions & 3 deletions packages/delegator-e2e/test/caveats/allowedMethods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
MetaMaskSmartAccount,
Delegation,
} from '@metamask/smart-accounts-kit';
import { createCaveatBuilder } from '@metamask/smart-accounts-kit/utils';
import { createCaveatBuilder, CaveatType } from '@metamask/smart-accounts-kit/utils';
import {
gasPrice,
sponsoredBundlerClient,
Expand Down Expand Up @@ -146,7 +146,7 @@ const runTest_expectSuccess = async (
authority: ROOT_AUTHORITY,
salt: '0x0',
caveats: createCaveatBuilder(environment)
.addCaveat('allowedMethods', { selectors: allowedMethods })
.addCaveat(CaveatType.AllowedMethods, { selectors: allowedMethods })
.build(),
signature: '0x',
};
Expand Down Expand Up @@ -216,7 +216,7 @@ const runTest_expectFailure = async (
authority: ROOT_AUTHORITY,
salt: '0x0',
caveats: createCaveatBuilder(environment)
.addCaveat('allowedMethods', { selectors: allowedMethods })
.addCaveat(CaveatType.AllowedMethods, { selectors: allowedMethods })
.build(),
signature: '0x',
};
Expand Down
5 changes: 3 additions & 2 deletions packages/delegator-e2e/test/caveats/allowedTargets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@metamask/smart-accounts-kit';
import {
createCaveatBuilder,
CaveatType,
encodeExecutionCalldatas,
encodeDelegations,
} from '@metamask/smart-accounts-kit/utils';
Expand Down Expand Up @@ -114,7 +115,7 @@ const runTest_expectSuccess = async (
authority: ROOT_AUTHORITY,
salt: '0x0',
caveats: createCaveatBuilder(environment)
.addCaveat('allowedTargets', { targets: allowedTargets })
.addCaveat(CaveatType.AllowedTargets, { targets: allowedTargets })
.build(),
signature: '0x',
};
Expand Down Expand Up @@ -184,7 +185,7 @@ const runTest_expectFailure = async (
authority: ROOT_AUTHORITY,
salt: '0x0',
caveats: createCaveatBuilder(environment)
.addCaveat('allowedTargets', { targets: allowedTargets })
.addCaveat(CaveatType.AllowedTargets, { targets: allowedTargets })
.build(),
signature: '0x',
};
Expand Down
5 changes: 3 additions & 2 deletions packages/delegator-e2e/test/caveats/argsEqualityCheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@metamask/smart-accounts-kit';
import {
createCaveatBuilder,
CaveatType,
encodeExecutionCalldatas,
encodeDelegations,
} from '@metamask/smart-accounts-kit/utils';
Expand Down Expand Up @@ -138,7 +139,7 @@ const runTest_expectSuccess = async (args: Hex, actualArgs: Hex) => {
authority: ROOT_AUTHORITY,
salt: '0x0',
caveats: createCaveatBuilder(environment)
.addCaveat('argsEqualityCheck', { args })
.addCaveat(CaveatType.ArgsEqualityCheck, { args })
.build(),
signature: '0x',
};
Expand Down Expand Up @@ -210,7 +211,7 @@ const runTest_expectFailure = async (
authority: ROOT_AUTHORITY,
salt: '0x0',
caveats: createCaveatBuilder(environment)
.addCaveat('argsEqualityCheck', { args })
.addCaveat(CaveatType.ArgsEqualityCheck, { args })
.build(),
signature: '0x',
};
Expand Down
5 changes: 3 additions & 2 deletions packages/delegator-e2e/test/caveats/blockNumber.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@metamask/smart-accounts-kit';
import {
createCaveatBuilder,
CaveatType,
encodeExecutionCalldatas,
encodeDelegations,
} from '@metamask/smart-accounts-kit/utils';
Expand Down Expand Up @@ -181,7 +182,7 @@ const runTest_expectSuccess = async (
authority: ROOT_AUTHORITY,
salt: '0x0',
caveats: createCaveatBuilder(environment)
.addCaveat('blockNumber', {
.addCaveat(CaveatType.BlockNumber, {
afterThreshold,
beforeThreshold,
})
Expand Down Expand Up @@ -257,7 +258,7 @@ const runTest_expectFailure = async (
authority: ROOT_AUTHORITY,
salt: '0x0',
caveats: createCaveatBuilder(environment)
.addCaveat('blockNumber', {
.addCaveat(CaveatType.BlockNumber, {
afterThreshold,
beforeThreshold,
})
Expand Down
9 changes: 5 additions & 4 deletions packages/delegator-e2e/test/caveats/caveatUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
encodeExecutionCalldatas,
encodeDelegations,
createCaveatBuilder,
CaveatType,
} from '@metamask/smart-accounts-kit/utils';
import {
createDelegation,
Expand Down Expand Up @@ -623,7 +624,7 @@ describe('MultiTokenPeriodEnforcer', () => {
delegator: aliceSmartAccount.address,
authority: ROOT_AUTHORITY as Address,
caveats: createCaveatBuilder(aliceSmartAccount.environment)
.addCaveat('multiTokenPeriod', {
.addCaveat(CaveatType.MultiTokenPeriod, {
tokenConfigs: [
{
token: erc20TokenAddress,
Expand Down Expand Up @@ -721,7 +722,7 @@ describe('MultiTokenPeriodEnforcer', () => {
delegator: aliceSmartAccount.address,
authority: ROOT_AUTHORITY as Address,
caveats: createCaveatBuilder(aliceSmartAccount.environment)
.addCaveat('multiTokenPeriod', {
.addCaveat(CaveatType.MultiTokenPeriod, {
tokenConfigs: [
{
token: erc20TokenAddress,
Expand Down Expand Up @@ -809,7 +810,7 @@ describe('MultiTokenPeriodEnforcer', () => {
delegator: aliceSmartAccount.address,
authority: ROOT_AUTHORITY as Address,
caveats: createCaveatBuilder(aliceSmartAccount.environment)
.addCaveat('multiTokenPeriod', {
.addCaveat(CaveatType.MultiTokenPeriod, {
tokenConfigs: [
{
token: erc20TokenAddress,
Expand Down Expand Up @@ -1507,7 +1508,7 @@ describe('Individual action functions vs client extension methods', () => {
delegator: aliceSmartAccount.address,
authority: ROOT_AUTHORITY as Address,
caveats: createCaveatBuilder(aliceSmartAccount.environment)
.addCaveat('multiTokenPeriod', {
.addCaveat(CaveatType.MultiTokenPeriod, {
tokenConfigs: [
{
token: erc20TokenAddress,
Expand Down
5 changes: 3 additions & 2 deletions packages/delegator-e2e/test/caveats/deployed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@metamask/smart-accounts-kit';
import {
createCaveatBuilder,
CaveatType,
encodeExecutionCalldatas,
encodeDelegations,
} from '@metamask/smart-accounts-kit/utils';
Expand Down Expand Up @@ -160,7 +161,7 @@ const runTest_expectSuccess = async (deployedAddress: Hex, salt: Hex) => {
authority: ROOT_AUTHORITY,
salt: '0x0',
caveats: createCaveatBuilder(environment)
.addCaveat('deployed', {
.addCaveat(CaveatType.Deployed, {
contractAddress: deployedAddress,
salt,
bytecode: CounterMetadata.bytecode.object as Hex,
Expand Down Expand Up @@ -247,7 +248,7 @@ const runTest_expectFailure = async (
authority: ROOT_AUTHORITY,
salt: '0x0',
caveats: createCaveatBuilder(environment)
.addCaveat('deployed', {
.addCaveat(CaveatType.Deployed, {
contractAddress: deployedAddress,
salt,
bytecode: CounterMetadata.bytecode.object as Hex,
Expand Down
Loading
Loading