Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
nix_path: nixpkgs=channel:nixos-unstable
- name: Run tests
env:
NETWORK: ${{ matrix.network }}
SETH_NETWORK: ${{ matrix.network }}
run: |
nix develop -c make lint
6 changes: 3 additions & 3 deletions .github/workflows/test_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
matrix:
network: [ Anvil, Geth ]
env:
ROOT_PRIVATE_KEY: ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
SETH_ROOT_PRIVATE_KEY: ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Run tests
env:
NETWORK: ${{ matrix.network }}
SETH_NETWORK: ${{ matrix.network }}
run: |
nix develop -c make $NETWORK && make root_private_key=$ROOT_PRIVATE_KEY network=$NETWORK test_api
nix develop -c make $SETH_NETWORK && make root_private_key=$SETH_ROOT_PRIVATE_KEY network=$SETH_NETWORK test_api
6 changes: 3 additions & 3 deletions .github/workflows/test_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
matrix:
network: [ Anvil, Geth ]
env:
ROOT_PRIVATE_KEY: ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
SETH_ROOT_PRIVATE_KEY: ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Run tests
env:
NETWORK: ${{ matrix.network }}
SETH_NETWORK: ${{ matrix.network }}
run: |
nix develop -c make $NETWORK && make root_private_key=$ROOT_PRIVATE_KEY network=$NETWORK test_cli
nix develop -c make $SETH_NETWORK && make root_private_key=$SETH_ROOT_PRIVATE_KEY network=$SETH_NETWORK test_cli
6 changes: 3 additions & 3 deletions .github/workflows/test_decode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
matrix:
network: [ Anvil, Geth ]
env:
ROOT_PRIVATE_KEY: ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
SETH_ROOT_PRIVATE_KEY: ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Run tests
env:
NETWORK: ${{ matrix.network }}
SETH_NETWORK: ${{ matrix.network }}
run: |
nix develop -c make $NETWORK && make root_private_key=$ROOT_PRIVATE_KEY network=$NETWORK test
nix develop -c make $SETH_NETWORK && make root_private_key=$SETH_ROOT_PRIVATE_KEY network=$SETH_NETWORK test
6 changes: 3 additions & 3 deletions .github/workflows/test_decode_testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
nix_path: nixpkgs=channel:nixos-unstable
- name: Run tests
env:
NETWORK: ${{ matrix.network }}
ROOT_PRIVATE_KEY: ${{ secrets.TESTNET_COMMON_KEYS }}
SETH_NETWORK: ${{ matrix.network }}
SETH_ROOT_PRIVATE_KEY: ${{ secrets.TESTNET_COMMON_KEYS }}
run: |
nix develop -c make root_private_key=$ROOT_PRIVATE_KEY network=$NETWORK test
nix develop -c make root_private_key=$SETH_ROOT_PRIVATE_KEY network=$SETH_NETWORK test
6 changes: 3 additions & 3 deletions .github/workflows/test_others.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
matrix:
network: [ Geth ]
env:
ROOT_PRIVATE_KEY: ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
SETH_ROOT_PRIVATE_KEY: ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Run tests
env:
NETWORK: ${{ matrix.network }}
SETH_NETWORK: ${{ matrix.network }}
run: |
nix develop -c make $NETWORK && make root_private_key=$ROOT_PRIVATE_KEY network=$NETWORK test_others
nix develop -c make $SETH_NETWORK && make root_private_key=$SETH_ROOT_PRIVATE_KEY network=$SETH_NETWORK test_others
6 changes: 3 additions & 3 deletions .github/workflows/test_trace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
matrix:
network: [ Anvil, Geth ]
env:
ROOT_PRIVATE_KEY: ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
SETH_ROOT_PRIVATE_KEY: ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Run tests
env:
NETWORK: ${{ matrix.network }}
SETH_NETWORK: ${{ matrix.network }}
run: |
nix develop -c make $NETWORK && make root_private_key=$ROOT_PRIVATE_KEY network=$NETWORK test_trace
nix develop -c make $SETH_NETWORK && make root_private_key=$SETH_ROOT_PRIVATE_KEY network=$SETH_NETWORK test_trace
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,35 @@ GethSync:

.PHONY: test
test:
NETWORK=$(network) ROOT_PRIVATE_KEY=$(root_private_key) go test -v -count 1 `go list ./... | grep -v examples` -run TestSmoke
SETH_NETWORK=$(network) SETH_ROOT_PRIVATE_KEY=$(root_private_key) go test -v -count 1 `go list ./... | grep -v examples` -run TestSmoke

.PHONY: kill_node
kill_node:
pkill -f geth || pkill -f anvil || true

.PHONY: test_api
test_api:
NETWORK=$(network) ROOT_PRIVATE_KEY=$(root_private_key) go test -v -count 1 `go list ./... | grep -v examples` -run TestAPI
SETH_NETWORK=$(network) SETH_ROOT_PRIVATE_KEY=$(root_private_key) go test -v -count 1 `go list ./... | grep -v examples` -run TestAPI

.PHONY: test_trace
test_trace:
NETWORK=$(network) ROOT_PRIVATE_KEY=$(root_private_key) go test -v -count 1 `go list ./... | grep -v examples` -run TestTrace
SETH_NETWORK=$(network) SETH_ROOT_PRIVATE_KEY=$(root_private_key) go test -v -count 1 `go list ./... | grep -v examples` -run TestTrace

.PHONY: test_cli
test_cli:
NETWORK=$(network) ROOT_PRIVATE_KEY=$(root_private_key) go test -v -count 1 `go list ./... | grep -v examples` -run TestCLI
SETH_NETWORK=$(network) SETH_ROOT_PRIVATE_KEY=$(root_private_key) go test -v -count 1 `go list ./... | grep -v examples` -run TestCLI

.PHONY: test_others
test_others:
NETWORK=$(network) ROOT_PRIVATE_KEY=$(root_private_key) go test -v -count 1 `go list ./... | grep -v examples` -run "TestContractMap|TestGasEstimator|TestRPCHealtCheck|TestUtil"
SETH_NETWORK=$(network) SETH_ROOT_PRIVATE_KEY=$(root_private_key) go test -v -count 1 `go list ./... | grep -v examples` -run "TestContractMap|TestGasEstimator|TestRPCHealtCheck|TestUtil"

.PHONY: test_race
test_race:
NETWORK=$(network) ROOT_PRIVATE_KEY=$(root_private_key) go test -v -race -count 1 `go list ./... | grep -v examples` -run TestSmoke
SETH_NETWORK=$(network) SETH_ROOT_PRIVATE_KEY=$(root_private_key) go test -v -race -count 1 `go list ./... | grep -v examples` -run TestSmoke

.PHONY: test+cover
test_cover:
NETWORK=$(network) ROOT_PRIVATE_KEY=$(root_private_key) go test -v -coverprofile cover.out -count 1 `go list ./... | grep -v examples` -run "TestAPI|TestSmoke|TestContract|TestGasEstimator"
SETH_NETWORK=$(network) SETH_ROOT_PRIVATE_KEY=$(root_private_key) go test -v -coverprofile cover.out -count 1 `go list ./... | grep -v examples` -run "TestAPI|TestSmoke|TestContract|TestGasEstimator"
go tool cover -html cover.out

.PHONY: lint
Expand Down
47 changes: 38 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,18 @@ Some crucial data is stored in env vars, create `.envrc` and use `source .envrc`
export SETH_LOG_LEVEL=info # global logger level
export SETH_CONFIG_PATH=seth.toml # path to the toml config
export SETH_KEYFILE_PATH=keyfile.toml # keyfile path for using multiple keys
export NETWORK=Geth # selected network
export ROOT_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 # root private key
export SETH_NETWORK=Geth # selected network
export SETH_ROOT_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 # root private key

alias seth="go run cmd/seth/seth.go" # useful alias for keyfile CLI
alias seth="SETH_CONFIG_PATH=seth.toml go run cmd/seth/seth.go" # useful alias for keyfile CLI
```

Alternatively if you don't have a network defined in the TOML you can still use the CLI by providing these 2 key env vars:
```
export SETH_URL=https://rpc.fuji.testnet.anyswap.exchange
export SETH_CHAIN_ID=43113

go run cmd/seth/seth.go ... # your command
```

If `SETH_KEYFILE_PATH` is not set then client will create X ephemeral keys (60 by default, configurable) and won't return any funds.
Expand Down Expand Up @@ -160,7 +168,7 @@ Example:
tracing_level = "reverted"
```

Additionally you can also enable saving all decoding/tracing information to JSON files with:
Additionally, you can also enable saving all decoding/tracing information to JSON files with:
```
trace_to_json = true
```
Expand Down Expand Up @@ -196,27 +204,28 @@ gas_price_estimation_blocks = 1000
# priority of the transaction, can be "fast", "standard" or "slow" (the higher the priority, the higher adjustment factor and buffer will be used for gas estimation) [default: "standard"]
gas_price_estimation_tx_priority = "slow"
```
If you don't we will use the default settings for `Default` network.

If you want to save addresses of deployed contracts, you can enable it with:
```
save_deployed_contracts_map = true
```


If you want to re-use previously deployed contracts you can indicate file name in `seth.toml`:
```
contract_map_file = "deployed_contracts_mumbai.toml"
```
Both features only work for live networks. Otherwise, they are ignored, and nothing is saved/read from for simulated networks.

## CLI
You can either define the network you want to interact with in your TOML config and then refer it in the CLI command, or you can pass all network parameters via env vars. Most of the examples below show how to use the former approach.

### Multiple keys manipulation (keyfile.toml)
To use multiple keys in your tests you can create a `keyfile.toml` using CLI

Set up the alias, see `.envrc` configuration above
```
alias seth="go run cmd/seth/seth.go"
alias seth="SETH_CONFIG_PATH=seth.toml go run cmd/seth/seth.go"
```

Create a new `keyfile` with 10 new accounts funded from the root key (KEYS env var)
Expand Down Expand Up @@ -247,6 +256,8 @@ This will analyze last 10k blocks and give you 25/50/75/99th/Max percentiles for
### Block stats
If you need to get some insights into network stats and create a realistic load/chaos profile with simulators (`anvil` as an example), you can use `stats` CLI command

#### Define your network in `seth.toml`

Edit your `seth.toml`
```
[[networks]]
Expand All @@ -260,12 +271,25 @@ rpc_requests_per_second_limit = 5

Then check the stats for the last N blocks
```bash
seth -n MyCustomNetwork blocks -s -10
SETH_CONFIG_PATH=seth.toml seth -n MyCustomNetwork stats -s -10
```

To check stats for the interval (A, B)
```bash
SETH_CONFIG_PATH=seth.toml seth -n MyCustomNetwork stats -s A -e B
```

#### Pass all network parameters via env vars
If you don't have a network defined in the TOML you can still use the CLI by providing these 2 key parameter via cmd arg.

Then check the stats for the last N blocks
```bash
SETH_CONFIG_PATH=seth.toml seth -c 327172 -u "https://my-rpc.network.io" stats -s -10
```

To check stats for the interval (A, B)
```bash
seth -n MyCustomNetwork blocks -s A -e B
SETH_CONFIG_PATH=seth.toml seth -c 327172 -u "https://my-rpc.network.io" stats -s A -e B
```

Results can help you to understand if network is stable, what is avg block time, gas price, block utilization and transactions per second
Expand Down Expand Up @@ -297,6 +321,11 @@ You can trace multiple transactions at once using `seth trace` command. Example:
SETH_CONFIG_PATH=seth.toml go run cmd/seth/seth.go -n=Geth trace -f reverted_transactions.json
```

or using cmd args
```
SETH_CONFIG_PATH=seth.toml go run cmd/seth/seth.go -c 327172 -u "https://my-rpc.network.io" trace -f reverted_transactions.json
```

You need to pass a file with a list of transaction hashes to trace. The file should be a JSON array of transaction hashes, like this:
```
[
Expand Down Expand Up @@ -337,7 +366,7 @@ You need to pass a file with a list of transaction hashes to trace. The file sho

You can read more about how ABI finding and contract map works [here](./docs/abi_finder_contract_map.md) and about contract store here [here](./docs/contract_store.md).

### Autmoatic gas estimator
### Automatic gas estimator

This section explains how to configure and understand the automatic gas estimator, which is crucial for executing transactions on Ethereum-based networks. Here’s what you need to know:

Expand Down
10 changes: 5 additions & 5 deletions client_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ func TestAPIKeys(t *testing.T) {
_ = os.Remove(keyFilePath)
_ = os.Setenv(seth.KEYFILE_PATH_ENV_VAR, keyFilePath)

err := sethcmd.RunCLI([]string{"seth", "-n", os.Getenv("NETWORK"), "keys", "split", "-a", "60"})
err := sethcmd.RunCLI([]string{"seth", "-n", os.Getenv(seth.NETWORK_ENV_VAR), "keys", "split", "-a", "60"})
require.NoError(t, err)
t.Cleanup(func() {
err = sethcmd.RunCLI([]string{"seth", "-n", os.Getenv("NETWORK"), "keys", "return"})
err = sethcmd.RunCLI([]string{"seth", "-n", os.Getenv(seth.NETWORK_ENV_VAR), "keys", "return"})
require.NoError(t, err)
_ = os.Unsetenv(seth.KEYFILE_PATH_ENV_VAR)
})
Expand Down Expand Up @@ -287,13 +287,13 @@ func TestAPISyncKeysPool(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
keyfilePath := "keyfile_test_api.toml"
_ = os.Remove(keyfilePath)
t.Setenv("SETH_LOG_LEVEL", "trace")
t.Setenv(seth.LogLevelEnvVar, "trace")
if !tc.ephemeral {
t.Setenv(seth.KEYFILE_PATH_ENV_VAR, keyfilePath)
err := sethcmd.RunCLI([]string{"seth", "-n", os.Getenv("NETWORK"), "keys", "split", "-a", strconv.Itoa(tc.keys)})
err := sethcmd.RunCLI([]string{"seth", "-n", os.Getenv(seth.NETWORK_ENV_VAR), "keys", "split", "-a", strconv.Itoa(tc.keys)})
require.NoError(t, err)
t.Cleanup(func() {
err = sethcmd.RunCLI([]string{"seth", "-n", os.Getenv("NETWORK"), "keys", "return"})
err = sethcmd.RunCLI([]string{"seth", "-n", os.Getenv(seth.NETWORK_ENV_VAR), "keys", "return"})
require.NoError(t, err)
_ = os.Unsetenv(seth.KEYFILE_PATH_ENV_VAR)
})
Expand Down
Loading