diff --git a/go.mod b/go.mod index b31f4f4..c6a6310 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/golang/protobuf v1.5.3 github.com/golangci/golangci-lint v1.55.3-0.20231203192459-84442f26446b github.com/grpc-ecosystem/grpc-gateway v1.16.0 + github.com/skip-mev/chaintestutil v0.0.0-00010101000000-000000000000 github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.17.0 github.com/stretchr/testify v1.8.4 @@ -26,6 +27,7 @@ require ( google.golang.org/grpc v1.59.0 google.golang.org/protobuf v1.31.0 mvdan.cc/gofumpt v0.5.0 + pgregory.net/rapid v1.1.0 ) require ( @@ -316,7 +318,6 @@ require ( mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b // indirect mvdan.cc/unparam v0.0.0-20221223090309-7455f1af531d // indirect nhooyr.io/websocket v1.8.6 // indirect - pgregory.net/rapid v1.1.0 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) @@ -328,3 +329,5 @@ replace ( github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 golang.org/x/exp => golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2 ) + +replace github.com/skip-mev/chaintestutil => ../chaintestutil diff --git a/tests/e2e/setup.go b/tests/e2e/setup.go index 154c2f7..7a443be 100644 --- a/tests/e2e/setup.go +++ b/tests/e2e/setup.go @@ -15,8 +15,6 @@ import ( "testing" "time" - "github.com/skip-mev/feemarket/testutils/sample" - rpctypes "github.com/cometbft/cometbft/rpc/core/types" comettypes "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/client" @@ -27,6 +25,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/skip-mev/chaintestutil/sample" interchaintest "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v7/ibc" diff --git a/testutils/encoding/encoding.go b/testutils/encoding/encoding.go index 636f883..301ba80 100644 --- a/testutils/encoding/encoding.go +++ b/testutils/encoding/encoding.go @@ -2,17 +2,24 @@ package encoding import ( "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/x/auth/tx" + "github.com/skip-mev/chaintestutil/sample" appparams "github.com/skip-mev/feemarket/tests/app/params" - "github.com/skip-mev/feemarket/testutils/sample" + feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" ) -// MakeTestEncodingConfig creates a test EncodingConfig for a test configuration. +// MakeTestEncodingConfig creates a test EncodingConfig for a test configuration. func MakeTestEncodingConfig() appparams.EncodingConfig { amino := codec.NewLegacyAmino() - interfaceRegistry := sample.InterfaceRegistry() + + addFeeMarket := func(ir codectypes.InterfaceRegistry) { + feemarkettypes.RegisterInterfaces(ir) + } + + interfaceRegistry := sample.InterfaceRegistry(addFeeMarket) cdc := codec.NewProtoCodec(interfaceRegistry) txCfg := tx.NewTxConfig(cdc, tx.DefaultSignModes) diff --git a/testutils/keeper/bank_test.go b/testutils/keeper/bank_test.go index d9eac16..2daa847 100644 --- a/testutils/keeper/bank_test.go +++ b/testutils/keeper/bank_test.go @@ -5,10 +5,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/skip-mev/chaintestutil/sample" "github.com/stretchr/testify/require" testkeeper "github.com/skip-mev/feemarket/testutils/keeper" - "github.com/skip-mev/feemarket/testutils/sample" ) func TestTestKeepers_MintToAccount(t *testing.T) { diff --git a/testutils/keeper/initializer.go b/testutils/keeper/initializer.go index c09287c..740ac8f 100644 --- a/testutils/keeper/initializer.go +++ b/testutils/keeper/initializer.go @@ -22,8 +22,8 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/skip-mev/chaintestutil/sample" - "github.com/skip-mev/feemarket/testutils/sample" feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper" feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" ) diff --git a/testutils/networksuite/networksuite.go b/testutils/networksuite/networksuite.go index 8f39766..72f1d41 100644 --- a/testutils/networksuite/networksuite.go +++ b/testutils/networksuite/networksuite.go @@ -8,8 +8,8 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "github.com/skip-mev/chaintestutil/sample" "github.com/skip-mev/feemarket/testutils/network" - "github.com/skip-mev/feemarket/testutils/sample" feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" ) diff --git a/testutils/sample/sample.go b/testutils/sample/sample.go deleted file mode 100644 index 744a4e0..0000000 --- a/testutils/sample/sample.go +++ /dev/null @@ -1,234 +0,0 @@ -// Package sample provides methods to initialize sample object of various types for test purposes -package sample - -import ( - "math/rand" - "strconv" - "testing" - "time" - - "github.com/cosmos/cosmos-sdk/x/group" - - sdkmath "cosmossdk.io/math" - "github.com/cometbft/cometbft/crypto" - "github.com/cometbft/cometbft/crypto/ed25519" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - cosmosed25519 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" - "github.com/cosmos/cosmos-sdk/x/authz" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" - crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" - "github.com/cosmos/cosmos-sdk/x/feegrant" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/stretchr/testify/require" - - feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" -) - -func InterfaceRegistry() codectypes.InterfaceRegistry { - interfaceRegistry := codectypes.NewInterfaceRegistry() - - cryptocodec.RegisterInterfaces(interfaceRegistry) - authtypes.RegisterInterfaces(interfaceRegistry) - authz.RegisterInterfaces(interfaceRegistry) - stakingtypes.RegisterInterfaces(interfaceRegistry) - banktypes.RegisterInterfaces(interfaceRegistry) - consensusparamtypes.RegisterInterfaces(interfaceRegistry) - slashingtypes.RegisterInterfaces(interfaceRegistry) - upgradetypes.RegisterInterfaces(interfaceRegistry) - distrtypes.RegisterInterfaces(interfaceRegistry) - vestingtypes.RegisterInterfaces(interfaceRegistry) - feegrant.RegisterInterfaces(interfaceRegistry) - group.RegisterInterfaces(interfaceRegistry) - govtypes.RegisterInterfaces(interfaceRegistry) - evidencetypes.RegisterInterfaces(interfaceRegistry) - crisistypes.RegisterInterfaces(interfaceRegistry) - minttypes.RegisterInterfaces(interfaceRegistry) - - feemarkettypes.RegisterInterfaces(interfaceRegistry) - - return interfaceRegistry -} - -// Codec returns a codec with preregistered interfaces -func Codec() codec.Codec { - return codec.NewProtoCodec(InterfaceRegistry()) -} - -// Bool returns randomly true or false -func Bool(r *rand.Rand) bool { - b := r.Intn(100) - return b < 50 -} - -// Bytes returns a random array of bytes -func Bytes(r *rand.Rand, n int) []byte { - return []byte(String(r, n)) -} - -// Uint64 returns a random uint64 -func Uint64(r *rand.Rand) uint64 { - return uint64(r.Intn(10000)) -} - -// String returns a random string of length n -func String(r *rand.Rand, n int) string { - letter := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") - - randomString := make([]rune, n) - for i := range randomString { - randomString[i] = letter[r.Intn(len(letter))] - } - return string(randomString) -} - -// AlphaString returns a random string with lowercase alpha char of length n -func AlphaString(r *rand.Rand, n int) string { - letter := []rune("abcdefghijklmnopqrstuvwxyz") - - randomString := make([]rune, n) - for i := range randomString { - randomString[i] = letter[r.Intn(len(letter))] - } - return string(randomString) -} - -// NonAlphaString returns a random string with non alpha char of length n -func NonAlphaString(r *rand.Rand, n int) string { - letter := []rune("0123456789!@#$%^&*()_+") - - randomString := make([]rune, n) - for i := range randomString { - randomString[i] = letter[r.Intn(len(letter))] - } - return string(randomString) -} - -// PubKey returns a sample account PubKey -func PubKey(r *rand.Rand) crypto.PubKey { - seed := []byte(strconv.Itoa(r.Int())) - return ed25519.GenPrivKeyFromSecret(seed).PubKey() -} - -// ConsAddress returns a sample consensus address -func ConsAddress(r *rand.Rand) sdk.ConsAddress { - return sdk.ConsAddress(PubKey(r).Address()) -} - -// AccAddress returns a sample account address -func AccAddress(r *rand.Rand) sdk.AccAddress { - addr := PubKey(r).Address() - return sdk.AccAddress(addr) -} - -// Address returns a sample string account address -func Address(r *rand.Rand) string { - return AccAddress(r).String() -} - -// ValAddress returns a sample validator operator address -func ValAddress(r *rand.Rand) sdk.ValAddress { - return sdk.ValAddress(PubKey(r).Address()) -} - -// OperatorAddress returns a sample string validator operator address -func OperatorAddress(r *rand.Rand) string { - return ValAddress(r).String() -} - -// Validator returns a sample staking validator -func Validator(t testing.TB, r *rand.Rand) stakingtypes.Validator { - seed := []byte(strconv.Itoa(r.Int())) - val, err := stakingtypes.NewValidator( - ValAddress(r), - cosmosed25519.GenPrivKeyFromSecret(seed).PubKey(), - stakingtypes.Description{}) - require.NoError(t, err) - return val -} - -// Delegation returns staking delegation with the given address -func Delegation(t testing.TB, r *rand.Rand, addr string) stakingtypes.Delegation { - delAcc, err := sdk.AccAddressFromBech32(addr) - require.NoError(t, err) - - return stakingtypes.NewDelegation( - delAcc, - ValAddress(r), - sdk.NewDec(int64(r.Intn(10000))), - ) -} - -// Coin returns a sample coin structure -func Coin(r *rand.Rand) sdk.Coin { - return sdk.NewCoin(AlphaString(r, 5), sdkmath.NewInt(r.Int63n(10000)+1)) -} - -// CoinWithRange returns a sample coin structure where the amount is a random number between provided min and max values -// with a random denom -func CoinWithRange(r *rand.Rand, min, max int64) sdk.Coin { - return sdk.NewCoin(AlphaString(r, 5), sdkmath.NewInt(r.Int63n(max-min)+min)) -} - -// CoinWithRangeAmount returns a sample coin structure where the amount is a random number between provided min and max values -// with a given denom -func CoinWithRangeAmount(r *rand.Rand, denom string, min, max int64) sdk.Coin { - return sdk.NewCoin(denom, sdkmath.NewInt(r.Int63n(max-min)+min)) -} - -// Coins returns a sample coins structure -func Coins(r *rand.Rand) sdk.Coins { - return sdk.NewCoins(Coin(r), Coin(r), Coin(r)) -} - -// CoinsWithRange returns a sample coins structure where the amount is a random number between provided min and max values -func CoinsWithRange(r *rand.Rand, min, max int64) sdk.Coins { - return sdk.NewCoins(CoinWithRange(r, min, max), CoinWithRange(r, min, max), CoinWithRange(r, min, max)) -} - -// CoinsWithRangeAmount returns a sample coins structure where the amount is a random number between provided min and max values -// with a set of given denoms -func CoinsWithRangeAmount(r *rand.Rand, denom1, denom2, denom3 string, min, max int64) sdk.Coins { - return sdk.NewCoins(CoinWithRangeAmount(r, denom1, min, max), CoinWithRangeAmount(r, denom2, min, max), CoinWithRangeAmount(r, denom3, min, max)) -} - -// Duration returns a sample time.Duration between a second and 21 days -func Duration(r *rand.Rand) time.Duration { - return time.Duration(r.Int63n(int64(time.Hour*24*21-time.Second))) + time.Second -} - -// DurationFromRange returns a sample time.Duration between the min and max values provided -func DurationFromRange(r *rand.Rand, min, max time.Duration) time.Duration { - return time.Duration(r.Int63n(int64(max-min))) + min -} - -// Int returns a sample sdkmath.Int -func Int(r *rand.Rand) sdkmath.Int { - return sdkmath.NewInt(r.Int63()) -} - -// Time returns a sample time -func Time(r *rand.Rand) time.Time { - return time.UnixMilli(r.Int63n(1000) + 1).UTC() -} - -// ZeroTime returns time.Time that represents 0 -func ZeroTime() time.Time { - return time.UnixMilli(0).UTC() -} - -// Rand returns a sample Rand object for randomness -func Rand() *rand.Rand { - return rand.New(rand.NewSource(time.Now().Unix())) -}