Skip to content

Commit 9ed1c9d

Browse files
committed
hf test go: support passing in fork method flag
1 parent 5a3ef38 commit 9ed1c9d

File tree

4 files changed

+77
-2
lines changed

4 files changed

+77
-2
lines changed

scripts/hardfork/build-and-test.sh

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
set -eux -o pipefail
1414

1515
PREFORK=""
16+
FORK_METHOD="legacy"
1617

1718
usage() {
18-
echo "Usage: $0 --fork-from <PREFORK>"
19+
echo "Usage: $0 --fork-from <PREFORK> --fork-method <FORK_METHOD>"
1920
exit 1
2021
}
2122

@@ -31,6 +32,23 @@ while [[ $# -gt 0 ]]; do
3132
PREFORK="$2"
3233
shift 2
3334
;;
35+
--fork-method)
36+
# ensure value exists
37+
if [[ $# -lt 2 ]]; then
38+
echo "Error: --fork-from requires an argument."
39+
usage
40+
fi
41+
case "$2" in
42+
legacy|advanced-generate-hf-config)
43+
FORK_METHOD="$2"
44+
;;
45+
*)
46+
echo "Error: --fork-method must be either 'legacy' or 'advanced-generate-hf-config'."
47+
usage
48+
;;
49+
esac
50+
shift 2
51+
;;
3452
--help|-h)
3553
usage
3654
;;
@@ -51,6 +69,11 @@ if [[ -z "$PREFORK" ]]; then
5169
usage
5270
fi
5371

72+
if [[ "$FORK_METHOD" == "advanced-generate-hf-config" ]]; then
73+
echo "Error: unimplemented fork mode 'advanced-generate-hf-config'"
74+
usage
75+
fi
76+
5477
NIX_OPTS=( --accept-flake-config --experimental-features 'nix-command flakes' )
5578

5679
if [[ -n "${NIX_CACHE_NAR_SECRET:-}" ]]; then
@@ -152,6 +175,7 @@ hardfork_test/bin/hardfork_test \
152175
--slot-tx-end "$SLOT_TX_END" \
153176
--slot-chain-end "$SLOT_CHAIN_END" \
154177
--script-dir "$SCRIPT_DIR" \
155-
--root "$NETWORK_ROOT"
178+
--root "$NETWORK_ROOT" \
179+
--fork-method "$FORK_METHOD"
156180
157181
popd

src/app/hardfork_test/src/internal/app/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func init() {
8585
rootCmd.Flags().IntVar(&cfg.ForkEarliestBlockMaxRetries, "fork-earliest-block-max-retries", cfg.ForkEarliestBlockMaxRetries, "Maximum number of retries to wait for earliest block in fork network")
8686
rootCmd.Flags().IntVar(&cfg.HTTPClientTimeoutSeconds, "http-timeout", cfg.HTTPClientTimeoutSeconds, "HTTP client timeout in seconds for GraphQL requests")
8787
rootCmd.Flags().IntVar(&cfg.ClientMaxRetries, "client-max-retries", cfg.ClientMaxRetries, "Maximum number of retries for client requests")
88+
rootCmd.Flags().Var(&cfg.ForkMethod, "mode", "The implementation of fork")
8889

8990
// Mark required flags
9091
rootCmd.MarkFlagRequired("main-mina-exe")

src/app/hardfork_test/src/internal/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ type Config struct {
6161
ForkEarliestBlockMaxRetries int // Max retries to wait for earliest block in fork network
6262
HTTPClientTimeoutSeconds int // HTTP client timeout for GraphQL requests
6363
ClientMaxRetries int // Max number of retries for client requests
64+
65+
ForkMethod ForkMethod
6466
}
6567

6668
// DefaultConfig returns the default configuration with values
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package config
2+
3+
import (
4+
"fmt"
5+
"sort"
6+
"strings"
7+
)
8+
9+
type ForkMethod int
10+
11+
const (
12+
Legacy ForkMethod = iota
13+
)
14+
15+
var forkMethodToString = map[ForkMethod]string{
16+
Legacy: "legacy",
17+
}
18+
19+
var stringToForkMethod = map[string]ForkMethod{
20+
"legacy": Legacy,
21+
}
22+
23+
func (m *ForkMethod) String() string {
24+
if s, ok := forkMethodToString[*m]; ok {
25+
return s
26+
}
27+
return "unknown"
28+
}
29+
30+
func validKeys(m map[string]ForkMethod) string {
31+
keys := make([]string, 0, len(m))
32+
for k := range m {
33+
keys = append(keys, k)
34+
}
35+
sort.Strings(keys)
36+
return strings.Join(keys, "|")
37+
}
38+
39+
func (m *ForkMethod) Set(s string) error {
40+
v, ok := stringToForkMethod[s]
41+
if !ok {
42+
return fmt.Errorf("invalid mode %q (valid: %s)", s, validKeys(stringToForkMethod))
43+
}
44+
*m = v
45+
return nil
46+
}
47+
48+
func (m *ForkMethod) Type() string { return "fork method" }

0 commit comments

Comments
 (0)