Skip to content

Commit

Permalink
remove native node, use anvil
Browse files Browse the repository at this point in the history
  • Loading branch information
marsian83 committed Nov 21, 2024
1 parent a499a41 commit 7a1b80a
Show file tree
Hide file tree
Showing 7 changed files with 3,530 additions and 329 deletions.
Empty file modified bin/anvil.exe
100644 → 100755
Empty file.
3,781 changes: 3,474 additions & 307 deletions deno.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/contracts/deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"tasks": {
"re": "deno run -A mod.ts"
"re": "deno run -A mod.ts",
"anvil": "../../bin/anvil.exe"
},
"imports": {
"@openzeppelin/contracts": "npm:@openzeppelin/contracts@^5.1.0",
Expand Down
43 changes: 26 additions & 17 deletions packages/contracts/environment/localnode.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import { createTestClient, http, parseEther } from "viem";
import { privateKeyToAddress } from "viem/accounts";
import { anvil } from "viem/chains";
import environmentConfig from "../environment.config.ts";
import { parseArgs } from "jsr:@std/cli";
import { cliError, consoleFmt } from "../utils.ts";
import { resolve } from "jsr:@std/path";
import { spawn } from "node:child_process";
import { anvil } from "viem/chains";

async function main() {
const args = parseArgs(Deno.args);

function main() {
const os = Deno.build.os;

if (os === "linux" || os === "darwin") {
const process = spawn(
resolve(`../../scripts/evm-node${args.log ? "-logged" : ""}.sh`),
);

if (!args.log) {
console.log(`Running EVM node in background with pid : ${process.pid}`);
} else {
console.log(`Running EVM node and logging to evmnode.logs`);
}
} else if (os === "windows") {
console.log(
consoleFmt.magenta(
Expand All @@ -19,22 +32,18 @@ async function main() {
cliError("Unsupported OS");
}

// const admin = createTestClient({
// mode: "anvil",
// transport: http(),
// chain: anvil,
// });

// environmentConfig.accounts.forEach(async (key) => {
// await admin.setBalance({
// address: privateKeyToAddress(key),
// value: parseEther("1000"),
// });
// });
}
const admin = createTestClient({
mode: "anvil",
transport: http(),
chain: anvil,
});

function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
environmentConfig.accounts.forEach(async (key) => {
await admin.setBalance({
address: privateKeyToAddress(key),
value: parseEther("1000"),
});
});
}

if (import.meta.main) {
Expand Down
12 changes: 8 additions & 4 deletions packages/contracts/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ async function main() {
await commands.compile();
} else if (command === "tests") {
await commands.compile();
await commands.node();
// await commands.node();
await commands.tests();
} else if (command === "node") {
await commands.node();
await commands.node([args.log && "--log"]);
}
}

Expand All @@ -63,9 +63,13 @@ async function execCommand(
const commands = {
compile: () =>
execCommand("deno", { args: ["run", "-A", "environment/compiler.ts"] }),

tests: () => execCommand("deno", { args: ["test"] }),
node: () =>
execCommand("deno", { args: ["run", "-A", "environment/localnode.ts"] }),

node: (args?: string[]) =>
execCommand("deno", {
args: ["run", "-A", "environment/localnode.ts", ...(args || [])],
}),
};

if (import.meta.main) {
Expand Down
10 changes: 10 additions & 0 deletions scripts/evm-node-logged.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

SCRIPT_DIR="$(dirname "$0")"
ANVIL_EXECUTABLE="$SCRIPT_DIR/../bin/anvil.exe"
LOG_LOC="$SCRIPT_DIR/../evmnode.log"

rm -f "$LOG_LOC"

pkill -9 anvil.exe
"$ANVIL_EXECUTABLE" --host 0.0.0.0 > "$LOG_LOC" 2>"$LOG_LOC" & echo $!
10 changes: 10 additions & 0 deletions scripts/evm-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

SCRIPT_DIR="$(dirname "$0")"
ANVIL_EXECUTABLE="$SCRIPT_DIR/../bin/anvil.exe"
LOG_LOC="$SCRIPT_DIR/../evmnode.log"

rm -f "$LOG_LOC"

pkill -9 anvil.exe
"$ANVIL_EXECUTABLE" > /dev/null 2>&1 & echo $!

0 comments on commit 7a1b80a

Please sign in to comment.