Skip to content

Commit 0a1fd55

Browse files
joaquim-vergesd4mr
andauthored
Refactor e2e tests (#667)
* e2e tests refactor * fix userop types error --------- Co-authored-by: Prithvish Baidya <deformercoding@gmail.com>
1 parent a34fbf9 commit 0a1fd55

File tree

22 files changed

+5989
-233
lines changed

22 files changed

+5989
-233
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"prisma": "^5.14.0",
7070
"prom-client": "^15.1.3",
7171
"superjson": "^2.2.1",
72-
"thirdweb": "^5.56.0",
72+
"thirdweb": "^5.58.4",
7373
"uuid": "^9.0.1",
7474
"winston": "^3.14.1",
7575
"zod": "^3.23.8"

src/server/routes/contract/extensions/erc1155/write/claimTo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export async function erc1155claimTo(fastify: FastifyInstance) {
7777
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7878

7979
const chainId = await getChainIdFromChain(chain);
80-
const contract = getContractV5({
80+
const contract = await getContractV5({
8181
chainId,
8282
contractAddress,
8383
});

src/server/routes/contract/extensions/erc20/write/claimTo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export async function erc20claimTo(fastify: FastifyInstance) {
7474
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7575

7676
const chainId = await getChainIdFromChain(chain);
77-
const contract = getContractV5({
77+
const contract = await getContractV5({
7878
chainId,
7979
contractAddress,
8080
});

src/server/routes/contract/extensions/erc721/write/claimTo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export async function erc721claimTo(fastify: FastifyInstance) {
7373
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7474

7575
const chainId = await getChainIdFromChain(chain);
76-
const contract = getContractV5({
76+
const contract = await getContractV5({
7777
chainId,
7878
contractAddress,
7979
});

src/server/routes/contract/extensions/erc721/write/signatureMint.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import { SignedPayload721WithQuantitySignature } from "@thirdweb-dev/sdk";
33
import { BigNumber } from "ethers";
44
import { FastifyInstance } from "fastify";
55
import { StatusCodes } from "http-status-codes";
6-
import { Address, Hex, getContract as getContractV5 } from "thirdweb";
6+
import { Address, Hex } from "thirdweb";
77
import { mintWithSignature } from "thirdweb/extensions/erc721";
88
import { resolvePromisedValue } from "thirdweb/utils";
99
import { queueTx } from "../../../../../../db/transactions/queueTx";
1010
import { getContract } from "../../../../../../utils/cache/getContract";
11-
import { getChain } from "../../../../../../utils/chain";
11+
import { getContractV5 } from "../../../../../../utils/cache/getContractv5";
1212
import { maybeBigInt } from "../../../../../../utils/primitiveTypes";
13-
import { thirdwebClient } from "../../../../../../utils/sdk";
1413
import { insertTransaction } from "../../../../../../utils/transaction/insertTransaction";
1514
import { thirdwebSdkVersionSchema } from "../../../../../schemas/httpHeaders/thirdwebSdkVersion";
1615
import { signature721OutputSchema } from "../../../../../schemas/nft";
@@ -97,10 +96,9 @@ export async function erc721SignatureMint(fastify: FastifyInstance) {
9796
let queueId: string;
9897
if (sdkVersion === "5") {
9998
const payloadV5 = payload as Static<typeof signature721OutputSchemaV5>;
100-
const contract = getContractV5({
101-
client: thirdwebClient,
102-
chain: await getChain(chainId),
103-
address: contractAddress,
99+
const contract = await getContractV5({
100+
chainId,
101+
contractAddress,
104102
});
105103
const transaction = mintWithSignature({
106104
contract,

src/server/routes/contract/write/write.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { prepareContractCall, resolveMethod } from "thirdweb";
55
import { getContractV5 } from "../../../../utils/cache/getContractv5";
66
import { maybeBigInt } from "../../../../utils/primitiveTypes";
77
import { queueTransaction } from "../../../../utils/transaction/queueTransation";
8+
import { createCustomError } from "../../../middleware/error";
89
import { abiSchema } from "../../../schemas/contract";
910
import {
1011
contractParamSchema,
@@ -76,7 +77,7 @@ export async function writeToContract(fastify: FastifyInstance) {
7677
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7778

7879
const chainId = await getChainIdFromChain(chain);
79-
const contract = getContractV5({
80+
const contract = await getContractV5({
8081
chainId,
8182
contractAddress,
8283
abi,
@@ -87,9 +88,15 @@ export async function writeToContract(fastify: FastifyInstance) {
8788
// 2. functionName passed as function name + passed in ABI
8889
// 3. functionName passed as function name + inferred ABI (fetched at encode time)
8990
// this is all handled inside the `resolveMethod` function
91+
let method;
92+
try {
93+
method = await resolveMethod(functionName)(contract);
94+
} catch (e: any) {
95+
throw createCustomError(`${e}`, StatusCodes.BAD_REQUEST, "BAD_REQUEST");
96+
}
9097
const transaction = prepareContractCall({
9198
contract,
92-
method: resolveMethod(functionName),
99+
method,
93100
params: args,
94101
gas: maybeBigInt(txOverrides?.gas),
95102
value: maybeBigInt(txOverrides?.value),

src/server/schemas/contract/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface readSchema extends contractSchemaTypes {
2424
const abiTypeSchema = Type.Object({
2525
type: Type.Optional(Type.String()),
2626
name: Type.Optional(Type.String()),
27+
internalType: Type.Optional(Type.String()),
2728
stateMutability: Type.Optional(Type.String()),
2829
components: Type.Optional(
2930
Type.Array(
@@ -56,6 +57,7 @@ export const abiSchema = Type.Object({
5657
type: Type.String(),
5758
name: Type.Optional(Type.String()),
5859
inputs: Type.Array(abiTypeSchema),
60+
outputs: Type.Array(abiTypeSchema),
5961
stateMutability: Type.Optional(Type.String()),
6062
});
6163

src/utils/cache/getContractv5.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { defineChain, getContract } from "thirdweb";
1+
import { getContract } from "thirdweb";
22
import { thirdwebClient } from "../../utils/sdk";
3+
import { getChain } from "../chain";
34

45
interface GetContractParams {
56
chainId: number;
@@ -8,12 +9,12 @@ interface GetContractParams {
89
}
910

1011
// Using new v5 SDK
11-
export const getContractV5 = ({
12+
export const getContractV5 = async ({
1213
chainId,
1314
contractAddress,
1415
abi,
1516
}: GetContractParams) => {
16-
const definedChain = defineChain(chainId);
17+
const definedChain = await getChain(chainId);
1718

1819
// get a contract
1920
return getContract({

src/utils/transaction/userOperation.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ export const generateSignedUserOperation = async (
8888

8989
// Create Unsigned UserOperation
9090
// Todo: Future expose a way to skip paymaster
91-
let unsignedOp = await createUnsignedUserOp({
91+
let unsignedOp = (await createUnsignedUserOp({
9292
transaction: userOpCall,
9393
accountContract: smartAccountContract,
9494
sponsorGas: true,
9595
factoryContract: accountFactoryContract,
9696
adminAddress: signerAddress,
97-
});
97+
})) as UserOperation; // TODO support entrypoint v0.7 accounts
9898

9999
// Pass custom gas limit for UserOperation
100100
if (gas) {
@@ -109,7 +109,10 @@ export const generateSignedUserOperation = async (
109109
client: thirdwebClient,
110110
});
111111

112-
const paymasterAndData = paymasterResult.paymasterAndData;
112+
const paymasterAndData =
113+
"paymasterAndData" in paymasterResult
114+
? paymasterResult.paymasterAndData
115+
: "0x";
113116
if (paymasterAndData && paymasterAndData !== "0x") {
114117
unsignedOp.paymasterAndData = paymasterAndData as Hex;
115118
}
@@ -122,11 +125,12 @@ export const generateSignedUserOperation = async (
122125
});
123126

124127
// Sign UserOperation
125-
const signedUserOp = await signUserOp({
128+
const signedUserOp = (await signUserOp({
129+
client: thirdwebClient,
126130
userOp: unsignedOp,
127131
adminAccount,
128132
chain,
129-
});
133+
})) as UserOperation; // TODO support entrypoint v0.7 accounts
130134

131135
// Return Signed UserOperation
132136
return signedUserOp;

test/e2e/bun.lockb

-51.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)