Skip to content

Commit c6621dc

Browse files
test: enable SmartWallet policy tests
1 parent df128bf commit c6621dc

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

.changeset/smooth-walls-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Ensure smart accounts are deployed before validating signatures

packages/thirdweb/src/wallets/smart/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,19 @@ async function createSmartAccount(
249249
import("../../utils/hashing/hashMessage.js"),
250250
import("../../extensions/erc1271/checkContractWalletSignature.js"),
251251
]);
252-
const isDeployed = await isContractDeployed(accountContract);
252+
let isDeployed = await isContractDeployed(accountContract);
253253
if (!isDeployed) {
254254
await _deployAccount({
255255
options,
256256
account,
257257
accountContract,
258258
});
259+
// the bundler and rpc might not be in sync, so while the bundler has a transaction hash for the deployment,
260+
// the rpc might not have it yet, so we wait until the rpc confirms the contract is deployed
261+
while (!isDeployed) {
262+
await new Promise((resolve) => setTimeout(resolve, 500));
263+
isDeployed = await isContractDeployed(accountContract);
264+
}
259265
}
260266

261267
const originalMsgHash = hashMessage(message);
@@ -337,13 +343,19 @@ async function createSmartAccount(
337343
return options.personalAccount.signTypedData(typedData);
338344
}
339345

340-
const isDeployed = await isContractDeployed(accountContract);
346+
let isDeployed = await isContractDeployed(accountContract);
341347
if (!isDeployed) {
342348
await _deployAccount({
343349
options,
344350
account,
345351
accountContract,
346352
});
353+
// the bundler and rpc might not be in sync, so while the bundler has a transaction hash for the deployment,
354+
// the rpc might not have it yet, so we wait until the rpc confirms the contract is deployed
355+
while (!isDeployed) {
356+
await new Promise((resolve) => setTimeout(resolve, 500));
357+
isDeployed = await isContractDeployed(accountContract);
358+
}
347359
}
348360

349361
const originalMsgHash = hashTypedData(typedData);

packages/thirdweb/src/wallets/smart/smart-wallet-dev.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { beforeAll, describe, expect, it } from "vitest";
22
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
33
import { arbitrumSepolia } from "../../chains/chain-definitions/arbitrum-sepolia.js";
44
import { type ThirdwebContract, getContract } from "../../contract/contract.js";
5-
65
import { balanceOf } from "../../extensions/erc1155/__generated__/IERC1155/read/balanceOf.js";
76
import { claimTo } from "../../extensions/erc1155/drops/write/claimTo.js";
87
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
@@ -62,6 +61,12 @@ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential(
6261
expect(smartWalletAddress).toHaveLength(42);
6362
});
6463

64+
it("can sign a msg", async () => {
65+
await smartAccount.signMessage({ message: "hello world" });
66+
const isDeployed = await isContractDeployed(accountContract);
67+
expect(isDeployed).toEqual(true);
68+
});
69+
6570
it("can execute a tx", async () => {
6671
const tx = await sendAndConfirmTransaction({
6772
transaction: claimTo({

0 commit comments

Comments
 (0)