Skip to content

Commit 28eb39e

Browse files
authored
Upgrade viem dependency (#22)
* Upgrade viem peer dependency * Use stringToHex from viem in e2e tests * Use shared util to convert error message to unprefixed hex. Remove some cruft form e2e tests.
1 parent b082f61 commit 28eb39e

37 files changed

Lines changed: 397 additions & 419 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"prettier": "^3.3.3",
5353
"turbo": "latest",
5454
"typescript": "5.0.4",
55-
"viem": "2.21.55",
55+
"viem": "^2.31.4",
5656
"webauthn-p256": "^0.0.10"
5757
},
5858
"packageManager": "yarn@4.2.2",

packages/delegation-toolkit/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@
139139
"tsconfig-paths": "^4.2.0",
140140
"tsup": "^8.5.0",
141141
"typescript": "5.0.4",
142-
"viem": "2.21.55",
142+
"viem": "2.31.4",
143143
"vitest": "^3.2.4"
144144
},
145145
"peerDependencies": {
146-
"viem": ">=2.18.2 <3.0.0"
146+
"viem": "^2.31.4"
147147
}
148148
}

packages/delegation-toolkit/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import type {
88
Account,
99
Address,
1010
Chain,
11-
Client,
1211
Hex,
1312
OneOf,
13+
PublicClient,
1414
Transport,
1515
WalletClient,
1616
} from 'viem';
@@ -143,7 +143,7 @@ export type DeployParams<TImplementation extends Implementation> = {
143143
export type ToMetaMaskSmartAccountParameters<
144144
TImplementation extends Implementation,
145145
> = {
146-
client: Client;
146+
client: PublicClient;
147147
implementation: TImplementation;
148148
signatory: SignatoryConfigByImplementation<TImplementation>;
149149
environment?: DeleGatorEnvironment;

packages/delegation-toolkit/test/experimental/erc7710RedeemDelegationAction.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type {
88
WalletClient,
99
} from 'viem';
1010
import {
11-
createClient,
1211
createPublicClient,
1312
createWalletClient,
1413
custom,
@@ -65,10 +64,7 @@ describe('erc7710RedeemDelegationAction', () => {
6564
});
6665

6766
metaMaskSmartAccount = await toMetaMaskSmartAccount({
68-
client: createClient({
69-
transport: custom({ request: async () => '0x' }),
70-
chain,
71-
}),
67+
client: publicClient,
7268
implementation: Implementation.MultiSig,
7369
signatory: [{ account: owner }],
7470
deployParams: [[owner.address], 1n],

packages/delegation-toolkit/test/toMetaMaskSmartAccount.test.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { Account, Client } from 'viem';
1+
import type { Account, PublicClient } from 'viem';
22
import {
3-
createClient,
3+
createPublicClient,
44
custom,
55
hashTypedData,
66
isAddress,
@@ -19,7 +19,7 @@ import type { DeleGatorEnvironment, MetaMaskSmartAccount } from '../src/types';
1919
import { SIGNABLE_USER_OP_TYPED_DATA } from '../src/userOp';
2020

2121
describe('MetaMaskSmartAccount', () => {
22-
let client: Client;
22+
let publicClient: PublicClient;
2323
let alice: Account;
2424
let bob: Account;
2525
let environment: DeleGatorEnvironment;
@@ -28,7 +28,8 @@ describe('MetaMaskSmartAccount', () => {
2828
const transport = custom({
2929
request: async () => '0x',
3030
});
31-
client = createClient({ transport, chain });
31+
publicClient = createPublicClient({ transport, chain });
32+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
3233

3334
environment = {
3435
SimpleFactory: randomAddress(),
@@ -48,7 +49,7 @@ describe('MetaMaskSmartAccount', () => {
4849
// note derivation of the correctness of counterfactual account data is validated in counterfactualAccountData.test.ts
4950
it('creates a MetaMaskSmartAccount for Hybrid implementation', async () => {
5051
const smartAccount = await toMetaMaskSmartAccount({
51-
client,
52+
client: publicClient,
5253
implementation: Implementation.Hybrid,
5354
deployParams: [alice.address, [], [], []],
5455
deploySalt: '0x0',
@@ -65,7 +66,7 @@ describe('MetaMaskSmartAccount', () => {
6566

6667
it('creates a MetaMaskSmartAccount for MultiSig implementation', async () => {
6768
const smartAccount = await toMetaMaskSmartAccount({
68-
client,
69+
client: publicClient,
6970
implementation: Implementation.MultiSig,
7071
deployParams: [[alice.address, bob.address], 2n],
7172
deploySalt: '0x0',
@@ -82,7 +83,7 @@ describe('MetaMaskSmartAccount', () => {
8283

8384
it('creates a MetaMaskSmartAccount for Stateless7702 implementation with existing address', async () => {
8485
const smartAccount = await toMetaMaskSmartAccount({
85-
client,
86+
client: publicClient,
8687
implementation: Implementation.Stateless7702,
8788
address: alice.address,
8889
signatory: { account: alice },
@@ -102,7 +103,7 @@ describe('MetaMaskSmartAccount', () => {
102103
it('throws error when creating Stateless7702 without address (counterfactual not supported)', async () => {
103104
await expect(
104105
toMetaMaskSmartAccount({
105-
client,
106+
client: publicClient,
106107
implementation: Implementation.Stateless7702,
107108
signatory: { account: alice },
108109
environment,
@@ -115,7 +116,7 @@ describe('MetaMaskSmartAccount', () => {
115116
it('throws an error for unsupported implementation', async () => {
116117
await expect(
117118
toMetaMaskSmartAccount({
118-
client,
119+
client: publicClient,
119120
implementation: 99 as any as Implementation,
120121
deployParams: [alice.address, [], [], []],
121122
deploySalt: '0x0',
@@ -128,7 +129,7 @@ describe('MetaMaskSmartAccount', () => {
128129
it('has a default for MetaMaskSmartAccount generic TImplementation parameter', async () => {
129130
// MetaMaskSmartAccount requires a generic parameter, and defaults to `Implementation` which covers all implementations
130131
const smartAccount: MetaMaskSmartAccount = await toMetaMaskSmartAccount({
131-
client,
132+
client: publicClient,
132133
implementation: Implementation.MultiSig,
133134
deployParams: [[alice.address, bob.address], 2n],
134135
deploySalt: '0x0',
@@ -142,7 +143,7 @@ describe('MetaMaskSmartAccount', () => {
142143
describe('signUserOperation()', () => {
143144
it('signs a user operation for MultiSig implementation', async () => {
144145
const smartAccount = await toMetaMaskSmartAccount({
145-
client,
146+
client: publicClient,
146147
implementation: Implementation.MultiSig,
147148
deployParams: [[alice.address, bob.address], 2n],
148149
deploySalt: '0x0',
@@ -188,7 +189,7 @@ describe('MetaMaskSmartAccount', () => {
188189

189190
it('signs a user operation for Hybrid implementation', async () => {
190191
const smartAccount = await toMetaMaskSmartAccount({
191-
client,
192+
client: publicClient,
192193
implementation: Implementation.Hybrid,
193194
deployParams: [alice.address, [], [], []],
194195
deploySalt: '0x0',
@@ -234,7 +235,7 @@ describe('MetaMaskSmartAccount', () => {
234235

235236
it('signs a user operation for Stateless7702 implementation', async () => {
236237
const smartAccount = await toMetaMaskSmartAccount({
237-
client,
238+
client: publicClient,
238239
implementation: Implementation.Stateless7702,
239240
address: alice.address,
240241
signatory: { account: alice },

packages/delegation-toolkit/test/utils.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import { bytesToHex, getAddress } from 'viem';
2-
import type {
3-
Chain,
4-
Hex,
5-
WalletClient,
6-
PublicClient,
7-
Account,
8-
Client,
9-
} from 'viem';
2+
import type { Chain, Hex, WalletClient, PublicClient, Account } from 'viem';
103
import {
114
generatePrivateKey,
125
privateKeyToAccount,
@@ -48,7 +41,7 @@ export const randomBytes = (byteLength: number): Hex => {
4841

4942
export const counterfactualAccountConfig: ToMetaMaskSmartAccountParameters<Implementation.Hybrid> =
5043
{
51-
client: {} as Client,
44+
client: {} as PublicClient,
5245
implementation: Implementation.Hybrid,
5346
deployParams: [
5447
OWNER_ACCOUNT.address,
@@ -62,7 +55,7 @@ export const counterfactualAccountConfig: ToMetaMaskSmartAccountParameters<Imple
6255

6356
export const multiSigAccountConfig: ToMetaMaskSmartAccountParameters<Implementation.MultiSig> =
6457
{
65-
client: {} as Client,
58+
client: {} as PublicClient,
6659
implementation: Implementation.MultiSig,
6760
deployParams: [[OWNER_ACCOUNT.address], 1n],
6861
deploySalt: SALT,
@@ -71,7 +64,7 @@ export const multiSigAccountConfig: ToMetaMaskSmartAccountParameters<Implementat
7164

7265
export const deployedAccountConfig: ToMetaMaskSmartAccountParameters<Implementation.Hybrid> =
7366
{
74-
client: {} as Client,
67+
client: {} as PublicClient,
7568
implementation: Implementation.Hybrid,
7669
address: DEPLOYED_ADDRESS,
7770
signatory: { account: OWNER_ACCOUNT },

packages/delegator-e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
"teardown": "docker compose down"
2222
},
2323
"peerDependencies": {
24-
"viem": ">=2.18.2 <3.0.0"
24+
"viem": "^2.31.4"
2525
}
2626
}

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,29 @@ import {
1313
encodePermissionContexts,
1414
} from '@metamask/delegation-toolkit/utils';
1515
import {
16-
transport,
1716
gasPrice,
1817
sponsoredBundlerClient,
1918
deploySmartAccount,
2019
deployCounter,
2120
CounterContract,
2221
randomBytes,
22+
publicClient,
23+
stringToUnprefixedHex,
2324
} from '../utils/helpers';
24-
import {
25-
createClient,
26-
encodeFunctionData,
27-
Hex,
28-
hexToBigInt,
29-
slice,
30-
} from 'viem';
25+
import { encodeFunctionData, Hex, hexToBigInt, slice } from 'viem';
3126
import { expectUserOperationToSucceed } from '../utils/assertions';
3227
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
33-
import { chain } from '../../src/config';
3428

35-
let aliceSmartAccount: MetaMaskSmartAccount<Implementation.Hybrid>;
36-
let bobSmartAccount: MetaMaskSmartAccount<Implementation.Hybrid>;
29+
let aliceSmartAccount: MetaMaskSmartAccount;
30+
let bobSmartAccount: MetaMaskSmartAccount;
3731
let aliceCounter: CounterContract;
3832

3933
beforeEach(async () => {
40-
const client = createClient({ transport, chain });
4134
const alice = privateKeyToAccount(generatePrivateKey());
4235
const bob = privateKeyToAccount(generatePrivateKey());
4336

4437
aliceSmartAccount = await toMetaMaskSmartAccount({
45-
client,
38+
client: publicClient,
4639
implementation: Implementation.Hybrid,
4740
deployParams: [alice.address, [], [], []],
4841
deploySalt: '0x1',
@@ -52,7 +45,7 @@ beforeEach(async () => {
5245
await deploySmartAccount(aliceSmartAccount);
5346

5447
bobSmartAccount = await toMetaMaskSmartAccount({
55-
client,
48+
client: publicClient,
5649
implementation: Implementation.Hybrid,
5750
deployParams: [bob.address, [], [], []],
5851
deploySalt: '0x1',
@@ -255,7 +248,7 @@ const runTest_expectFailure = async (
255248
],
256249
...gasPrice,
257250
}),
258-
).rejects.toThrow(expectedError);
251+
).rejects.toThrow(stringToUnprefixedHex(expectedError));
259252

260253
const counterAfter = await aliceCounter.read.count?.();
261254
expect(counterAfter, 'Expected count to remain 0n').toEqual(0n);

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,29 @@ import {
1313
} from '@metamask/delegation-toolkit';
1414
import { createCaveatBuilder } from '@metamask/delegation-toolkit/utils';
1515
import {
16-
transport,
1716
gasPrice,
1817
sponsoredBundlerClient,
1918
deploySmartAccount,
2019
deployCounter,
2120
CounterContract,
21+
publicClient,
22+
stringToUnprefixedHex,
2223
} from '../utils/helpers';
23-
import {
24-
createClient,
25-
encodeFunctionData,
26-
AbiFunction,
27-
Hex,
28-
toFunctionSelector,
29-
} from 'viem';
24+
import { encodeFunctionData, AbiFunction, Hex, toFunctionSelector } from 'viem';
3025
import { expectUserOperationToSucceed } from '../utils/assertions';
3126
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
32-
import { chain } from '../../src/config';
3327
import CounterMetadata from '../utils/counter/metadata.json';
3428

35-
let aliceSmartAccount: MetaMaskSmartAccount<Implementation.Hybrid>;
36-
let bobSmartAccount: MetaMaskSmartAccount<Implementation.Hybrid>;
29+
let aliceSmartAccount: MetaMaskSmartAccount;
30+
let bobSmartAccount: MetaMaskSmartAccount;
3731
let aliceCounter: CounterContract;
3832

3933
beforeEach(async () => {
40-
const client = createClient({ transport, chain });
4134
const alice = privateKeyToAccount(generatePrivateKey());
4235
const bob = privateKeyToAccount(generatePrivateKey());
4336

4437
aliceSmartAccount = await toMetaMaskSmartAccount({
45-
client,
38+
client: publicClient,
4639
implementation: Implementation.Hybrid,
4740
deployParams: [alice.address, [], [], []],
4841
deploySalt: '0x1',
@@ -52,7 +45,7 @@ beforeEach(async () => {
5245
await deploySmartAccount(aliceSmartAccount);
5346

5447
bobSmartAccount = await toMetaMaskSmartAccount({
55-
client,
48+
client: publicClient,
5649
implementation: Implementation.Hybrid,
5750
deployParams: [bob.address, [], [], []],
5851
deploySalt: '0x1',
@@ -249,7 +242,7 @@ const runTest_expectFailure = async (
249242
],
250243
...gasPrice,
251244
}),
252-
).rejects.toThrow(expectedError);
245+
).rejects.toThrow(stringToUnprefixedHex(expectedError));
253246

254247
const counterAfter = await aliceCounter.read.count();
255248
expect(counterAfter, 'Expected count to remain 0n').toEqual(0n);

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,30 @@ import {
1313
type MetaMaskSmartAccount,
1414
} from '@metamask/delegation-toolkit';
1515
import {
16-
transport,
1716
gasPrice,
1817
sponsoredBundlerClient,
1918
deploySmartAccount,
2019
deployCounter,
2120
CounterContract,
2221
randomBytes,
22+
publicClient,
23+
stringToUnprefixedHex,
2324
} from '../utils/helpers';
24-
import { createClient, encodeFunctionData, Hex } from 'viem';
25+
import { encodeFunctionData, Hex } from 'viem';
2526
import { expectUserOperationToSucceed } from '../utils/assertions';
2627
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
27-
import { chain } from '../../src/config';
2828
import CounterMetadata from '../utils/counter/metadata.json';
2929

30-
let aliceSmartAccount: MetaMaskSmartAccount<Implementation.Hybrid>;
31-
let bobSmartAccount: MetaMaskSmartAccount<Implementation.Hybrid>;
30+
let aliceSmartAccount: MetaMaskSmartAccount;
31+
let bobSmartAccount: MetaMaskSmartAccount;
3232
let aliceCounter: CounterContract;
3333

3434
beforeEach(async () => {
35-
const client = createClient({ transport, chain });
3635
const alice = privateKeyToAccount(generatePrivateKey());
3736
const bob = privateKeyToAccount(generatePrivateKey());
3837

3938
aliceSmartAccount = await toMetaMaskSmartAccount({
40-
client,
39+
client: publicClient,
4140
implementation: Implementation.Hybrid,
4241
deployParams: [alice.address, [], [], []],
4342
deploySalt: '0x1',
@@ -47,7 +46,7 @@ beforeEach(async () => {
4746
await deploySmartAccount(aliceSmartAccount);
4847

4948
bobSmartAccount = await toMetaMaskSmartAccount({
50-
client,
49+
client: publicClient,
5150
implementation: Implementation.Hybrid,
5251
deployParams: [bob.address, [], [], []],
5352
deploySalt: '0x1',
@@ -219,7 +218,7 @@ const runTest_expectFailure = async (
219218
],
220219
...gasPrice,
221220
}),
222-
).rejects.toThrow(expectedError);
221+
).rejects.toThrow(stringToUnprefixedHex(expectedError));
223222

224223
const counterAfter = await aliceCounter.read.count();
225224
expect(counterAfter, 'Expected count to remain 0n').toEqual(0n);

0 commit comments

Comments
 (0)