update readme & test

This commit is contained in:
ligun0805 2025-05-06 20:08:22 +03:00
parent 16a0421511
commit a999db8cc1
2 changed files with 57 additions and 0 deletions

View file

@ -43,6 +43,8 @@ directory.
| `evm` | Developer utility version of the EVM (Ethereum Virtual Machine) that is capable of running bytecode snippets within a configurable environment and execution mode. Its purpose is to allow isolated, fine-grained debugging of EVM opcodes (e.g. `evm --code 60ff60ff --debug run`). |
| `rlpdump` | Developer utility tool to convert binary RLP ([Recursive Length Prefix](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp)) dumps (data encoding used by the Ethereum protocol both network as well as consensus wise) to user-friendlier hierarchical representation (e.g. `rlpdump --hex CE0183FFFFFFC4C304050583616263`). |
| **`dump-balances`** | Export all non-zero accounts from the current state trie to a file `addresses_balances.txt`. The output is a two-column list (address and ETH balance with 6 decimal places), sorted in descending order by balance. |
## Running `geth`
Going through all the possible command line flags is out of scope here (please consult our

View file

@ -0,0 +1,55 @@
package main
import (
"bytes"
"strings"
"testing"
"github.com/urfave/cli/v2"
)
// TestDumpBalancesCommandRegistered checks that our dump-balances
// command is present in app.Commands with the correct Usage text.
func TestDumpBalancesCommandRegistered(t *testing.T) {
found := false
for _, cmd := range app.Commands {
if cmd.Name == dumpBalancesCommand.Name {
found = true
// Ensure that the Usage string mentions "non-zero accounts"
if !strings.Contains(cmd.Usage, "non-zero accounts") {
t.Errorf("Usage for %q does not include expected text, got %q", cmd.Name, cmd.Usage)
}
break
}
}
if !found {
t.Fatalf("command %q is not registered in app.Commands", dumpBalancesCommand.Name)
}
}
// TestDumpBalancesHelpInProcess simulates running `geth dump-balances --help`
// in memory and verifies that help output includes the command name and its Usage.
func TestDumpBalancesHelpInProcess(t *testing.T) {
// Create a fresh CLI app with our commands
app := cli.NewApp()
app.Commands = append([]*cli.Command{}, app.Commands...) // copy existing commands
// No need to re-register dumpBalancesCommand because init() already ran
// Capture the help output in a buffer
buf := &bytes.Buffer{}
app.Writer = buf
// Run the help command; cli returns flag.ErrHelp on --help
err := app.Run([]string{"geth", "dump-balances", "--help"})
if err == nil {
t.Fatalf("expected error when running help, got nil")
}
output := buf.String()
if !strings.Contains(output, "dump-balances") {
t.Errorf("help output missing command name; got:\n%s", output)
}
if !strings.Contains(output, "non-zero accounts") {
t.Errorf("help output missing Usage description; got:\n%s", output)
}
}