Skip to content

Commit c8e9b05

Browse files
committed
add base sepolia tests
1 parent 84dbd76 commit c8e9b05

File tree

4 files changed

+184
-18
lines changed

4 files changed

+184
-18
lines changed

example.env

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GNOSIS_RPC=
55
ARBITRUM_RPC=
66
SEPOLIA_RPC=
77
BASE_RPC=
8+
BASE_SEPOLIA_RPC=
89
CELO_RPC=
910
ETHERSCAN_KEY=
1011

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"tslib": "^2.6.2",
2525
"tsx": "^4.7.0",
2626
"typescript": "^5.1.6",
27-
"viem": "1.11.0",
27+
"viem": "1.16.5",
2828
"zod": "^3.22.4"
2929
}
3030
}

test/baseSepoliaDeployments.test.ts

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
import {
2+
HatsModulesClient,
3+
solidityToTypescriptType,
4+
} from "@hatsprotocol/modules-sdk";
5+
import { createPublicClient, createWalletClient, http } from "viem";
6+
import { privateKeyToAccount } from "viem/accounts";
7+
import { base, baseSepolia } from "viem/chains";
8+
import { createAnvil } from "@viem/anvil";
9+
import { bundleModules } from "../bundler";
10+
import type {
11+
PublicClient,
12+
WalletClient,
13+
PrivateKeyAccount,
14+
Address,
15+
} from "viem";
16+
import type { Anvil } from "@viem/anvil";
17+
import type { Module, Registry } from "@hatsprotocol/modules-sdk";
18+
import "dotenv/config";
19+
20+
describe("Base deployments", () => {
21+
let publicClient: PublicClient;
22+
let walletClient: WalletClient;
23+
let hatsModulesClient: HatsModulesClient;
24+
let anvil: Anvil;
25+
let deployerAccount: PrivateKeyAccount;
26+
let instances: Address[] = [];
27+
28+
beforeAll(async () => {
29+
anvil = createAnvil({
30+
forkUrl: process.env.BASE_SEPOLIA_RPC,
31+
startTimeout: 20000,
32+
});
33+
await anvil.start();
34+
35+
deployerAccount = privateKeyToAccount(
36+
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
37+
);
38+
39+
// init Viem clients
40+
publicClient = createPublicClient({
41+
chain: baseSepolia,
42+
transport: http("http://127.0.0.1:8545"),
43+
}) as PublicClient;
44+
walletClient = createWalletClient({
45+
chain: baseSepolia,
46+
transport: http("http://127.0.0.1:8545"),
47+
});
48+
49+
const registryModules: Registry = bundleModules() as unknown as Registry;
50+
51+
hatsModulesClient = new HatsModulesClient({
52+
publicClient,
53+
walletClient,
54+
});
55+
56+
await hatsModulesClient.prepare(registryModules);
57+
}, 30000);
58+
59+
afterAll(async () => {
60+
await anvil.stop();
61+
}, 30000);
62+
63+
test("Test create all modules", async () => {
64+
const modules = hatsModulesClient.getModules();
65+
66+
// create new module instance for each module which is deployed on goerli
67+
for (const [id, module] of Object.entries(modules)) {
68+
console.log(`Testing module: ${module.name}`);
69+
if (module.name === "JokeRace Eligibility") {
70+
continue;
71+
}
72+
73+
// the unlock module has dependencies on other external contracts
74+
if (
75+
module.implementationAddress ===
76+
"0x4c7803041851f7a17Fc6b5Ff5c911FC748160637"
77+
) {
78+
continue;
79+
}
80+
81+
// check if module is deployed on base sepolia. If not, then skip
82+
let isOnBaseSepolia = false;
83+
for (let i = 0; i < module.deployments.length; i++) {
84+
if (module.deployments[i].chainId === "84532") {
85+
isOnBaseSepolia = true;
86+
break;
87+
}
88+
}
89+
if (!isOnBaseSepolia) {
90+
continue;
91+
}
92+
93+
const hatId = module.creationArgs.useHatId
94+
? BigInt(
95+
"0x0000000100000000000000000000000000000000000000000000000000000000",
96+
)
97+
: BigInt("0");
98+
const immutableArgs: unknown[] = [];
99+
const mutableArgs: unknown[] = [];
100+
101+
// prepare immutable args
102+
for (let i = 0; i < module.creationArgs.immutable.length; i++) {
103+
let arg: unknown;
104+
const exampleArg = module.creationArgs.immutable[i].example;
105+
const tsType = solidityToTypescriptType(
106+
module.creationArgs.immutable[i].type,
107+
);
108+
if (tsType === "bigint") {
109+
arg = BigInt(exampleArg as string);
110+
} else if (tsType === "bigint[]") {
111+
arg = (exampleArg as Array<string>).map((val) => BigInt(val));
112+
} else {
113+
arg = exampleArg;
114+
}
115+
116+
immutableArgs.push(arg);
117+
}
118+
119+
// prepare mutable args
120+
for (let i = 0; i < module.creationArgs.mutable.length; i++) {
121+
let arg: unknown;
122+
const exampleArg = module.creationArgs.mutable[i].example;
123+
const tsType = solidityToTypescriptType(
124+
module.creationArgs.mutable[i].type,
125+
);
126+
if (tsType === "bigint") {
127+
arg = BigInt(exampleArg as string);
128+
} else if (tsType === "bigint[]") {
129+
arg = (exampleArg as Array<string>).map((val) => BigInt(val));
130+
} else {
131+
arg = exampleArg;
132+
}
133+
134+
mutableArgs.push(arg);
135+
}
136+
137+
// create new module instance
138+
const res = await hatsModulesClient.createNewInstance({
139+
account: deployerAccount,
140+
moduleId: id,
141+
hatId: hatId,
142+
immutableArgs: immutableArgs,
143+
mutableArgs: mutableArgs,
144+
});
145+
146+
instances.push(res.newInstance);
147+
148+
// check correct hat Id in the new instance
149+
const hatIdResult = await publicClient.readContract({
150+
address: res.newInstance as Address,
151+
abi: module.abi,
152+
functionName: "hatId",
153+
args: [],
154+
});
155+
expect(hatIdResult).toBe(hatId);
156+
}
157+
}, 30000);
158+
159+
test("Test module parameters", async () => {
160+
for (let i = 0; i < instances.length; i++) {
161+
let instance = instances[i];
162+
163+
const module = await hatsModulesClient.getModuleByInstance(instance);
164+
const res = await hatsModulesClient.getInstanceParameters(instance);
165+
166+
if (res === undefined || res.length !== module?.parameters.length) {
167+
throw new Error(
168+
`Error: could not read all parameters from the instance of module ${module?.name}`,
169+
);
170+
}
171+
}
172+
}, 30000);
173+
});

yarn.lock

+9-17
Original file line numberDiff line numberDiff line change
@@ -837,13 +837,6 @@
837837
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.3.tgz#6209321eb2c1712a7e7466422b8cb1fc0d9dd5d8"
838838
integrity sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==
839839

840-
"@types/ws@^8.5.5":
841-
version "8.5.10"
842-
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.10.tgz#4acfb517970853fa6574a3a6886791d04a396787"
843-
integrity sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==
844-
dependencies:
845-
"@types/node" "*"
846-
847840
"@types/yargs-parser@*":
848841
version "21.0.3"
849842
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.3.tgz#815e30b786d2e8f0dcd85fd5bcf5e1a04d008f15"
@@ -1596,10 +1589,10 @@ isexe@^2.0.0:
15961589
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
15971590
integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==
15981591

1599-
isomorphic-ws@5.0.0:
1600-
version "5.0.0"
1601-
resolved "https://registry.yarnpkg.com/isomorphic-ws/-/isomorphic-ws-5.0.0.tgz#e5529148912ecb9b451b46ed44d53dae1ce04bbf"
1602-
integrity sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw==
1592+
isows@1.0.3:
1593+
version "1.0.3"
1594+
resolved "https://registry.yarnpkg.com/isows/-/isows-1.0.3.tgz#93c1cf0575daf56e7120bab5c8c448b0809d0d74"
1595+
integrity sha512-2cKei4vlmg2cxEjm3wVSqn8pcoRF/LX/wpifuuNquFO4SQmPwarClT+SUCA2lt+l581tTeZIPIZuIDo2jWN1fg==
16031596

16041597
istanbul-lib-coverage@^3.0.0, istanbul-lib-coverage@^3.2.0:
16051598
version "3.2.2"
@@ -2613,19 +2606,18 @@ v8-to-istanbul@^9.0.1:
26132606
"@types/istanbul-lib-coverage" "^2.0.1"
26142607
convert-source-map "^2.0.0"
26152608

2616-
viem@1.11.0:
2617-
version "1.11.0"
2618-
resolved "https://registry.yarnpkg.com/viem/-/viem-1.11.0.tgz#67398c0735027c2f63e04ff125f7f53136148333"
2619-
integrity sha512-k53ewCObCHMc5zex/lXB4+HeRW1NIlezqkR/S4OXKV5MZvltMYqsgKABuWVgiMdfIL/NvDjtIgwbaA24AAn31g==
2609+
viem@1.16.5:
2610+
version "1.16.5"
2611+
resolved "https://registry.yarnpkg.com/viem/-/viem-1.16.5.tgz#99bac3bd6a2ccdff4a097438a8ef23a91f01d414"
2612+
integrity sha512-D8aE6cp/5w6PDtOOkJjkN+FtLyfsNWkfE78N4yTgCt4BG7KsBsePp4O68r1IaTVTVa41anebiZAy9kNEIwAXiw==
26202613
dependencies:
26212614
"@adraffy/ens-normalize" "1.9.4"
26222615
"@noble/curves" "1.2.0"
26232616
"@noble/hashes" "1.3.2"
26242617
"@scure/bip32" "1.3.2"
26252618
"@scure/bip39" "1.2.1"
2626-
"@types/ws" "^8.5.5"
26272619
abitype "0.9.8"
2628-
isomorphic-ws "5.0.0"
2620+
isows "1.0.3"
26292621
ws "8.13.0"
26302622

26312623
walker@^1.0.8:

0 commit comments

Comments
 (0)