Skip to content

Commit c6178bd

Browse files
committed
test
1 parent c8aa165 commit c6178bd

File tree

3 files changed

+284
-181
lines changed

3 files changed

+284
-181
lines changed

packages/thirdweb/src/extensions/prebuilts/deploy-published.ts

Lines changed: 1 addition & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type { FetchDeployMetadataResult } from "../../utils/any-evm/deploy-metad
1919
import type { Hex } from "../../utils/encoding/hex.js";
2020
import type { Account } from "../../wallets/interfaces/wallet.js";
2121
import { getAllDefaultConstructorParamsForImplementation } from "./get-required-transactions.js";
22+
import { processRefDeployments, type ImplementationConstructorParam } from "./process-ref-deployments.js";
2223

2324
/**
2425
* @extension DEPLOY
@@ -129,187 +130,6 @@ export type DeployContractfromDeployMetadataOptions = {
129130
salt?: string;
130131
};
131132

132-
type DynamicParams = {
133-
type: "address" | "address[]" | "bytes" | "bytes[]";
134-
refContracts: {
135-
publisherAddress: string;
136-
version: string;
137-
contractId: string;
138-
salt?: string;
139-
}[];
140-
decodedBytes: Array<
141-
Array<{
142-
type: string;
143-
defaultValue?: string;
144-
dynamicValue?: DynamicParams;
145-
}>
146-
>;
147-
}
148-
149-
type ImplementationConstructorParam = {
150-
defaultValue?: string;
151-
dynamicValue?: DynamicParams;
152-
}
153-
154-
type ProcessRefDeploymentsOptions = {
155-
client: ThirdwebClient;
156-
chain: Chain;
157-
account: Account;
158-
paramValue: string | ImplementationConstructorParam;
159-
};
160-
161-
async function processRefDeployments(
162-
options: ProcessRefDeploymentsOptions,
163-
): Promise<string> {
164-
const { client, account, chain, paramValue } = options;
165-
166-
try {
167-
if (typeof paramValue === "object") {
168-
if (
169-
"defaultValue" in paramValue &&
170-
paramValue.defaultValue &&
171-
paramValue.defaultValue.length > 0
172-
) {
173-
return paramValue.defaultValue;
174-
}
175-
176-
if ("dynamicValue" in paramValue && paramValue.dynamicValue) {
177-
const dynamicValue = paramValue.dynamicValue;
178-
const contracts = dynamicValue.refContracts;
179-
180-
if (dynamicValue.type === "address") {
181-
const salt =
182-
contracts[0]?.salt && contracts[0]?.salt.length > 0
183-
? contracts[0]?.salt
184-
: undefined;
185-
186-
const addr = await deployPublishedContract({
187-
client,
188-
chain,
189-
account,
190-
contractId: contracts[0]?.contractId as string,
191-
publisher: contracts[0]?.publisherAddress,
192-
version: contracts[0]?.version,
193-
salt,
194-
});
195-
196-
return addr;
197-
}
198-
199-
if (dynamicValue.type === "address[]") {
200-
const addressArray = [];
201-
202-
for (const c of contracts) {
203-
const salt = c?.salt && c?.salt.length > 0 ? c?.salt : undefined;
204-
205-
addressArray.push(
206-
await deployPublishedContract({
207-
client,
208-
chain,
209-
account,
210-
contractId: c.contractId,
211-
publisher: c.publisherAddress,
212-
version: c.version,
213-
salt,
214-
}),
215-
);
216-
}
217-
218-
return JSON.stringify(addressArray);
219-
}
220-
221-
if (dynamicValue.type === "bytes") {
222-
const decodedBytes = dynamicValue.decodedBytes[0];
223-
224-
if (decodedBytes) {
225-
const types = [];
226-
const values = [];
227-
for (const v of decodedBytes) {
228-
types.push(v.type);
229-
230-
if (v.defaultValue) {
231-
values.push(v.defaultValue);
232-
}
233-
234-
if (v.dynamicValue) {
235-
values.push(
236-
await processRefDeployments({
237-
client,
238-
account,
239-
chain,
240-
paramValue: v,
241-
}),
242-
);
243-
}
244-
}
245-
246-
return encodeAbiParameters(
247-
types.map((t) => {
248-
return { name: "", type: t };
249-
}),
250-
values,
251-
);
252-
}
253-
}
254-
255-
if (dynamicValue.type === "bytes[]") {
256-
const bytesArray = [];
257-
const decodedBytesArray = dynamicValue.decodedBytes;
258-
259-
for (const a of decodedBytesArray) {
260-
const decodedBytes = a;
261-
262-
if (decodedBytes) {
263-
const types = [];
264-
const values = [];
265-
for (const v of decodedBytes) {
266-
types.push(v.type);
267-
268-
if (v.defaultValue) {
269-
values.push(v.defaultValue);
270-
}
271-
272-
if (v.dynamicValue) {
273-
values.push(
274-
await processRefDeployments({
275-
client,
276-
account,
277-
chain,
278-
paramValue: v,
279-
}),
280-
);
281-
}
282-
}
283-
284-
bytesArray.push(
285-
encodeAbiParameters(
286-
types.map((t) => {
287-
return { name: "", type: t };
288-
}),
289-
values,
290-
),
291-
);
292-
}
293-
}
294-
295-
return JSON.stringify(bytesArray);
296-
}
297-
}
298-
}
299-
// biome-ignore lint/suspicious/noExplicitAny: catch multiple errors
300-
} catch (e: any) {
301-
const err = "error" in e ? e.error?.message : e?.message;
302-
303-
if (err.toString().includes("Contract already deployed")) {
304-
return paramValue as string;
305-
}
306-
307-
throw e;
308-
}
309-
310-
return paramValue as string;
311-
}
312-
313133
/**
314134
* @internal
315135
*/
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { beforeAll, describe, expect, it } from "vitest";
2+
import { ANVIL_CHAIN } from "../../../test/src/chains.js";
3+
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
4+
import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js";
5+
import { getContract } from "../../contract/contract.js";
6+
import { getInstalledModules } from "../modules/__generated__/IModularCore/read/getInstalledModules.js";
7+
import {
8+
deployPublishedContract,
9+
} from "./deploy-published.js";
10+
import { readContract } from "../../transaction/read-contract.js";
11+
12+
describe.runIf(process.env.TW_SECRET_KEY)(
13+
"deployref",
14+
{
15+
timeout: 120000,
16+
},
17+
() => {
18+
let multisigAddress: string;
19+
let mintfeeManagerModuleAddress: string;
20+
let mintfeeManagerCoreAddress: string;
21+
let claimableModuleAddress: string;
22+
23+
beforeAll(async () => {
24+
multisigAddress = await deployPublishedContract({
25+
client: TEST_CLIENT,
26+
chain: ANVIL_CHAIN,
27+
account: TEST_ACCOUNT_A,
28+
contractId: "MultiSig",
29+
version: "0.0.3",
30+
salt: "tw",
31+
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
32+
});
33+
mintfeeManagerModuleAddress = await deployPublishedContract({
34+
client: TEST_CLIENT,
35+
chain: ANVIL_CHAIN,
36+
account: TEST_ACCOUNT_A,
37+
contractId: "MintFeeManagerModule",
38+
version: "0.0.1",
39+
salt: "tw",
40+
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
41+
});
42+
mintfeeManagerCoreAddress = await deployPublishedContract({
43+
client: TEST_CLIENT,
44+
chain: ANVIL_CHAIN,
45+
account: TEST_ACCOUNT_A,
46+
contractId: "MintFeeManagerCore",
47+
version: "0.0.23",
48+
salt: "tw",
49+
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
50+
});
51+
claimableModuleAddress = await deployPublishedContract({
52+
client: TEST_CLIENT,
53+
chain: ANVIL_CHAIN,
54+
account: TEST_ACCOUNT_A,
55+
contractId: "ClaimableERC721",
56+
version: "0.0.12",
57+
salt: "tw",
58+
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
59+
});
60+
}, 120000);
61+
62+
it("should set ref contract dependencies", async () => {
63+
const claimableModule = getContract({
64+
client: TEST_CLIENT,
65+
chain: ANVIL_CHAIN,
66+
address: claimableModuleAddress,
67+
});
68+
const fetchedMintFeeManagerAddress = await readContract({
69+
contract: claimableModule,
70+
method: "function mintFeeManager() returns (address)",
71+
});
72+
expect(fetchedMintFeeManagerAddress.toLowerCase()).to.eq(mintfeeManagerCoreAddress);
73+
74+
const mintFeeManager = getContract({
75+
client: TEST_CLIENT,
76+
chain: ANVIL_CHAIN,
77+
address: mintfeeManagerCoreAddress,
78+
});
79+
const owner = await readContract({
80+
contract: mintFeeManager,
81+
method: "function owner() returns (address)",
82+
});
83+
const modules = await getInstalledModules({
84+
contract: mintFeeManager,
85+
});
86+
const feeRecipient = await readContract({
87+
contract: mintFeeManager,
88+
method: "function getfeeRecipient() returns (address)",
89+
});
90+
const fee = await readContract({
91+
contract: mintFeeManager,
92+
method: "function getDefaultMintFee() returns (uint256)",
93+
});
94+
expect(owner.toLowerCase()).to.eq(multisigAddress);
95+
expect(modules.length).to.eq(1);
96+
expect(modules[0]?.implementation.toLowerCase()).to.eq(mintfeeManagerModuleAddress);
97+
expect(feeRecipient.toLowerCase()).to.eq("0x000000000000000000000000000000000000dead");
98+
expect(fee).to.eq(5n);
99+
});
100+
},
101+
);

0 commit comments

Comments
 (0)