Skip to content

Commit abe57a5

Browse files
committed
tests
1 parent 299d3b0 commit abe57a5

File tree

4 files changed

+89
-24
lines changed

4 files changed

+89
-24
lines changed

packages/thirdweb/src/extensions/prebuilts/compute-ref-deployments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export async function computeRefDeployments(
4040
const salt =
4141
contracts[0]?.salt && contracts[0]?.salt.length > 0
4242
? contracts[0]?.salt
43-
: "thirdweb";
43+
: "";
4444

4545
const addr = await computePublishedContractAddress({
4646
client,
@@ -61,7 +61,7 @@ export async function computeRefDeployments(
6161
const addressArray: string[] = [];
6262

6363
for (const c of contracts) {
64-
const salt = c?.salt && c?.salt.length > 0 ? c?.salt : "thirdweb";
64+
const salt = c?.salt && c?.salt.length > 0 ? c?.salt : "";
6565

6666
addressArray.push(
6767
await computePublishedContractAddress({

packages/thirdweb/src/extensions/prebuilts/process-ref-deployments.test.ts

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ANVIL_CHAIN } from "../../../test/src/chains.js";
33
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
44
import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js";
55
import { getContract } from "../../contract/contract.js";
6+
import { getDeployedInfraContract } from "../../contract/deployment/utils/infra.js";
67
import { readContract } from "../../transaction/read-contract.js";
78
import { getInstalledModules } from "../modules/__generated__/IModularCore/read/getInstalledModules.js";
89
import { deployPublishedContract } from "./deploy-published.js";
@@ -29,16 +30,16 @@ describe.runIf(process.env.TW_SECRET_KEY)(
2930
account: TEST_ACCOUNT_A,
3031
contractId: "MultiSig",
3132
version: "0.0.4",
32-
salt: "tw",
33+
salt: "",
3334
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
3435
});
3536
dummyContractAddress = await deployPublishedContract({
3637
client: TEST_CLIENT,
3738
chain: ANVIL_CHAIN,
3839
account: TEST_ACCOUNT_A,
3940
contractId: "ContractWithBytes",
40-
version: "0.0.1",
41-
salt: "tw",
41+
version: "0.0.2",
42+
salt: "",
4243
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
4344
});
4445
mintfeeManagerModuleAddress = await deployPublishedContract({
@@ -47,35 +48,34 @@ describe.runIf(process.env.TW_SECRET_KEY)(
4748
account: TEST_ACCOUNT_A,
4849
contractId: "MintFeeManagerModule",
4950
version: "0.0.1",
50-
salt: "tw",
51+
salt: "",
5152
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
5253
});
5354
mintfeeManagerCoreAddress = await deployPublishedContract({
5455
client: TEST_CLIENT,
5556
chain: ANVIL_CHAIN,
5657
account: TEST_ACCOUNT_A,
5758
contractId: "MintFeeManagerCore",
58-
version: "0.0.25",
59-
salt: "tw",
59+
version: "0.0.26",
60+
salt: "",
6061
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
6162
});
6263
claimableModuleAddress = await deployPublishedContract({
6364
client: TEST_CLIENT,
6465
chain: ANVIL_CHAIN,
6566
account: TEST_ACCOUNT_A,
6667
contractId: "ClaimableERC721",
67-
version: "0.0.13",
68-
salt: "tw",
68+
version: "0.0.14",
69+
salt: "",
6970
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
7071
});
71-
7272
wethAddress = await deployPublishedContract({
7373
client: TEST_CLIENT,
7474
chain: ANVIL_CHAIN,
7575
account: TEST_ACCOUNT_A,
7676
contractId: "WETH9",
7777
version: "0.0.1",
78-
salt: "thirdweb",
78+
salt: "",
7979
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
8080
});
8181
forwarderAddress = await deployPublishedContract({
@@ -84,7 +84,7 @@ describe.runIf(process.env.TW_SECRET_KEY)(
8484
account: TEST_ACCOUNT_A,
8585
contractId: "Forwarder",
8686
version: "0.0.1",
87-
salt: "thirdweb",
87+
salt: "",
8888
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
8989
});
9090
multiwrapAddress = await deployPublishedContract({
@@ -192,5 +192,67 @@ describe.runIf(process.env.TW_SECRET_KEY)(
192192
expect(fetchedWethAddress.toLowerCase()).to.eq(wethAddress);
193193
expect(isTrustedForwarder).to.be.true;
194194
});
195+
196+
it("should correctly compute addresses for deployed contracts with refs", async () => {
197+
const [
198+
multisigAddressComputed,
199+
dummyContractAddressComputed,
200+
mintfeeManagerModuleAddressComputed,
201+
mintfeeManagerCoreAddressComputed,
202+
claimableModuleAddressComputed,
203+
] = await Promise.all([
204+
getDeployedInfraContract({
205+
client: TEST_CLIENT,
206+
chain: ANVIL_CHAIN,
207+
contractId: "MultiSig",
208+
version: "0.0.4",
209+
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
210+
}),
211+
getDeployedInfraContract({
212+
client: TEST_CLIENT,
213+
chain: ANVIL_CHAIN,
214+
contractId: "ContractWithBytes",
215+
version: "0.0.2",
216+
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
217+
}),
218+
getDeployedInfraContract({
219+
client: TEST_CLIENT,
220+
chain: ANVIL_CHAIN,
221+
contractId: "MintFeeManagerModule",
222+
version: "0.0.1",
223+
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
224+
}),
225+
getDeployedInfraContract({
226+
client: TEST_CLIENT,
227+
chain: ANVIL_CHAIN,
228+
contractId: "MintFeeManagerCore",
229+
version: "0.0.26",
230+
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
231+
}),
232+
getDeployedInfraContract({
233+
client: TEST_CLIENT,
234+
chain: ANVIL_CHAIN,
235+
contractId: "ClaimableERC721",
236+
version: "0.0.14",
237+
publisher: "0x6453a486d52e0EB6E79Ec4491038E2522a926936",
238+
}),
239+
]);
240+
241+
expect(multisigAddressComputed?.address.toLowerCase()).to.eq(
242+
multisigAddress,
243+
);
244+
expect(dummyContractAddressComputed?.address.toLowerCase()).to.eq(
245+
dummyContractAddress,
246+
);
247+
expect(mintfeeManagerModuleAddressComputed?.address.toLowerCase()).to.eq(
248+
mintfeeManagerModuleAddress,
249+
);
250+
expect(mintfeeManagerCoreAddressComputed?.address.toLowerCase()).to.eq(
251+
mintfeeManagerCoreAddress,
252+
);
253+
expect(claimableModuleAddressComputed?.address.toLowerCase()).to.eq(
254+
claimableModuleAddress,
255+
);
256+
});
195257
},
196258
);

packages/thirdweb/src/extensions/prebuilts/process-ref-deployments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function processRefDeployments(
4747
const salt =
4848
contracts[0]?.salt && contracts[0]?.salt.length > 0
4949
? contracts[0]?.salt
50-
: "thirdweb";
50+
: "";
5151

5252
const addr = await deployPublishedContract({
5353
client,
@@ -69,7 +69,7 @@ export async function processRefDeployments(
6969
const addressArray = [];
7070

7171
for (const c of contracts) {
72-
const salt = c?.salt && c?.salt.length > 0 ? c?.salt : "thirdweb";
72+
const salt = c?.salt && c?.salt.length > 0 ? c?.salt : "";
7373

7474
addressArray.push(
7575
await deployPublishedContract({

packages/thirdweb/src/utils/any-evm/compute-published-contract-deploy-info.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,18 @@ export async function computeDeploymentInfoFromMetadata(args: {
5656
const { client, chain, constructorParams, contractMetadata } = args;
5757
const definedConstructorParams =
5858
constructorParams || contractMetadata.constructorParams;
59-
const processedConstructorParams: Record<string, string | string[]> = {};
60-
for (const key in definedConstructorParams) {
61-
processedConstructorParams[key] = await computeRefDeployments({
62-
client,
63-
chain,
64-
paramValue: definedConstructorParams[key] as
65-
| string
66-
| ImplementationConstructorParam,
67-
});
59+
let processedConstructorParams: Record<string, string | string[]> | undefined;
60+
if (definedConstructorParams) {
61+
processedConstructorParams = {};
62+
for (const key in definedConstructorParams) {
63+
processedConstructorParams[key] = await computeRefDeployments({
64+
client,
65+
chain,
66+
paramValue: definedConstructorParams[key] as
67+
| string
68+
| ImplementationConstructorParam,
69+
});
70+
}
6871
}
6972

7073
return computeDeploymentInfoFromBytecode({

0 commit comments

Comments
 (0)