Skip to content

Commit 3db59d2

Browse files
[test] Add load Framework (#1991)
Signed-off-by: rodrigo <[email protected]> Co-authored-by: Aaron Buchwald <[email protected]>
1 parent 06685b6 commit 3db59d2

23 files changed

+1333
-1156
lines changed

cli/spam.go

Lines changed: 0 additions & 131 deletions
This file was deleted.

examples/morpheusvm/cmd/morpheus-cli/cmd/root.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ var (
3131
validityWindow int64
3232
hideTxs bool
3333
checkAllChains bool
34-
spamDefaults bool
35-
spamKey string
36-
clusterInfo string
3734
prometheusBaseURI string
3835
prometheusOpenBrowser bool
3936
prometheusFile string
@@ -53,7 +50,6 @@ func init() {
5350
keyCmd,
5451
chainCmd,
5552
actionCmd,
56-
spamCmd,
5753
prometheusCmd,
5854
)
5955
rootCmd.PersistentFlags().StringVar(
@@ -152,32 +148,6 @@ func init() {
152148
transferCmd,
153149
)
154150

155-
runSpamCmd.PersistentFlags().BoolVar(
156-
&spamDefaults,
157-
"defaults",
158-
false,
159-
"use default spam parameters",
160-
)
161-
162-
runSpamCmd.PersistentFlags().StringVar(
163-
&clusterInfo,
164-
"cluster-info",
165-
"",
166-
"output from avalanche-cli with cluster info",
167-
)
168-
169-
runSpamCmd.PersistentFlags().StringVar(
170-
&spamKey,
171-
"key",
172-
"",
173-
"private key used to distribute funds",
174-
)
175-
176-
// spam
177-
spamCmd.AddCommand(
178-
runSpamCmd,
179-
)
180-
181151
// prometheus
182152
generatePrometheusCmd.PersistentFlags().StringVar(
183153
&prometheusBaseURI,

examples/morpheusvm/cmd/morpheus-cli/cmd/spam.go

Lines changed: 0 additions & 76 deletions
This file was deleted.

examples/morpheusvm/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
github.com/onsi/ginkgo/v2 v2.13.1
1010
github.com/spf13/cobra v1.8.1
1111
github.com/stretchr/testify v1.10.0
12-
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e
1312
)
1413

1514
require (
@@ -131,6 +130,7 @@ require (
131130
go.uber.org/multierr v1.11.0 // indirect
132131
go.uber.org/zap v1.26.0 // indirect
133132
golang.org/x/crypto v0.35.0 // indirect
133+
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e // indirect
134134
golang.org/x/net v0.36.0 // indirect
135135
golang.org/x/oauth2 v0.21.0 // indirect
136136
golang.org/x/sync v0.11.0 // indirect
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package load
5+
6+
import (
7+
"context"
8+
"encoding/binary"
9+
"errors"
10+
"time"
11+
12+
"github.com/ava-labs/hypersdk/chain"
13+
"github.com/ava-labs/hypersdk/examples/morpheusvm/actions"
14+
"github.com/ava-labs/hypersdk/fees"
15+
"github.com/ava-labs/hypersdk/load"
16+
)
17+
18+
var (
19+
ErrTxGeneratorFundsExhausted = errors.New("tx generator funds exhausted")
20+
21+
_ load.TxGenerator[*chain.Transaction] = (*TxGenerator)(nil)
22+
)
23+
24+
type TxGenerator struct {
25+
authFactory chain.AuthFactory
26+
currBalance uint64
27+
ruleFactory chain.RuleFactory
28+
unitPrices fees.Dimensions
29+
}
30+
31+
func NewTxGenerator(
32+
authFactory chain.AuthFactory,
33+
ruleFactory chain.RuleFactory,
34+
currBalance uint64,
35+
unitPrices fees.Dimensions,
36+
) *TxGenerator {
37+
return &TxGenerator{
38+
authFactory: authFactory,
39+
ruleFactory: ruleFactory,
40+
currBalance: currBalance,
41+
unitPrices: unitPrices,
42+
}
43+
}
44+
45+
func (t *TxGenerator) GenerateTx(context.Context) (*chain.Transaction, error) {
46+
tx, err := chain.GenerateTransaction(
47+
t.ruleFactory,
48+
t.unitPrices,
49+
time.Now().UnixMilli(),
50+
[]chain.Action{
51+
&actions.Transfer{
52+
To: t.authFactory.Address(),
53+
Value: 1,
54+
Memo: binary.BigEndian.AppendUint64(nil, t.currBalance),
55+
},
56+
},
57+
t.authFactory,
58+
)
59+
if err != nil {
60+
return nil, err
61+
}
62+
if tx.MaxFee() > t.currBalance {
63+
return nil, ErrTxGeneratorFundsExhausted
64+
}
65+
t.currBalance -= tx.MaxFee()
66+
return tx, nil
67+
}

0 commit comments

Comments
 (0)