Skip to content

Commit 006d49c

Browse files
Auto-merge
2 parents 782b21b + 5edf3cd commit 006d49c

File tree

4 files changed

+180
-0
lines changed

4 files changed

+180
-0
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
BASE_RPC: https://mainnet.base.org
1818
BASE_SEPOLIA_RPC: https://sepolia.base.org
1919
CELO_RPC: https://forno.celo.org
20+
AVALANCHE_RPC: https://api.avax.network/ext/bc/C/rpc
2021
ETHERSCAN_KEY: HDMPWG86NYEF1Y5KWZU1XI4HZX4SNHFW3B
2122
runs-on: ubuntu-latest
2223
steps:
@@ -55,6 +56,7 @@ jobs:
5556
BASE_RPC: ${{ secrets.BASE_HTTP_PROVIDER }}
5657
BASE_SEPOLIA_RPC: ${{ secrets.BASE_SEPOLIA_HTTP_PROVIDER }}
5758
CELO_RPC: ${{ secrets.CELO_HTTP_PROVIDER }}
59+
AVALANCHE_RPC: ${{ secrets.AVALANCHE_HTTP_PROVIDER }}
5860
ETHERSCAN_KEY: ${{ secrets.ETHERSCAN_KEY }}
5961
runs-on: ubuntu-latest
6062
steps:

example.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ SEPOLIA_RPC=
77
BASE_RPC=
88
BASE_SEPOLIA_RPC=
99
CELO_RPC=
10+
AVALANCHE_RPC=
1011
ETHERSCAN_KEY=
1112

modules/haberdasher-labs_passthrough-module_v0.1.0.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
{
7171
"chainId": "42220",
7272
"block": "22842477"
73+
},
74+
{
75+
"chainId": "43114",
76+
"block": "64681307"
7377
}
7478
],
7579
"creationArgs": {

test/avalancheDeployments.test.ts

Lines changed: 173 additions & 0 deletions
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 { avalanche } 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("Avalanche 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.AVALANCHE_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: avalanche,
42+
transport: http("http://127.0.0.1:8545"),
43+
});
44+
walletClient = createWalletClient({
45+
chain: avalanche,
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 avalanche
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 avalanche. If not, then skip
82+
let isOnAvalanche = false;
83+
for (let i = 0; i < module.deployments.length; i++) {
84+
if (module.deployments[i].chainId === "43114") {
85+
isOnAvalanche = true;
86+
break;
87+
}
88+
}
89+
if (!isOnAvalanche) {
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+
});

0 commit comments

Comments
 (0)