Skip to content

Commit

Permalink
feat: add cli command for using upgrade sequences with txsim (#3903)
Browse files Browse the repository at this point in the history
We need this so our e2e tests can schedule an upgrade to a new network
version
  • Loading branch information
cmwaters authored Sep 24, 2024
1 parent 051b268 commit af38e41
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/cmd/txsim/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
send, sendIterations, sendAmount int
stake, stakeValue, blob int
useFeegrant, suppressLogs bool
upgradeSchedule string
)

func main() {
Expand Down Expand Up @@ -130,6 +131,15 @@ well funded account that can act as the master account. The command runs until a
sequences = append(sequences, txsim.NewBlobSequence(sizes, blobsPerPFB).Clone(blob)...)
}

upgradeScheduleMap, err := parseUpgradeSchedule(upgradeSchedule)
if err != nil {
return fmt.Errorf("invalid upgrade schedule: %w", err)
}

for height, version := range upgradeScheduleMap {
sequences = append(sequences, txsim.NewUpgradeSequence(version, height))
}

if seed == 0 {
if os.Getenv(TxsimSeed) != "" {
seed, err = strconv.ParseInt(os.Getenv(TxsimSeed), 10, 64)
Expand Down Expand Up @@ -195,6 +205,7 @@ func flags() *flag.FlagSet {
flags.IntVar(&stake, "stake", 0, "number of stake sequences to run")
flags.IntVar(&stakeValue, "stake-value", 1000, "amount of initial stake per sequence")
flags.IntVar(&blob, "blob", 0, "number of blob sequences to run")
flags.StringVar(&upgradeSchedule, "upgrade-schedule", "", "upgrade schedule for the network in format height:version i.e. 100:3,200:4")
flags.StringVar(&blobSizes, "blob-sizes", "100-1000", "range of blob sizes to send")
flags.StringVar(&blobAmounts, "blob-amounts", "1", "range of blobs per PFB specified as a single value or a min-max range (e.g., 10 or 5-10). A single value indicates the exact number of blobs to be created.")
flags.BoolVar(&useFeegrant, "feegrant", false, "use the feegrant module to pay for fees")
Expand Down Expand Up @@ -224,3 +235,27 @@ func readRange(r string) (txsim.Range, error) {

return txsim.NewRange(n, m), nil
}

func parseUpgradeSchedule(schedule string) (map[int64]uint64, error) {
scheduleMap := make(map[int64]uint64)
if schedule == "" {
return nil, nil
}
scheduleParts := strings.Split(schedule, ",")
for _, part := range scheduleParts {
parts := strings.Split(part, ":")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid upgrade schedule format: %s", part)
}
height, err := strconv.ParseInt(parts[0], 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid height in upgrade schedule: %s", parts[0])
}
version, err := strconv.ParseUint(parts[1], 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid version in upgrade schedule: %s", parts[1])
}
scheduleMap[height] = version
}
return scheduleMap, nil
}
1 change: 1 addition & 0 deletions test/cmd/txsim/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestTxsimCommandFlags(t *testing.T) {
"--grpc-endpoint", grpcAddr,
"--blob", "5",
"--seed", "1234",
"--upgrade-schedule", "10:3",
})
err := cmd.ExecuteContext(ctx)
require.NoError(t, err)
Expand Down

0 comments on commit af38e41

Please sign in to comment.