Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Common Test Boilerplate out of Morpheus VM #1664

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
10 changes: 5 additions & 5 deletions examples/morpheusvm/tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package e2e_test

import (
"encoding/json"
"testing"

"github.com/ava-labs/avalanchego/tests/fixture/e2e"
Expand Down Expand Up @@ -38,10 +37,11 @@ func init() {
var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
require := require.New(ginkgo.GinkgoT())

gen, workloadFactory, spamKey, err := workload.New(100 /* minBlockGap: 100ms */)
require.NoError(err)

genesisBytes, err := json.Marshal(gen)
testVM := fixture.NewTestVM(workload.TxCheckInterval)
keys := testVM.GetKeys()
workloadFactory := workload.NewWorkloadFactory(keys)
spamKey := keys[0].GetPrivateKey()
genesisBytes, err := testVM.GetGenesisBytes()
require.NoError(err)

expectedABI, err := abi.NewABI(vm.ActionParser.GetRegisteredTypes(), vm.OutputParser.GetRegisteredTypes())
Expand Down
8 changes: 4 additions & 4 deletions examples/morpheusvm/tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
package integration_test

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/require"

"github.com/ava-labs/hypersdk/auth"
"github.com/ava-labs/hypersdk/crypto/ed25519"
"github.com/ava-labs/hypersdk/examples/morpheusvm/vm"
"github.com/ava-labs/hypersdk/tests/fixture"
"github.com/ava-labs/hypersdk/tests/integration"

lconsts "github.com/ava-labs/hypersdk/examples/morpheusvm/consts"
Expand All @@ -25,10 +25,10 @@ func TestIntegration(t *testing.T) {

var _ = ginkgo.BeforeSuite(func() {
require := require.New(ginkgo.GinkgoT())
genesis, workloadFactory, _, err := morpheusWorkload.New(0 /* minBlockGap: 0ms */)
require.NoError(err)

genesisBytes, err := json.Marshal(genesis)
testVM := fixture.NewTestVM(0)
workloadFactory := morpheusWorkload.NewWorkloadFactory(testVM.GetKeys())
genesisBytes, err := testVM.GetGenesisBytes()
require.NoError(err)

randomEd25519Priv, err := ed25519.GeneratePrivateKey()
Expand Down
70 changes: 9 additions & 61 deletions examples/morpheusvm/tests/workload/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package workload

import (
"context"
"math"
"time"

"github.com/ava-labs/avalanchego/ids"
Expand All @@ -22,78 +21,27 @@ import (
"github.com/ava-labs/hypersdk/examples/morpheusvm/actions"
"github.com/ava-labs/hypersdk/examples/morpheusvm/consts"
"github.com/ava-labs/hypersdk/examples/morpheusvm/vm"
"github.com/ava-labs/hypersdk/fees"
"github.com/ava-labs/hypersdk/genesis"
"github.com/ava-labs/hypersdk/tests/fixture"
"github.com/ava-labs/hypersdk/tests/workload"
)

const (
initialBalance uint64 = 10_000_000_000_000
txCheckInterval = 100 * time.Millisecond
TxCheckInterval = 100 * time.Millisecond
)

var (
_ workload.TxWorkloadFactory = (*workloadFactory)(nil)
_ workload.TxWorkloadIterator = (*simpleTxWorkload)(nil)
ed25519HexKeys = []string{
"323b1d8f4eed5f0da9da93071b034f2dce9d2d22692c172f3cb252a64ddfafd01b057de320297c29ad0c1f589ea216869cf1938d88c9fbd70d6748323dbf2fa7", //nolint:lll
"8a7be2e0c9a2d09ac2861c34326d6fe5a461d920ba9c2b345ae28e603d517df148735063f8d5d8ba79ea4668358943e5c80bc09e9b2b9a15b5b15db6c1862e88", //nolint:lll
}
ed25519PrivKeys = make([]ed25519.PrivateKey, len(ed25519HexKeys))
ed25519Addrs = make([]codec.Address, len(ed25519HexKeys))
ed25519AuthFactories = make([]*auth.ED25519Factory, len(ed25519HexKeys))
)

func init() {
for i, keyHex := range ed25519HexKeys {
privBytes, err := codec.LoadHex(keyHex, ed25519.PrivateKeyLen)
if err != nil {
panic(err)
}
priv := ed25519.PrivateKey(privBytes)
ed25519PrivKeys[i] = priv
ed25519AuthFactories[i] = auth.NewED25519Factory(priv)
addr := auth.NewED25519Address(priv.PublicKey())
ed25519Addrs[i] = addr
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing this and the genesis configuration is an improvement imo. VM developers are probably going to be fine with these defaults, and if not we can expose a way for them to customize.

Still some more work to be done cleaning up the workloadfactory or removing it all together.

type workloadFactory struct {
factories []*auth.ED25519Factory
addrs []codec.Address
keys []*fixture.Ed25519TestKey
}

func New(minBlockGap int64) (*genesis.DefaultGenesis, workload.TxWorkloadFactory, *auth.PrivateKey, error) {
customAllocs := make([]*genesis.CustomAllocation, 0, len(ed25519Addrs))
for _, prefundedAddr := range ed25519Addrs {
customAllocs = append(customAllocs, &genesis.CustomAllocation{
Address: prefundedAddr,
Balance: initialBalance,
})
}
spamKey := &auth.PrivateKey{
Address: ed25519Addrs[0],
Bytes: ed25519PrivKeys[0][:],
}
genesis := genesis.NewDefaultGenesis(customAllocs)
// Set WindowTargetUnits to MaxUint64 for all dimensions to iterate full mempool during block building.
genesis.Rules.WindowTargetUnits = fees.Dimensions{math.MaxUint64, math.MaxUint64, math.MaxUint64, math.MaxUint64, math.MaxUint64}
// Set all limits to MaxUint64 to avoid limiting block size for all dimensions except bandwidth. Must limit bandwidth to avoid building
// a block that exceeds the maximum size allowed by AvalancheGo.
genesis.Rules.MaxBlockUnits = fees.Dimensions{1800000, math.MaxUint64, math.MaxUint64, math.MaxUint64, math.MaxUint64}
genesis.Rules.MinBlockGap = minBlockGap

return genesis, &workloadFactory{
factories: ed25519AuthFactories,
addrs: ed25519Addrs,
}, spamKey, nil
func NewWorkloadFactory(keys []*fixture.Ed25519TestKey) *workloadFactory {
return &workloadFactory{keys: keys}
}

func (f *workloadFactory) NewSizedTxWorkload(uri string, size int) (workload.TxWorkloadIterator, error) {
cli := jsonrpc.NewJSONRPCClient(uri)
lcli := vm.NewJSONRPCClient(uri)
return &simpleTxWorkload{
factory: f.factories[0],
factory: f.keys[0].AuthFactory,
cli: cli,
lcli: lcli,
size: size,
Expand Down Expand Up @@ -168,11 +116,11 @@ func (f *workloadFactory) NewWorkloads(uri string) ([]workload.TxWorkloadIterato

generator := &mixedAuthWorkload{
addressAndFactories: []addressAndFactory{
{address: f.addrs[1], authFactory: f.factories[1]},
{address: f.keys[1].Addr, authFactory: f.keys[1].AuthFactory},
{address: blsAddr, authFactory: blsFactory},
{address: secpAddr, authFactory: secpFactory},
},
balance: initialBalance,
balance: fixture.DefaultInitialBalance,
cli: cli,
lcli: lcli,
networkID: networkID,
Expand Down Expand Up @@ -233,7 +181,7 @@ func (g *mixedAuthWorkload) GenerateTxWithAssertion(ctx context.Context) (*chain

func confirmTx(ctx context.Context, require *require.Assertions, uri string, txID ids.ID, receiverAddr codec.Address, receiverExpectedBalance uint64) {
indexerCli := indexer.NewClient(uri)
success, _, err := indexerCli.WaitForTransaction(ctx, txCheckInterval, txID)
success, _, err := indexerCli.WaitForTransaction(ctx, TxCheckInterval, txID)
require.NoError(err)
require.True(success)
lcli := vm.NewJSONRPCClient(uri)
Expand Down
63 changes: 2 additions & 61 deletions examples/vmwithcontracts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,16 @@ require (
github.com/ava-labs/hypersdk v0.0.16
github.com/fatih/color v1.13.0
github.com/near/borsh-go v0.3.1
github.com/onsi/ginkgo/v2 v2.13.1
github.com/spf13/cobra v1.7.0
github.com/status-im/keycard-go v0.2.0
github.com/stretchr/testify v1.8.4
)

require (
filippo.io/edwards25519 v1.0.0 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.1 // indirect
github.com/ava-labs/coreth v0.13.8 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.3 // indirect
github.com/bytecodealliance/wasmtime-go/v14 v14.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand All @@ -32,94 +26,46 @@ require (
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/ethereum/go-ethereum v1.13.14 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/pprof v0.0.0-20230406165453-00490a63f317 // indirect
github.com/google/renameio/v2 v2.0.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/rpc v1.2.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hashicorp/go-bexpr v0.1.10 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.2.0 // indirect
github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackpal/gateway v1.0.6 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/pointerstructure v1.2.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/ginkgo/v2 v2.13.1 // indirect
github.com/openzipkin/zipkin-go v0.4.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pires/go-proxyproto v0.6.2 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/cors v1.7.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/urfave/cli/v2 v2.25.7 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.opentelemetry.io/otel v1.22.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.22.0 // indirect
Expand All @@ -131,7 +77,6 @@ require (
go.opentelemetry.io/otel/trace v1.22.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
Expand All @@ -141,18 +86,14 @@ require (
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.17.0 // indirect
gonum.org/v1/gonum v0.11.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ava-labs/hypersdk => ../../
Loading
Loading