-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathisEip7702StatelessDelegatedAccount.test.ts
More file actions
60 lines (47 loc) · 2.11 KB
/
Copy pathisEip7702StatelessDelegatedAccount.test.ts
File metadata and controls
60 lines (47 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import type { PublicClient } from 'viem';
import { createPublicClient, http } from 'viem';
import { foundry } from 'viem/chains';
import { beforeEach, describe, expect, it } from 'vitest';
import { isEip7702StatelessDelegatedAccount } from '../../src/actions/isEip7702StatelessDelegatedAccount';
describe('isEip7702StatelessDelegatedAccount', () => {
let publicClient: PublicClient;
beforeEach(() => {
publicClient = createPublicClient({
chain: foundry,
transport: http(),
});
});
it('should return false for an address with no code', async () => {
const randomAddress = '0x1234567890123456789012345678901234567890';
const result = await isEip7702StatelessDelegatedAccount({
client: publicClient,
accountAddress: randomAddress,
});
expect(result).toBe(false);
});
it('should return false for an address that does not implement NAME() function', async () => {
// Use an address that we know has code but doesn't implement NAME()
// In this case, we'll use the zero address which should fail
const zeroAddress = '0x0000000000000000000000000000000000000000';
const result = await isEip7702StatelessDelegatedAccount({
client: publicClient,
accountAddress: zeroAddress,
});
expect(result).toBe(false);
});
it('should return false for a contract that implements NAME() but returns a different name', async () => {
// This test would need a mock contract that implements NAME() but returns something else
// For now, we'll just test the error handling path with an invalid address
const invalidAddress = '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd';
const result = await isEip7702StatelessDelegatedAccount({
client: publicClient,
accountAddress: invalidAddress,
});
expect(result).toBe(false);
});
// Note: A full integration test would require:
// 1. Deploying the EIP7702StatelessDeleGator contract
// 2. Creating an EOA and delegating it to that contract using EIP-7702
// 3. Testing that the function returns true for that delegated account
// This would be better suited for the e2e test suite
});