Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new pkgs #293

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/real-papayas-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@moonwall/types": patch
"@moonwall/util": patch
"@moonwall/cli": patch
"@moonwall/tests": patch
---

Pkg Bumps
24 changes: 12 additions & 12 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"prepublish": "pnpm run build && pnpm run generate-types"
},
"dependencies": {
"@acala-network/chopsticks": "^0.8.3",
"@acala-network/chopsticks": "^0.8.4",
"@moonbeam-network/api-augment": "^0.2400.0",
"@moonwall/types": "workspace:*",
"@moonwall/util": "workspace:*",
Expand All @@ -73,38 +73,38 @@
"@polkadot/types-codec": "^10.10.1",
"@polkadot/util": "^12.5.1",
"@polkadot/util-crypto": "^12.5.1",
"@zombienet/orchestrator": "^0.0.56",
"@zombienet/utils": "^0.0.22",
"@zombienet/orchestrator": "^0.0.59",
"@zombienet/utils": "^0.0.23",
"bottleneck": "^2.19.5",
"chalk": "^5.3.0",
"clear": "^0.1.0",
"cli-progress": "^3.12.0",
"colors": "^1.4.0",
"debug": "^4.3.4",
"dotenv": "^16.3.1",
"ethers": "^6.7.1",
"ethers": "^6.8.0",
"execa": "^8.0.1",
"inquirer": "^9.2.11",
"inquirer-press-to-continue": "^1.2.0",
"minimatch": "^9.0.3",
"node-fetch": "^3.3.2",
"semver": "^7.5.4",
"viem": "^1.16.5",
"vitest": "1.0.0-beta.2",
"web3": "4.0.3",
"viem": "^1.18.0",
"vitest": "1.0.0-beta.3",
"web3": "4.2.1",
"web3-providers-ws": "4.0.3",
"ws": "^8.14.2",
"yaml": "^2.3.3",
"yargs": "^17.7.2"
},
"devDependencies": {
"@types/cli-progress": "^3.11.3",
"@types/debug": "^4.1.9",
"@types/node": "^20.8.6",
"@types/yargs": "^17.0.26",
"@types/cli-progress": "^3.11.4",
"@types/debug": "^4.1.10",
"@types/node": "^20.8.9",
"@types/yargs": "^17.0.29",
"prettier": "^2.8.8",
"tsup": "^7.2.0",
"tsx": "^3.13.0",
"tsx": "^3.14.0",
"typescript": "^5.2.2"
},
"publishConfig": {
Expand Down
11 changes: 8 additions & 3 deletions packages/cli/src/cmds/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function addThreadConfig(
config: UserConfig,
threads: number | boolean | object = false
): UserConfig {
const configWithThreads = {
const configWithThreads: UserConfig = {
...config,
pool: "threads",
poolOptions: {
Expand Down Expand Up @@ -146,8 +146,13 @@ function addThreadConfig(
}

if (typeof threads === "object") {
configWithThreads.pool = Object.keys(threads)[0];
configWithThreads.poolOptions = Object.values(threads)[0];
const key = Object.keys(threads)[0];
if (["threads", "forks", "vmThreads", "typescript"].includes(key)) {
configWithThreads.pool = key as "threads" | "forks" | "vmThreads" | "typescript";
configWithThreads.poolOptions = Object.values(threads)[0];
} else {
throw new Error(`Invalid pool type: ${key}`);
}
}
return configWithThreads;
}
100 changes: 56 additions & 44 deletions packages/cli/src/internal/localNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,49 @@ export async function launchNode(cmd: string, args: string[], name: string): Pro

const WEB_SOCKET_TIMEOUT = 5000; // e.g., 5 seconds

// async function checkWebSocketJSONRPC(port: number): Promise<boolean> {
// return new Promise((resolve, reject) => {
// const ws = new WebSocket(`ws://localhost:${port}`);
// const timeout = setTimeout(() => {
// ws.close();
// reject(new Error("WebSocket response timeout"));
// }, WEB_SOCKET_TIMEOUT);

// ws.once("open", () => {
// ws.send(
// JSON.stringify({
// jsonrpc: "2.0",
// id: 1,
// method: "system_chain",
// params: [],
// })
// );
// });

// ws.once("message", (data) => {
// clearTimeout(timeout);
// try {
// const { jsonrpc, id } = JSON.parse(data.toString());
// if (jsonrpc === "2.0" && id === 1) {
// resolve(true);
// } else {
// reject(new Error("Invalid JSON-RPC response"));
// }
// } catch (e) {
// reject(new Error("Failed to parse WebSocket message"));
// } finally {
// ws.close();
// }
// });

// ws.once("error", (err) => {
// clearTimeout(timeout);
// ws.close();
// reject(new Error(`WebSocket error: ${err.message}`));
// });
// });
// }

async function checkWebSocketJSONRPC(port: number): Promise<boolean> {
return new Promise((resolve, reject) => {
const ws = new WebSocket(`ws://localhost:${port}`);
Expand All @@ -67,7 +110,7 @@ async function checkWebSocketJSONRPC(port: number): Promise<boolean> {
reject(new Error("WebSocket response timeout"));
}, WEB_SOCKET_TIMEOUT);

ws.once("open", () => {
const openHandler = () => {
ws.send(
JSON.stringify({
jsonrpc: "2.0",
Expand All @@ -76,9 +119,9 @@ async function checkWebSocketJSONRPC(port: number): Promise<boolean> {
params: [],
})
);
});
};

ws.once("message", (data) => {
const messageHandler = (data: string) => {
clearTimeout(timeout);
try {
const { jsonrpc, id } = JSON.parse(data.toString());
Expand All @@ -90,56 +133,25 @@ async function checkWebSocketJSONRPC(port: number): Promise<boolean> {
} catch (e) {
reject(new Error("Failed to parse WebSocket message"));
} finally {
ws.removeListener("error", errorHandler);
ws.close();
}
});
};

ws.once("error", (err) => {
const errorHandler = (err: Error) => {
clearTimeout(timeout);
ws.removeListener("open", openHandler);
ws.removeListener("message", messageHandler);
ws.close();
reject(new Error(`WebSocket error: ${err.message}`));
});
};

ws.once("open", openHandler);
ws.once("message", messageHandler);
ws.once("error", errorHandler);
});
}

// async function checkWebSocketJSONRPC(port: number): Promise<boolean> {
// return new Promise((resolve, reject) => {
// const ws = new WebSocket(`ws://localhost:${port}`);

// ws.once("open", () => {
// ws.send(
// JSON.stringify({
// jsonrpc: "2.0",
// id: 1,
// method: "system_chain",
// params: [],
// })
// );
// });

// ws.once("message", (data) => {
// try {
// const response = JSON.parse(data.toString());
// if (response.jsonrpc === "2.0" && response.id === 1) {
// ws.close();
// resolve(true);
// } else {
// ws.close();
// reject(false);
// }
// } catch (e) {
// ws.close();
// reject(false);
// }
// });

// ws.once("error", () => {
// ws.close();
// reject(false);
// });
// });
// }

function findPortsByPid(pid: number, retryDelay: number = 10000) {
for (;;) {
const command = `lsof -i -n -P | grep LISTEN | grep ${pid} || true`;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/internal/providerFactories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class ProviderFactory {
{ delay: 50, autoReconnect: false, maxAttempts: 10 }
);

return new Web3(provider);
return new Web3(provider) as Web3<any>;
},
};
}
Expand Down
8 changes: 4 additions & 4 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@
"@polkadot/types": "^10.10.1",
"@polkadot/util": "^12.5.1",
"@polkadot/util-crypto": "^12.5.1",
"@types/node": "^20.8.6",
"@types/node": "^20.8.9",
"@zombienet/utils": "^0.0.22",
"bottleneck": "^2.19.5",
"debug": "^4.3.4",
"ethers": "^6.7.1",
"viem": "^1.16.5",
"web3": "4.0.3"
"ethers": "^6.8.0",
"viem": "^1.18.0",
"web3": "4.2.1"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type MoonwallEnvironment = {
export interface MoonwallProvider {
name: string;
type: ProviderType;
connect: () => Promise<ApiPromise> | Signer | Web3 | Promise<ViemClient> | void;
connect: () => Promise<ApiPromise> | Signer | Web3<any> | Promise<ViemClient> | void;
ws?: () => WsProvider;
}

Expand Down
14 changes: 7 additions & 7 deletions packages/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@
"colors": "^1.4.0",
"debug": "^4.3.4",
"dotenv": "^16.3.1",
"ethers": "^6.7.1",
"ethers": "^6.8.0",
"inquirer": "^9.2.11",
"inquirer-press-to-continue": "^1.2.0",
"node-fetch": "^3.3.2",
"rlp": "^3.0.0",
"semver": "^7.5.4",
"viem": "^1.16.5",
"vitest": "1.0.0-beta.2",
"web3": "4.0.3",
"viem": "^1.16.6",
"vitest": "1.0.0-beta.3",
"web3": "4.2.1",
"ws": "^8.14.2",
"yaml": "^2.3.3",
"yargs": "^17.7.2"
},
"devDependencies": {
"@types/debug": "^4.1.9",
"@types/node": "^20.8.6",
"@types/yargs": "^17.0.26",
"@types/debug": "^4.1.10",
"@types/node": "^20.8.7",
"@types/yargs": "^17.0.29",
"prettier": "^2.8.8",
"tsup": "^7.2.0",
"typescript": "^5.2.2"
Expand Down
Loading