diff --git a/go.mod b/go.mod index b31f4f4..749b552 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-20231207155412-975710cc9051 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 ) diff --git a/go.sum b/go.sum index 6c0fbd0..63430d2 100644 --- a/go.sum +++ b/go.sum @@ -1394,6 +1394,8 @@ github.com/sivchari/nosnakecase v1.7.0 h1:7QkpWIRMe8x25gckkFd2A5Pi6Ymo0qgr4JrhGt github.com/sivchari/nosnakecase v1.7.0/go.mod h1:CwDzrzPea40/GB6uynrNLiorAlgFRvRbFSgJx2Gs+QY= github.com/sivchari/tenv v1.7.1 h1:PSpuD4bu6fSmtWMxSGWcvqUUgIn7k3yOJhOIzVWn8Ak= github.com/sivchari/tenv v1.7.1/go.mod h1:64yStXKSOxDfX47NlhVwND4dHwfZDdbp2Lyl018Icvg= +github.com/skip-mev/chaintestutil v0.0.0-20231207155412-975710cc9051 h1:ZTD4dFUTv+h+BgGTv4PtXnSxgMTUrCvGX+NQjNo/hqA= +github.com/skip-mev/chaintestutil v0.0.0-20231207155412-975710cc9051/go.mod h1:P7icBoBSf+Ci1b2moqSXQZTThtBs33eJ8dPajce2ViQ= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= diff --git a/tests/e2e/go.mod b/tests/e2e/go.mod index 14ecba2..813f117 100644 --- a/tests/e2e/go.mod +++ b/tests/e2e/go.mod @@ -19,6 +19,7 @@ replace ( require ( github.com/cometbft/cometbft v0.37.2 github.com/cosmos/cosmos-sdk v0.47.6 + github.com/skip-mev/chaintestutil v0.0.0-20231207155412-975710cc9051 github.com/skip-mev/feemarket v0.0.0-00010101000000-000000000000 github.com/strangelove-ventures/interchaintest/v7 v7.0.0 github.com/stretchr/testify v1.8.4 @@ -214,15 +215,15 @@ require ( go.etcd.io/bbolt v1.3.7 // indirect go.opencensus.io v0.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.15.0 // indirect + golang.org/x/crypto v0.16.0 // indirect golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect golang.org/x/mod v0.14.0 // indirect - golang.org/x/net v0.18.0 // indirect + golang.org/x/net v0.19.0 // indirect golang.org/x/oauth2 v0.12.0 // indirect - golang.org/x/sys v0.14.0 // indirect - golang.org/x/term v0.14.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/term v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.15.0 // indirect + golang.org/x/tools v0.16.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/api v0.143.0 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/tests/e2e/go.sum b/tests/e2e/go.sum index cb59d6a..6652f17 100644 --- a/tests/e2e/go.sum +++ b/tests/e2e/go.sum @@ -1228,6 +1228,8 @@ github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrf github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/skip-mev/chaintestutil v0.0.0-20231207155412-975710cc9051 h1:ZTD4dFUTv+h+BgGTv4PtXnSxgMTUrCvGX+NQjNo/hqA= +github.com/skip-mev/chaintestutil v0.0.0-20231207155412-975710cc9051/go.mod h1:P7icBoBSf+Ci1b2moqSXQZTThtBs33eJ8dPajce2ViQ= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= @@ -1374,8 +1376,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= -golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= -golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= +golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= +golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2 h1:Jvc7gsqn21cJHCmAWx0LiimpP18LZmUxkT5Mp7EZ1mI= golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -1472,8 +1474,8 @@ golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= -golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= -golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= +golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= +golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1622,8 +1624,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -1632,8 +1634,8 @@ golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= -golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8= -golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww= +golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1719,8 +1721,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.15.0 h1:zdAyfUGbYmuVokhzVmghFl2ZJh5QhcfebBgmVPFYA+8= -golang.org/x/tools v0.15.0/go.mod h1:hpksKq4dtpQWS1uQ61JkdqWM3LscIS6Slf+VVkm+wQk= +golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM= +golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 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/tests/integration/integration_test.go b/tests/integration/integration_test.go index 8270681..9e33cf3 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -5,21 +5,21 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/skip-mev/chaintestutil/encoding" "github.com/stretchr/testify/suite" - appparams "github.com/skip-mev/feemarket/tests/app/params" - "github.com/skip-mev/feemarket/testutils/encoding" + "github.com/skip-mev/feemarket/tests/app" testkeeper "github.com/skip-mev/feemarket/testutils/keeper" "github.com/skip-mev/feemarket/x/feemarket/types" ) type IntegrationTestSuite struct { suite.Suite + testkeeper.TestKeepers + testkeeper.TestMsgServers - testKeepers testkeeper.TestKeepers - testMsgServers testkeeper.TestMsgServers - encCfg appparams.EncodingConfig - ctx sdk.Context + encCfg encoding.TestEncodingConfig + ctx sdk.Context } func TestIntegrationTestSuite(t *testing.T) { @@ -27,19 +27,19 @@ func TestIntegrationTestSuite(t *testing.T) { } func (s *IntegrationTestSuite) SetupTest() { - s.encCfg = encoding.MakeTestEncodingConfig() + s.encCfg = encoding.MakeTestEncodingConfig(app.ModuleBasics.RegisterInterfaces) - s.ctx, s.testKeepers, s.testMsgServers = testkeeper.NewTestSetup(s.T()) + s.ctx, s.TestKeepers, s.TestMsgServers = testkeeper.NewTestSetup(s.T()) } func (s *IntegrationTestSuite) TestState() { s.Run("set and get default eip1559 state", func() { state := types.DefaultState() - err := s.testKeepers.FeeMarketKeeper.SetState(s.ctx, state) + err := s.TestKeepers.FeeMarketKeeper.SetState(s.ctx, state) s.Require().NoError(err) - gotState, err := s.testKeepers.FeeMarketKeeper.GetState(s.ctx) + gotState, err := s.TestKeepers.FeeMarketKeeper.GetState(s.ctx) s.Require().NoError(err) s.Require().EqualValues(state, gotState) @@ -48,10 +48,10 @@ func (s *IntegrationTestSuite) TestState() { s.Run("set and get aimd eip1559 state", func() { state := types.DefaultAIMDState() - err := s.testKeepers.FeeMarketKeeper.SetState(s.ctx, state) + err := s.TestKeepers.FeeMarketKeeper.SetState(s.ctx, state) s.Require().NoError(err) - gotState, err := s.testKeepers.FeeMarketKeeper.GetState(s.ctx) + gotState, err := s.TestKeepers.FeeMarketKeeper.GetState(s.ctx) s.Require().NoError(err) s.Require().Equal(state, gotState) @@ -62,10 +62,10 @@ func (s *IntegrationTestSuite) TestParams() { s.Run("set and get default params", func() { params := types.DefaultParams() - err := s.testKeepers.FeeMarketKeeper.SetParams(s.ctx, params) + err := s.TestKeepers.FeeMarketKeeper.SetParams(s.ctx, params) s.Require().NoError(err) - gotParams, err := s.testKeepers.FeeMarketKeeper.GetParams(s.ctx) + gotParams, err := s.TestKeepers.FeeMarketKeeper.GetParams(s.ctx) s.Require().NoError(err) s.Require().EqualValues(params, gotParams) @@ -86,10 +86,10 @@ func (s *IntegrationTestSuite) TestParams() { Enabled: true, } - err := s.testKeepers.FeeMarketKeeper.SetParams(s.ctx, params) + err := s.TestKeepers.FeeMarketKeeper.SetParams(s.ctx, params) s.Require().NoError(err) - gotParams, err := s.testKeepers.FeeMarketKeeper.GetParams(s.ctx) + gotParams, err := s.TestKeepers.FeeMarketKeeper.GetParams(s.ctx) s.Require().NoError(err) s.Require().EqualValues(params, gotParams) diff --git a/tests/integration/network_test.go b/tests/integration/network_test.go index 31fca8c..a305919 100644 --- a/tests/integration/network_test.go +++ b/tests/integration/network_test.go @@ -15,12 +15,12 @@ import ( "github.com/skip-mev/feemarket/x/feemarket/types" ) -// QueryTestSuite is a test suite for query tests +// NetworkTestSuite is a test suite for network integration tests. type NetworkTestSuite struct { networksuite.NetworkTestSuite } -// TestQueryTestSuite runs test of the query suite +// TestQueryTestSuite runs test of network integration tests. func TestNetworkTestSuite(t *testing.T) { suite.Run(t, new(NetworkTestSuite)) } diff --git a/testutils/encoding/encoding.go b/testutils/encoding/encoding.go deleted file mode 100644 index 636f883..0000000 --- a/testutils/encoding/encoding.go +++ /dev/null @@ -1,28 +0,0 @@ -package encoding - -import ( - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/std" - "github.com/cosmos/cosmos-sdk/x/auth/tx" - - appparams "github.com/skip-mev/feemarket/tests/app/params" - "github.com/skip-mev/feemarket/testutils/sample" -) - -// MakeTestEncodingConfig creates a test EncodingConfig for a test configuration. -func MakeTestEncodingConfig() appparams.EncodingConfig { - amino := codec.NewLegacyAmino() - interfaceRegistry := sample.InterfaceRegistry() - cdc := codec.NewProtoCodec(interfaceRegistry) - txCfg := tx.NewTxConfig(cdc, tx.DefaultSignModes) - - std.RegisterLegacyAminoCodec(amino) - std.RegisterInterfaces(interfaceRegistry) - - return appparams.EncodingConfig{ - InterfaceRegistry: interfaceRegistry, - Codec: cdc, - TxConfig: txCfg, - Amino: amino, - } -} diff --git a/testutils/keeper/bank.go b/testutils/keeper/bank.go deleted file mode 100644 index ec5724f..0000000 --- a/testutils/keeper/bank.go +++ /dev/null @@ -1,21 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - "github.com/stretchr/testify/require" -) - -// MintToAccount mints the specified coins into the account balance. -func (tk *TestKeepers) MintToAccount(ctx sdk.Context, address string, coins sdk.Coins) { - sdkAddr, err := sdk.AccAddressFromBech32(address) - require.NoError(tk.T, err) - require.NoError(tk.T, tk.BankKeeper.MintCoins(ctx, minttypes.ModuleName, coins)) - require.NoError(tk.T, tk.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, sdkAddr, coins)) -} - -// MintToModule mints the specified coins into the module account balance. -func (tk *TestKeepers) MintToModule(ctx sdk.Context, moduleAcc string, coins sdk.Coins) { - require.NoError(tk.T, tk.BankKeeper.MintCoins(ctx, minttypes.ModuleName, coins)) - require.NoError(tk.T, tk.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, moduleAcc, coins)) -} diff --git a/testutils/keeper/bank_test.go b/testutils/keeper/bank_test.go deleted file mode 100644 index d9eac16..0000000 --- a/testutils/keeper/bank_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package keeper_test - -import ( - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "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) { - sdkCtx, tk, _ := testkeeper.NewTestSetup(t) - r := sample.Rand() - ctx := sdk.WrapSDKContext(sdkCtx) - address := sample.Address(r) - coins, otherCoins := sample.Coins(r), sample.Coins(r) - - getBalances := func(address string) sdk.Coins { - res, err := tk.BankKeeper.AllBalances(ctx, &banktypes.QueryAllBalancesRequest{ - Address: address, - }) - require.NoError(t, err) - require.NotNil(t, res) - return res.Balances - } - - // should create the account - tk.MintToAccount(sdkCtx, address, coins) - require.True(t, getBalances(address).IsEqual(coins)) - - // should add the minted coins in the balance - previousBalance := getBalances(address) - tk.MintToAccount(sdkCtx, address, otherCoins) - require.True(t, getBalances(address).IsEqual(previousBalance.Add(otherCoins...))) -} diff --git a/testutils/keeper/initializer.go b/testutils/keeper/initializer.go deleted file mode 100644 index c09287c..0000000 --- a/testutils/keeper/initializer.go +++ /dev/null @@ -1,198 +0,0 @@ -package keeper - -import ( - tmdb "github.com/cometbft/cometbft-db" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/store" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - "github.com/cosmos/cosmos-sdk/x/feegrant" - feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - 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/feemarket/testutils/sample" - feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper" - feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" -) - -var moduleAccountPerms = map[string][]string{ - authtypes.FeeCollectorName: nil, - distrtypes.ModuleName: nil, - minttypes.ModuleName: {authtypes.Minter}, - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - feemarkettypes.ModuleName: nil, - feemarkettypes.FeeCollectorName: {authtypes.Burner}, -} - -// initializer allows to initialize each module keeper -type initializer struct { - Codec codec.Codec - Amino *codec.LegacyAmino - DB *tmdb.MemDB - StateStore store.CommitMultiStore -} - -func newInitializer() initializer { - db := tmdb.NewMemDB() - return initializer{ - DB: db, - Codec: sample.Codec(), - StateStore: store.NewCommitMultiStore(db), - } -} - -// ModuleAccountAddrs returns all the app's module account addresses. -func ModuleAccountAddrs(maccPerms map[string][]string) map[string]bool { - modAccAddrs := make(map[string]bool) - for acc := range maccPerms { - modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true - } - - return modAccAddrs -} - -func (i *initializer) Param() paramskeeper.Keeper { - storeKey := sdk.NewKVStoreKey(paramstypes.StoreKey) - tkeys := sdk.NewTransientStoreKey(paramstypes.TStoreKey) - - i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB) - i.StateStore.MountStoreWithDB(tkeys, storetypes.StoreTypeTransient, i.DB) - - return paramskeeper.NewKeeper( - i.Codec, - i.Amino, - storeKey, - tkeys, - ) -} - -func (i *initializer) Auth(paramKeeper paramskeeper.Keeper) authkeeper.AccountKeeper { - storeKey := sdk.NewKVStoreKey(authtypes.StoreKey) - i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB) - paramKeeper.Subspace(authtypes.ModuleName) - - return authkeeper.NewAccountKeeper( - i.Codec, - storeKey, - authtypes.ProtoBaseAccount, - moduleAccountPerms, - sdk.Bech32PrefixAccAddr, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), - ) -} - -func (i *initializer) Bank(paramKeeper paramskeeper.Keeper, authKeeper authkeeper.AccountKeeper) bankkeeper.Keeper { - storeKey := sdk.NewKVStoreKey(banktypes.StoreKey) - i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB) - paramKeeper.Subspace(banktypes.ModuleName) - modAccAddrs := ModuleAccountAddrs(moduleAccountPerms) - - return bankkeeper.NewBaseKeeper( - i.Codec, - storeKey, - authKeeper, - modAccAddrs, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), - ) -} - -// create mock ProtocolVersionSetter for UpgradeKeeper - -type ProtocolVersionSetter struct{} - -func (vs ProtocolVersionSetter) SetProtocolVersion(uint64) {} - -func (i *initializer) Upgrade() *upgradekeeper.Keeper { - storeKey := sdk.NewKVStoreKey(upgradetypes.StoreKey) - i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB) - - skipUpgradeHeights := make(map[int64]bool) - vs := ProtocolVersionSetter{} - - return upgradekeeper.NewKeeper( - skipUpgradeHeights, - storeKey, - i.Codec, - "", - vs, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), - ) -} - -func (i *initializer) Staking( - authKeeper authkeeper.AccountKeeper, - bankKeeper bankkeeper.Keeper, - paramKeeper paramskeeper.Keeper, -) *stakingkeeper.Keeper { - storeKey := sdk.NewKVStoreKey(stakingtypes.StoreKey) - i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB) - paramKeeper.Subspace(stakingtypes.ModuleName) - - return stakingkeeper.NewKeeper( - i.Codec, - storeKey, - authKeeper, - bankKeeper, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), - ) -} - -func (i *initializer) Distribution( - authKeeper authkeeper.AccountKeeper, - bankKeeper bankkeeper.Keeper, - stakingKeeper *stakingkeeper.Keeper, -) distrkeeper.Keeper { - storeKey := sdk.NewKVStoreKey(distrtypes.StoreKey) - i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB) - - return distrkeeper.NewKeeper( - i.Codec, - storeKey, - authKeeper, - bankKeeper, - stakingKeeper, - authtypes.FeeCollectorName, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), - ) -} - -func (i *initializer) FeeMarket( - authKeeper authkeeper.AccountKeeper, -) *feemarketkeeper.Keeper { - storeKey := sdk.NewKVStoreKey(feemarkettypes.StoreKey) - i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB) - - return feemarketkeeper.NewKeeper( - i.Codec, - storeKey, - authKeeper, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), - ) -} - -func (i *initializer) FeeGrant( - authKeeper authkeeper.AccountKeeper, -) feegrantkeeper.Keeper { - storeKey := sdk.NewKVStoreKey(feegrant.StoreKey) - i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB) - - return feegrantkeeper.NewKeeper( - i.Codec, - storeKey, - authKeeper, - ) -} diff --git a/testutils/keeper/keeper.go b/testutils/keeper/keeper.go index 1eae498..a8c069a 100644 --- a/testutils/keeper/keeper.go +++ b/testutils/keeper/keeper.go @@ -3,114 +3,86 @@ package keeper import ( "testing" - "time" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + testkeeper "github.com/skip-mev/chaintestutil/keeper" "github.com/stretchr/testify/require" feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper" feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" ) -var ( - // ExampleTimestamp is a timestamp used as the current time for the context of the keepers returned from the package - ExampleTimestamp = time.Date(2020, time.January, 1, 12, 0, 0, 0, time.UTC) - - // ExampleHeight is a block height used as the current block height for the context of test keeper - ExampleHeight = int64(1111) -) - // TestKeepers holds all keepers used during keeper tests for all modules type TestKeepers struct { - T testing.TB - AccountKeeper authkeeper.AccountKeeper - BankKeeper bankkeeper.Keeper - DistrKeeper distrkeeper.Keeper - StakingKeeper *stakingkeeper.Keeper + testkeeper.TestKeepers FeeMarketKeeper *feemarketkeeper.Keeper - FeeGrantKeeper feegrantkeeper.Keeper } // TestMsgServers holds all message servers used during keeper tests for all modules type TestMsgServers struct { - T testing.TB + testkeeper.TestMsgServers FeeMarketMsgServer feemarkettypes.MsgServer } -// SetupOption represents an option that can be provided to NewTestSetup -type SetupOption func(*setupOptions) - -// setupOptions represents the set of SetupOption -type setupOptions struct{} +var additionalMaccPerms = map[string][]string{ + feemarkettypes.ModuleName: nil, + feemarkettypes.FeeCollectorName: {authtypes.Burner}, +} // NewTestSetup returns initialized instances of all the keepers and message servers of the modules -func NewTestSetup(t testing.TB, options ...SetupOption) (sdk.Context, TestKeepers, TestMsgServers) { - // setup options - var so setupOptions - for _, option := range options { - option(&so) - } +func NewTestSetup(t testing.TB, options ...testkeeper.SetupOption) (sdk.Context, TestKeepers, TestMsgServers) { + options = append(options, testkeeper.WithAdditionalModuleAccounts(additionalMaccPerms)) - initializer := newInitializer() + _, tk, tms := testkeeper.NewTestSetup(t, options...) - paramKeeper := initializer.Param() - authKeeper := initializer.Auth(paramKeeper) - bankKeeper := initializer.Bank(paramKeeper, authKeeper) - stakingKeeper := initializer.Staking(authKeeper, bankKeeper, paramKeeper) - distrKeeper := initializer.Distribution(authKeeper, bankKeeper, stakingKeeper) - feeMarketKeeper := initializer.FeeMarket(authKeeper) - feeGrantKeeper := initializer.FeeGrant(authKeeper) + // initialize extra keeper + feeMarketKeeper := FeeMarket(tk.Initializer, tk.AccountKeeper) + require.NoError(t, tk.Initializer.LoadLatest()) - require.NoError(t, initializer.StateStore.LoadLatestVersion()) + // initialize msg servers + feeMarketMsgSrv := feemarketkeeper.NewMsgServer(*feeMarketKeeper) - // Create a context using a custom timestamp - ctx := sdk.NewContext(initializer.StateStore, tmproto.Header{ - Time: ExampleTimestamp, - Height: ExampleHeight, + ctx := sdk.NewContext(tk.Initializer.StateStore, tmproto.Header{ + Time: testkeeper.ExampleTimestamp, + Height: testkeeper.ExampleHeight, }, false, log.NewNopLogger()) - // initialize params - err := distrKeeper.SetParams(ctx, distrtypes.DefaultParams()) - if err != nil { - panic(err) - } - err = stakingKeeper.SetParams(ctx, stakingtypes.DefaultParams()) - if err != nil { - panic(err) - } - err = feeMarketKeeper.SetState(ctx, feemarkettypes.DefaultState()) - if err != nil { - panic(err) - } + err := feeMarketKeeper.SetState(ctx, feemarkettypes.DefaultState()) + require.NoError(t, err) err = feeMarketKeeper.SetParams(ctx, feemarkettypes.DefaultParams()) - if err != nil { - panic(err) + require.NoError(t, err) + + testKeepers := TestKeepers{ + TestKeepers: tk, + FeeMarketKeeper: feeMarketKeeper, } - // initialize msg servers - feeMarketMsgSrv := feemarketkeeper.NewMsgServer(*feeMarketKeeper) + testMsgServers := TestMsgServers{ + TestMsgServers: tms, + FeeMarketMsgServer: feeMarketMsgSrv, + } + + return ctx, testKeepers, testMsgServers +} - return ctx, - TestKeepers{ - T: t, - AccountKeeper: authKeeper, - BankKeeper: bankKeeper, - DistrKeeper: distrKeeper, - StakingKeeper: stakingKeeper, - FeeMarketKeeper: feeMarketKeeper, - FeeGrantKeeper: feeGrantKeeper, - }, - TestMsgServers{ - T: t, - FeeMarketMsgServer: feeMarketMsgSrv, - } +// FeeMarket initializes the fee market module using the testkeepers intializer. +func FeeMarket( + initializer *testkeeper.Initializer, + authKeeper authkeeper.AccountKeeper, +) *feemarketkeeper.Keeper { + storeKey := sdk.NewKVStoreKey(feemarkettypes.StoreKey) + initializer.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, initializer.DB) + + return feemarketkeeper.NewKeeper( + initializer.Codec, + storeKey, + authKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) } diff --git a/testutils/network/network.go b/testutils/network/network.go deleted file mode 100644 index 168f416..0000000 --- a/testutils/network/network.go +++ /dev/null @@ -1,80 +0,0 @@ -// Package network allows to programmatically spin up a local network for CLI tests -package network - -import ( - "fmt" - "testing" - "time" - - "github.com/skip-mev/feemarket/testutils/encoding" - - tmdb "github.com/cometbft/cometbft-db" - tmrand "github.com/cometbft/cometbft/libs/rand" - "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/crypto/hd" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - servertypes "github.com/cosmos/cosmos-sdk/server/types" - pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" - "github.com/cosmos/cosmos-sdk/testutil/network" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/stretchr/testify/require" - - "github.com/skip-mev/feemarket/tests/app" -) - -type ( - Network = network.Network - Config = network.Config -) - -// New creates instance with fully configured cosmos network. -// Accepts optional config, that will be used in place of the DefaultConfig() if provided. -func New(t *testing.T, cfg network.Config) *network.Network { - net, err := network.New(t, t.TempDir(), cfg) - require.NoError(t, err) - t.Cleanup(net.Cleanup) - return net -} - -// DefaultConfig will initialize config for the network with custom application, -// genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig -func DefaultConfig() network.Config { - var ( - encCfg = encoding.MakeTestEncodingConfig() - chainID = "chain-" + tmrand.NewRand().Str(6) - ) - return network.Config{ - Codec: encCfg.Codec, - TxConfig: encCfg.TxConfig, - LegacyAmino: encCfg.Amino, - InterfaceRegistry: encCfg.InterfaceRegistry, - AccountRetriever: authtypes.AccountRetriever{}, - AppConstructor: func(val network.ValidatorI) servertypes.Application { - return app.New( - val.GetCtx().Logger, - tmdb.NewMemDB(), - nil, - true, - simtestutil.EmptyAppOptions{}, - baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), - baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices), - baseapp.SetChainID(chainID), - ) - }, - GenesisState: app.ModuleBasics.DefaultGenesis(encCfg.Codec), - TimeoutCommit: 2 * time.Second, - ChainID: chainID, - NumValidators: 1, - BondDenom: sdk.DefaultBondDenom, - MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom), - AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction), - StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction), - BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), - PruningStrategy: pruningtypes.PruningOptionNothing, - CleanupDir: true, - SigningAlgo: string(hd.Secp256k1Type), - KeyringOptions: []keyring.Option{}, - } -} diff --git a/testutils/networksuite/networksuite.go b/testutils/networksuite/networksuite.go index 8f39766..64b82bb 100644 --- a/testutils/networksuite/networksuite.go +++ b/testutils/networksuite/networksuite.go @@ -4,18 +4,44 @@ package networksuite import ( "math/rand" + tmdb "github.com/cometbft/cometbft-db" + tmrand "github.com/cometbft/cometbft/libs/rand" + "github.com/cosmos/cosmos-sdk/baseapp" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/gogoproto/proto" + + "github.com/skip-mev/chaintestutil/network" + "github.com/skip-mev/chaintestutil/sample" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/skip-mev/feemarket/testutils/network" - "github.com/skip-mev/feemarket/testutils/sample" + "github.com/skip-mev/feemarket/tests/app" feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" ) +var ( + chainID = "chain-" + tmrand.NewRand().Str(6) + + DefaultAppConstructor = func(val network.ValidatorI) servertypes.Application { + return app.New( + val.GetCtx().Logger, + tmdb.NewMemDB(), + nil, + true, + simtestutil.EmptyAppOptions{}, + baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), + baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices), + baseapp.SetChainID(chainID), + ) + } +) + // NetworkTestSuite is a test suite for query tests that initializes a network instance. type NetworkTestSuite struct { suite.Suite + Network *network.Network FeeMarketState feemarkettypes.GenesisState } @@ -24,7 +50,7 @@ type NetworkTestSuite struct { func (nts *NetworkTestSuite) SetupSuite() { var ( r = sample.Rand() - cfg = network.DefaultConfig() + cfg = network.NewConfig(DefaultAppConstructor, app.ModuleBasics, chainID) ) updateGenesisConfigState := func(moduleName string, moduleState proto.Message) { 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())) -} diff --git a/x/feemarket/ante/expected_keepers.go b/x/feemarket/ante/expected_keepers.go index c3c2592..f879ae9 100644 --- a/x/feemarket/ante/expected_keepers.go +++ b/x/feemarket/ante/expected_keepers.go @@ -42,4 +42,7 @@ type BankKeeper interface { type FeeMarketKeeper interface { GetState(ctx sdk.Context) (feemarkettypes.State, error) GetMinGasPrices(ctx sdk.Context) (sdk.Coins, error) + GetParams(ctx sdk.Context) (feemarkettypes.Params, error) + SetState(ctx sdk.Context, state feemarkettypes.State) error + SetParams(ctx sdk.Context, params feemarkettypes.Params) error } diff --git a/x/feemarket/ante/suite/suite.go b/x/feemarket/ante/suite/suite.go index ddbb402..5390748 100644 --- a/x/feemarket/ante/suite/suite.go +++ b/x/feemarket/ante/suite/suite.go @@ -12,11 +12,11 @@ import ( authante "github.com/cosmos/cosmos-sdk/x/auth/ante" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/skip-mev/chaintestutil/encoding" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - appparams "github.com/skip-mev/feemarket/tests/app/params" - "github.com/skip-mev/feemarket/testutils/encoding" + "github.com/skip-mev/feemarket/tests/app" testkeeper "github.com/skip-mev/feemarket/testutils/keeper" feemarketante "github.com/skip-mev/feemarket/x/feemarket/ante" "github.com/skip-mev/feemarket/x/feemarket/ante/mocks" @@ -39,7 +39,7 @@ type TestSuite struct { MockBankKeeper *mocks.BankKeeper MockFeeGrantKeeper *mocks.FeeGrantKeeper - EncCfg appparams.EncodingConfig + EncCfg encoding.TestEncodingConfig } // TestAccount represents an account used in the tests in x/auth/ante. @@ -69,7 +69,7 @@ func (s *TestSuite) CreateTestAccounts(numAccs int) []TestAccount { func SetupTestSuite(t *testing.T, mock bool) *TestSuite { s := &TestSuite{} - s.EncCfg = encoding.MakeTestEncodingConfig() + s.EncCfg = encoding.MakeTestEncodingConfig(app.ModuleBasics.RegisterInterfaces) ctx, testKeepers, _ := testkeeper.NewTestSetup(t) s.Ctx = ctx diff --git a/x/feemarket/keeper/keeper_test.go b/x/feemarket/keeper/keeper_test.go index f2841e1..e7c64d4 100644 --- a/x/feemarket/keeper/keeper_test.go +++ b/x/feemarket/keeper/keeper_test.go @@ -4,14 +4,13 @@ import ( "testing" "cosmossdk.io/math" - storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/skip-mev/chaintestutil/encoding" "github.com/stretchr/testify/suite" - appparams "github.com/skip-mev/feemarket/tests/app/params" - "github.com/skip-mev/feemarket/testutils/encoding" + "github.com/skip-mev/feemarket/tests/app" testkeeper "github.com/skip-mev/feemarket/testutils/keeper" "github.com/skip-mev/feemarket/x/feemarket/keeper" "github.com/skip-mev/feemarket/x/feemarket/types" @@ -23,9 +22,8 @@ type KeeperTestSuite struct { accountKeeper *mocks.AccountKeeper feeMarketKeeper *keeper.Keeper - encCfg appparams.EncodingConfig + encCfg encoding.TestEncodingConfig ctx sdk.Context - key *storetypes.KVStoreKey authorityAccount sdk.AccAddress // Message server variables @@ -40,7 +38,7 @@ func TestKeeperTestSuite(t *testing.T) { } func (s *KeeperTestSuite) SetupTest() { - s.encCfg = encoding.MakeTestEncodingConfig() + s.encCfg = encoding.MakeTestEncodingConfig(app.ModuleBasics.RegisterInterfaces) s.authorityAccount = authtypes.NewModuleAddress(govtypes.ModuleName) s.accountKeeper = mocks.NewAccountKeeper(s.T()) ctx, tk, tm := testkeeper.NewTestSetup(s.T()) diff --git a/x/feemarket/post/expected_keeper.go b/x/feemarket/post/expected_keeper.go index bce9fb7..dfa94ff 100644 --- a/x/feemarket/post/expected_keeper.go +++ b/x/feemarket/post/expected_keeper.go @@ -42,6 +42,7 @@ type BankKeeper interface { type FeeMarketKeeper interface { GetState(ctx sdk.Context) (feemarkettypes.State, error) GetParams(ctx sdk.Context) (feemarkettypes.Params, error) + SetParams(ctx sdk.Context, params feemarkettypes.Params) error SetState(ctx sdk.Context, state feemarkettypes.State) error GetMinGasPrices(ctx sdk.Context) (sdk.Coins, error) }