|
| 1 | +import test from 'ava'; |
| 2 | +import { account } from '.'; |
| 3 | + |
| 4 | +import type { AccountOptions } from './account'; |
| 5 | +import { buildAccount } from './account'; |
| 6 | +import { printContract } from './print'; |
| 7 | + |
| 8 | +/** |
| 9 | + * Tests external API for equivalence with internal API |
| 10 | + */ |
| 11 | +function testAPIEquivalence(title: string, opts?: AccountOptions) { |
| 12 | + test(title, t => { |
| 13 | + t.is( |
| 14 | + account.print(opts), |
| 15 | + printContract( |
| 16 | + buildAccount({ |
| 17 | + name: 'MyAccount', |
| 18 | + signatureValidation: 'ERC7739', |
| 19 | + ERC721Holder: true, |
| 20 | + ERC1155Holder: true, |
| 21 | + batchedExecution: false, |
| 22 | + ERC7579Modules: false, |
| 23 | + ...opts, |
| 24 | + }), |
| 25 | + ), |
| 26 | + ); |
| 27 | + }); |
| 28 | +} |
| 29 | + |
| 30 | +function testAccount(title: string, opts: Partial<AccountOptions>) { |
| 31 | + const fullOpts = { |
| 32 | + name: 'MyAccount', |
| 33 | + ERC1271: false as const, |
| 34 | + ERC721Holder: false, |
| 35 | + ERC1155Holder: false, |
| 36 | + ERC7821: false as const, |
| 37 | + ERC7579: false as const, |
| 38 | + ...opts, |
| 39 | + }; |
| 40 | + test(title, t => { |
| 41 | + const c = buildAccount(fullOpts); |
| 42 | + t.snapshot(printContract(c)); |
| 43 | + }); |
| 44 | + testAPIEquivalence(`${title} API equivalence`, fullOpts); |
| 45 | +} |
| 46 | + |
| 47 | +testAPIEquivalence('account API default'); |
| 48 | + |
| 49 | +test('account API assert defaults', async t => { |
| 50 | + t.is(account.print(account.defaults), account.print()); |
| 51 | +}); |
| 52 | + |
| 53 | +for (const signer of [undefined, 'ERC7702', 'ECDSA', 'P256', 'RSA'] as const) { |
| 54 | + let title = 'Account'; |
| 55 | + if (signer) { |
| 56 | + title += ` with Signer${signer}`; |
| 57 | + } |
| 58 | + |
| 59 | + testAccount(`${title} named`, { |
| 60 | + name: `Custom${title}`, |
| 61 | + signer, |
| 62 | + }); |
| 63 | + |
| 64 | + testAccount(`${title} with ERC1271`, { |
| 65 | + name: `Custom${title}ERC1271`, |
| 66 | + signatureValidation: 'ERC1271', |
| 67 | + signer, |
| 68 | + }); |
| 69 | + |
| 70 | + testAccount(`${title} with ERC7739`, { |
| 71 | + name: `Custom${title}ERC7739`, |
| 72 | + signatureValidation: 'ERC7739', |
| 73 | + signer, |
| 74 | + }); |
| 75 | + |
| 76 | + testAccount(`${title} with ERC721Holder`, { |
| 77 | + name: `Custom${title}ERC721Holder`, |
| 78 | + ERC721Holder: true, |
| 79 | + signer, |
| 80 | + }); |
| 81 | + |
| 82 | + testAccount(`${title} with ERC1155Holder`, { |
| 83 | + name: `Custom${title}ERC1155Holder`, |
| 84 | + ERC1155Holder: true, |
| 85 | + signer, |
| 86 | + }); |
| 87 | + |
| 88 | + testAccount(`${title} with ERC721Holder and ERC1155Holder`, { |
| 89 | + name: `Custom${title}ERC721HolderERC1155Holder`, |
| 90 | + ERC721Holder: true, |
| 91 | + ERC1155Holder: true, |
| 92 | + signer, |
| 93 | + }); |
| 94 | + |
| 95 | + testAccount(`${title} with ERC7821 Execution`, { |
| 96 | + signer, |
| 97 | + batchedExecution: true, |
| 98 | + }); |
| 99 | + |
| 100 | + testAccount(`${title} with ERC7579`, { |
| 101 | + signer, |
| 102 | + ERC7579Modules: 'AccountERC7579', |
| 103 | + }); |
| 104 | + |
| 105 | + testAccount(`${title} with ERC7579 hooks`, { |
| 106 | + signer, |
| 107 | + ERC7579Modules: 'AccountERC7579Hooked', |
| 108 | + }); |
| 109 | +} |
0 commit comments