|
| 1 | +import * as ox__Bytes from "ox/Bytes"; |
1 | 2 | import { describe, expect, it, test } from "vitest"; |
2 | 3 | import { FORKED_ETHEREUM_CHAIN } from "../../test/src/chains.js"; |
3 | 4 | import { TEST_CLIENT } from "../../test/src/test-clients.js"; |
4 | 5 | import { TEST_ACCOUNT_A } from "../../test/src/test-wallets.js"; |
5 | | -import { mainnet } from "../chains/chain-definitions/ethereum.js"; |
| 6 | +import { ethereum, mainnet } from "../chains/chain-definitions/ethereum.js"; |
6 | 7 | import { sepolia } from "../chains/chain-definitions/sepolia.js"; |
7 | | -import { verifyEOASignature, verifySignature } from "./verify-signature.js"; |
| 8 | +import { smartWallet } from "../wallets/smart/smart-wallet.js"; |
| 9 | +import { |
| 10 | + verifyContractWalletSignature, |
| 11 | + verifyEOASignature, |
| 12 | + verifySignature, |
| 13 | +} from "./verify-signature.js"; |
8 | 14 |
|
9 | 15 | describe("verifyEOASignature", () => { |
10 | 16 | test("should return true for a valid signature", async () => { |
@@ -98,3 +104,43 @@ describe.runIf(process.env.TW_SECRET_KEY)( |
98 | 104 | }); |
99 | 105 | }, |
100 | 106 | ); |
| 107 | + |
| 108 | +describe.runIf(process.env.TW_SECRET_KEY)( |
| 109 | + "verifyContractWalletSignature", |
| 110 | + async () => { |
| 111 | + const message = "Hakuna matata"; |
| 112 | + const wallet = smartWallet({ |
| 113 | + chain: ethereum, |
| 114 | + gasless: true, |
| 115 | + }); |
| 116 | + const smartAccount = await wallet.connect({ |
| 117 | + client: TEST_CLIENT, |
| 118 | + personalAccount: TEST_ACCOUNT_A, |
| 119 | + }); |
| 120 | + |
| 121 | + test("should verify a smart account signature", async () => { |
| 122 | + const rawSignature = await smartAccount.signMessage({ message }); |
| 123 | + const result = await verifyContractWalletSignature({ |
| 124 | + signature: rawSignature, |
| 125 | + message, |
| 126 | + address: smartAccount.address, |
| 127 | + chain: ethereum, |
| 128 | + client: TEST_CLIENT, |
| 129 | + }); |
| 130 | + expect(result).toBe(true); |
| 131 | + }); |
| 132 | + |
| 133 | + test("should verify a smart account signature as bytes", async () => { |
| 134 | + const rawSignature = await smartAccount.signMessage({ message }); |
| 135 | + const bytesSignature = ox__Bytes.fromHex(rawSignature); |
| 136 | + const result = await verifyContractWalletSignature({ |
| 137 | + signature: bytesSignature, |
| 138 | + message, |
| 139 | + address: smartAccount.address, |
| 140 | + chain: ethereum, |
| 141 | + client: TEST_CLIENT, |
| 142 | + }); |
| 143 | + expect(result).toBe(true); |
| 144 | + }); |
| 145 | + }, |
| 146 | +); |
0 commit comments