Skip to content

Commit 77c386d

Browse files
committed
forge-exec-ipc-client v0.1.1
1 parent 3e60eef commit 77c386d

File tree

5 files changed

+84
-44
lines changed

5 files changed

+84
-44
lines changed

README.md

Lines changed: 77 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Install `forge-exec-ipc-client` on your machine, see [release files](https://git
1414

1515
This need to be in your `PATH`
1616

17-
You can also easily instal from source, see folder: [forge-exec-ipc-client](./forge-exec-ipc-client/)
17+
You can also easily install it from source using cargo:
1818

1919
```bash
2020
cargo install forge-exec-ipc-client
@@ -78,20 +78,14 @@ for now, only create, send, call and balance are implemented
7878

7979
### Example
8080

81-
We have example usage for both [tests](./demo-js/test/Exec.t.sol) and [scripts](./demo-js/script/ExecDemo.s.sol). See [example.js](./demo-js/example.js) in the [demo-js folder](./demo-js/)
81+
## Javascript
82+
83+
A demo repo can be found here where forge-exed is used both in test and script :
8284

8385
## Rust
8486

8587
`forge-exec` is agnostic to what program you execute, you just need to follow the ipc communication protocol. you can find a very basic rust example in the [demo-rust folder](./demo-rust/)
8688

87-
## Why?
88-
89-
[Forge scripting](https://book.getfoundry.sh/tutorials/solidity-scripting.html) allow you to perform deployment task in solidity. With forge-exec you can run external program to deploy contracts and more.
90-
91-
## Development
92-
93-
This project uses [Foundry](https://getfoundry.sh). See the [book](https://book.getfoundry.sh/getting-started/installation.html) for instructions on how to install and use Foundry.
94-
9589

9690
## Quick Start
9791

@@ -107,69 +101,115 @@ cat >> .gitignore <<EOF
107101
node_modules/
108102
.ipc.log
109103
EOF
104+
105+
cat >> foundry.toml <<EOF
106+
107+
ffi=true
108+
EOF
109+
110110
cat > package.json <<EOF
111111
{
112-
"name": "my-forge-exec-project",
112+
"name": "forge-exec-demo",
113113
"private": true,
114114
"type": "module",
115115
"devDependencies": {
116-
"forge-exec-ipc-server": "0.0.1"
116+
"forge-exec-ipc-server": "0.1.11",
117+
"viem": "^0.3.14"
117118
},
118119
"scripts": {
119-
"execute": "forge script --ffi script/Counter.s.sol -vvvvv"
120+
"execute": "forge script script/Counter.s.sol -vvvvv",
121+
"test": "forge test"
120122
}
121123
}
122124
EOF
123125

124-
cat >> remappings.txt <<EOF
125-
forge-exec/=lib/forge-exec/src/
126-
EOF
127-
126+
# install dependencies
128127
pnpm i
129128

130-
cat > script/example.js <<EOF
129+
cat > example.js <<EOF
131130
// @ts-check
132131
import { execute } from "forge-exec-ipc-server";
132+
import { encodeDeployData, encodeFunctionData } from 'viem';
133+
134+
import fs from 'fs';
135+
const Counter = JSON.parse(fs.readFileSync('out/Counter.sol/Counter.json', 'utf-8'));
136+
133137
execute(async (forge) => {
134-
const results = await Promise.all([
135-
forge.create({
136-
from: "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
137-
data: "0x608060405234801561001057600080fd5b5060f78061001f6000396000f3fe6080604052348015600f57600080fd5b5060043610603c5760003560e01c80633fb5c1cb1460415780638381f58a146053578063d09de08a14606d575b600080fd5b6051604c3660046083565b600055565b005b605b60005481565b60405190815260200160405180910390f35b6051600080549080607c83609b565b9190505550565b600060208284031215609457600080fd5b5035919050565b60006001820160ba57634e487b7160e01b600052601160045260246000fd5b506001019056fea2646970667358221220f0cfb2159c518c3da0ad864362bad5dc0715514a9ab679237253d506773a0a1b64736f6c63430008130033",
138-
}),
139-
]);
140-
141-
const tx = await forge.send({
142-
to: "0x0000000000000000000000000000000000000001",
143-
value: 1n,
138+
const counter = await forge.create({
139+
data:encodeDeployData({abi: Counter.abi, args: [], bytecode: Counter.bytecode.object})
140+
});
141+
142+
await forge.call({
143+
from: "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
144+
to: counter,
145+
data: encodeFunctionData({...Counter, functionName: 'setNumber', args: [42n]})
144146
});
145-
console.log({ tx: tx });
147+
146148
return {
147-
types: results.map(() => ({
149+
types: [{
148150
type: "address",
149-
})),
150-
values: results,
151+
}],
152+
values: [counter],
151153
};
152154
});
153155
EOF
156+
cat > test/Counter.t.sol <<EOF
157+
// SPDX-License-Identifier: UNLICENSED
158+
pragma solidity ^0.8.13;
159+
160+
import "forge-std/Test.sol";
161+
import "../src/Counter.sol";
162+
import "forge-exec/src/Exec.sol";
163+
164+
# An example test
165+
contract CounterTest is Test {
166+
Counter public counter;
167+
function setUp() public {
168+
string[] memory args = new string[](1);
169+
args[0] = "example.js";
170+
bytes memory returnData = Exec.execute("node", args);
171+
counter = abi.decode(returnData,(Counter));
172+
}
173+
174+
function testIncrement() public {
175+
counter.increment();
176+
assertEq(counter.number(), 43);
177+
}
178+
179+
function testSetNumber(uint256 x) public {
180+
counter.setNumber(x);
181+
assertEq(counter.number(), x);
182+
}
183+
}
184+
EOF
185+
186+
# An example script
154187
cat > script/Counter.s.sol <<EOF
155188
// SPDX-License-Identifier: UNLICENSED
156189
pragma solidity ^0.8.13;
157190

158-
import {Script, console} from "forge-std/Script.sol";
159-
import {Exec} from "forge-exec/Exec.sol";
191+
import "forge-std/Script.sol";
192+
import {Exec} from "forge-exec/src/Exec.sol";
160193

161194
contract CounterScript is Script {
162195
function setUp() public {}
163196

164197
function run() public {
165198
string[] memory args = new string[](1);
166-
args[0] = "./script/example.js";
167-
Exec.execute("node", args, true);
199+
args[0] = "example.js";
200+
Exec.execute("node", args);
168201
}
169202
}
170203
EOF
171204

172205
# we ensure forge-exec-ipc-client is in the path
173206
# you can install it as mentioned in the README
174-
PATH=lib/forge-exec/forge-exec-ipc-client/bin:$PATH pnpm execute;
207+
# or simply do to download them from github. (not that it will not put them in your PATH)
208+
bash lib/forge-exec/forge-exec-ipc-client/bin/download.sh
209+
210+
# in test
211+
PATH=lib/forge-exec/forge-exec-ipc-client/bin:$PATH pnpm test
212+
213+
# in script
214+
PATH=lib/forge-exec/forge-exec-ipc-client/bin:$PATH pnpm execute
175215
```

forge-exec-ipc-client/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

forge-exec-ipc-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "forge-exec-ipc-client"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
description = "ipc client that let forge to connect to an ipc server while executing solidity"
66
repository = "https://github.com/wighawag/forge-exec"

forge-exec-ipc-client/bin/download.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
99
done
1010
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
1111

12-
tag="v0.0.0-rc.10"
12+
tag="v0.1.1"
13+
release=forge-exec-ipc-client-${tag}
1314
targets=("aarch64-apple-darwin" "x86_64-apple-darwin" "x86_64-pc-windows-gnu" "x86_64-pc-windows-msvc" "x86_64-unknown-linux-musl")
1415

1516
mkdir -p $DIR/downloads
1617
cd $DIR/downloads
1718
for target in "${targets[@]}"
1819
do
19-
https://github.com/wighawag/forge-exec/releases/download/v0.0.0-rc.10/forge-exec-ipc-client_v0.0.0-rc.10_x86_64-pc-windows-msvc.tar.gz
20-
echo https://github.com/wighawag/forge-exec/releases/download/${tag}/forge-exec-ipc-client_${tag}_${target}.tar.gz
21-
curl -L -O https://github.com/wighawag/forge-exec/releases/download/${tag}/forge-exec-ipc-client_${tag}_${target}.tar.gz
20+
echo https://github.com/wighawag/forge-exec/releases/download/${release}/forge-exec-ipc-client_${tag}_${target}.tar.gz
21+
curl -L -O https://github.com/wighawag/forge-exec/releases/download/${release}/forge-exec-ipc-client_${tag}_${target}.tar.gz
2222
mkdir -p ../$target; tar -xf forge-exec-ipc-client_${tag}_${target}.tar.gz --strip=1 -C ../$target
2323
rm forge-exec-ipc-client_${tag}_${target}.tar.gz
2424
done

forge-exec-ipc-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "forge-exec-ipc-client",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/wighawag/forge-exec"

0 commit comments

Comments
 (0)