Skip to content

Commit 470ef93

Browse files
committed
Update all of the e2e tests to match the new interface (in reality we're mostly just creating delegation object literals).
1 parent b8fa1d2 commit 470ef93

28 files changed

Lines changed: 1007 additions & 751 deletions

packages/delegator-e2e/test/caveats/allowedCalldata.test.ts

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { beforeEach, test, expect } from 'vitest';
22
import {
3-
createCaveatBuilder,
4-
createDelegation,
53
createExecution,
4+
Delegation,
65
Implementation,
6+
ROOT_AUTHORITY,
77
toMetaMaskSmartAccount,
88
type MetaMaskSmartAccount,
99
} from '@metamask/delegation-toolkit';
10+
import { createCaveatBuilder } from '@metamask/delegation-toolkit/utils';
1011
import {
1112
encodeExecutionCalldatas,
1213
encodePermissionContexts,
@@ -139,14 +140,22 @@ const runTest_expectSuccess = async (
139140
) => {
140141
const { environment } = aliceSmartAccount;
141142

142-
const delegation = createDelegation({
143-
to: bobSmartAccount.address,
144-
from: aliceSmartAccount.address,
145-
caveats: caveats.reduce((builder, caveat) => {
146-
builder.addCaveat('allowedCalldata', caveat.from, caveat.calldata);
147-
return builder;
148-
}, createCaveatBuilder(environment)),
149-
});
143+
const delegation: Delegation = {
144+
delegate: bobSmartAccount.address,
145+
delegator: aliceSmartAccount.address,
146+
authority: ROOT_AUTHORITY,
147+
caveats: caveats
148+
.reduce((builder, caveat) => {
149+
builder.addCaveat('allowedCalldata', {
150+
startIndex: caveat.from,
151+
value: caveat.calldata,
152+
});
153+
return builder;
154+
}, createCaveatBuilder(environment))
155+
.build(),
156+
salt: '0x',
157+
signature: '0x',
158+
};
150159

151160
const signedDelegation = {
152161
...delegation,
@@ -207,14 +216,22 @@ const runTest_expectFailure = async (
207216
caveats: { from: number; calldata: Hex }[],
208217
expectedError: string,
209218
) => {
210-
const delegation = createDelegation({
211-
to: bobSmartAccount.address,
212-
from: aliceSmartAccount.address,
213-
caveats: caveats.reduce((builder, caveat) => {
214-
builder.addCaveat('allowedCalldata', caveat.from, caveat.calldata);
215-
return builder;
216-
}, createCaveatBuilder(aliceSmartAccount.environment)),
217-
});
219+
const delegation: Delegation = {
220+
delegate: bobSmartAccount.address,
221+
delegator: aliceSmartAccount.address,
222+
authority: ROOT_AUTHORITY,
223+
caveats: caveats
224+
.reduce((builder, caveat) => {
225+
builder.addCaveat('allowedCalldata', {
226+
startIndex: caveat.from,
227+
value: caveat.calldata,
228+
});
229+
return builder;
230+
}, createCaveatBuilder(aliceSmartAccount.environment))
231+
.build(),
232+
salt: '0x',
233+
signature: '0x',
234+
};
218235

219236
const signedDelegation = {
220237
...delegation,

packages/delegator-e2e/test/caveats/allowedMethods.test.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import {
55
SINGLE_DEFAULT_MODE,
66
} from '@metamask/delegation-toolkit/utils';
77
import {
8-
createCaveatBuilder,
98
createExecution,
10-
createDelegation,
9+
Delegation,
1110
Implementation,
11+
ROOT_AUTHORITY,
1212
toMetaMaskSmartAccount,
1313
type MetaMaskSmartAccount,
1414
} from '@metamask/delegation-toolkit';
15+
import { createCaveatBuilder } from '@metamask/delegation-toolkit/utils';
1516
import {
1617
transport,
1718
gasPrice,
@@ -135,14 +136,16 @@ const runTest_expectSuccess = async (
135136
allowedMethods: (string | AbiFunction | Hex)[],
136137
calledMethod: string,
137138
) => {
138-
const delegation = createDelegation({
139-
to: bobSmartAccount.address,
140-
from: aliceSmartAccount.address,
141-
caveats: createCaveatBuilder(aliceSmartAccount.environment).addCaveat(
142-
'allowedMethods',
143-
allowedMethods,
144-
),
145-
});
139+
const delegation: Delegation = {
140+
delegate: bobSmartAccount.address,
141+
delegator: aliceSmartAccount.address,
142+
authority: ROOT_AUTHORITY,
143+
caveats: createCaveatBuilder(aliceSmartAccount.environment)
144+
.addCaveat('allowedMethods', { selectors: allowedMethods })
145+
.build(),
146+
salt: '0x',
147+
signature: '0x',
148+
};
146149

147150
const signedDelegation = {
148151
...delegation,
@@ -201,14 +204,16 @@ const runTest_expectFailure = async (
201204
calledMethod: string,
202205
expectedError: string,
203206
) => {
204-
const delegation = createDelegation({
205-
to: bobSmartAccount.address,
206-
from: aliceSmartAccount.address,
207-
caveats: createCaveatBuilder(aliceSmartAccount.environment).addCaveat(
208-
'allowedMethods',
209-
allowedMethods,
210-
),
211-
});
207+
const delegation: Delegation = {
208+
delegate: bobSmartAccount.address,
209+
delegator: aliceSmartAccount.address,
210+
authority: ROOT_AUTHORITY,
211+
caveats: createCaveatBuilder(aliceSmartAccount.environment)
212+
.addCaveat('allowedMethods', { selectors: allowedMethods })
213+
.build(),
214+
salt: '0x',
215+
signature: '0x',
216+
};
212217

213218
const signedDelegation = {
214219
...delegation,

packages/delegator-e2e/test/caveats/allowedTargets.test.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import {
55
SINGLE_DEFAULT_MODE,
66
} from '@metamask/delegation-toolkit/utils';
77
import {
8-
createCaveatBuilder,
98
createExecution,
10-
createDelegation,
9+
Delegation,
1110
Implementation,
11+
ROOT_AUTHORITY,
1212
toMetaMaskSmartAccount,
1313
type MetaMaskSmartAccount,
1414
} from '@metamask/delegation-toolkit';
15+
import { createCaveatBuilder } from '@metamask/delegation-toolkit/utils';
1516
import {
1617
transport,
1718
gasPrice,
@@ -105,14 +106,16 @@ const runTest_expectSuccess = async (
105106
allowedTargets: Hex[],
106107
calledTarget: Hex,
107108
) => {
108-
const delegation = createDelegation({
109-
to: bobSmartAccount.address,
110-
from: aliceSmartAccount.address,
111-
caveats: createCaveatBuilder(aliceSmartAccount.environment).addCaveat(
112-
'allowedTargets',
113-
allowedTargets,
114-
),
115-
});
109+
const delegation: Delegation = {
110+
delegate: bobSmartAccount.address,
111+
delegator: aliceSmartAccount.address,
112+
authority: ROOT_AUTHORITY,
113+
caveats: createCaveatBuilder(aliceSmartAccount.environment)
114+
.addCaveat('allowedTargets', { targets: allowedTargets })
115+
.build(),
116+
salt: '0x',
117+
signature: '0x',
118+
};
116119

117120
const signedDelegation = {
118121
...delegation,
@@ -171,14 +174,16 @@ const runTest_expectFailure = async (
171174
calledTarget: Hex,
172175
expectedError: string,
173176
) => {
174-
const delegation = createDelegation({
175-
to: bobSmartAccount.address,
176-
from: aliceSmartAccount.address,
177-
caveats: createCaveatBuilder(aliceSmartAccount.environment).addCaveat(
178-
'allowedTargets',
179-
allowedTargets,
180-
),
181-
});
177+
const delegation: Delegation = {
178+
delegate: bobSmartAccount.address,
179+
delegator: aliceSmartAccount.address,
180+
authority: ROOT_AUTHORITY,
181+
caveats: createCaveatBuilder(aliceSmartAccount.environment)
182+
.addCaveat('allowedTargets', { targets: allowedTargets })
183+
.build(),
184+
salt: '0x',
185+
signature: '0x',
186+
};
182187

183188
const signedDelegation = {
184189
...delegation,

packages/delegator-e2e/test/caveats/argsEqualityCheck.test.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import {
55
SINGLE_DEFAULT_MODE,
66
} from '@metamask/delegation-toolkit/utils';
77
import {
8-
createCaveatBuilder,
98
createExecution,
10-
createDelegation,
9+
Delegation,
1110
Implementation,
11+
ROOT_AUTHORITY,
1212
toMetaMaskSmartAccount,
1313
type MetaMaskSmartAccount,
1414
} from '@metamask/delegation-toolkit';
15+
import { createCaveatBuilder } from '@metamask/delegation-toolkit/utils';
1516
import {
1617
transport,
1718
gasPrice,
@@ -129,14 +130,16 @@ test('Bob attempts to redeem the delegation with args when none are expected', a
129130
});
130131

131132
const runTest_expectSuccess = async (expectedArgs: Hex, actualArgs: Hex) => {
132-
const delegation = createDelegation({
133-
to: bobSmartAccount.address,
134-
from: aliceSmartAccount.address,
135-
caveats: createCaveatBuilder(aliceSmartAccount.environment).addCaveat(
136-
'argsEqualityCheck',
137-
expectedArgs,
138-
),
139-
});
133+
const delegation: Delegation = {
134+
delegate: bobSmartAccount.address,
135+
delegator: aliceSmartAccount.address,
136+
authority: ROOT_AUTHORITY,
137+
caveats: createCaveatBuilder(aliceSmartAccount.environment)
138+
.addCaveat('argsEqualityCheck', { expectedArgs })
139+
.build(),
140+
salt: '0x',
141+
signature: '0x',
142+
};
140143

141144
const signedDelegation = {
142145
...delegation,
@@ -197,14 +200,16 @@ const runTest_expectFailure = async (
197200
actualArgs: Hex,
198201
expectedError: string,
199202
) => {
200-
const delegation = createDelegation({
201-
to: bobSmartAccount.address,
202-
from: aliceSmartAccount.address,
203-
caveats: createCaveatBuilder(aliceSmartAccount.environment).addCaveat(
204-
'argsEqualityCheck',
205-
expectedArgs,
206-
),
207-
});
203+
const delegation: Delegation = {
204+
delegate: bobSmartAccount.address,
205+
delegator: aliceSmartAccount.address,
206+
authority: ROOT_AUTHORITY,
207+
caveats: createCaveatBuilder(aliceSmartAccount.environment)
208+
.addCaveat('argsEqualityCheck', { expectedArgs })
209+
.build(),
210+
salt: '0x',
211+
signature: '0x',
212+
};
208213

209214
const signedDelegation = {
210215
...delegation,

packages/delegator-e2e/test/caveats/blockNumber.test.ts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import {
55
SINGLE_DEFAULT_MODE,
66
} from '@metamask/delegation-toolkit/utils';
77
import {
8-
createCaveatBuilder,
98
createExecution,
10-
createDelegation,
9+
Delegation,
1110
Implementation,
11+
ROOT_AUTHORITY,
1212
toMetaMaskSmartAccount,
1313
type MetaMaskSmartAccount,
1414
} from '@metamask/delegation-toolkit';
15+
import { createCaveatBuilder } from '@metamask/delegation-toolkit/utils';
1516
import {
1617
transport,
1718
gasPrice,
@@ -173,15 +174,19 @@ const runTest_expectSuccess = async (
173174
afterThreshold: bigint,
174175
beforeThreshold: bigint,
175176
) => {
176-
const delegation = createDelegation({
177-
to: bobSmartAccount.address,
178-
from: aliceSmartAccount.address,
179-
caveats: createCaveatBuilder(aliceSmartAccount.environment).addCaveat(
180-
'blockNumber',
181-
afterThreshold,
182-
beforeThreshold,
183-
),
184-
});
177+
const delegation: Delegation = {
178+
delegate: bobSmartAccount.address,
179+
delegator: aliceSmartAccount.address,
180+
authority: ROOT_AUTHORITY,
181+
caveats: createCaveatBuilder(aliceSmartAccount.environment)
182+
.addCaveat('blockNumber', {
183+
blockAfterThreshold: afterThreshold,
184+
blockBeforeThreshold: beforeThreshold,
185+
})
186+
.build(),
187+
salt: '0x',
188+
signature: '0x',
189+
};
185190

186191
const signedDelegation = {
187192
...delegation,
@@ -243,15 +248,19 @@ const runTest_expectFailure = async (
243248
beforeThreshold: bigint,
244249
expectedError: string,
245250
) => {
246-
const delegation = createDelegation({
247-
to: bobSmartAccount.address,
248-
from: aliceSmartAccount.address,
249-
caveats: createCaveatBuilder(aliceSmartAccount.environment).addCaveat(
250-
'blockNumber',
251-
afterThreshold,
252-
beforeThreshold,
253-
),
254-
});
251+
const delegation: Delegation = {
252+
delegate: bobSmartAccount.address,
253+
delegator: aliceSmartAccount.address,
254+
authority: ROOT_AUTHORITY,
255+
caveats: createCaveatBuilder(aliceSmartAccount.environment)
256+
.addCaveat('blockNumber', {
257+
blockAfterThreshold: afterThreshold,
258+
blockBeforeThreshold: beforeThreshold,
259+
})
260+
.build(),
261+
salt: '0x',
262+
signature: '0x',
263+
};
255264

256265
const signedDelegation = {
257266
...delegation,

0 commit comments

Comments
 (0)