From b305db9d44d6d9f218cbc828a8535e992ef72227 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 29 Nov 2023 11:27:22 -0500 Subject: [PATCH 01/53] clean --- tests/integration/setup.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/integration/setup.go b/tests/integration/setup.go index 714c620..d83174c 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -515,7 +515,6 @@ func (s *TestSuite) GetAndFundTestUsers( } s.Require().NoError(eg.Wait()) - // TODO(nix 05-17-2022): Map with generics once using go 1.18 chainHeights := make([]testutil.ChainHeighter, len(chains)) for i := range chains { chainHeights[i] = chains[i] @@ -528,10 +527,10 @@ func (s *TestSuite) ExecTx(ctx context.Context, chain *cosmos.CosmosChain, keyNa return node.ExecTx(ctx, keyName, command...) } -var chars = []byte("abcdefghijklmnopqrstuvwxyz") - // RandLowerCaseLetterString returns a lowercase letter string of given length func RandLowerCaseLetterString(length int) string { + chars := []byte("abcdefghijklmnopqrstuvwxyz") + b := make([]byte, length) for i := range b { b[i] = chars[rand.Intn(len(chars))] From abe18660486929d247a9f9cf927bdd09a79d9289 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 29 Nov 2023 14:13:39 -0500 Subject: [PATCH 02/53] fix --- tests/integration/setup.go | 187 ++++++++++++++----------------------- tests/integration/suite.go | 20 +++- 2 files changed, 84 insertions(+), 123 deletions(-) diff --git a/tests/integration/setup.go b/tests/integration/setup.go index d83174c..6151df2 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -15,17 +15,17 @@ import ( "testing" "time" - "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - + coretypes "github.com/cometbft/cometbft/rpc/core/types" rpctypes "github.com/cometbft/cometbft/rpc/core/types" comettypes "github.com/cometbft/cometbft/types" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" @@ -88,8 +88,23 @@ func BuildInterchain(t *testing.T, ctx context.Context, chain ibc.Chain) *interc return ic } +// SendCoins creates a bank SendCoins message and broadcasts the transaction with commit. +func (s *TestSuite) SendCoins(ctx context.Context, chain *cosmos.CosmosChain, sender, reciever cosmos.User, amt, fees sdk.Coins) (*coretypes.ResultBroadcastTxCommit, error) { + msg := &banktypes.MsgSend{ + FromAddress: sender.FormattedAddress(), + ToAddress: reciever.FormattedAddress(), + Amount: amt, + } + + txbz := s.CreateTx(ctx, sender, fees, msg) + + // get an rpc endpoint for the chain + nodeClient := chain.FullNodes[0].Client + return nodeClient.BroadcastTxCommit(context.Background(), txbz) +} + // CreateTx creates a new transaction to be signed by the given user, including a provided set of messages -func (s *TestSuite) CreateTx(ctx context.Context, chain *cosmos.CosmosChain, user cosmos.User, seqIncrement, height uint64, GasPrice int64, msgs ...sdk.Msg) []byte { +func (s *TestSuite) CreateTx(ctx context.Context, user cosmos.User, fees sdk.Coins, msgs ...sdk.Msg) []byte { // create tx factory + Client Context txf, err := s.bc.GetFactory(ctx, user) s.Require().NoError(err) @@ -102,17 +117,16 @@ func (s *TestSuite) CreateTx(ctx context.Context, chain *cosmos.CosmosChain, use txf, err = txf.Prepare(cc) s.Require().NoError(err) - // set timeout height - if height != 0 { - txf = txf.WithTimeoutHeight(height) - } + txf = txf.WithSimulateAndExecute(true) // get gas for tx txf.WithGas(25000000) // update sequence number - txf = txf.WithSequence(txf.Sequence() + seqIncrement) - txf = txf.WithGasPrices(sdk.NewDecCoins(sdk.NewDecCoin(chain.Config().Denom, math.NewInt(GasPrice))).String()) + txf = txf.WithSequence(txf.Sequence()) + + // set fee + txf = txf.WithFees(fees.String()) // sign the tx txBuilder, err := txf.BuildUnsignedTx(msgs...) @@ -127,7 +141,7 @@ func (s *TestSuite) CreateTx(ctx context.Context, chain *cosmos.CosmosChain, use } // SimulateTx simulates the provided messages, and checks whether the provided failure condition is met -func (s *TestSuite) SimulateTx(ctx context.Context, chain *cosmos.CosmosChain, user cosmos.User, height uint64, expectFail bool, msgs ...sdk.Msg) { +func (s *TestSuite) SimulateTx(ctx context.Context, user cosmos.User, height uint64, expectFail bool, msgs ...sdk.Msg) { // create tx factory + Client Context txf, err := s.bc.GetFactory(ctx, user) s.Require().NoError(err) @@ -148,95 +162,9 @@ func (s *TestSuite) SimulateTx(ctx context.Context, chain *cosmos.CosmosChain, u s.Require().Equal(err != nil, expectFail) } -type Tx struct { - User cosmos.User - Msgs []sdk.Msg - GasPrice int64 - SequenceIncrement uint64 - Height uint64 - SkipInclusionCheck bool - ExpectFail bool -} - -// BroadcastTxs broadcasts the given messages for each user. This function returns the broadcasted txs. If a message -// is not expected to be included in a block, set SkipInclusionCheck to true and the method -// will not block on the tx's inclusion in a block, otherwise this method will block on the tx's inclusion -func (s *TestSuite) BroadcastTxs(ctx context.Context, chain *cosmos.CosmosChain, txs []Tx) [][]byte { - return s.BroadcastTxsWithCallback(ctx, chain, txs, nil) -} - -// BroadcastTxsWithCallback broadcasts the given messages for each user. This function returns the broadcasted txs. If a message -// is not expected to be included in a block, set SkipInclusionCheck to true and the method -// will not block on the tx's inclusion in a block, otherwise this method will block on the tx's inclusion. The callback -// function is called for each tx that is included in a block. -func (s *TestSuite) BroadcastTxsWithCallback( - ctx context.Context, - chain *cosmos.CosmosChain, - txs []Tx, - cb func(tx []byte, resp *rpctypes.ResultTx), -) [][]byte { - rawTxs := make([][]byte, len(txs)) - - for i, msg := range txs { - rawTxs[i] = s.CreateTx(ctx, chain, msg.User, msg.SequenceIncrement, msg.Height, msg.GasPrice, msg.Msgs...) - } - - // broadcast each tx - s.Require().True(len(chain.Nodes()) > 0) - client := chain.Nodes()[0].Client - - statusResp, err := client.Status(context.Background()) - s.Require().NoError(err) - - s.T().Logf("broadcasting transactions at latest height of %d", statusResp.SyncInfo.LatestBlockHeight) - - for i, tx := range rawTxs { - // broadcast tx - resp, err := client.BroadcastTxSync(ctx, tx) - - // check execution was successful - if !txs[i].ExpectFail { - s.Require().Equal(resp.Code, uint32(0)) - } else { - if resp != nil { - s.Require().NotEqual(resp.Code, uint32(0)) - } else { - s.Require().Error(err) - } - } - } - - // block on all txs being included in block - eg := errgroup.Group{} - for i, tx := range rawTxs { - // if we don't expect this tx to be included.. skip it - if txs[i].SkipInclusionCheck || txs[i].ExpectFail { - continue - } - - tx := tx // pin - eg.Go(func() error { - return testutil.WaitForCondition(30*time.Second, 500*time.Millisecond, func() (bool, error) { - res, err := client.Tx(context.Background(), comettypes.Tx(tx).Hash(), false) - if err != nil || res.TxResult.Code != uint32(0) { - return false, nil - } - - if cb != nil { - cb(tx, res) - } - - return true, nil - }) - }) - } - - s.Require().NoError(eg.Wait()) - - return rawTxs -} - func (s *TestSuite) QueryParams() types.Params { + s.T().Helper() + // cast chain to cosmos-chain cosmosChain, ok := s.chain.(*cosmos.CosmosChain) s.Require().True(ok) @@ -255,6 +183,27 @@ func (s *TestSuite) QueryParams() types.Params { return params } +func (s *TestSuite) QueryState() types.State { + s.T().Helper() + + // cast chain to cosmos-chain + cosmosChain, ok := s.chain.(*cosmos.CosmosChain) + s.Require().True(ok) + // get nodes + nodes := cosmosChain.Nodes() + s.Require().True(len(nodes) > 0) + + // make params query to first node + resp, _, err := nodes[0].ExecQuery(context.Background(), "feemarket", "state") + s.Require().NoError(err) + + // unmarshal state + var state types.State + err = s.cdc.UnmarshalJSON(resp, &state) + s.Require().NoError(err) + return state +} + // QueryValidators queries for all the network's validators func (s *TestSuite) QueryValidators(chain *cosmos.CosmosChain) []sdk.ValAddress { s.T().Helper() @@ -265,10 +214,10 @@ func (s *TestSuite) QueryValidators(chain *cosmos.CosmosChain) []sdk.ValAddress s.Require().NoError(err) defer cc.Close() - client := stakingtypes.NewQueryClient(cc) + nodeClient := stakingtypes.NewQueryClient(cc) // query validators - resp, err := client.Validators(context.Background(), &stakingtypes.QueryValidatorsRequest{}) + resp, err := nodeClient.Validators(context.Background(), &stakingtypes.QueryValidatorsRequest{}) s.Require().NoError(err) addrs := make([]sdk.ValAddress, len(resp.Validators)) @@ -335,6 +284,8 @@ func (s *TestSuite) Block(chain *cosmos.CosmosChain, height int64) *rpctypes.Res // WaitForHeight waits for the chain to reach the given height func (s *TestSuite) WaitForHeight(chain *cosmos.CosmosChain, height uint64) { + s.T().Helper() + // wait for next height err := testutil.WaitForCondition(30*time.Second, 100*time.Millisecond, func() (bool, error) { pollHeight, err := chain.Height(context.Background()) @@ -348,6 +299,8 @@ func (s *TestSuite) WaitForHeight(chain *cosmos.CosmosChain, height uint64) { // VerifyBlock takes a Block and verifies that it contains the given bid at the 0-th index, and the bundled txs immediately after func (s *TestSuite) VerifyBlock(block *rpctypes.ResultBlock, offset int, bidTxHash string, txs [][]byte) { + s.T().Helper() + // verify the block if bidTxHash != "" { s.Require().Equal(bidTxHash, TxHash(block.Block.Data.Txs[offset+1])) @@ -363,6 +316,8 @@ func (s *TestSuite) VerifyBlock(block *rpctypes.ResultBlock, offset int, bidTxHa // VerifyBlockWithExpectedBlock takes in a list of raw tx bytes and compares each tx hash to the tx hashes in the block. // The expected block is the block that should be returned by the chain at the given height. func (s *TestSuite) VerifyBlockWithExpectedBlock(chain *cosmos.CosmosChain, height uint64, txs [][]byte) { + s.T().Helper() + block := s.Block(chain, int64(height)) blockTxs := block.Block.Data.Txs[1:] @@ -466,25 +421,21 @@ func (s *TestSuite) GetAndFundTestUserWithMnemonic( return nil, fmt.Errorf("failed to get source user wallet: %w", err) } - err = chain.SendFunds(ctx, interchaintest.FaucetAccountKeyName, ibc.WalletAmount{ - Address: user.FormattedAddress(), - Amount: math.NewInt(amount), - Denom: chainCfg.Denom, - }) + addrBz, err := chain.GetAddress(ctx, interchaintest.FaucetAccountKeyName) + if err != nil { + return nil, fmt.Errorf("failed to get faucet user address: %w", err) + } - _, err = s.ExecTx( - ctx, - chain, - interchaintest.FaucetAccountKeyName, - "bank", - "send", + facuetWallet := cosmos.NewWallet( + "", + addrBz, interchaintest.FaucetAccountKeyName, - user.FormattedAddress(), - fmt.Sprintf("%d%s", amount, chainCfg.Denom), - "--fees", - fmt.Sprintf("%d%s", 200000000000, chainCfg.Denom), + chainCfg, ) + sendCoins := sdk.NewCoins(sdk.NewCoin(chainCfg.Denom, sdk.NewInt(amount))) + feeCoins := sdk.NewCoins(sdk.NewCoin(chainCfg.Denom, sdk.NewInt(200000000000))) + _, err = s.SendCoins(ctx, chain, facuetWallet, user, sendCoins, feeCoins) if err != nil { return nil, fmt.Errorf("failed to get funds from faucet: %w", err) } diff --git a/tests/integration/suite.go b/tests/integration/suite.go index b5c973e..3dfa9cf 100644 --- a/tests/integration/suite.go +++ b/tests/integration/suite.go @@ -80,16 +80,17 @@ func (s *TestSuite) SetupSuite() { panic("unable to assert ibc.Chain as CosmosChain") } - // get the users - s.user1 = s.GetAndFundTestUsers(ctx, s.T().Name(), initBalance, cc)[0] - s.user2 = s.GetAndFundTestUsers(ctx, s.T().Name(), initBalance, cc)[0] - s.user3 = s.GetAndFundTestUsers(ctx, s.T().Name(), initBalance, cc)[0] - // create the broadcaster s.T().Log("creating broadcaster") s.setupBroadcaster() s.cdc = s.chain.Config().EncodingConfig.Codec + + // get the users + s.user1 = s.GetAndFundTestUsers(ctx, s.T().Name(), initBalance, cc)[0] + s.user2 = s.GetAndFundTestUsers(ctx, s.T().Name(), initBalance, cc)[0] + s.user3 = s.GetAndFundTestUsers(ctx, s.T().Name(), initBalance, cc)[0] + } func (s *TestSuite) TearDownSuite() { @@ -103,6 +104,7 @@ func (s *TestSuite) SetupSubTest() { height, err := s.chain.(*cosmos.CosmosChain).Height(context.Background()) s.Require().NoError(err) s.WaitForHeight(s.chain.(*cosmos.CosmosChain), height+1) + } func (s *TestSuite) TestQueryParams() { @@ -112,3 +114,11 @@ func (s *TestSuite) TestQueryParams() { // expect validate to pass require.NoError(s.T(), params.ValidateBasic(), params) } + +func (s *TestSuite) TestQueryState() { + // query params + state := s.QueryState() + + // expect validate to pass + require.NoError(s.T(), state.ValidateBasic(), state) +} From 11cf89a3ce4757eb593321b32864511c8a61c3cb Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 29 Nov 2023 14:18:12 -0500 Subject: [PATCH 03/53] state query --- proto/feemarket/feemarket/v1/query.proto | 14 + x/feemarket/client/cli/query.go | 28 ++ x/feemarket/keeper/query_server.go | 12 + x/feemarket/types/query.pb.go | 362 ++++++++++++++++++++++- x/feemarket/types/query.pb.gw.go | 65 ++++ 5 files changed, 468 insertions(+), 13 deletions(-) diff --git a/proto/feemarket/feemarket/v1/query.proto b/proto/feemarket/feemarket/v1/query.proto index 1349271..e505627 100644 --- a/proto/feemarket/feemarket/v1/query.proto +++ b/proto/feemarket/feemarket/v1/query.proto @@ -6,6 +6,7 @@ option go_package = "github.com/skip-mev/feemarket/x/feemarket/types"; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; import "feemarket/feemarket/v1/params.proto"; +import "feemarket/feemarket/v1/genesis.proto"; // Query Service for the feemarket module. service Query { @@ -15,6 +16,13 @@ service Query { get : "/feemarket/v1/params" }; }; + + // State returns the current feemarket module state. + rpc State(StateRequest) returns (StateResponse) { + option (google.api.http) = { + get : "/feemarket/v1/state" + }; + }; } // ParamsRequest is the request type for the Query/Params RPC method. @@ -22,3 +30,9 @@ message ParamsRequest {} // ParamsResponse is the response type for the Query/Params RPC method. message ParamsResponse { Params params = 1 [ (gogoproto.nullable) = false ]; } + +// StateRequest is the request type for the Query/State RPC method. +message StateRequest {} + +// StateResponse is the response type for the Query/State RPC method. +message StateResponse { State state = 1 [ (gogoproto.nullable) = false ]; } diff --git a/x/feemarket/client/cli/query.go b/x/feemarket/client/cli/query.go index d36139b..851c674 100644 --- a/x/feemarket/client/cli/query.go +++ b/x/feemarket/client/cli/query.go @@ -24,6 +24,7 @@ func GetQueryCmd() *cobra.Command { // add sub-commands cmd.AddCommand( GetParamsCmd(), + GetStateCmd(), ) return cmd @@ -55,3 +56,30 @@ func GetParamsCmd() *cobra.Command { return cmd } + +// GetStateCmd returns the cli-command that queries the current feemarket state. +func GetStateCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "state", + Short: "Query for the current feemarket state", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + resp, err := queryClient.State(cmd.Context(), &types.StateRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(&resp.State) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/feemarket/keeper/query_server.go b/x/feemarket/keeper/query_server.go index 1907402..af0dc58 100644 --- a/x/feemarket/keeper/query_server.go +++ b/x/feemarket/keeper/query_server.go @@ -31,3 +31,15 @@ func (q QueryServer) Params(goCtx context.Context, _ *types.ParamsRequest) (*typ return &types.ParamsResponse{Params: params}, nil } + +// State defines a method that returns the current feemarket state. +func (q QueryServer) State(goCtx context.Context, _ *types.StateRequest) (*types.StateResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + state, err := q.k.GetState(ctx) + if err != nil { + return nil, err + } + + return &types.StateResponse{State: state}, nil +} diff --git a/x/feemarket/types/query.pb.go b/x/feemarket/types/query.pb.go index 60b7b52..2cb5cd9 100644 --- a/x/feemarket/types/query.pb.go +++ b/x/feemarket/types/query.pb.go @@ -111,9 +111,93 @@ func (m *ParamsResponse) GetParams() Params { return Params{} } +// StateRequest is the request type for the Query/State RPC method. +type StateRequest struct { +} + +func (m *StateRequest) Reset() { *m = StateRequest{} } +func (m *StateRequest) String() string { return proto.CompactTextString(m) } +func (*StateRequest) ProtoMessage() {} +func (*StateRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d683b3b0d8494138, []int{2} +} +func (m *StateRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StateRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *StateRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_StateRequest.Merge(m, src) +} +func (m *StateRequest) XXX_Size() int { + return m.Size() +} +func (m *StateRequest) XXX_DiscardUnknown() { + xxx_messageInfo_StateRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_StateRequest proto.InternalMessageInfo + +// StateResponse is the response type for the Query/State RPC method. +type StateResponse struct { + State State `protobuf:"bytes,1,opt,name=state,proto3" json:"state"` +} + +func (m *StateResponse) Reset() { *m = StateResponse{} } +func (m *StateResponse) String() string { return proto.CompactTextString(m) } +func (*StateResponse) ProtoMessage() {} +func (*StateResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d683b3b0d8494138, []int{3} +} +func (m *StateResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StateResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *StateResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_StateResponse.Merge(m, src) +} +func (m *StateResponse) XXX_Size() int { + return m.Size() +} +func (m *StateResponse) XXX_DiscardUnknown() { + xxx_messageInfo_StateResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_StateResponse proto.InternalMessageInfo + +func (m *StateResponse) GetState() State { + if m != nil { + return m.State + } + return State{} +} + func init() { proto.RegisterType((*ParamsRequest)(nil), "feemarket.feemarket.v1.ParamsRequest") proto.RegisterType((*ParamsResponse)(nil), "feemarket.feemarket.v1.ParamsResponse") + proto.RegisterType((*StateRequest)(nil), "feemarket.feemarket.v1.StateRequest") + proto.RegisterType((*StateResponse)(nil), "feemarket.feemarket.v1.StateResponse") } func init() { @@ -121,24 +205,29 @@ func init() { } var fileDescriptor_d683b3b0d8494138 = []byte{ - // 268 bytes of a gzipped FileDescriptorProto + // 346 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4a, 0x4b, 0x4d, 0xcd, 0x4d, 0x2c, 0xca, 0x4e, 0x2d, 0xd1, 0x47, 0xb0, 0xca, 0x0c, 0xf5, 0x0b, 0x4b, 0x53, 0x8b, 0x2a, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0xc4, 0xe0, 0x32, 0x7a, 0x08, 0x56, 0x99, 0xa1, 0x94, 0x48, 0x7a, 0x7e, 0x7a, 0x3e, 0x58, 0x89, 0x3e, 0x88, 0x05, 0x51, 0x2d, 0x25, 0x93, 0x9e, 0x9f, 0x9f, 0x9e, 0x93, 0xaa, 0x9f, 0x58, 0x90, 0xa9, 0x9f, 0x98, 0x97, 0x97, 0x5f, 0x92, 0x58, 0x92, - 0x99, 0x9f, 0x57, 0x0c, 0x95, 0x55, 0xc6, 0x61, 0x5f, 0x41, 0x62, 0x51, 0x62, 0x2e, 0x54, 0x91, - 0x12, 0x3f, 0x17, 0x6f, 0x00, 0x98, 0x1f, 0x94, 0x5a, 0x58, 0x9a, 0x5a, 0x5c, 0xa2, 0xe4, 0xc7, - 0xc5, 0x07, 0x13, 0x28, 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0x15, 0xb2, 0xe1, 0x62, 0x83, 0x68, 0x91, - 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x36, 0x92, 0xd3, 0xc3, 0xee, 0x48, 0x3d, 0x88, 0x3e, 0x27, 0x96, - 0x13, 0xf7, 0xe4, 0x19, 0x82, 0xa0, 0x7a, 0x8c, 0xea, 0xb8, 0x58, 0x03, 0x41, 0x1e, 0x14, 0x2a, - 0xe5, 0x62, 0x83, 0x28, 0x10, 0x52, 0xc5, 0x6f, 0x00, 0xd4, 0x25, 0x52, 0x6a, 0x84, 0x94, 0x41, - 0xdc, 0xa7, 0x24, 0xd3, 0x74, 0xf9, 0xc9, 0x64, 0x26, 0x31, 0x21, 0x11, 0x6c, 0xde, 0x74, 0xf2, - 0x3c, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, - 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xfd, 0xf4, 0xcc, 0x92, 0x8c, - 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xe2, 0xec, 0xcc, 0x02, 0xdd, 0xdc, 0xd4, 0x32, 0x24, - 0x23, 0x2a, 0x90, 0xd8, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0x20, 0x33, 0x06, 0x04, - 0x00, 0x00, 0xff, 0xff, 0x5d, 0xe7, 0x26, 0x76, 0xc9, 0x01, 0x00, 0x00, + 0x99, 0x9f, 0x57, 0x0c, 0x95, 0x55, 0xc6, 0x61, 0x5f, 0x41, 0x62, 0x51, 0x62, 0x2e, 0x4c, 0x91, + 0x0a, 0x0e, 0x45, 0xe9, 0xa9, 0x79, 0xa9, 0xc5, 0x99, 0x50, 0x55, 0x4a, 0xfc, 0x5c, 0xbc, 0x01, + 0x60, 0x5d, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x4a, 0x7e, 0x5c, 0x7c, 0x30, 0x81, 0xe2, + 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x21, 0x1b, 0x2e, 0x36, 0x88, 0xc1, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, + 0xdc, 0x46, 0x72, 0x7a, 0xd8, 0xbd, 0xa2, 0x07, 0xd1, 0xe7, 0xc4, 0x72, 0xe2, 0x9e, 0x3c, 0x43, + 0x10, 0x54, 0x8f, 0x12, 0x1f, 0x17, 0x4f, 0x70, 0x49, 0x62, 0x49, 0x2a, 0xcc, 0x7c, 0x2f, 0x2e, + 0x5e, 0x28, 0x1f, 0x6a, 0xbc, 0x25, 0x17, 0x6b, 0x31, 0x48, 0x00, 0x6a, 0xba, 0x2c, 0x2e, 0xd3, + 0xc1, 0xba, 0xa0, 0x86, 0x43, 0x74, 0x18, 0x7d, 0x64, 0xe4, 0x62, 0x0d, 0x04, 0x85, 0xb1, 0x50, + 0x29, 0x17, 0x1b, 0xc4, 0x76, 0x21, 0x55, 0xfc, 0xae, 0x83, 0x3a, 0x43, 0x4a, 0x8d, 0x90, 0x32, + 0x88, 0xeb, 0x94, 0x64, 0x9a, 0x2e, 0x3f, 0x99, 0xcc, 0x24, 0x26, 0x24, 0x82, 0x2d, 0xa4, 0x85, + 0x0a, 0xb9, 0x58, 0xc1, 0xce, 0x12, 0x52, 0xc1, 0xeb, 0x6a, 0x98, 0xa5, 0xaa, 0x04, 0x54, 0x41, + 0xed, 0x94, 0x06, 0xdb, 0x29, 0x2a, 0x24, 0x8c, 0x6a, 0x27, 0xd8, 0xcf, 0x4e, 0x9e, 0x27, 0x1e, + 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, + 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x9f, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, + 0x97, 0x9c, 0x9f, 0xab, 0x5f, 0x9c, 0x9d, 0x59, 0xa0, 0x9b, 0x9b, 0x5a, 0x86, 0x64, 0x42, 0x05, + 0x12, 0xbb, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x9c, 0x04, 0x8c, 0x01, 0x01, 0x00, 0x00, + 0xff, 0xff, 0x49, 0x79, 0x9e, 0x42, 0xbf, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -155,6 +244,8 @@ const _ = grpc.SupportPackageIsVersion4 type QueryClient interface { // Params returns the current feemarket module parameters. Params(ctx context.Context, in *ParamsRequest, opts ...grpc.CallOption) (*ParamsResponse, error) + // State returns the current feemarket module state. + State(ctx context.Context, in *StateRequest, opts ...grpc.CallOption) (*StateResponse, error) } type queryClient struct { @@ -174,10 +265,21 @@ func (c *queryClient) Params(ctx context.Context, in *ParamsRequest, opts ...grp return out, nil } +func (c *queryClient) State(ctx context.Context, in *StateRequest, opts ...grpc.CallOption) (*StateResponse, error) { + out := new(StateResponse) + err := c.cc.Invoke(ctx, "/feemarket.feemarket.v1.Query/State", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Params returns the current feemarket module parameters. Params(context.Context, *ParamsRequest) (*ParamsResponse, error) + // State returns the current feemarket module state. + State(context.Context, *StateRequest) (*StateResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -187,6 +289,9 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) Params(ctx context.Context, req *ParamsRequest) (*ParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") } +func (*UnimplementedQueryServer) State(ctx context.Context, req *StateRequest) (*StateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method State not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -210,6 +315,24 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } +func _Query_State_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).State(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/feemarket.feemarket.v1.Query/State", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).State(ctx, req.(*StateRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "feemarket.feemarket.v1.Query", HandlerType: (*QueryServer)(nil), @@ -218,6 +341,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "Params", Handler: _Query_Params_Handler, }, + { + MethodName: "State", + Handler: _Query_State_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "feemarket/feemarket/v1/query.proto", @@ -279,6 +406,62 @@ func (m *ParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *StateRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *StateRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StateRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *StateResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *StateResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.State.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -310,6 +493,26 @@ func (m *ParamsResponse) Size() (n int) { return n } +func (m *StateRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *StateResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.State.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -449,6 +652,139 @@ func (m *ParamsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *StateRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: StateRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StateRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *StateResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: StateResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StateResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field State", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.State.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/feemarket/types/query.pb.gw.go b/x/feemarket/types/query.pb.gw.go index 3cc3407..ed8c553 100644 --- a/x/feemarket/types/query.pb.gw.go +++ b/x/feemarket/types/query.pb.gw.go @@ -51,6 +51,24 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal } +func request_Query_State_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq StateRequest + var metadata runtime.ServerMetadata + + msg, err := client.State(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_State_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq StateRequest + var metadata runtime.ServerMetadata + + msg, err := server.State(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -80,6 +98,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_State_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_State_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_State_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -141,13 +182,37 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_State_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_State_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_State_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } var ( pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"feemarket", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_State_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"feemarket", "v1", "state"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( forward_Query_Params_0 = runtime.ForwardResponseMessage + + forward_Query_State_0 = runtime.ForwardResponseMessage ) From c11844d433e74716e04bd5391a533e63549c7249 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 29 Nov 2023 14:21:47 -0500 Subject: [PATCH 04/53] test: --- x/feemarket/keeper/keeper_test.go | 3 ++ x/feemarket/keeper/query_server_test.go | 42 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/x/feemarket/keeper/keeper_test.go b/x/feemarket/keeper/keeper_test.go index 75694ef..69ce456 100644 --- a/x/feemarket/keeper/keeper_test.go +++ b/x/feemarket/keeper/keeper_test.go @@ -56,6 +56,9 @@ func (s *KeeperTestSuite) SetupTest() { err := s.feemarketKeeper.SetParams(s.ctx, types.DefaultParams()) s.Require().NoError(err) + err = s.feemarketKeeper.SetState(s.ctx, types.DefaultState()) + s.Require().NoError(err) + s.msgServer = keeper.NewMsgServer(*s.feemarketKeeper) s.queryServer = keeper.NewQueryServer(*s.feemarketKeeper) } diff --git a/x/feemarket/keeper/query_server_test.go b/x/feemarket/keeper/query_server_test.go index fd91bf2..ab9e1c9 100644 --- a/x/feemarket/keeper/query_server_test.go +++ b/x/feemarket/keeper/query_server_test.go @@ -51,3 +51,45 @@ func (s *KeeperTestSuite) TestParamsRequest() { s.Require().Equal(resp.Params, params) }) } + +func (s *KeeperTestSuite) TestStateRequest() { + s.Run("can get default state", func() { + req := &types.StateRequest{} + resp, err := s.queryServer.State(s.ctx, req) + s.Require().NoError(err) + s.Require().NotNil(resp) + + s.Require().Equal(types.DefaultState(), resp.State) + + state, err := s.feemarketKeeper.GetState(s.ctx) + s.Require().NoError(err) + + s.Require().Equal(resp.State, state) + }) + + s.Run("can get updated params", func() { + state := types.State{ + BaseFee: math.OneInt(), + MinBaseFee: math.OneInt(), + LearningRate: math.LegacyOneDec(), + Window: []uint64{1}, + Index: 0, + MaxBlockUtilization: 10, + TargetBlockUtilization: 5, + } + err := s.feemarketKeeper.SetState(s.ctx, state) + s.Require().NoError(err) + + req := &types.StateRequest{} + resp, err := s.queryServer.State(s.ctx, req) + s.Require().NoError(err) + s.Require().NotNil(resp) + + s.Require().Equal(state, resp.State) + + state, err = s.feemarketKeeper.GetState(s.ctx) + s.Require().NoError(err) + + s.Require().Equal(resp.State, state) + }) +} From 84e8063c5d95a7675d079092f038b63ee7d5fe1b Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 29 Nov 2023 15:01:16 -0500 Subject: [PATCH 05/53] wip --- tests/integration/integration_test.go | 2 -- tests/integration/setup.go | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 6acf54a..63a3b48 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -1,7 +1,6 @@ package integration_test import ( - "fmt" "testing" "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -62,7 +61,6 @@ var ( Bech32Prefix: "cosmos", CoinType: "118", GasAdjustment: gasAdjustment, - GasPrices: fmt.Sprintf("200%s", denom), TrustingPeriod: "48h", NoHostMount: noHostMount, ModifyGenesis: cosmos.ModifyGenesis(genesisKV), diff --git a/tests/integration/setup.go b/tests/integration/setup.go index 6151df2..f8cb6ee 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -122,6 +122,9 @@ func (s *TestSuite) CreateTx(ctx context.Context, user cosmos.User, fees sdk.Coi // get gas for tx txf.WithGas(25000000) + // set gas prices to 0 so that fees are used + txf.WithGasPrices("") + // update sequence number txf = txf.WithSequence(txf.Sequence()) From ad9cad8d0592af57f129753e45bb2d41d1891edb Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 29 Nov 2023 15:03:47 -0500 Subject: [PATCH 06/53] remove test --- x/feemarket/keeper/keeper_test.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/x/feemarket/keeper/keeper_test.go b/x/feemarket/keeper/keeper_test.go index 69ce456..5343e35 100644 --- a/x/feemarket/keeper/keeper_test.go +++ b/x/feemarket/keeper/keeper_test.go @@ -64,13 +64,6 @@ func (s *KeeperTestSuite) SetupTest() { } func (s *KeeperTestSuite) TestState() { - s.Run("get state with no state set", func() { - gotState, err := s.feemarketKeeper.GetState(s.ctx) - s.Require().NoError(err) - - s.Require().Equal(types.State{}, gotState) - }) - s.Run("set and get default eip1559 state", func() { state := types.DefaultState() From c354608762ef9319dedddd590b5211b8b8f738c5 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 29 Nov 2023 15:45:48 -0500 Subject: [PATCH 07/53] fix --- tests/integration/integration_test.go | 2 ++ tests/integration/setup.go | 14 +++++++------- tests/integration/suite.go | 2 -- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 63a3b48..6acf54a 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -1,6 +1,7 @@ package integration_test import ( + "fmt" "testing" "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -61,6 +62,7 @@ var ( Bech32Prefix: "cosmos", CoinType: "118", GasAdjustment: gasAdjustment, + GasPrices: fmt.Sprintf("200%s", denom), TrustingPeriod: "48h", NoHostMount: noHostMount, ModifyGenesis: cosmos.ModifyGenesis(genesisKV), diff --git a/tests/integration/setup.go b/tests/integration/setup.go index f8cb6ee..10b9a11 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -71,7 +71,7 @@ func BuildInterchain(t *testing.T, ctx context.Context, chain ibc.Chain) *interc ic.AddChain(chain) // create docker network - client, networkID := interchaintest.DockerSetup(t) + dockerClient, networkID := interchaintest.DockerSetup(t) ctx, cancel := context.WithTimeout(ctx, 2*time.Minute) defer cancel() @@ -79,7 +79,7 @@ func BuildInterchain(t *testing.T, ctx context.Context, chain ibc.Chain) *interc // build the interchain err := ic.Build(ctx, nil, interchaintest.InterchainBuildOptions{ SkipPathCreation: true, - Client: client, + Client: dockerClient, NetworkID: networkID, TestName: t.Name(), }) @@ -89,7 +89,7 @@ func BuildInterchain(t *testing.T, ctx context.Context, chain ibc.Chain) *interc } // SendCoins creates a bank SendCoins message and broadcasts the transaction with commit. -func (s *TestSuite) SendCoins(ctx context.Context, chain *cosmos.CosmosChain, sender, reciever cosmos.User, amt, fees sdk.Coins) (*coretypes.ResultBroadcastTxCommit, error) { +func (s *TestSuite) SendCoins(ctx context.Context, chain *cosmos.CosmosChain, sender, receiver cosmos.User, amt, fees sdk.Coins) (*coretypes.ResultBroadcastTxCommit, error) { msg := &banktypes.MsgSend{ FromAddress: sender.FormattedAddress(), ToAddress: reciever.FormattedAddress(), @@ -120,10 +120,10 @@ func (s *TestSuite) CreateTx(ctx context.Context, user cosmos.User, fees sdk.Coi txf = txf.WithSimulateAndExecute(true) // get gas for tx - txf.WithGas(25000000) + txf = txf.WithGas(25000000) // set gas prices to 0 so that fees are used - txf.WithGasPrices("") + txf = txf.WithGasPrices("") // update sequence number txf = txf.WithSequence(txf.Sequence()) @@ -135,7 +135,7 @@ func (s *TestSuite) CreateTx(ctx context.Context, user cosmos.User, fees sdk.Coi txBuilder, err := txf.BuildUnsignedTx(msgs...) s.Require().NoError(err) - s.Require().NoError(tx.Sign(txf, cc.GetFromName(), txBuilder, true)) + s.Require().NoError(tx.Sign(txf, user.KeyName(), txBuilder, true)) // encode and return bz, err := cc.TxConfig.TxEncoder()(txBuilder.GetTx()) @@ -430,7 +430,7 @@ func (s *TestSuite) GetAndFundTestUserWithMnemonic( } facuetWallet := cosmos.NewWallet( - "", + interchaintest.FaucetAccountKeyName, addrBz, interchaintest.FaucetAccountKeyName, chainCfg, diff --git a/tests/integration/suite.go b/tests/integration/suite.go index 3dfa9cf..7e03b31 100644 --- a/tests/integration/suite.go +++ b/tests/integration/suite.go @@ -90,7 +90,6 @@ func (s *TestSuite) SetupSuite() { s.user1 = s.GetAndFundTestUsers(ctx, s.T().Name(), initBalance, cc)[0] s.user2 = s.GetAndFundTestUsers(ctx, s.T().Name(), initBalance, cc)[0] s.user3 = s.GetAndFundTestUsers(ctx, s.T().Name(), initBalance, cc)[0] - } func (s *TestSuite) TearDownSuite() { @@ -104,7 +103,6 @@ func (s *TestSuite) SetupSubTest() { height, err := s.chain.(*cosmos.CosmosChain).Height(context.Background()) s.Require().NoError(err) s.WaitForHeight(s.chain.(*cosmos.CosmosChain), height+1) - } func (s *TestSuite) TestQueryParams() { From 69f64d299a8eef61efb9c9bd817949f5914eea72 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 29 Nov 2023 16:08:05 -0500 Subject: [PATCH 08/53] fix --- tests/integration/setup.go | 2 +- tests/integration/suite.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/integration/setup.go b/tests/integration/setup.go index 10b9a11..e8aa57e 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -92,7 +92,7 @@ func BuildInterchain(t *testing.T, ctx context.Context, chain ibc.Chain) *interc func (s *TestSuite) SendCoins(ctx context.Context, chain *cosmos.CosmosChain, sender, receiver cosmos.User, amt, fees sdk.Coins) (*coretypes.ResultBroadcastTxCommit, error) { msg := &banktypes.MsgSend{ FromAddress: sender.FormattedAddress(), - ToAddress: reciever.FormattedAddress(), + ToAddress: receiver.FormattedAddress(), Amount: amt, } diff --git a/tests/integration/suite.go b/tests/integration/suite.go index 7e03b31..1600b3c 100644 --- a/tests/integration/suite.go +++ b/tests/integration/suite.go @@ -3,14 +3,13 @@ package integration import ( "context" - "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v7/ibc" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" ) @@ -35,7 +34,7 @@ type TestSuite struct { // overrides for key-ring configuration of the broadcaster broadcasterOverrides *KeyringOverride - // broadcaster is the RPC interface to the ITS network + // bc is the RPC interface to the ITS network bc *cosmos.Broadcaster cdc codec.Codec @@ -103,6 +102,13 @@ func (s *TestSuite) SetupSubTest() { height, err := s.chain.(*cosmos.CosmosChain).Height(context.Background()) s.Require().NoError(err) s.WaitForHeight(s.chain.(*cosmos.CosmosChain), height+1) + + params := s.QueryParams() + state := s.QueryState() + + s.T().Log("new test case at block height ", height+1) + s.T().Log("params", params) + s.T().Log("state", state) } func (s *TestSuite) TestQueryParams() { From 83b539fb6e486740509955aa2a056a54bbac60f7 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 29 Nov 2023 17:07:36 -0500 Subject: [PATCH 09/53] wip --- tests/integration/setup.go | 2 +- tests/integration/suite.go | 45 ++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/tests/integration/setup.go b/tests/integration/setup.go index e8aa57e..1a63a94 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -135,7 +135,7 @@ func (s *TestSuite) CreateTx(ctx context.Context, user cosmos.User, fees sdk.Coi txBuilder, err := txf.BuildUnsignedTx(msgs...) s.Require().NoError(err) - s.Require().NoError(tx.Sign(txf, user.KeyName(), txBuilder, true)) + s.Require().NoError(tx.Sign(txf, cc.GetFromName(), txBuilder, true)) // encode and return bz, err := cc.TxConfig.TxEncoder()(txBuilder.GetTx()) diff --git a/tests/integration/suite.go b/tests/integration/suite.go index 1600b3c..73b8c8b 100644 --- a/tests/integration/suite.go +++ b/tests/integration/suite.go @@ -2,15 +2,16 @@ package integration import ( "context" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v7/ibc" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "strings" ) const ( @@ -89,6 +90,10 @@ func (s *TestSuite) SetupSuite() { s.user1 = s.GetAndFundTestUsers(ctx, s.T().Name(), initBalance, cc)[0] s.user2 = s.GetAndFundTestUsers(ctx, s.T().Name(), initBalance, cc)[0] s.user3 = s.GetAndFundTestUsers(ctx, s.T().Name(), initBalance, cc)[0] + + // create the broadcaster + s.T().Log("creating broadcaster") + s.setupBroadcaster() } func (s *TestSuite) TearDownSuite() { @@ -106,12 +111,14 @@ func (s *TestSuite) SetupSubTest() { params := s.QueryParams() state := s.QueryState() - s.T().Log("new test case at block height ", height+1) - s.T().Log("params", params) - s.T().Log("state", state) + s.T().Log("new test case at block height", height+1) + s.T().Log("params:", params.String()) + s.T().Log("state:", state.String()) } func (s *TestSuite) TestQueryParams() { + s.SetupSubTest() + // query params params := s.QueryParams() @@ -120,9 +127,39 @@ func (s *TestSuite) TestQueryParams() { } func (s *TestSuite) TestQueryState() { + s.SetupSubTest() + // query params state := s.QueryState() // expect validate to pass require.NoError(s.T(), state.ValidateBasic(), state) } + +func (s *TestSuite) TestSendTxUpdating() { + s.SetupSubTest() + + // cast chain to cosmos-chain + cosmosChain, ok := s.chain.(*cosmos.CosmosChain) + s.Require().True(ok) + // get nodes + nodes := cosmosChain.Nodes() + s.Require().True(len(nodes) > 0) + + // make params query to first node + resp, _, err := nodes[0].ExecQuery(context.Background(), "auth", "accounts") + s.Require().NoError(err) + + // unmarshal params + var accs authtypes.QueryAccountsResponse + err = s.cdc.UnmarshalJSON(resp, &accs) + s.Require().NoError(err) + + s.T().Log(string(resp)) + + for _, acc := range accs.Accounts { + if strings.Contains(string(acc.Value), s.user1.FormattedAddress()) { + s.T().Log(string(acc.Value), s.user1.FormattedAddress()) + } + } +} From 642dea135507f338fd3da72d687cd2d5df41b427 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 30 Nov 2023 10:50:19 -0500 Subject: [PATCH 10/53] wrong --- tests/integration/suite.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/tests/integration/suite.go b/tests/integration/suite.go index 73b8c8b..a596c86 100644 --- a/tests/integration/suite.go +++ b/tests/integration/suite.go @@ -11,7 +11,6 @@ import ( "github.com/strangelove-ventures/interchaintest/v7/ibc" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "strings" ) const ( @@ -147,19 +146,13 @@ func (s *TestSuite) TestSendTxUpdating() { s.Require().True(len(nodes) > 0) // make params query to first node - resp, _, err := nodes[0].ExecQuery(context.Background(), "auth", "accounts") + resp, _, err := nodes[0].ExecQuery(context.Background(), "auth", "account", s.user1.FormattedAddress()) s.Require().NoError(err) // unmarshal params - var accs authtypes.QueryAccountsResponse - err = s.cdc.UnmarshalJSON(resp, &accs) + var acc authtypes.QueryAccountResponse + err = s.cdc.UnmarshalJSON(resp, &acc) s.Require().NoError(err) s.T().Log(string(resp)) - - for _, acc := range accs.Accounts { - if strings.Contains(string(acc.Value), s.user1.FormattedAddress()) { - s.T().Log(string(acc.Value), s.user1.FormattedAddress()) - } - } } From 70d9fdcb0c000efe6fdb20383f55d2d835bccdca Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 30 Nov 2023 11:31:04 -0500 Subject: [PATCH 11/53] working --- tests/integration/setup.go | 94 ++++++++++---------------------------- tests/integration/suite.go | 8 ++-- 2 files changed, 29 insertions(+), 73 deletions(-) diff --git a/tests/integration/setup.go b/tests/integration/setup.go index 1a63a94..771f69b 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/strangelove-ventures/interchaintest/v7" "io" "math/rand" "os" @@ -15,7 +16,6 @@ import ( "testing" "time" - coretypes "github.com/cometbft/cometbft/rpc/core/types" rpctypes "github.com/cometbft/cometbft/rpc/core/types" comettypes "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/client" @@ -25,9 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v7/ibc" "github.com/strangelove-ventures/interchaintest/v7/testutil" @@ -88,61 +86,6 @@ func BuildInterchain(t *testing.T, ctx context.Context, chain ibc.Chain) *interc return ic } -// SendCoins creates a bank SendCoins message and broadcasts the transaction with commit. -func (s *TestSuite) SendCoins(ctx context.Context, chain *cosmos.CosmosChain, sender, receiver cosmos.User, amt, fees sdk.Coins) (*coretypes.ResultBroadcastTxCommit, error) { - msg := &banktypes.MsgSend{ - FromAddress: sender.FormattedAddress(), - ToAddress: receiver.FormattedAddress(), - Amount: amt, - } - - txbz := s.CreateTx(ctx, sender, fees, msg) - - // get an rpc endpoint for the chain - nodeClient := chain.FullNodes[0].Client - return nodeClient.BroadcastTxCommit(context.Background(), txbz) -} - -// CreateTx creates a new transaction to be signed by the given user, including a provided set of messages -func (s *TestSuite) CreateTx(ctx context.Context, user cosmos.User, fees sdk.Coins, msgs ...sdk.Msg) []byte { - // create tx factory + Client Context - txf, err := s.bc.GetFactory(ctx, user) - s.Require().NoError(err) - - cc, err := s.bc.GetClientContext(ctx, user) - s.Require().NoError(err) - - txf = txf.WithSimulateAndExecute(true) - - txf, err = txf.Prepare(cc) - s.Require().NoError(err) - - txf = txf.WithSimulateAndExecute(true) - - // get gas for tx - txf = txf.WithGas(25000000) - - // set gas prices to 0 so that fees are used - txf = txf.WithGasPrices("") - - // update sequence number - txf = txf.WithSequence(txf.Sequence()) - - // set fee - txf = txf.WithFees(fees.String()) - - // sign the tx - txBuilder, err := txf.BuildUnsignedTx(msgs...) - s.Require().NoError(err) - - s.Require().NoError(tx.Sign(txf, cc.GetFromName(), txBuilder, true)) - - // encode and return - bz, err := cc.TxConfig.TxEncoder()(txBuilder.GetTx()) - s.Require().NoError(err) - return bz -} - // SimulateTx simulates the provided messages, and checks whether the provided failure condition is met func (s *TestSuite) SimulateTx(ctx context.Context, user cosmos.User, height uint64, expectFail bool, msgs ...sdk.Msg) { // create tx factory + Client Context @@ -408,6 +351,24 @@ func (s *TestSuite) keyringDirFromNode() string { return localDir } +// SendCoins creates a executes a SendCoins message and broadcasts the transaction. +func (s *TestSuite) SendCoins(ctx context.Context, chain *cosmos.CosmosChain, keyName, sender, receiver string, amt, fees sdk.Coins) (string, error) { + resp, err := s.ExecTx( + ctx, + chain, + keyName, + "bank", + "send", + sender, + receiver, + amt.String(), + "--fees", + fees.String(), + ) + + return resp, err +} + // GetAndFundTestUserWithMnemonic restores a user using the given mnemonic // and funds it with the native chain denom. // The caller should wait for some blocks to complete before the funds will be accessible. @@ -424,21 +385,16 @@ func (s *TestSuite) GetAndFundTestUserWithMnemonic( return nil, fmt.Errorf("failed to get source user wallet: %w", err) } - addrBz, err := chain.GetAddress(ctx, interchaintest.FaucetAccountKeyName) - if err != nil { - return nil, fmt.Errorf("failed to get faucet user address: %w", err) - } - - facuetWallet := cosmos.NewWallet( + _, err = s.SendCoins( + ctx, + chain, interchaintest.FaucetAccountKeyName, - addrBz, interchaintest.FaucetAccountKeyName, - chainCfg, + user.FormattedAddress(), + sdk.NewCoins(sdk.NewCoin(chainCfg.Denom, sdk.NewInt(amount))), + sdk.NewCoins(sdk.NewCoin(chainCfg.Denom, sdk.NewInt(200000000000))), ) - sendCoins := sdk.NewCoins(sdk.NewCoin(chainCfg.Denom, sdk.NewInt(amount))) - feeCoins := sdk.NewCoins(sdk.NewCoin(chainCfg.Denom, sdk.NewInt(200000000000))) - _, err = s.SendCoins(ctx, chain, facuetWallet, user, sendCoins, feeCoins) if err != nil { return nil, fmt.Errorf("failed to get funds from faucet: %w", err) } diff --git a/tests/integration/suite.go b/tests/integration/suite.go index a596c86..6e3f237 100644 --- a/tests/integration/suite.go +++ b/tests/integration/suite.go @@ -5,7 +5,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v7/ibc" @@ -149,9 +148,10 @@ func (s *TestSuite) TestSendTxUpdating() { resp, _, err := nodes[0].ExecQuery(context.Background(), "auth", "account", s.user1.FormattedAddress()) s.Require().NoError(err) - // unmarshal params - var acc authtypes.QueryAccountResponse - err = s.cdc.UnmarshalJSON(resp, &acc) + s.T().Log(string(resp)) + + // make params query to first node + resp, _, err = nodes[0].ExecQuery(context.Background(), "bank", "balances", s.user1.FormattedAddress()) s.Require().NoError(err) s.T().Log(string(resp)) From e31e3a01c2ffd3a2af6c62fbaa01b0841bb3a0d1 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 30 Nov 2023 14:44:51 -0500 Subject: [PATCH 12/53] fix --- tests/integration/integration_test.go | 21 +++++++++++++++--- tests/integration/setup.go | 30 ++++++++++++++++++------- tests/integration/suite.go | 32 ++++++++++++++++++--------- x/feemarket/ante/fee.go | 10 +++++++-- x/feemarket/post/fee.go | 10 +++++++++ 5 files changed, 79 insertions(+), 24 deletions(-) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 6acf54a..d0c4bc9 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module/testutil" interchaintest "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" @@ -32,8 +34,21 @@ var ( genesisKV = []cosmos.GenesisKV{ { - Key: "app_state.feemarket.params", - Value: feemarkettypes.DefaultParams(), + Key: "app_state.feemarket.params", + Value: feemarkettypes.NewParams( + feemarkettypes.DefaultWindow, + feemarkettypes.DefaultAlpha, + feemarkettypes.DefaultBeta, + feemarkettypes.DefaultTheta, + feemarkettypes.DefaultDelta, + feemarkettypes.DefaultTargetBlockSize, + feemarkettypes.DefaultMaxBlockSize, + sdk.NewInt(1000), + feemarkettypes.DefaultMinLearningRate, + feemarkettypes.DefaultMaxLearningRate, + feemarkettypes.DefaultFeeDenom, + true, + ), }, } @@ -62,7 +77,7 @@ var ( Bech32Prefix: "cosmos", CoinType: "118", GasAdjustment: gasAdjustment, - GasPrices: fmt.Sprintf("200%s", denom), + GasPrices: fmt.Sprintf("50%s", denom), TrustingPeriod: "48h", NoHostMount: noHostMount, ModifyGenesis: cosmos.ModifyGenesis(genesisKV), diff --git a/tests/integration/setup.go b/tests/integration/setup.go index 771f69b..6f7bda2 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -7,15 +7,17 @@ import ( "encoding/hex" "encoding/json" "fmt" - "github.com/strangelove-ventures/interchaintest/v7" "io" "math/rand" "os" "path" + "strconv" "strings" "testing" "time" + "github.com/strangelove-ventures/interchaintest/v7" + rpctypes "github.com/cometbft/cometbft/rpc/core/types" comettypes "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/client" @@ -352,7 +354,7 @@ func (s *TestSuite) keyringDirFromNode() string { } // SendCoins creates a executes a SendCoins message and broadcasts the transaction. -func (s *TestSuite) SendCoins(ctx context.Context, chain *cosmos.CosmosChain, keyName, sender, receiver string, amt, fees sdk.Coins) (string, error) { +func (s *TestSuite) SendCoins(ctx context.Context, chain *cosmos.CosmosChain, keyName, sender, receiver string, amt, fees sdk.Coins, gas int64) (string, error) { resp, err := s.ExecTx( ctx, chain, @@ -364,6 +366,8 @@ func (s *TestSuite) SendCoins(ctx context.Context, chain *cosmos.CosmosChain, ke amt.String(), "--fees", fees.String(), + "--gas", + strconv.FormatInt(gas, 10), ) return resp, err @@ -392,12 +396,10 @@ func (s *TestSuite) GetAndFundTestUserWithMnemonic( interchaintest.FaucetAccountKeyName, user.FormattedAddress(), sdk.NewCoins(sdk.NewCoin(chainCfg.Denom, sdk.NewInt(amount))), - sdk.NewCoins(sdk.NewCoin(chainCfg.Denom, sdk.NewInt(200000000000))), + sdk.NewCoins(sdk.NewCoin(chainCfg.Denom, sdk.NewInt(1000000000000))), + 1000000, ) - - if err != nil { - return nil, fmt.Errorf("failed to get funds from faucet: %w", err) - } + s.Require().NoError(err, "failed to get funds from faucet") return user, nil } @@ -434,7 +436,19 @@ func (s *TestSuite) GetAndFundTestUsers( func (s *TestSuite) ExecTx(ctx context.Context, chain *cosmos.CosmosChain, keyName string, command ...string) (string, error) { node := chain.FullNodes[0] - return node.ExecTx(ctx, keyName, command...) + + resp, err := node.ExecTx(ctx, keyName, command...) + s.Require().NoError(err) + + height, err := chain.Height(context.Background()) + s.Require().NoError(err) + s.WaitForHeight(chain, height+1) + + stdout, stderr, err := chain.FullNodes[0].ExecQuery(ctx, "tx", resp, "--type", "hash") + s.Require().NoError(err) + s.Require().Nil(stderr) + + return string(stdout), nil } // RandLowerCaseLetterString returns a lowercase letter string of given length diff --git a/tests/integration/suite.go b/tests/integration/suite.go index 6e3f237..d98a254 100644 --- a/tests/integration/suite.go +++ b/tests/integration/suite.go @@ -2,6 +2,7 @@ package integration import ( "context" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" @@ -13,7 +14,7 @@ import ( ) const ( - initBalance = 1000000000000 + initBalance = 10000000000000 ) // TestSuite runs the feemarket integration test-suite against a given interchaintest specification @@ -137,6 +138,8 @@ func (s *TestSuite) TestQueryState() { func (s *TestSuite) TestSendTxUpdating() { s.SetupSubTest() + ctx := context.Background() + // cast chain to cosmos-chain cosmosChain, ok := s.chain.(*cosmos.CosmosChain) s.Require().True(ok) @@ -144,15 +147,22 @@ func (s *TestSuite) TestSendTxUpdating() { nodes := cosmosChain.Nodes() s.Require().True(len(nodes) > 0) - // make params query to first node - resp, _, err := nodes[0].ExecQuery(context.Background(), "auth", "account", s.user1.FormattedAddress()) - s.Require().NoError(err) - - s.T().Log(string(resp)) - - // make params query to first node - resp, _, err = nodes[0].ExecQuery(context.Background(), "bank", "balances", s.user1.FormattedAddress()) - s.Require().NoError(err) + state := s.QueryState() + params := s.QueryParams() - s.T().Log(string(resp)) + gas := int64(1000000) + minBaseFee := sdk.NewCoins(sdk.NewCoin(params.FeeDenom, state.MinBaseFee.MulRaw(gas))) + + // send with the exact expected fee + _, err := s.SendCoins( + ctx, + cosmosChain, + s.user1.KeyName(), + s.user1.FormattedAddress(), + s.user2.FormattedAddress(), + sdk.NewCoins(sdk.NewCoin(cosmosChain.Config().Denom, sdk.NewInt(10000))), + minBaseFee, + gas, + ) + s.Require().NoError(err, s.user1.FormattedAddress(), s.user2.FormattedAddress()) } diff --git a/x/feemarket/ante/fee.go b/x/feemarket/ante/fee.go index 53dc0e9..170dc4b 100644 --- a/x/feemarket/ante/fee.go +++ b/x/feemarket/ante/fee.go @@ -49,10 +49,16 @@ func (dfd FeeMarketCheckDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula fee := feeTx.GetFee() gas := feeTx.GetGas() // use provided gas limit + ctx.Logger().Info("fee deduct ante handle", + "min gas prices", minGasPrices, + "fee", fee, + "gas limit", gas, + ) + if !simulate { fee, _, err = CheckTxFees(minGasPrices, feeTx, gas) if err != nil { - return ctx, err + return ctx, errorsmod.Wrapf(err, "error checking fee") } } @@ -82,7 +88,7 @@ func CheckTxFees(minFees sdk.Coins, feeTx sdk.FeeTx, gas uint64) (feeCoins sdk.C } if !feeCoins.IsAnyGTE(requiredFees) { - return nil, nil, sdkerrors.ErrInsufficientFee.Wrapf("got: %s required: %s", feeCoins, requiredFees) + return nil, nil, sdkerrors.ErrInsufficientFee.Wrapf("got: %s required: %s, minGasPrices: %s, gas: %d", feeCoins, requiredFees, minGasPrices, gas) } tip = feeCoins.Sub(minFees...) // tip is the difference between feeCoins and the min fees diff --git a/x/feemarket/post/fee.go b/x/feemarket/post/fee.go index 425c607..b7aacb0 100644 --- a/x/feemarket/post/fee.go +++ b/x/feemarket/post/fee.go @@ -63,6 +63,11 @@ func (dfd FeeMarketDeductDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simul fee := feeTx.GetFee() gas := ctx.GasMeter().GasConsumed() // use context gas consumed + ctx.Logger().Info("fee deduct post handle", + "min gas prices", minGasPrices, + "gas consumed", gas, + ) + if !simulate { fee, tip, err = ante.CheckTxFees(minGasPrices, feeTx, gas) if err != nil { @@ -70,6 +75,11 @@ func (dfd FeeMarketDeductDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simul } } + ctx.Logger().Info("fee deduct post handle", + "fee", fee, + "tip", tip, + ) + if err := dfd.DeductFeeAndTip(ctx, tx, fee, tip); err != nil { return ctx, err } From 127a2b1d6115a6c50060bc200eb1456bd4041e95 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 30 Nov 2023 14:49:29 -0500 Subject: [PATCH 13/53] fix --- tests/integration/suite.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/integration/suite.go b/tests/integration/suite.go index d98a254..eb2e5a4 100644 --- a/tests/integration/suite.go +++ b/tests/integration/suite.go @@ -6,7 +6,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v7/ibc" "github.com/stretchr/testify/require" @@ -111,7 +110,6 @@ func (s *TestSuite) SetupSubTest() { state := s.QueryState() s.T().Log("new test case at block height", height+1) - s.T().Log("params:", params.String()) s.T().Log("state:", state.String()) } From bc36f96de82f7b21ffad7f88ba8806df14284358 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 30 Nov 2023 15:34:38 -0500 Subject: [PATCH 14/53] refactor to use params --- proto/feemarket/feemarket/v1/genesis.proto | 22 +- tests/integration/suite.go | 2 +- x/feemarket/keeper/feemarket.go | 12 +- x/feemarket/keeper/feemarket_test.go | 65 ++--- x/feemarket/keeper/genesis.go | 9 - x/feemarket/keeper/genesis_test.go | 18 -- x/feemarket/keeper/query_server_test.go | 11 +- x/feemarket/post/expected_keeper.go | 1 + x/feemarket/post/fee.go | 25 +- x/feemarket/types/eip1559.go | 14 +- x/feemarket/types/eip1559_aimd.go | 2 - x/feemarket/types/genesis.pb.go | 191 +++----------- x/feemarket/types/state.go | 66 ++--- x/feemarket/types/state_fuzz_test.go | 32 ++- x/feemarket/types/state_test.go | 277 ++++++++++----------- 15 files changed, 275 insertions(+), 472 deletions(-) diff --git a/proto/feemarket/feemarket/v1/genesis.proto b/proto/feemarket/feemarket/v1/genesis.proto index 4653282..968e883 100644 --- a/proto/feemarket/feemarket/v1/genesis.proto +++ b/proto/feemarket/feemarket/v1/genesis.proto @@ -30,16 +30,8 @@ message State { (gogoproto.nullable) = false ]; - // MinBaseFee is the minimum base fee that can be charged. This is denominated - // in the fee per gas unit. - string min_base_fee = 2 [ - (cosmos_proto.scalar) = "cosmos.Int", - (gogoproto.customtype) = "cosmossdk.io/math.Int", - (gogoproto.nullable) = false - ]; - // LearningRate is the current learning rate. - string learning_rate = 3 [ + string learning_rate = 2 [ (cosmos_proto.scalar) = "cosmos.Legacy", (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false @@ -48,16 +40,8 @@ message State { // Window contains a list of the last blocks' utilization values. This is used // to calculate the next base fee. This stores the number of units of gas // consumed per block. - repeated uint64 window = 4; + repeated uint64 window = 3; // Index is the index of the current block in the block utilization window. - uint64 index = 5; - - // MaxBlockUtilization is the maximum utilization of a given block. This is - // denominated in the number of gas units consumed per block. - uint64 max_block_utilization = 6; - - // TargetBlockUtilization is the target utilization of a given block. This is - // denominated in the number of gas units consumed per block. - uint64 target_block_utilization = 7; + uint64 index = 4; } diff --git a/tests/integration/suite.go b/tests/integration/suite.go index eb2e5a4..60c4e0b 100644 --- a/tests/integration/suite.go +++ b/tests/integration/suite.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v7/ibc" "github.com/stretchr/testify/require" @@ -106,7 +107,6 @@ func (s *TestSuite) SetupSubTest() { s.Require().NoError(err) s.WaitForHeight(s.chain.(*cosmos.CosmosChain), height+1) - params := s.QueryParams() state := s.QueryState() s.T().Log("new test case at block height", height+1) diff --git a/x/feemarket/keeper/feemarket.go b/x/feemarket/keeper/feemarket.go index 7c3feac..d95d725 100644 --- a/x/feemarket/keeper/feemarket.go +++ b/x/feemarket/keeper/feemarket.go @@ -28,23 +28,19 @@ func (k *Keeper) UpdateFeeMarket(ctx sdk.Context) error { // Update the learning rate based on the block utilization seen in the // current block. This is the AIMD learning rate adjustment algorithm. newLR := state.UpdateLearningRate( - params.Theta, - params.Alpha, - params.Beta, - params.MinLearningRate, - params.MaxLearningRate, + params, ) // Update the base fee based with the new learning rate and delta adjustment. - newBaseFee := state.UpdateBaseFee(params.Delta) + newBaseFee := state.UpdateBaseFee(params) k.Logger(ctx).Info( "updated the fee market", "height", ctx.BlockHeight(), "new_base_fee", newBaseFee, "new_learning_rate", newLR, - "average_block_utilization", state.GetAverageUtilization(), - "net_block_utilization", state.GetNetUtilization(), + "average_block_utilization", state.GetAverageUtilization(params), + "net_block_utilization", state.GetNetUtilization(params), ) // Increment the height of the state and set the new state. diff --git a/x/feemarket/keeper/feemarket_test.go b/x/feemarket/keeper/feemarket_test.go index 09565e8..ad5a600 100644 --- a/x/feemarket/keeper/feemarket_test.go +++ b/x/feemarket/keeper/feemarket_test.go @@ -70,12 +70,13 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Run("target block with default eip1559 at min base fee", func() { state := types.DefaultState() + params := types.DefaultParams() + // Reaching the target block size means that we expect this to not // increase. - err := state.Update(state.TargetBlockUtilization) + err := state.Update(params.TargetBlockUtilization, params) s.Require().NoError(err) - params := types.DefaultParams() s.setGenesisState(params, state) s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) @@ -92,13 +93,14 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Run("target block with default eip1559 at preset base fee", func() { state := types.DefaultState() + params := types.DefaultParams() + state.BaseFee = state.BaseFee.Mul(math.NewInt(2)) // Reaching the target block size means that we expect this to not // increase. - err := state.Update(state.TargetBlockUtilization) + err := state.Update(params.TargetBlockUtilization, params) s.Require().NoError(err) - params := types.DefaultParams() s.setGenesisState(params, state) s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) @@ -115,12 +117,13 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Run("max block with default eip1559 at min base fee", func() { state := types.DefaultState() + params := types.DefaultParams() + // Reaching the target block size means that we expect this to not // increase. - err := state.Update(state.MaxBlockUtilization) + err := state.Update(params.MaxBlockUtilization, params) s.Require().NoError(err) - params := types.DefaultParams() s.setGenesisState(params, state) s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) @@ -140,13 +143,14 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Run("max block with default eip1559 at preset base fee", func() { state := types.DefaultState() + params := types.DefaultParams() + state.BaseFee = state.BaseFee.Mul(math.NewInt(2)) // Reaching the target block size means that we expect this to not // increase. - err := state.Update(state.MaxBlockUtilization) + err := state.Update(params.MaxBlockUtilization, params) s.Require().NoError(err) - params := types.DefaultParams() s.setGenesisState(params, state) s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) @@ -166,14 +170,13 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Run("in-between min and target block with default eip1559 at min base fee", func() { state := types.DefaultState() - state.MaxBlockUtilization = 100 - state.TargetBlockUtilization = 50 - err := state.Update(25) - s.Require().NoError(err) - params := types.DefaultParams() params.MaxBlockUtilization = 100 params.TargetBlockUtilization = 50 + + err := state.Update(25, params) + s.Require().NoError(err) + s.setGenesisState(params, state) s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) @@ -191,14 +194,14 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Run("in-between min and target block with default eip1559 at preset base fee", func() { state := types.DefaultState() state.BaseFee = state.BaseFee.Mul(math.NewInt(2)) - state.MaxBlockUtilization = 100 - state.TargetBlockUtilization = 50 - err := state.Update(25) - s.Require().NoError(err) params := types.DefaultParams() params.MaxBlockUtilization = 100 params.TargetBlockUtilization = 50 + err := state.Update(25, params) + + s.Require().NoError(err) + s.setGenesisState(params, state) s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) @@ -218,14 +221,13 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Run("in-between target and max block with default eip1559 at min base fee", func() { state := types.DefaultState() - state.MaxBlockUtilization = 100 - state.TargetBlockUtilization = 50 - err := state.Update(75) - s.Require().NoError(err) - params := types.DefaultParams() params.MaxBlockUtilization = 100 params.TargetBlockUtilization = 50 + + err := state.Update(75, params) + s.Require().NoError(err) + s.setGenesisState(params, state) s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) @@ -246,14 +248,13 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Run("in-between target and max block with default eip1559 at preset base fee", func() { state := types.DefaultState() state.BaseFee = state.BaseFee.Mul(math.NewInt(2)) - state.MaxBlockUtilization = 100 - state.TargetBlockUtilization = 50 - err := state.Update(75) - s.Require().NoError(err) - params := types.DefaultParams() params.MaxBlockUtilization = 100 params.TargetBlockUtilization = 50 + + err := state.Update(75, params) + s.Require().NoError(err) + s.setGenesisState(params, state) s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) @@ -338,13 +339,14 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.Run("target block with aimd eip1559 at min base fee + LR", func() { state := types.DefaultAIMDState() + params := types.DefaultAIMDParams() + // Reaching the target block size means that we expect this to not // increase. for i := 0; i < len(state.Window); i++ { - state.Window[i] = state.TargetBlockUtilization + state.Window[i] = params.TargetBlockUtilization } - params := types.DefaultAIMDParams() s.setGenesisState(params, state) s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) @@ -364,13 +366,14 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { state := types.DefaultAIMDState() state.BaseFee = state.BaseFee.Mul(math.NewInt(2)) state.LearningRate = math.LegacyMustNewDecFromStr("0.125") + params := types.DefaultAIMDParams() + // Reaching the target block size means that we expect this to not // increase. for i := 0; i < len(state.Window); i++ { - state.Window[i] = state.TargetBlockUtilization + state.Window[i] = params.TargetBlockUtilization } - params := types.DefaultAIMDParams() s.setGenesisState(params, state) s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) diff --git a/x/feemarket/keeper/genesis.go b/x/feemarket/keeper/genesis.go index 453f479..5226c82 100644 --- a/x/feemarket/keeper/genesis.go +++ b/x/feemarket/keeper/genesis.go @@ -12,15 +12,6 @@ func (k *Keeper) InitGenesis(ctx sdk.Context, gs types.GenesisState) { panic(err) } - // Ensure that state and fee market match required configurations. - if gs.Params.MaxBlockUtilization != gs.State.MaxBlockUtilization { - panic("genesis state and parameters do not match for max block utilization") - } - - if gs.Params.TargetBlockUtilization != gs.State.TargetBlockUtilization { - panic("genesis state and parameters do not match for target block utilization") - } - if gs.Params.Window != uint64(len(gs.State.Window)) { panic("genesis state and parameters do not match for window") } diff --git a/x/feemarket/keeper/genesis_test.go b/x/feemarket/keeper/genesis_test.go index 31434fe..d56b461 100644 --- a/x/feemarket/keeper/genesis_test.go +++ b/x/feemarket/keeper/genesis_test.go @@ -33,24 +33,6 @@ func (s *KeeperTestSuite) TestInitGenesis() { s.feemarketKeeper.InitGenesis(s.ctx, *gs) }) }) - - s.Run("mismatch in params and state for target utilization should panic", func() { - gs := types.DefaultAIMDGenesisState() - gs.Params.TargetBlockUtilization = 1 - - s.Require().Panics(func() { - s.feemarketKeeper.InitGenesis(s.ctx, *gs) - }) - }) - - s.Run("mismatch in params and state for max utilization should panic", func() { - gs := types.DefaultAIMDGenesisState() - gs.Params.MaxBlockUtilization = 1 - - s.Require().Panics(func() { - s.feemarketKeeper.InitGenesis(s.ctx, *gs) - }) - }) } func (s *KeeperTestSuite) TestExportGenesis() { diff --git a/x/feemarket/keeper/query_server_test.go b/x/feemarket/keeper/query_server_test.go index ab9e1c9..aafdf5f 100644 --- a/x/feemarket/keeper/query_server_test.go +++ b/x/feemarket/keeper/query_server_test.go @@ -69,13 +69,10 @@ func (s *KeeperTestSuite) TestStateRequest() { s.Run("can get updated params", func() { state := types.State{ - BaseFee: math.OneInt(), - MinBaseFee: math.OneInt(), - LearningRate: math.LegacyOneDec(), - Window: []uint64{1}, - Index: 0, - MaxBlockUtilization: 10, - TargetBlockUtilization: 5, + BaseFee: math.OneInt(), + LearningRate: math.LegacyOneDec(), + Window: []uint64{1}, + Index: 0, } err := s.feemarketKeeper.SetState(s.ctx, state) s.Require().NoError(err) diff --git a/x/feemarket/post/expected_keeper.go b/x/feemarket/post/expected_keeper.go index 246e07d..bce9fb7 100644 --- a/x/feemarket/post/expected_keeper.go +++ b/x/feemarket/post/expected_keeper.go @@ -41,6 +41,7 @@ type BankKeeper interface { //go:generate mockery --name FeeMarketKeeper --filename mock_feemarket_keeper.go type FeeMarketKeeper interface { GetState(ctx sdk.Context) (feemarkettypes.State, error) + GetParams(ctx sdk.Context) (feemarkettypes.Params, error) SetState(ctx sdk.Context, state feemarkettypes.State) error GetMinGasPrices(ctx sdk.Context) (sdk.Coins, error) } diff --git a/x/feemarket/post/fee.go b/x/feemarket/post/fee.go index b7aacb0..9486f5b 100644 --- a/x/feemarket/post/fee.go +++ b/x/feemarket/post/fee.go @@ -55,11 +55,26 @@ func (dfd FeeMarketDeductDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simul var tip sdk.Coins - minGasPrices, err := dfd.feemarketKeeper.GetMinGasPrices(ctx) + // update fee market params + params, err := dfd.feemarketKeeper.GetParams(ctx) + if err != nil { + return ctx, errorsmod.Wrapf(err, "unable to get fee market params") + } + + // return if disabled + if !params.Enabled { + return next(ctx, tx, simulate, success) + } + + // update fee market state + state, err := dfd.feemarketKeeper.GetState(ctx) if err != nil { return ctx, errorsmod.Wrapf(err, "unable to get fee market state") } + baseFee := sdk.NewCoin(params.FeeDenom, state.BaseFee) + minGasPrices := sdk.NewCoins(baseFee) + fee := feeTx.GetFee() gas := ctx.GasMeter().GasConsumed() // use context gas consumed @@ -84,13 +99,7 @@ func (dfd FeeMarketDeductDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simul return ctx, err } - // update fee market state - state, err := dfd.feemarketKeeper.GetState(ctx) - if err != nil { - return ctx, errorsmod.Wrapf(err, "unable to get fee market state") - } - - err = state.Update(gas) + err = state.Update(gas, params) if err != nil { return ctx, errorsmod.Wrapf(err, "unable to update fee market state") } diff --git a/x/feemarket/types/eip1559.go b/x/feemarket/types/eip1559.go index 2d21af3..0dae6e1 100644 --- a/x/feemarket/types/eip1559.go +++ b/x/feemarket/types/eip1559.go @@ -27,13 +27,13 @@ var ( // DefaultDelta is not used in the base EIP-1559 implementation. DefaultDelta = math.LegacyMustNewDecFromStr("0.0") - // DefaultTargetBlockSize is the default target block utilization. This is the default + // DefaultTargetBlockUtilization is the default target block utilization. This is the default // on Ethereum. This denominated in units of gas consumed in a block. - DefaultTargetBlockSize uint64 = 15_000_000 + DefaultTargetBlockUtilization uint64 = 15_000_000 - // DefaultMaxBlockSize is the default maximum block utilization. This is the default + // DefaultMaxBlockUtilization is the default maximum block utilization. This is the default // on Ethereum. This denominated in units of gas consumed in a block. - DefaultMaxBlockSize uint64 = 30_000_000 + DefaultMaxBlockUtilization uint64 = 30_000_000 // DefaultMinBaseFee is the default minimum base fee. This is the default // on Ethereum. Note that Ethereum is denominated in 1e18 wei. Cosmos chains will @@ -60,8 +60,8 @@ func DefaultParams() Params { DefaultBeta, DefaultTheta, DefaultDelta, - DefaultTargetBlockSize, - DefaultMaxBlockSize, + DefaultTargetBlockUtilization, + DefaultMaxBlockUtilization, DefaultMinBaseFee, DefaultMinLearningRate, DefaultMaxLearningRate, @@ -75,8 +75,6 @@ func DefaultParams() Params { func DefaultState() State { return NewState( DefaultWindow, - DefaultTargetBlockSize, - DefaultMaxBlockSize, DefaultMinBaseFee, DefaultMinLearningRate, ) diff --git a/x/feemarket/types/eip1559_aimd.go b/x/feemarket/types/eip1559_aimd.go index 8cd102d..39c62c8 100644 --- a/x/feemarket/types/eip1559_aimd.go +++ b/x/feemarket/types/eip1559_aimd.go @@ -86,8 +86,6 @@ func DefaultAIMDParams() Params { func DefaultAIMDState() State { return NewState( DefaultAIMDWindow, - DefaultAIMDTargetBlockSize, - DefaultAIMDMaxBlockSize, DefaultAIMDMinBaseFee, DefaultAIMDMinLearningRate, ) diff --git a/x/feemarket/types/genesis.pb.go b/x/feemarket/types/genesis.pb.go index 54bda5b..6a8faf2 100644 --- a/x/feemarket/types/genesis.pb.go +++ b/x/feemarket/types/genesis.pb.go @@ -89,23 +89,14 @@ type State struct { // BaseFee is the current base fee. This is denominated in the fee per gas // unit. BaseFee cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=base_fee,json=baseFee,proto3,customtype=cosmossdk.io/math.Int" json:"base_fee"` - // MinBaseFee is the minimum base fee that can be charged. This is denominated - // in the fee per gas unit. - MinBaseFee cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=min_base_fee,json=minBaseFee,proto3,customtype=cosmossdk.io/math.Int" json:"min_base_fee"` // LearningRate is the current learning rate. - LearningRate cosmossdk_io_math.LegacyDec `protobuf:"bytes,3,opt,name=learning_rate,json=learningRate,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"learning_rate"` + LearningRate cosmossdk_io_math.LegacyDec `protobuf:"bytes,2,opt,name=learning_rate,json=learningRate,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"learning_rate"` // Window contains a list of the last blocks' utilization values. This is used // to calculate the next base fee. This stores the number of units of gas // consumed per block. - Window []uint64 `protobuf:"varint,4,rep,packed,name=window,proto3" json:"window,omitempty"` + Window []uint64 `protobuf:"varint,3,rep,packed,name=window,proto3" json:"window,omitempty"` // Index is the index of the current block in the block utilization window. - Index uint64 `protobuf:"varint,5,opt,name=index,proto3" json:"index,omitempty"` - // MaxBlockUtilization is the maximum utilization of a given block. This is - // denominated in the number of gas units consumed per block. - MaxBlockUtilization uint64 `protobuf:"varint,6,opt,name=max_block_utilization,json=maxBlockUtilization,proto3" json:"max_block_utilization,omitempty"` - // TargetBlockUtilization is the target utilization of a given block. This is - // denominated in the number of gas units consumed per block. - TargetBlockUtilization uint64 `protobuf:"varint,7,opt,name=target_block_utilization,json=targetBlockUtilization,proto3" json:"target_block_utilization,omitempty"` + Index uint64 `protobuf:"varint,4,opt,name=index,proto3" json:"index,omitempty"` } func (m *State) Reset() { *m = State{} } @@ -155,20 +146,6 @@ func (m *State) GetIndex() uint64 { return 0 } -func (m *State) GetMaxBlockUtilization() uint64 { - if m != nil { - return m.MaxBlockUtilization - } - return 0 -} - -func (m *State) GetTargetBlockUtilization() uint64 { - if m != nil { - return m.TargetBlockUtilization - } - return 0 -} - func init() { proto.RegisterType((*GenesisState)(nil), "feemarket.feemarket.v1.GenesisState") proto.RegisterType((*State)(nil), "feemarket.feemarket.v1.State") @@ -179,35 +156,31 @@ func init() { } var fileDescriptor_2180652c84279298 = []byte{ - // 447 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0x41, 0x6b, 0xd4, 0x40, - 0x14, 0xc7, 0x37, 0xdd, 0x24, 0xd5, 0x71, 0x7b, 0x89, 0xed, 0x12, 0x2b, 0xa6, 0x4b, 0xf5, 0xb0, - 0x20, 0x9b, 0xd0, 0xea, 0x41, 0xc1, 0x53, 0x90, 0xca, 0x82, 0x82, 0x44, 0x3c, 0xe8, 0x25, 0x4c, - 0xb2, 0xaf, 0xe9, 0x90, 0x9d, 0x99, 0x90, 0x99, 0x6e, 0x53, 0xbf, 0x80, 0x57, 0x2f, 0x7e, 0x93, - 0x7e, 0x88, 0x1e, 0x4b, 0x4f, 0xe2, 0xa1, 0xc8, 0xee, 0x17, 0x91, 0xcc, 0x8c, 0xdd, 0xa2, 0xdd, - 0x83, 0xb7, 0xf7, 0xe6, 0xff, 0xff, 0xff, 0xde, 0x7b, 0x30, 0xe8, 0xc9, 0x21, 0x00, 0xc5, 0x75, - 0x09, 0x32, 0x5a, 0x56, 0xb3, 0xbd, 0xa8, 0x00, 0x06, 0x82, 0x88, 0xb0, 0xaa, 0xb9, 0xe4, 0x5e, - 0xff, 0x5a, 0x0b, 0x97, 0xd5, 0x6c, 0x6f, 0x7b, 0xb3, 0xe0, 0x05, 0x57, 0x96, 0xa8, 0xad, 0xb4, - 0x7b, 0xfb, 0x41, 0xce, 0x05, 0xe5, 0x22, 0xd5, 0x82, 0x6e, 0x8c, 0xf4, 0x78, 0xc5, 0xb8, 0x0a, - 0xd7, 0x98, 0x1a, 0xd3, 0xee, 0x57, 0x0b, 0xf5, 0xde, 0xe8, 0xf9, 0x1f, 0x24, 0x96, 0xe0, 0xbd, - 0x42, 0xae, 0x36, 0xf8, 0xd6, 0xc0, 0x1a, 0xde, 0xdb, 0x0f, 0xc2, 0xdb, 0xf7, 0x09, 0xdf, 0x2b, - 0x57, 0x6c, 0x9f, 0x5f, 0xed, 0x74, 0x12, 0x93, 0xf1, 0x5e, 0x22, 0x47, 0xb4, 0x18, 0x7f, 0x4d, - 0x85, 0x1f, 0xad, 0x0a, 0xab, 0x59, 0x26, 0xab, 0x13, 0xbb, 0xdf, 0xbb, 0xc8, 0xd1, 0x2b, 0x1c, - 0xa0, 0x3b, 0x19, 0x16, 0x90, 0x1e, 0x02, 0xa8, 0x25, 0xee, 0xc6, 0x4f, 0x5b, 0xe3, 0xcf, 0xab, - 0x9d, 0x2d, 0x7d, 0xa0, 0x98, 0x94, 0x21, 0xe1, 0x11, 0xc5, 0xf2, 0x28, 0x1c, 0x33, 0x79, 0x79, - 0x36, 0x42, 0xe6, 0xf2, 0x31, 0x93, 0xc9, 0x7a, 0x1b, 0x3e, 0x00, 0xf0, 0xde, 0xa1, 0x1e, 0x25, - 0x2c, 0xbd, 0x66, 0xad, 0xfd, 0x3f, 0x0b, 0x51, 0xc2, 0x62, 0x83, 0xfb, 0x84, 0x36, 0xa6, 0x80, - 0x6b, 0x46, 0x58, 0x91, 0xd6, 0xed, 0x8d, 0x5d, 0xc5, 0x7b, 0x6e, 0x78, 0x0f, 0xff, 0xe5, 0xbd, - 0x85, 0x02, 0xe7, 0xa7, 0xaf, 0x21, 0xbf, 0x3c, 0x1b, 0x6d, 0x18, 0xaa, 0x7e, 0x4b, 0x7a, 0x7f, - 0x50, 0x49, 0x7b, 0x71, 0x1f, 0xb9, 0x27, 0x84, 0x4d, 0xf8, 0x89, 0x6f, 0x0f, 0xba, 0x43, 0x3b, - 0x31, 0x9d, 0xb7, 0x89, 0x1c, 0xc2, 0x26, 0xd0, 0xf8, 0xce, 0xc0, 0x1a, 0xda, 0x89, 0x6e, 0xbc, - 0x7d, 0xb4, 0x45, 0x71, 0x93, 0x66, 0x53, 0x9e, 0x97, 0xe9, 0xb1, 0x24, 0x53, 0xf2, 0x05, 0x4b, - 0xc2, 0x99, 0xef, 0x2a, 0xd7, 0x7d, 0x8a, 0x9b, 0xb8, 0xd5, 0x3e, 0x2e, 0x25, 0xef, 0x05, 0xf2, - 0x25, 0xae, 0x0b, 0x90, 0xb7, 0xc4, 0xd6, 0x55, 0xac, 0xaf, 0xf5, 0xbf, 0x93, 0xf1, 0xf8, 0x7c, - 0x1e, 0x58, 0x17, 0xf3, 0xc0, 0xfa, 0x35, 0x0f, 0xac, 0x6f, 0x8b, 0xa0, 0x73, 0xb1, 0x08, 0x3a, - 0x3f, 0x16, 0x41, 0xe7, 0x73, 0x54, 0x10, 0x79, 0x74, 0x9c, 0x85, 0x39, 0xa7, 0x91, 0x28, 0x49, - 0x35, 0xa2, 0x30, 0xbb, 0xf1, 0xd5, 0x9a, 0x1b, 0xb5, 0x3c, 0xad, 0x40, 0x64, 0xae, 0xfa, 0x73, - 0xcf, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0x42, 0xf0, 0xf1, 0x69, 0x09, 0x03, 0x00, 0x00, + // 374 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x51, 0xcf, 0x6a, 0xe2, 0x40, + 0x18, 0xcf, 0xac, 0xd1, 0x5d, 0x67, 0xf5, 0x12, 0x5c, 0xc9, 0xba, 0x6c, 0x14, 0x77, 0x0f, 0xc2, + 0x62, 0x82, 0xbb, 0x7b, 0x29, 0xf4, 0x14, 0x8a, 0x45, 0xe8, 0xa1, 0xa4, 0xa7, 0xf6, 0x22, 0x63, + 0xfc, 0x8c, 0xc1, 0x26, 0x13, 0x32, 0x53, 0xff, 0x3c, 0x41, 0xaf, 0x7d, 0x18, 0x1f, 0xc2, 0xa3, + 0x78, 0x92, 0x1e, 0xa4, 0xe8, 0x8b, 0x94, 0x64, 0xc6, 0x2a, 0xb4, 0xde, 0x7e, 0xdf, 0x7c, 0xbf, + 0x7f, 0xc3, 0x87, 0x7f, 0x0f, 0x00, 0x02, 0x12, 0x8f, 0x80, 0x5b, 0x07, 0x34, 0x6e, 0x59, 0x1e, + 0x84, 0xc0, 0x7c, 0x66, 0x46, 0x31, 0xe5, 0x54, 0x2b, 0xbf, 0xed, 0xcc, 0x03, 0x1a, 0xb7, 0x2a, + 0x25, 0x8f, 0x7a, 0x34, 0xa5, 0x58, 0x09, 0x12, 0xec, 0xca, 0x77, 0x97, 0xb2, 0x80, 0xb2, 0xae, + 0x58, 0x88, 0x41, 0xae, 0x7e, 0x9d, 0x88, 0x8b, 0x48, 0x4c, 0x02, 0x49, 0xaa, 0x3f, 0x22, 0x5c, + 0xb8, 0x14, 0xf9, 0x37, 0x9c, 0x70, 0xd0, 0xce, 0x71, 0x4e, 0x10, 0x74, 0x54, 0x43, 0x8d, 0xaf, + 0x7f, 0x0d, 0xf3, 0xe3, 0x3e, 0xe6, 0x75, 0xca, 0xb2, 0xd5, 0xc5, 0xa6, 0xaa, 0x38, 0x52, 0xa3, + 0x9d, 0xe1, 0x2c, 0x4b, 0x6c, 0xf4, 0x4f, 0xa9, 0xf8, 0xe7, 0x29, 0x71, 0x9a, 0x25, 0xb5, 0x42, + 0x51, 0x5f, 0x23, 0x9c, 0x15, 0x15, 0xda, 0xf8, 0x4b, 0x8f, 0x30, 0xe8, 0x0e, 0x00, 0xd2, 0x12, + 0x79, 0xfb, 0x4f, 0x42, 0x7c, 0xde, 0x54, 0xbf, 0x89, 0x0f, 0xb2, 0xfe, 0xc8, 0xf4, 0xa9, 0x15, + 0x10, 0x3e, 0x34, 0x3b, 0x21, 0x5f, 0xcd, 0x9b, 0x58, 0xfe, 0xbc, 0x13, 0x72, 0xe7, 0x73, 0x22, + 0x6e, 0x03, 0x68, 0xb7, 0xb8, 0x78, 0x0f, 0x24, 0x0e, 0xfd, 0xd0, 0xeb, 0xc6, 0xfb, 0x52, 0x79, + 0xfb, 0xbf, 0x34, 0xfb, 0xf1, 0xde, 0xec, 0x0a, 0x3c, 0xe2, 0xce, 0x2e, 0xc0, 0x5d, 0xcd, 0x9b, + 0x45, 0x69, 0x29, 0xde, 0x9c, 0xc2, 0xde, 0xca, 0x49, 0x2a, 0x96, 0x71, 0x6e, 0xe2, 0x87, 0x7d, + 0x3a, 0xd1, 0x33, 0xb5, 0x4c, 0x43, 0x75, 0xe4, 0xa4, 0x95, 0x70, 0xd6, 0x0f, 0xfb, 0x30, 0xd5, + 0xd5, 0x1a, 0x6a, 0xa8, 0x8e, 0x18, 0xec, 0xce, 0x62, 0x6b, 0xa0, 0xe5, 0xd6, 0x40, 0x2f, 0x5b, + 0x03, 0x3d, 0xed, 0x0c, 0x65, 0xb9, 0x33, 0x94, 0xf5, 0xce, 0x50, 0xee, 0x2c, 0xcf, 0xe7, 0xc3, + 0x87, 0x9e, 0xe9, 0xd2, 0xc0, 0x62, 0x23, 0x3f, 0x6a, 0x06, 0x30, 0x3e, 0xba, 0xd6, 0xf4, 0x08, + 0xf3, 0x59, 0x04, 0xac, 0x97, 0x4b, 0xcf, 0xf6, 0xef, 0x35, 0x00, 0x00, 0xff, 0xff, 0xd6, 0xcb, + 0x9b, 0x50, 0x4c, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -273,20 +246,10 @@ func (m *State) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.TargetBlockUtilization != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.TargetBlockUtilization)) - i-- - dAtA[i] = 0x38 - } - if m.MaxBlockUtilization != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.MaxBlockUtilization)) - i-- - dAtA[i] = 0x30 - } if m.Index != 0 { i = encodeVarintGenesis(dAtA, i, uint64(m.Index)) i-- - dAtA[i] = 0x28 + dAtA[i] = 0x20 } if len(m.Window) > 0 { dAtA4 := make([]byte, len(m.Window)*10) @@ -304,7 +267,7 @@ func (m *State) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], dAtA4[:j3]) i = encodeVarintGenesis(dAtA, i, uint64(j3)) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x1a } { size := m.LearningRate.Size() @@ -315,16 +278,6 @@ func (m *State) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1a - { - size := m.MinBaseFee.Size() - i -= size - if _, err := m.MinBaseFee.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- dAtA[i] = 0x12 { size := m.BaseFee.Size() @@ -371,8 +324,6 @@ func (m *State) Size() (n int) { _ = l l = m.BaseFee.Size() n += 1 + l + sovGenesis(uint64(l)) - l = m.MinBaseFee.Size() - n += 1 + l + sovGenesis(uint64(l)) l = m.LearningRate.Size() n += 1 + l + sovGenesis(uint64(l)) if len(m.Window) > 0 { @@ -385,12 +336,6 @@ func (m *State) Size() (n int) { if m.Index != 0 { n += 1 + sovGenesis(uint64(m.Index)) } - if m.MaxBlockUtilization != 0 { - n += 1 + sovGenesis(uint64(m.MaxBlockUtilization)) - } - if m.TargetBlockUtilization != 0 { - n += 1 + sovGenesis(uint64(m.TargetBlockUtilization)) - } return n } @@ -580,40 +525,6 @@ func (m *State) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinBaseFee", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.MinBaseFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field LearningRate", wireType) } @@ -647,7 +558,7 @@ func (m *State) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 4: + case 3: if wireType == 0 { var v uint64 for shift := uint(0); ; shift += 7 { @@ -723,7 +634,7 @@ func (m *State) Unmarshal(dAtA []byte) error { } else { return fmt.Errorf("proto: wrong wireType = %d for field Window", wireType) } - case 5: + case 4: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) } @@ -742,44 +653,6 @@ func (m *State) Unmarshal(dAtA []byte) error { break } } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxBlockUtilization", wireType) - } - m.MaxBlockUtilization = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MaxBlockUtilization |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TargetBlockUtilization", wireType) - } - m.TargetBlockUtilization = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TargetBlockUtilization |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/feemarket/types/state.go b/x/feemarket/types/state.go index 3ce6d9b..33b677c 100644 --- a/x/feemarket/types/state.go +++ b/x/feemarket/types/state.go @@ -11,27 +11,23 @@ import ( // AIMD EIP-1559 fee market implementation. Note that on init, you initialize // both the minimum and current base fee to the same value. func NewState( - window, - target, max uint64, + window uint64, baseFee math.Int, learningRate math.LegacyDec, ) State { return State{ - Window: make([]uint64, window), - BaseFee: baseFee, - MinBaseFee: baseFee, - LearningRate: learningRate, - Index: 0, - TargetBlockUtilization: target, - MaxBlockUtilization: max, + Window: make([]uint64, window), + BaseFee: baseFee, + Index: 0, + LearningRate: learningRate, } } // Update updates the block utilization for the current height with the given // transaction utilization i.e. gas limit. -func (s *State) Update(gas uint64) error { +func (s *State) Update(gas uint64, params Params) error { update := s.Window[s.Index] + gas - if update > s.MaxBlockUtilization { + if update > params.MaxBlockUtilization { return fmt.Errorf("block utilization cannot exceed max block utilization") } @@ -50,10 +46,10 @@ func (s *State) IncrementHeight() { // based on the average utilization of the block window. The base fee is // update using the new learning rate and the delta adjustment. Please // see the EIP-1559 specification for more details. -func (s *State) UpdateBaseFee(delta math.LegacyDec) math.Int { +func (s *State) UpdateBaseFee(params Params) math.Int { // Calculate the new base fee with the learning rate adjustment. currentBlockSize := math.LegacyNewDecFromInt(math.NewIntFromUint64(s.Window[s.Index])) - targetBlockSize := math.LegacyNewDecFromInt(math.NewIntFromUint64(s.TargetBlockUtilization)) + targetBlockSize := math.LegacyNewDecFromInt(math.NewIntFromUint64(params.TargetBlockUtilization)) utilization := (currentBlockSize.Sub(targetBlockSize)).Quo(targetBlockSize) // Truncate the learning rate adjustment to an integer. @@ -63,14 +59,14 @@ func (s *State) UpdateBaseFee(delta math.LegacyDec) math.Int { learningRateAdjustment := math.LegacyOneDec().Add(s.LearningRate.Mul(utilization)) // Calculate the delta adjustment. - net := math.LegacyNewDecFromInt(s.GetNetUtilization()).Mul(delta) + net := math.LegacyNewDecFromInt(s.GetNetUtilization(params)).Mul(params.Delta) // Update the base fee. fee := (math.LegacyNewDecFromInt(s.BaseFee).Mul(learningRateAdjustment)).Add(net).TruncateInt() // Ensure the base fee is greater than the minimum base fee. - if fee.LT(s.MinBaseFee) { - fee = s.MinBaseFee + if fee.LT(params.MinBaseFee) { + fee = params.MinBaseFee } s.BaseFee = fee @@ -90,22 +86,22 @@ func (s *State) UpdateBaseFee(delta math.LegacyDec) math.Int { // when blocks are relatively close to the target block utilization. // // For more details, please see the EIP-1559 specification. -func (s *State) UpdateLearningRate(theta, alpha, beta, minLR, maxLR math.LegacyDec) math.LegacyDec { +func (s *State) UpdateLearningRate(params Params) math.LegacyDec { // Calculate the average utilization of the block window. - avg := s.GetAverageUtilization() + avg := s.GetAverageUtilization(params) // Determine if the average utilization is above or below the target // threshold and adjust the learning rate accordingly. var updatedLearningRate math.LegacyDec - if avg.LTE(theta) || avg.GTE(math.LegacyOneDec().Sub(theta)) { - updatedLearningRate = alpha.Add(s.LearningRate) - if updatedLearningRate.GT(maxLR) { - updatedLearningRate = maxLR + if avg.LTE(params.Theta) || avg.GTE(math.LegacyOneDec().Sub(params.Theta)) { + updatedLearningRate = params.Alpha.Add(s.LearningRate) + if updatedLearningRate.GT(params.MaxLearningRate) { + updatedLearningRate = params.MaxLearningRate } } else { - updatedLearningRate = s.LearningRate.Mul(beta) - if updatedLearningRate.LT(minLR) { - updatedLearningRate = minLR + updatedLearningRate = s.LearningRate.Mul(params.Beta) + if updatedLearningRate.LT(params.MinLearningRate) { + updatedLearningRate = params.MinLearningRate } } @@ -115,10 +111,10 @@ func (s *State) UpdateLearningRate(theta, alpha, beta, minLR, maxLR math.LegacyD } // GetNetUtilization returns the net utilization of the block window. -func (s *State) GetNetUtilization() math.Int { +func (s *State) GetNetUtilization(params Params) math.Int { net := math.NewInt(0) - targetUtilization := math.NewIntFromUint64(s.TargetBlockUtilization) + targetUtilization := math.NewIntFromUint64(params.TargetBlockUtilization) for _, utilization := range s.Window { diff := math.NewIntFromUint64(utilization).Sub(targetUtilization) net = net.Add(diff) @@ -129,7 +125,7 @@ func (s *State) GetNetUtilization() math.Int { // GetAverageUtilization returns the average utilization of the block // window. -func (s *State) GetAverageUtilization() math.LegacyDec { +func (s *State) GetAverageUtilization(params Params) math.LegacyDec { var total uint64 for _, utilization := range s.Window { total += utilization @@ -138,25 +134,13 @@ func (s *State) GetAverageUtilization() math.LegacyDec { sum := math.LegacyNewDecFromInt(math.NewIntFromUint64(total)) multiple := math.LegacyNewDecFromInt(math.NewIntFromUint64(uint64(len(s.Window)))) - divisor := math.LegacyNewDecFromInt(math.NewIntFromUint64(s.MaxBlockUtilization)).Mul(multiple) + divisor := math.LegacyNewDecFromInt(math.NewIntFromUint64(params.MaxBlockUtilization)).Mul(multiple) return sum.Quo(divisor) } // ValidateBasic performs basic validation on the state. func (s *State) ValidateBasic() error { - if s.MaxBlockUtilization == 0 { - return fmt.Errorf("max utilization cannot be zero") - } - - if s.TargetBlockUtilization == 0 { - return fmt.Errorf("target utilization cannot be zero") - } - - if s.TargetBlockUtilization > s.MaxBlockUtilization { - return fmt.Errorf("target utilization cannot be greater than max utilization") - } - if s.Window == nil || len(s.Window) == 0 { return fmt.Errorf("block utilization window cannot be nil or empty") } diff --git a/x/feemarket/types/state_fuzz_test.go b/x/feemarket/types/state_fuzz_test.go index 66c6a2f..ec3c22a 100644 --- a/x/feemarket/types/state_fuzz_test.go +++ b/x/feemarket/types/state_fuzz_test.go @@ -25,16 +25,17 @@ func FuzzDefaultFeeMarket(f *testing.F) { } defaultLR := math.LegacyMustNewDecFromStr("0.125") - params := types.DefaultParams() // Default fee market. f.Fuzz(func(t *testing.T, blockGasUsed uint64) { state := types.DefaultState() - state.MinBaseFee = math.NewIntFromUint64(100) + params := types.DefaultParams() + + params.MinBaseFee = math.NewIntFromUint64(100) state.BaseFee = math.NewIntFromUint64(200) - err := state.Update(blockGasUsed) + err := state.Update(blockGasUsed, params) - if blockGasUsed > state.MaxBlockUtilization { + if blockGasUsed > params.MaxBlockUtilization { require.Error(t, err) return } @@ -44,18 +45,14 @@ func FuzzDefaultFeeMarket(f *testing.F) { // Ensure the learning rate is always the default learning rate. lr := state.UpdateLearningRate( - params.Theta, - params.Alpha, - params.Beta, - params.MinLearningRate, - params.MaxLearningRate, + params, ) require.Equal(t, defaultLR, lr) oldFee := state.BaseFee - newFee := state.UpdateBaseFee(params.Delta) + newFee := state.UpdateBaseFee(params) - if blockGasUsed > state.TargetBlockUtilization { + if blockGasUsed > params.TargetBlockUtilization { require.True(t, newFee.GT(oldFee)) } else { require.True(t, newFee.LT(oldFee)) @@ -78,17 +75,16 @@ func FuzzAIMDFeeMarket(f *testing.F) { f.Add(tc) } - params := types.DefaultAIMDParams() - // Fee market with adjustable learning rate. f.Fuzz(func(t *testing.T, blockGasUsed uint64) { state := types.DefaultAIMDState() - state.MinBaseFee = math.NewIntFromUint64(100) + params := types.DefaultAIMDParams() + params.MinBaseFee = math.NewIntFromUint64(100) state.BaseFee = math.NewIntFromUint64(200) state.Window = make([]uint64, 1) - err := state.Update(blockGasUsed) + err := state.Update(blockGasUsed, params) - if blockGasUsed > state.MaxBlockUtilization { + if blockGasUsed > params.MaxBlockUtilization { require.Error(t, err) return } @@ -97,9 +93,9 @@ func FuzzAIMDFeeMarket(f *testing.F) { require.Equal(t, blockGasUsed, state.Window[state.Index]) oldFee := state.BaseFee - newFee := state.UpdateBaseFee(params.Delta) + newFee := state.UpdateBaseFee(params) - if blockGasUsed > state.TargetBlockUtilization { + if blockGasUsed > params.TargetBlockUtilization { require.True(t, newFee.GT(oldFee)) } else { require.True(t, newFee.LT(oldFee)) diff --git a/x/feemarket/types/state_test.go b/x/feemarket/types/state_test.go index bdf8365..6dcd6e5 100644 --- a/x/feemarket/types/state_test.go +++ b/x/feemarket/types/state_test.go @@ -15,99 +15,105 @@ var OneHundred = math.LegacyNewDecFromInt(math.NewInt(100)) func TestState_Update(t *testing.T) { t.Run("can add to window", func(t *testing.T) { state := types.DefaultState() + params := types.DefaultParams() - err := state.Update(100) + err := state.Update(100, params) require.NoError(t, err) require.Equal(t, uint64(100), state.Window[0]) }) t.Run("can add several txs to window", func(t *testing.T) { state := types.DefaultState() + params := types.DefaultParams() - err := state.Update(100) + err := state.Update(100, params) require.NoError(t, err) require.Equal(t, uint64(100), state.Window[0]) - err = state.Update(200) + err = state.Update(200, params) require.NoError(t, err) require.Equal(t, uint64(300), state.Window[0]) }) t.Run("errors when it exceeds max block utilization", func(t *testing.T) { state := types.DefaultState() + params := types.DefaultParams() - err := state.Update(state.MaxBlockUtilization + 1) + err := state.Update(params.MaxBlockUtilization+1, params) require.Error(t, err) }) t.Run("can update with several blocks in default eip-1559", func(t *testing.T) { state := types.DefaultState() + params := types.DefaultParams() - err := state.Update(100) + err := state.Update(100, params) require.NoError(t, err) require.Equal(t, uint64(100), state.Window[0]) state.IncrementHeight() - err = state.Update(200) + err = state.Update(200, params) require.NoError(t, err) require.Equal(t, uint64(200), state.Window[0]) - err = state.Update(300) + err = state.Update(300, params) require.NoError(t, err) require.Equal(t, uint64(500), state.Window[0]) }) t.Run("can update with several blocks in default aimd eip-1559", func(t *testing.T) { state := types.DefaultAIMDState() + params := types.DefaultAIMDParams() - err := state.Update(100) + err := state.Update(100, params) require.NoError(t, err) require.Equal(t, uint64(100), state.Window[0]) state.IncrementHeight() - err = state.Update(200) + err = state.Update(200, params) require.NoError(t, err) require.Equal(t, uint64(200), state.Window[1]) state.IncrementHeight() - err = state.Update(300) + err = state.Update(300, params) require.NoError(t, err) require.Equal(t, uint64(300), state.Window[2]) state.IncrementHeight() - err = state.Update(400) + err = state.Update(400, params) require.NoError(t, err) require.Equal(t, uint64(400), state.Window[3]) }) t.Run("correctly wraps around with aimd eip-1559", func(t *testing.T) { state := types.DefaultAIMDState() + params := types.DefaultAIMDParams() state.Window = make([]uint64, 3) - err := state.Update(100) + err := state.Update(100, params) require.NoError(t, err) require.Equal(t, uint64(100), state.Window[0]) state.IncrementHeight() - err = state.Update(200) + err = state.Update(200, params) require.NoError(t, err) require.Equal(t, uint64(200), state.Window[1]) state.IncrementHeight() - err = state.Update(300) + err = state.Update(300, params) require.NoError(t, err) require.Equal(t, uint64(300), state.Window[2]) state.IncrementHeight() require.Equal(t, uint64(0), state.Window[0]) - err = state.Update(400) + err = state.Update(400, params) require.NoError(t, err) require.Equal(t, uint64(400), state.Window[0]) require.Equal(t, uint64(200), state.Window[1]) @@ -118,54 +124,54 @@ func TestState_Update(t *testing.T) { func TestState_UpdateBaseFee(t *testing.T) { t.Run("empty block with default eip-1559", func(t *testing.T) { state := types.DefaultState() - state.BaseFee = math.NewInt(1000) - state.MinBaseFee = math.NewInt(125) - params := types.DefaultParams() - newBaseFee := state.UpdateBaseFee(params.Delta) + state.BaseFee = math.NewInt(1000) + params.MinBaseFee = math.NewInt(125) + + newBaseFee := state.UpdateBaseFee(params) expectedBaseFee := math.NewInt(875) require.True(t, expectedBaseFee.Equal(newBaseFee)) }) t.Run("target block with default eip-1559", func(t *testing.T) { state := types.DefaultState() - state.BaseFee = math.NewInt(1000) - state.MinBaseFee = math.NewInt(125) - params := types.DefaultParams() + state.BaseFee = math.NewInt(1000) + params.MinBaseFee = math.NewInt(125) + state.Window[0] = params.TargetBlockUtilization - newBaseFee := state.UpdateBaseFee(params.Delta) + newBaseFee := state.UpdateBaseFee(params) expectedBaseFee := math.NewInt(1000) require.True(t, expectedBaseFee.Equal(newBaseFee)) }) t.Run("full block with default eip-1559", func(t *testing.T) { state := types.DefaultState() - state.BaseFee = math.NewInt(1000) - state.MinBaseFee = math.NewInt(125) - params := types.DefaultParams() + state.BaseFee = math.NewInt(1000) + params.MinBaseFee = math.NewInt(125) + state.Window[0] = params.MaxBlockUtilization - newBaseFee := state.UpdateBaseFee(params.Delta) + newBaseFee := state.UpdateBaseFee(params) expectedBaseFee := math.NewInt(1125) require.True(t, expectedBaseFee.Equal(newBaseFee)) }) t.Run("empty block with default aimd eip-1559", func(t *testing.T) { state := types.DefaultAIMDState() + params := types.DefaultAIMDParams() + state.BaseFee = math.NewInt(1000) - state.MinBaseFee = math.NewInt(125) + params.MinBaseFee = math.NewInt(125) state.LearningRate = math.LegacyMustNewDecFromStr("0.125") - params := types.DefaultAIMDParams() - - state.UpdateLearningRate(params.Theta, params.Alpha, params.Beta, params.MinLearningRate, params.MaxLearningRate) - newBaseFee := state.UpdateBaseFee(params.Delta) + state.UpdateLearningRate(params) + newBaseFee := state.UpdateBaseFee(params) expectedBaseFee := math.NewInt(850) require.True(t, expectedBaseFee.Equal(newBaseFee)) @@ -173,18 +179,18 @@ func TestState_UpdateBaseFee(t *testing.T) { t.Run("target block with default aimd eip-1559", func(t *testing.T) { state := types.DefaultAIMDState() + params := types.DefaultAIMDParams() + state.BaseFee = math.NewInt(1000) - state.MinBaseFee = math.NewInt(125) + params.MinBaseFee = math.NewInt(125) state.LearningRate = math.LegacyMustNewDecFromStr("0.125") - params := types.DefaultAIMDParams() - for i := 0; i < len(state.Window); i++ { state.Window[i] = params.TargetBlockUtilization } - state.UpdateLearningRate(params.Theta, params.Alpha, params.Beta, params.MinLearningRate, params.MaxLearningRate) - newBaseFee := state.UpdateBaseFee(params.Delta) + state.UpdateLearningRate(params) + newBaseFee := state.UpdateBaseFee(params) expectedBaseFee := math.NewInt(1000) require.True(t, expectedBaseFee.Equal(newBaseFee)) @@ -192,18 +198,18 @@ func TestState_UpdateBaseFee(t *testing.T) { t.Run("full blocks with default aimd eip-1559", func(t *testing.T) { state := types.DefaultAIMDState() + params := types.DefaultAIMDParams() + state.BaseFee = math.NewInt(1000) - state.MinBaseFee = math.NewInt(125) + params.MinBaseFee = math.NewInt(125) state.LearningRate = math.LegacyMustNewDecFromStr("0.125") - params := types.DefaultAIMDParams() - for i := 0; i < len(state.Window); i++ { state.Window[i] = params.MaxBlockUtilization } - state.UpdateLearningRate(params.Theta, params.Alpha, params.Beta, params.MinLearningRate, params.MaxLearningRate) - newBaseFee := state.UpdateBaseFee(params.Delta) + state.UpdateLearningRate(params) + newBaseFee := state.UpdateBaseFee(params) expectedBaseFee := math.NewInt(1150) require.True(t, expectedBaseFee.Equal(newBaseFee)) @@ -214,7 +220,7 @@ func TestState_UpdateBaseFee(t *testing.T) { params := types.DefaultParams() // Empty block - newBaseFee := state.UpdateBaseFee(params.Delta) + newBaseFee := state.UpdateBaseFee(params) expectedBaseFee := params.MinBaseFee require.True(t, expectedBaseFee.Equal(newBaseFee)) }) @@ -224,7 +230,7 @@ func TestState_UpdateBaseFee(t *testing.T) { params := types.DefaultAIMDParams() // Empty blocks - newBaseFee := state.UpdateBaseFee(params.Delta) + newBaseFee := state.UpdateBaseFee(params) expectedBaseFee := params.MinBaseFee require.True(t, expectedBaseFee.Equal(newBaseFee)) }) @@ -235,7 +241,7 @@ func TestState_UpdateLearningRate(t *testing.T) { state := types.DefaultState() params := types.DefaultParams() - state.UpdateLearningRate(params.Theta, params.Alpha, params.Beta, params.MinLearningRate, params.MaxLearningRate) + state.UpdateLearningRate(params) expectedLearningRate := math.LegacyMustNewDecFromStr("0.125") require.True(t, expectedLearningRate.Equal(state.LearningRate)) }) @@ -244,9 +250,9 @@ func TestState_UpdateLearningRate(t *testing.T) { state := types.DefaultState() params := types.DefaultParams() - state.Window[0] = state.TargetBlockUtilization + state.Window[0] = params.TargetBlockUtilization - state.UpdateLearningRate(params.Theta, params.Alpha, params.Beta, params.MinLearningRate, params.MaxLearningRate) + state.UpdateLearningRate(params) expectedLearningRate := math.LegacyMustNewDecFromStr("0.125") require.True(t, expectedLearningRate.Equal(state.LearningRate)) }) @@ -255,9 +261,9 @@ func TestState_UpdateLearningRate(t *testing.T) { state := types.DefaultState() params := types.DefaultParams() - state.Window[0] = state.MaxBlockUtilization + state.Window[0] = params.MaxBlockUtilization - state.UpdateLearningRate(params.Theta, params.Alpha, params.Beta, params.MinLearningRate, params.MaxLearningRate) + state.UpdateLearningRate(params) expectedLearningRate := math.LegacyMustNewDecFromStr("0.125") require.True(t, expectedLearningRate.Equal(state.LearningRate)) }) @@ -268,7 +274,7 @@ func TestState_UpdateLearningRate(t *testing.T) { state.Window[0] = 50000 - state.UpdateLearningRate(params.Theta, params.Alpha, params.Beta, params.MinLearningRate, params.MaxLearningRate) + state.UpdateLearningRate(params) expectedLearningRate := math.LegacyMustNewDecFromStr("0.125") require.True(t, expectedLearningRate.Equal(state.LearningRate)) }) @@ -277,9 +283,9 @@ func TestState_UpdateLearningRate(t *testing.T) { state := types.DefaultState() params := types.DefaultParams() - state.Window[0] = state.TargetBlockUtilization + 50000 + state.Window[0] = params.TargetBlockUtilization + 50000 - state.UpdateLearningRate(params.Theta, params.Alpha, params.Beta, params.MinLearningRate, params.MaxLearningRate) + state.UpdateLearningRate(params) expectedLearningRate := math.LegacyMustNewDecFromStr("0.125") require.True(t, expectedLearningRate.Equal(state.LearningRate)) }) @@ -291,7 +297,7 @@ func TestState_UpdateLearningRate(t *testing.T) { randomValue := rand.Int63n(1000000000) state.Window[0] = uint64(randomValue) - state.UpdateLearningRate(params.Theta, params.Alpha, params.Beta, params.MinLearningRate, params.MaxLearningRate) + state.UpdateLearningRate(params) expectedLearningRate := math.LegacyMustNewDecFromStr("0.125") require.True(t, expectedLearningRate.Equal(state.LearningRate)) }) @@ -300,7 +306,7 @@ func TestState_UpdateLearningRate(t *testing.T) { state := types.DefaultAIMDState() params := types.DefaultAIMDParams() - state.UpdateLearningRate(params.Theta, params.Alpha, params.Beta, params.MinLearningRate, params.MaxLearningRate) + state.UpdateLearningRate(params) expectedLearningRate := params.MinLearningRate.Add(params.Alpha) require.True(t, expectedLearningRate.Equal(state.LearningRate)) }) @@ -313,10 +319,10 @@ func TestState_UpdateLearningRate(t *testing.T) { params := types.DefaultAIMDParams() for i := 0; i < len(state.Window); i++ { - state.Window[i] = state.TargetBlockUtilization + state.Window[i] = params.TargetBlockUtilization } - state.UpdateLearningRate(params.Theta, params.Alpha, params.Beta, params.MinLearningRate, params.MaxLearningRate) + state.UpdateLearningRate(params) expectedLearningRate := defaultLR.Mul(params.Beta) require.True(t, expectedLearningRate.Equal(state.LearningRate)) }) @@ -329,10 +335,10 @@ func TestState_UpdateLearningRate(t *testing.T) { params := types.DefaultAIMDParams() for i := 0; i < len(state.Window); i++ { - state.Window[i] = state.MaxBlockUtilization + state.Window[i] = params.MaxBlockUtilization } - state.UpdateLearningRate(params.Theta, params.Alpha, params.Beta, params.MinLearningRate, params.MaxLearningRate) + state.UpdateLearningRate(params) expectedLearningRate := defaultLR.Add(params.Alpha) require.True(t, expectedLearningRate.Equal(state.LearningRate)) }) @@ -346,13 +352,13 @@ func TestState_UpdateLearningRate(t *testing.T) { for i := 0; i < len(state.Window); i++ { if i%2 == 0 { - state.Window[i] = state.MaxBlockUtilization + state.Window[i] = params.MaxBlockUtilization } else { state.Window[i] = 0 } } - state.UpdateLearningRate(params.Theta, params.Alpha, params.Beta, params.MinLearningRate, params.MaxLearningRate) + state.UpdateLearningRate(params) expectedLearningRate := defaultLR.Mul(params.Beta) require.True(t, expectedLearningRate.Equal(state.LearningRate)) }) @@ -366,13 +372,13 @@ func TestState_UpdateLearningRate(t *testing.T) { for i := 0; i < len(state.Window); i++ { if i%2 == 0 { - state.Window[i] = state.MaxBlockUtilization + state.Window[i] = params.MaxBlockUtilization } else { - state.Window[i] = state.TargetBlockUtilization + 1 + state.Window[i] = params.TargetBlockUtilization + 1 } } - state.UpdateLearningRate(params.Theta, params.Alpha, params.Beta, params.MinLearningRate, params.MaxLearningRate) + state.UpdateLearningRate(params) expectedLearningRate := defaultLR.Add(params.Alpha) require.True(t, expectedLearningRate.Equal(state.LearningRate)) }) @@ -381,68 +387,74 @@ func TestState_UpdateLearningRate(t *testing.T) { func TestState_GetNetUtilization(t *testing.T) { t.Run("empty block with default eip-1559", func(t *testing.T) { state := types.DefaultState() + params := types.DefaultParams() - netUtilization := state.GetNetUtilization() - expectedUtilization := math.NewInt(0).Sub(math.NewIntFromUint64(state.TargetBlockUtilization)) + netUtilization := state.GetNetUtilization(params) + expectedUtilization := math.NewInt(0).Sub(math.NewIntFromUint64(params.TargetBlockUtilization)) require.True(t, expectedUtilization.Equal(netUtilization)) }) t.Run("target block with default eip-1559", func(t *testing.T) { state := types.DefaultState() + params := types.DefaultParams() - state.Window[0] = state.TargetBlockUtilization + state.Window[0] = params.TargetBlockUtilization - netUtilization := state.GetNetUtilization() + netUtilization := state.GetNetUtilization(params) expectedUtilization := math.NewInt(0) require.True(t, expectedUtilization.Equal(netUtilization)) }) t.Run("full block with default eip-1559", func(t *testing.T) { state := types.DefaultState() + params := types.DefaultParams() - state.Window[0] = state.MaxBlockUtilization + state.Window[0] = params.MaxBlockUtilization - netUtilization := state.GetNetUtilization() - expectedUtilization := math.NewIntFromUint64(state.MaxBlockUtilization - state.TargetBlockUtilization) + netUtilization := state.GetNetUtilization(params) + expectedUtilization := math.NewIntFromUint64(params.MaxBlockUtilization - params.TargetBlockUtilization) require.True(t, expectedUtilization.Equal(netUtilization)) }) t.Run("empty block with default aimd eip-1559", func(t *testing.T) { state := types.DefaultAIMDState() + params := types.DefaultParams() - netUtilization := state.GetNetUtilization() + netUtilization := state.GetNetUtilization(params) multiple := math.NewIntFromUint64(uint64(len(state.Window))) - expectedUtilization := math.NewInt(0).Sub(math.NewIntFromUint64(state.TargetBlockUtilization)).Mul(multiple) + expectedUtilization := math.NewInt(0).Sub(math.NewIntFromUint64(params.TargetBlockUtilization)).Mul(multiple) require.True(t, expectedUtilization.Equal(netUtilization)) }) t.Run("full blocks with default aimd eip-1559", func(t *testing.T) { state := types.DefaultAIMDState() + params := types.DefaultAIMDParams() for i := 0; i < len(state.Window); i++ { - state.Window[i] = state.MaxBlockUtilization + state.Window[i] = params.MaxBlockUtilization } - netUtilization := state.GetNetUtilization() + netUtilization := state.GetNetUtilization(params) multiple := math.NewIntFromUint64(uint64(len(state.Window))) - expectedUtilization := math.NewIntFromUint64(state.MaxBlockUtilization).Sub(math.NewIntFromUint64(state.TargetBlockUtilization)).Mul(multiple) + expectedUtilization := math.NewIntFromUint64(params.MaxBlockUtilization).Sub(math.NewIntFromUint64(params.TargetBlockUtilization)).Mul(multiple) require.True(t, expectedUtilization.Equal(netUtilization)) }) t.Run("varying blocks with default aimd eip-1559", func(t *testing.T) { state := types.DefaultAIMDState() + params := types.DefaultAIMDParams() for i := 0; i < len(state.Window); i++ { if i%2 == 0 { - state.Window[i] = state.MaxBlockUtilization + state.Window[i] = params.MaxBlockUtilization } else { state.Window[i] = 0 } } - netUtilization := state.GetNetUtilization() + netUtilization := state.GetNetUtilization(params) expectedUtilization := math.ZeroInt() require.True(t, expectedUtilization.Equal(netUtilization)) }) @@ -459,7 +471,7 @@ func TestState_GetNetUtilization(t *testing.T) { } } - netUtilization := state.GetNetUtilization() + netUtilization := state.GetNetUtilization(params) first := math.NewIntFromUint64(params.MaxBlockUtilization).Mul(math.NewIntFromUint64(params.Window / 2)) second := math.NewIntFromUint64(params.TargetBlockUtilization).Mul(math.NewIntFromUint64(params.Window / 2)) expectedUtilization := first.Add(second).Sub(math.NewIntFromUint64(params.TargetBlockUtilization).Mul(math.NewIntFromUint64(params.Window))) @@ -469,15 +481,17 @@ func TestState_GetNetUtilization(t *testing.T) { t.Run("state with 4 entries in window with different updates", func(t *testing.T) { state := types.DefaultAIMDState() state.Window = make([]uint64, 4) - state.TargetBlockUtilization = 100 - state.MaxBlockUtilization = 200 + + params := types.DefaultAIMDParams() + params.TargetBlockUtilization = 100 + params.MaxBlockUtilization = 200 state.Window[0] = 100 state.Window[1] = 200 state.Window[2] = 0 state.Window[3] = 50 - netUtilization := state.GetNetUtilization() + netUtilization := state.GetNetUtilization(params) expectedUtilization := math.NewIntFromUint64(50).Mul(math.NewInt(-1)) require.True(t, expectedUtilization.Equal(netUtilization)) }) @@ -485,15 +499,17 @@ func TestState_GetNetUtilization(t *testing.T) { t.Run("state with 4 entries in window with monotonically increasing updates", func(t *testing.T) { state := types.DefaultAIMDState() state.Window = make([]uint64, 4) - state.TargetBlockUtilization = 100 - state.MaxBlockUtilization = 200 + + params := types.DefaultAIMDParams() + params.TargetBlockUtilization = 100 + params.MaxBlockUtilization = 200 state.Window[0] = 0 state.Window[1] = 25 state.Window[2] = 50 state.Window[3] = 75 - netUtilization := state.GetNetUtilization() + netUtilization := state.GetNetUtilization(params) expectedUtilization := math.NewIntFromUint64(250).Mul(math.NewInt(-1)) require.True(t, expectedUtilization.Equal(netUtilization)) }) @@ -502,92 +518,100 @@ func TestState_GetNetUtilization(t *testing.T) { func TestState_GetAverageUtilization(t *testing.T) { t.Run("empty block with default eip-1559", func(t *testing.T) { state := types.DefaultState() + params := types.DefaultParams() - avgUtilization := state.GetAverageUtilization() + avgUtilization := state.GetAverageUtilization(params) expectedUtilization := math.LegacyZeroDec() require.True(t, expectedUtilization.Equal(avgUtilization)) }) t.Run("target block with default eip-1559", func(t *testing.T) { state := types.DefaultState() + params := types.DefaultParams() - state.Window[0] = state.TargetBlockUtilization + state.Window[0] = params.TargetBlockUtilization - avgUtilization := state.GetAverageUtilization() + avgUtilization := state.GetAverageUtilization(params) expectedUtilization := math.LegacyMustNewDecFromStr("0.5") require.True(t, expectedUtilization.Equal(avgUtilization)) }) t.Run("full block with default eip-1559", func(t *testing.T) { state := types.DefaultState() + params := types.DefaultParams() - state.Window[0] = state.MaxBlockUtilization + state.Window[0] = params.MaxBlockUtilization - avgUtilization := state.GetAverageUtilization() + avgUtilization := state.GetAverageUtilization(params) expectedUtilization := math.LegacyMustNewDecFromStr("1.0") require.True(t, expectedUtilization.Equal(avgUtilization)) }) t.Run("empty block with default aimd eip-1559", func(t *testing.T) { state := types.DefaultAIMDState() + params := types.DefaultAIMDParams() - avgUtilization := state.GetAverageUtilization() + avgUtilization := state.GetAverageUtilization(params) expectedUtilization := math.LegacyZeroDec() require.True(t, expectedUtilization.Equal(avgUtilization)) }) t.Run("target block with default aimd eip-1559", func(t *testing.T) { state := types.DefaultAIMDState() + params := types.DefaultAIMDParams() for i := 0; i < len(state.Window); i++ { - state.Window[i] = state.TargetBlockUtilization + state.Window[i] = params.TargetBlockUtilization } - avgUtilization := state.GetAverageUtilization() + avgUtilization := state.GetAverageUtilization(params) expectedUtilization := math.LegacyMustNewDecFromStr("0.5") require.True(t, expectedUtilization.Equal(avgUtilization)) }) t.Run("full blocks with default aimd eip-1559", func(t *testing.T) { state := types.DefaultAIMDState() + params := types.DefaultAIMDParams() for i := 0; i < len(state.Window); i++ { - state.Window[i] = state.MaxBlockUtilization + state.Window[i] = params.MaxBlockUtilization } - avgUtilization := state.GetAverageUtilization() + avgUtilization := state.GetAverageUtilization(params) expectedUtilization := math.LegacyMustNewDecFromStr("1.0") require.True(t, expectedUtilization.Equal(avgUtilization)) }) t.Run("varying blocks with default aimd eip-1559", func(t *testing.T) { state := types.DefaultAIMDState() + params := types.DefaultAIMDParams() for i := 0; i < len(state.Window); i++ { if i%2 == 0 { - state.Window[i] = state.MaxBlockUtilization + state.Window[i] = params.MaxBlockUtilization } else { state.Window[i] = 0 } } - avgUtilization := state.GetAverageUtilization() + avgUtilization := state.GetAverageUtilization(params) expectedUtilization := math.LegacyMustNewDecFromStr("0.5") require.True(t, expectedUtilization.Equal(avgUtilization)) }) t.Run("exceeds target rate with default aimd eip-1559", func(t *testing.T) { state := types.DefaultAIMDState() + params := types.DefaultAIMDParams() for i := 0; i < len(state.Window); i++ { if i%2 == 0 { - state.Window[i] = state.MaxBlockUtilization + state.Window[i] = params.MaxBlockUtilization } else { - state.Window[i] = state.TargetBlockUtilization + state.Window[i] = params.TargetBlockUtilization } } - avgUtilization := state.GetAverageUtilization() + avgUtilization := state.GetAverageUtilization(params) expectedUtilization := math.LegacyMustNewDecFromStr("0.75") require.True(t, expectedUtilization.Equal(avgUtilization)) }) @@ -595,15 +619,17 @@ func TestState_GetAverageUtilization(t *testing.T) { t.Run("state with 4 entries in window with different updates", func(t *testing.T) { state := types.DefaultAIMDState() state.Window = make([]uint64, 4) - state.TargetBlockUtilization = 100 - state.MaxBlockUtilization = 200 + + params := types.DefaultAIMDParams() + params.TargetBlockUtilization = 100 + params.MaxBlockUtilization = 200 state.Window[0] = 100 state.Window[1] = 200 state.Window[2] = 0 state.Window[3] = 50 - avgUtilization := state.GetAverageUtilization() + avgUtilization := state.GetAverageUtilization(params) expectedUtilization := math.LegacyMustNewDecFromStr("0.4375") require.True(t, expectedUtilization.Equal(avgUtilization)) }) @@ -614,15 +640,15 @@ func TestState_GetAverageUtilization(t *testing.T) { params := types.DefaultAIMDParams() params.Window = 4 - state.TargetBlockUtilization = 100 - state.MaxBlockUtilization = 200 + params.TargetBlockUtilization = 100 + params.MaxBlockUtilization = 200 state.Window[0] = 0 state.Window[1] = 25 state.Window[2] = 50 state.Window[3] = 75 - avgUtilization := state.GetAverageUtilization() + avgUtilization := state.GetAverageUtilization(params) expectedUtilization := math.LegacyMustNewDecFromStr("0.1875") require.True(t, expectedUtilization.Equal(avgUtilization)) }) @@ -669,11 +695,9 @@ func TestState_ValidateBasic(t *testing.T) { { name: "valid other state", state: types.State{ - Window: make([]uint64, 1), - BaseFee: math.NewInt(1), - LearningRate: math.LegacyMustNewDecFromStr("0.5"), - MaxBlockUtilization: 10, - TargetBlockUtilization: 5, + Window: make([]uint64, 1), + BaseFee: math.NewInt(1), + LearningRate: math.LegacyMustNewDecFromStr("0.5"), }, expectErr: false, }, @@ -695,39 +719,6 @@ func TestState_ValidateBasic(t *testing.T) { }, expectErr: true, }, - { - name: "invalid target size", - state: types.State{ - Window: make([]uint64, 1), - BaseFee: math.NewInt(1), - LearningRate: math.LegacyMustNewDecFromStr("0.5"), - TargetBlockUtilization: 0, - MaxBlockUtilization: 100, - }, - expectErr: true, - }, - { - name: "invalid max size", - state: types.State{ - Window: make([]uint64, 1), - BaseFee: math.NewInt(1), - LearningRate: math.LegacyMustNewDecFromStr("0.5"), - TargetBlockUtilization: 10, - MaxBlockUtilization: 0, - }, - expectErr: true, - }, - { - name: "target is larger than max", - state: types.State{ - Window: make([]uint64, 1), - BaseFee: math.NewInt(1), - LearningRate: math.LegacyMustNewDecFromStr("0.5"), - TargetBlockUtilization: 10, - MaxBlockUtilization: 9, - }, - expectErr: true, - }, } for _, tc := range testCases { From 1935d456e2cf91586d2166519c4989d1b24dbd18 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 30 Nov 2023 15:54:11 -0500 Subject: [PATCH 15/53] clean --- tests/integration/integration_test.go | 12 ++++++++++-- tests/integration/suite.go | 5 +++-- x/feemarket/types/state.go | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index d0c4bc9..c11f47c 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -41,8 +41,8 @@ var ( feemarkettypes.DefaultBeta, feemarkettypes.DefaultTheta, feemarkettypes.DefaultDelta, - feemarkettypes.DefaultTargetBlockSize, - feemarkettypes.DefaultMaxBlockSize, + feemarkettypes.DefaultTargetBlockUtilization, + feemarkettypes.DefaultMaxBlockUtilization, sdk.NewInt(1000), feemarkettypes.DefaultMinLearningRate, feemarkettypes.DefaultMaxLearningRate, @@ -50,6 +50,14 @@ var ( true, ), }, + { + Key: "app_state.feemarket.state", + Value: feemarkettypes.NewState( + feemarkettypes.DefaultWindow, + sdk.NewInt(1000), + feemarkettypes.DefaultMaxLearningRate, + ), + }, } consensusParams = ictestutil.Toml{ diff --git a/tests/integration/suite.go b/tests/integration/suite.go index 60c4e0b..e506b6f 100644 --- a/tests/integration/suite.go +++ b/tests/integration/suite.go @@ -3,10 +3,11 @@ package integration import ( "context" + "github.com/strangelove-ventures/interchaintest/v7" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v7/ibc" "github.com/stretchr/testify/require" @@ -149,7 +150,7 @@ func (s *TestSuite) TestSendTxUpdating() { params := s.QueryParams() gas := int64(1000000) - minBaseFee := sdk.NewCoins(sdk.NewCoin(params.FeeDenom, state.MinBaseFee.MulRaw(gas))) + minBaseFee := sdk.NewCoins(sdk.NewCoin(params.FeeDenom, state.BaseFee.MulRaw(gas))) // send with the exact expected fee _, err := s.SendCoins( diff --git a/x/feemarket/types/state.go b/x/feemarket/types/state.go index 33b677c..d293aca 100644 --- a/x/feemarket/types/state.go +++ b/x/feemarket/types/state.go @@ -11,12 +11,12 @@ import ( // AIMD EIP-1559 fee market implementation. Note that on init, you initialize // both the minimum and current base fee to the same value. func NewState( - window uint64, + windowSize uint64, baseFee math.Int, learningRate math.LegacyDec, ) State { return State{ - Window: make([]uint64, window), + Window: make([]uint64, windowSize), BaseFee: baseFee, Index: 0, LearningRate: learningRate, From d6374931e287c9d34c0dcd19ed17618c0837b854 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 1 Dec 2023 10:20:18 -0500 Subject: [PATCH 16/53] wip --- tests/integration/setup.go | 1 + tests/integration/suite.go | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/integration/setup.go b/tests/integration/setup.go index 6f7bda2..a1306e8 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -434,6 +434,7 @@ func (s *TestSuite) GetAndFundTestUsers( return users } +// ExecTx executes a cli command on a node, waits a block and queries the Tx to verify it was included on chain. func (s *TestSuite) ExecTx(ctx context.Context, chain *cosmos.CosmosChain, keyName string, command ...string) (string, error) { node := chain.FullNodes[0] diff --git a/tests/integration/suite.go b/tests/integration/suite.go index e506b6f..dd75fba 100644 --- a/tests/integration/suite.go +++ b/tests/integration/suite.go @@ -110,8 +110,7 @@ func (s *TestSuite) SetupSubTest() { state := s.QueryState() - s.T().Log("new test case at block height", height+1) - s.T().Log("state:", state.String()) + s.T().Log("state at block height", height+1, ":", state.String()) } func (s *TestSuite) TestQueryParams() { @@ -153,7 +152,7 @@ func (s *TestSuite) TestSendTxUpdating() { minBaseFee := sdk.NewCoins(sdk.NewCoin(params.FeeDenom, state.BaseFee.MulRaw(gas))) // send with the exact expected fee - _, err := s.SendCoins( + txResp, err := s.SendCoins( ctx, cosmosChain, s.user1.KeyName(), @@ -164,4 +163,9 @@ func (s *TestSuite) TestSendTxUpdating() { gas, ) s.Require().NoError(err, s.user1.FormattedAddress(), s.user2.FormattedAddress()) + + s.SetupSubTest() + + // check fee deduction and events + s.chain.N } From 127629c837b972670342351b772180d05990623c Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 1 Dec 2023 11:59:31 -0500 Subject: [PATCH 17/53] fix --- tests/integration/setup.go | 11 ------ tests/integration/suite.go | 48 +------------------------ x/feemarket/client/cli/query.go | 6 ---- x/feemarket/keeper/query_server.go | 12 ------- x/feemarket/keeper/query_server_test.go | 7 ---- 5 files changed, 1 insertion(+), 83 deletions(-) diff --git a/tests/integration/setup.go b/tests/integration/setup.go index e0124f9..c37efcb 100644 --- a/tests/integration/setup.go +++ b/tests/integration/setup.go @@ -16,11 +16,6 @@ import ( "testing" "time" -<<<<<<< HEAD - "github.com/strangelove-ventures/interchaintest/v7" - -======= ->>>>>>> main rpctypes "github.com/cometbft/cometbft/rpc/core/types" comettypes "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/client" @@ -31,10 +26,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" -<<<<<<< HEAD -======= interchaintest "github.com/strangelove-ventures/interchaintest/v7" ->>>>>>> main "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v7/ibc" "github.com/strangelove-ventures/interchaintest/v7/testutil" @@ -159,8 +151,6 @@ func (s *TestSuite) QueryState() types.State { return state } -<<<<<<< HEAD -======= func (s *TestSuite) QueryBaseFee() sdk.Coins { s.T().Helper() @@ -181,7 +171,6 @@ func (s *TestSuite) QueryBaseFee() sdk.Coins { return fees } ->>>>>>> main // QueryValidators queries for all the network's validators func (s *TestSuite) QueryValidators(chain *cosmos.CosmosChain) []sdk.ValAddress { s.T().Helper() diff --git a/tests/integration/suite.go b/tests/integration/suite.go index fc952a6..06984a1 100644 --- a/tests/integration/suite.go +++ b/tests/integration/suite.go @@ -170,52 +170,6 @@ func (s *TestSuite) TestSendTxUpdating() { gas, ) s.Require().NoError(err, txResp) + s.T().Log(txResp) }) } - -func (s *TestSuite) TestQueryState() { - s.SetupSubTest() - - // query params - state := s.QueryState() - - // expect validate to pass - require.NoError(s.T(), state.ValidateBasic(), state) -} - -func (s *TestSuite) TestSendTxUpdating() { - s.SetupSubTest() - - ctx := context.Background() - - // cast chain to cosmos-chain - cosmosChain, ok := s.chain.(*cosmos.CosmosChain) - s.Require().True(ok) - // get nodes - nodes := cosmosChain.Nodes() - s.Require().True(len(nodes) > 0) - - state := s.QueryState() - params := s.QueryParams() - - gas := int64(1000000) - minBaseFee := sdk.NewCoins(sdk.NewCoin(params.FeeDenom, state.BaseFee.MulRaw(gas))) - - // send with the exact expected fee - txResp, err := s.SendCoins( - ctx, - cosmosChain, - s.user1.KeyName(), - s.user1.FormattedAddress(), - s.user2.FormattedAddress(), - sdk.NewCoins(sdk.NewCoin(cosmosChain.Config().Denom, sdk.NewInt(10000))), - minBaseFee, - gas, - ) - s.Require().NoError(err, s.user1.FormattedAddress(), s.user2.FormattedAddress()) - - s.SetupSubTest() - - // check fee deduction and events - s.chain.N -} diff --git a/x/feemarket/client/cli/query.go b/x/feemarket/client/cli/query.go index f2745d1..a7f7bc2 100644 --- a/x/feemarket/client/cli/query.go +++ b/x/feemarket/client/cli/query.go @@ -25,10 +25,7 @@ func GetQueryCmd() *cobra.Command { cmd.AddCommand( GetParamsCmd(), GetStateCmd(), -<<<<<<< HEAD -======= GetBaseFeeCmd(), ->>>>>>> main ) return cmd @@ -87,8 +84,6 @@ func GetStateCmd() *cobra.Command { return cmd } -<<<<<<< HEAD -======= // GetBaseFeeCmd returns the cli-command that queries the current feemarket base fee. func GetBaseFeeCmd() *cobra.Command { @@ -116,4 +111,3 @@ func GetBaseFeeCmd() *cobra.Command { return cmd } ->>>>>>> main diff --git a/x/feemarket/keeper/query_server.go b/x/feemarket/keeper/query_server.go index e986a36..35640ba 100644 --- a/x/feemarket/keeper/query_server.go +++ b/x/feemarket/keeper/query_server.go @@ -43,15 +43,3 @@ func (q QueryServer) BaseFee(goCtx context.Context, _ *types.BaseFeeRequest) (*t fees, err := q.k.GetMinGasPrices(ctx) return &types.BaseFeeResponse{Fees: fees}, err } - -// State defines a method that returns the current feemarket state. -func (q QueryServer) State(goCtx context.Context, _ *types.StateRequest) (*types.StateResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - state, err := q.k.GetState(ctx) - if err != nil { - return nil, err - } - - return &types.StateResponse{State: state}, nil -} diff --git a/x/feemarket/keeper/query_server_test.go b/x/feemarket/keeper/query_server_test.go index 4a1d069..37fe43b 100644 --- a/x/feemarket/keeper/query_server_test.go +++ b/x/feemarket/keeper/query_server_test.go @@ -67,11 +67,7 @@ func (s *KeeperTestSuite) TestStateRequest() { s.Require().Equal(resp.State, state) }) -<<<<<<< HEAD - s.Run("can get updated params", func() { -======= s.Run("can get updated state", func() { ->>>>>>> main state := types.State{ BaseFee: math.OneInt(), LearningRate: math.LegacyOneDec(), @@ -94,8 +90,6 @@ func (s *KeeperTestSuite) TestStateRequest() { s.Require().Equal(resp.State, state) }) } -<<<<<<< HEAD -======= func (s *KeeperTestSuite) TestBaseFeeRequest() { s.Run("can get default base fee", func() { @@ -134,4 +128,3 @@ func (s *KeeperTestSuite) TestBaseFeeRequest() { s.Require().Equal(resp.Fees, fees) }) } ->>>>>>> main From 20d1fdaf788d06a3776d9d8cc7110aeb316c14eb Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 1 Dec 2023 12:55:42 -0500 Subject: [PATCH 18/53] refactor --- x/feemarket/ante/fee.go | 32 ++++++++++++++++++++++++-------- x/feemarket/post/fee.go | 6 ++++-- x/feemarket/post/fee_test.go | 24 ++++++++++++++++++++++-- x/feemarket/types/keys.go | 1 + 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/x/feemarket/ante/fee.go b/x/feemarket/ante/fee.go index 170dc4b..6d586b5 100644 --- a/x/feemarket/ante/fee.go +++ b/x/feemarket/ante/fee.go @@ -56,7 +56,7 @@ func (dfd FeeMarketCheckDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula ) if !simulate { - fee, _, err = CheckTxFees(minGasPrices, feeTx, gas) + fee, _, err = CheckTxFees(ctx, minGasPrices, feeTx, true) if err != nil { return ctx, errorsmod.Wrapf(err, "error checking fee") } @@ -69,7 +69,7 @@ func (dfd FeeMarketCheckDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula // CheckTxFees implements the logic for the fee market to check if a Tx has provided sufficient // fees given the current state of the fee market. Returns an error if insufficient fees. -func CheckTxFees(minFees sdk.Coins, feeTx sdk.FeeTx, gas uint64) (feeCoins sdk.Coins, tip sdk.Coins, err error) { +func CheckTxFees(ctx sdk.Context, minFees sdk.Coins, feeTx sdk.FeeTx, isCheck bool) (feeCoins sdk.Coins, tip sdk.Coins, err error) { feesDec := sdk.NewDecCoinsFromCoins(minFees...) feeCoins = feeTx.GetFee() @@ -78,21 +78,37 @@ func CheckTxFees(minFees sdk.Coins, feeTx sdk.FeeTx, gas uint64) (feeCoins sdk.C minGasPrices := feesDec if !minGasPrices.IsZero() { requiredFees := make(sdk.Coins, len(minGasPrices)) + consumedFees := make(sdk.Coins, len(minGasPrices)) // Determine the required fees by multiplying each required minimum gas // price by the gas, where fee = ceil(minGasPrice * gas). - glDec := sdkmath.LegacyNewDec(int64(gas)) + gasConsumed := int64(ctx.GasMeter().GasConsumed()) + gcDec := sdkmath.LegacyNewDec(gasConsumed) + glDec := sdkmath.LegacyNewDec(int64(feeTx.GetGas())) + for i, gp := range minGasPrices { - fee := gp.Amount.Mul(glDec) - requiredFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt()) + fee := gp.Amount.Mul(gcDec) + limitFee := gp.Amount.Mul(glDec) + consumedFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt()) + requiredFees[i] = sdk.NewCoin(gp.Denom, limitFee.Ceil().RoundInt()) } if !feeCoins.IsAnyGTE(requiredFees) { - return nil, nil, sdkerrors.ErrInsufficientFee.Wrapf("got: %s required: %s, minGasPrices: %s, gas: %d", feeCoins, requiredFees, minGasPrices, gas) + return nil, nil, sdkerrors.ErrInsufficientFee.Wrapf( + "got: %s required: %s, minGasPrices: %s, gas: %d", + feeCoins, + requiredFees, + minGasPrices, + gasConsumed, + ) } - tip = feeCoins.Sub(minFees...) // tip is the difference between feeCoins and the min fees - feeCoins = requiredFees // set fee coins to be ONLY the required amount + tip = feeCoins.Sub(requiredFees...) // tip is the difference between feeCoins and the min fees + if isCheck { + feeCoins = requiredFees // set fee coins to be required amount if checking + } else { + feeCoins = consumedFees // set fee coins to be ONLY the consumed amount if we are calculated consumed fee to deduct + } } return feeCoins, tip, nil diff --git a/x/feemarket/post/fee.go b/x/feemarket/post/fee.go index 9486f5b..505b0e3 100644 --- a/x/feemarket/post/fee.go +++ b/x/feemarket/post/fee.go @@ -84,7 +84,7 @@ func (dfd FeeMarketDeductDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simul ) if !simulate { - fee, tip, err = ante.CheckTxFees(minGasPrices, feeTx, gas) + fee, tip, err = ante.CheckTxFees(ctx, minGasPrices, feeTx, false) if err != nil { return ctx, err } @@ -156,8 +156,9 @@ func (dfd FeeMarketDeductDecorator) DeductFeeAndTip(ctx sdk.Context, sdkTx sdk.T } } + proposer := sdk.AccAddress(ctx.BlockHeader().ProposerAddress) if !tip.IsZero() { - err := SendTip(dfd.bankKeeper, ctx, deductFeesFromAcc.GetAddress(), ctx.BlockHeader().ProposerAddress, tip) + err := SendTip(dfd.bankKeeper, ctx, deductFeesFromAcc.GetAddress(), proposer, tip) if err != nil { return err } @@ -170,6 +171,7 @@ func (dfd FeeMarketDeductDecorator) DeductFeeAndTip(ctx sdk.Context, sdkTx sdk.T sdk.NewAttribute(sdk.AttributeKeyFeePayer, deductFeesFrom.String()), sdk.NewAttribute(feemarkettypes.AttributeKeyTip, tip.String()), sdk.NewAttribute(feemarkettypes.AttributeKeyTipPayer, deductFeesFrom.String()), + sdk.NewAttribute(feemarkettypes.AttributeKeyTipPayee, proposer.String()), ), } ctx.EventManager().EmitEvents(events) diff --git a/x/feemarket/post/fee_test.go b/x/feemarket/post/fee_test.go index d221ed9..10d7b8a 100644 --- a/x/feemarket/post/fee_test.go +++ b/x/feemarket/post/fee_test.go @@ -103,7 +103,9 @@ func TestPostHandle(t *testing.T) { // Same data for every test case gasLimit := antesuite.NewTestGasLimit() validFeeAmount := types.DefaultMinBaseFee.MulRaw(int64(gasLimit)) + validFeeAmountWithTip := validFeeAmount.Add(sdk.NewInt(100)) validFee := sdk.NewCoins(sdk.NewCoin("stake", validFeeAmount)) + validFeeWithTip := sdk.NewCoins(sdk.NewCoin("stake", validFeeAmountWithTip)) testCases := []antesuite.TestCase{ { @@ -142,11 +144,10 @@ func TestPostHandle(t *testing.T) { ExpErr: sdkerrors.ErrInvalidGasLimit, }, { - Name: "signer has enough funds, should pass", + Name: "signer has enough funds, should pass, no tip", Malleate: func(suite *antesuite.TestSuite) antesuite.TestCaseArgs { accs := suite.CreateTestAccounts(1) suite.BankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil) - suite.BankKeeper.On("SendCoins", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once() return antesuite.TestCaseArgs{ Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())}, @@ -160,6 +161,25 @@ func TestPostHandle(t *testing.T) { ExpPass: true, ExpErr: nil, }, + { + Name: "signer has enough funds, should pass with tip", + Malleate: func(suite *antesuite.TestSuite) antesuite.TestCaseArgs { + accs := suite.CreateTestAccounts(1) + suite.BankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil) + suite.BankKeeper.On("SendCoins", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once() + + return antesuite.TestCaseArgs{ + Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())}, + GasLimit: gasLimit, + FeeAmount: validFeeWithTip, + } + }, + RunAnte: true, + RunPost: true, + Simulate: false, + ExpPass: true, + ExpErr: nil, + }, } for _, tc := range testCases { diff --git a/x/feemarket/types/keys.go b/x/feemarket/types/keys.go index c2aaf09..49927dc 100644 --- a/x/feemarket/types/keys.go +++ b/x/feemarket/types/keys.go @@ -24,4 +24,5 @@ var ( AttributeKeyTip = "tip" AttributeKeyTipPayer = "tip_payer" + AttributeKeyTipPayee = "tip_payee" ) From b1f618cabd962eb1880452ab828f4933674a213c Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 1 Dec 2023 16:29:45 -0500 Subject: [PATCH 19/53] fix --- x/feemarket/ante/fee.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/x/feemarket/ante/fee.go b/x/feemarket/ante/fee.go index 6d586b5..2404d7c 100644 --- a/x/feemarket/ante/fee.go +++ b/x/feemarket/ante/fee.go @@ -70,12 +70,11 @@ func (dfd FeeMarketCheckDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula // CheckTxFees implements the logic for the fee market to check if a Tx has provided sufficient // fees given the current state of the fee market. Returns an error if insufficient fees. func CheckTxFees(ctx sdk.Context, minFees sdk.Coins, feeTx sdk.FeeTx, isCheck bool) (feeCoins sdk.Coins, tip sdk.Coins, err error) { - feesDec := sdk.NewDecCoinsFromCoins(minFees...) - + minFeesDecCoins := sdk.NewDecCoinsFromCoins(minFees...) feeCoins = feeTx.GetFee() // Ensure that the provided fees meet the minimum - minGasPrices := feesDec + minGasPrices := minFeesDecCoins if !minGasPrices.IsZero() { requiredFees := make(sdk.Coins, len(minGasPrices)) consumedFees := make(sdk.Coins, len(minGasPrices)) @@ -87,9 +86,9 @@ func CheckTxFees(ctx sdk.Context, minFees sdk.Coins, feeTx sdk.FeeTx, isCheck bo glDec := sdkmath.LegacyNewDec(int64(feeTx.GetGas())) for i, gp := range minGasPrices { - fee := gp.Amount.Mul(gcDec) + consumedFee := gp.Amount.Mul(gcDec) limitFee := gp.Amount.Mul(glDec) - consumedFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt()) + consumedFees[i] = sdk.NewCoin(gp.Denom, consumedFee.Ceil().RoundInt()) requiredFees[i] = sdk.NewCoin(gp.Denom, limitFee.Ceil().RoundInt()) } @@ -103,11 +102,12 @@ func CheckTxFees(ctx sdk.Context, minFees sdk.Coins, feeTx sdk.FeeTx, isCheck bo ) } - tip = feeCoins.Sub(requiredFees...) // tip is the difference between feeCoins and the min fees if isCheck { feeCoins = requiredFees // set fee coins to be required amount if checking } else { - feeCoins = consumedFees // set fee coins to be ONLY the consumed amount if we are calculated consumed fee to deduct + tip = feeCoins.Sub(requiredFees...) // tip is the difference between feeCoins and the required fees + // set fee coins to be ONLY the consumed amount if we are calculated consumed fee to deduct + feeCoins = consumedFees } } From 1e2df2f15f26355283eba8f3bd7c100242302fa1 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 1 Dec 2023 16:29:58 -0500 Subject: [PATCH 20/53] fix --- x/feemarket/ante/fee.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x/feemarket/ante/fee.go b/x/feemarket/ante/fee.go index 2404d7c..307055a 100644 --- a/x/feemarket/ante/fee.go +++ b/x/feemarket/ante/fee.go @@ -103,9 +103,11 @@ func CheckTxFees(ctx sdk.Context, minFees sdk.Coins, feeTx sdk.FeeTx, isCheck bo } if isCheck { - feeCoins = requiredFees // set fee coins to be required amount if checking + // set fee coins to be required amount if checking + feeCoins = requiredFees } else { - tip = feeCoins.Sub(requiredFees...) // tip is the difference between feeCoins and the required fees + // tip is the difference between feeCoins and the required fees + tip = feeCoins.Sub(requiredFees...) // set fee coins to be ONLY the consumed amount if we are calculated consumed fee to deduct feeCoins = consumedFees } From d426f2c728c643346a28237e68de1fcb468e574e Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 1 Dec 2023 16:44:12 -0500 Subject: [PATCH 21/53] rename --- .../{integration/integration_test.go => e2e/e2e_test.go} | 5 ++--- tests/{integration => e2e}/go.mod | 8 ++++---- tests/{integration => e2e}/go.sum | 4 ++-- tests/{integration => e2e}/setup.go | 2 +- tests/{integration => e2e}/suite.go | 4 ++-- 5 files changed, 11 insertions(+), 12 deletions(-) rename tests/{integration/integration_test.go => e2e/e2e_test.go} (96%) rename tests/{integration => e2e}/go.mod (99%) rename tests/{integration => e2e}/go.sum (99%) rename tests/{integration => e2e}/setup.go (99%) rename tests/{integration => e2e}/suite.go (97%) diff --git a/tests/integration/integration_test.go b/tests/e2e/e2e_test.go similarity index 96% rename from tests/integration/integration_test.go rename to tests/e2e/e2e_test.go index c11f47c..3e04fe1 100644 --- a/tests/integration/integration_test.go +++ b/tests/e2e/e2e_test.go @@ -1,4 +1,4 @@ -package integration_test +package e2e_test import ( "fmt" @@ -13,7 +13,6 @@ import ( ictestutil "github.com/strangelove-ventures/interchaintest/v7/testutil" "github.com/stretchr/testify/suite" - "github.com/skip-mev/feemarket/tests/integration" feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" ) @@ -24,7 +23,7 @@ var ( denom = "stake" image = ibc.DockerImage{ - Repository: "feemarket-integration", + Repository: "feemarket-e2e", Version: "latest", UidGid: "1000:1000", } diff --git a/tests/integration/go.mod b/tests/e2e/go.mod similarity index 99% rename from tests/integration/go.mod rename to tests/e2e/go.mod index 28adf49..14ecba2 100644 --- a/tests/integration/go.mod +++ b/tests/e2e/go.mod @@ -1,4 +1,6 @@ -module github.com/skip-mev/feemarket/tests/integration +module github.com/skip-mev/feemarket/tests/e2e + +go 1.21.4 replace ( cosmossdk.io/api => cosmossdk.io/api v0.3.1 @@ -14,11 +16,9 @@ replace ( golang.org/x/exp => golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2 ) -go 1.21.4 - require ( github.com/cometbft/cometbft v0.37.2 - github.com/cosmos/cosmos-sdk v0.47.5 + github.com/cosmos/cosmos-sdk v0.47.6 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 diff --git a/tests/integration/go.sum b/tests/e2e/go.sum similarity index 99% rename from tests/integration/go.sum rename to tests/e2e/go.sum index abac436..cb59d6a 100644 --- a/tests/integration/go.sum +++ b/tests/e2e/go.sum @@ -560,8 +560,8 @@ github.com/cosmos/btcutil v1.0.5 h1:t+ZFcX77LpKtDBhjucvnOH8C2l2ioGsBNEQ3jef8xFk= github.com/cosmos/btcutil v1.0.5/go.mod h1:IyB7iuqZMJlthe2tkIFL33xPyzbFYP0XVdS8P5lUPis= github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o= github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I= -github.com/cosmos/cosmos-sdk v0.47.5 h1:n1+WjP/VM/gAEOx3TqU2/Ny734rj/MX1kpUnn7zVJP8= -github.com/cosmos/cosmos-sdk v0.47.5/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c= +github.com/cosmos/cosmos-sdk v0.47.6 h1:uyo/eg9NMB66aQZIZUv/LeOPTdSnsU23wZkgFYpjikQ= +github.com/cosmos/cosmos-sdk v0.47.6/go.mod h1:xTc1chW8HyUWCfrgGbjS5jNu9RzlPVrBNfbL9RmZUio= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= diff --git a/tests/integration/setup.go b/tests/e2e/setup.go similarity index 99% rename from tests/integration/setup.go rename to tests/e2e/setup.go index c37efcb..dac5b1f 100644 --- a/tests/integration/setup.go +++ b/tests/e2e/setup.go @@ -1,4 +1,4 @@ -package integration +package e2e import ( "archive/tar" diff --git a/tests/integration/suite.go b/tests/e2e/suite.go similarity index 97% rename from tests/integration/suite.go rename to tests/e2e/suite.go index 06984a1..b6115c5 100644 --- a/tests/integration/suite.go +++ b/tests/e2e/suite.go @@ -1,4 +1,4 @@ -package integration +package e2e import ( "context" @@ -17,7 +17,7 @@ const ( initBalance = 10000000000000 ) -// TestSuite runs the feemarket integration test-suite against a given interchaintest specification +// TestSuite runs the feemarket e2e test-suite against a given interchaintest specification type TestSuite struct { suite.Suite // spec From 03ce1ffdd7f778e58d675fd5bc89f0960e733886 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 1 Dec 2023 16:55:43 -0500 Subject: [PATCH 22/53] rename --- .github/workflows/ictest.yml | 2 +- Makefile | 26 +++++++++---------- ...on.Dockerfile => feemarket.e2e.Dockerfile} | 0 tests/e2e/e2e_test.go | 6 ++--- tests/e2e/suite.go | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) rename contrib/images/{feemarket.integration.Dockerfile => feemarket.e2e.Dockerfile} (100%) diff --git a/.github/workflows/ictest.yml b/.github/workflows/ictest.yml index 8bfdd6d..5545cc8 100644 --- a/.github/workflows/ictest.yml +++ b/.github/workflows/ictest.yml @@ -25,4 +25,4 @@ jobs: - name: tests if: env.GIT_DIFF run: | - go work init && make test-integration \ No newline at end of file + go work init && make test-e2e \ No newline at end of file diff --git a/Makefile b/Makefile index e21f5ba..4186520 100644 --- a/Makefile +++ b/Makefile @@ -18,11 +18,11 @@ COVER_HTML_FILE := cover.html use-main: @go work edit -use . - @go work edit -dropuse ./tests/integration + @go work edit -dropuse ./tests/e2e -use-integration: +use-e2e: @go work edit -dropuse . - @go work edit -use ./tests/integration + @go work edit -use ./tests/e2e tidy: @go mod tidy @@ -102,7 +102,7 @@ build-and-start-app: build-test-app .PHONY: build-test-app build-and-start-app -.PHONY: docker-build docker-build-integration +.PHONY: docker-build docker-build-e2e ############################################################################### ## Docker ## ############################################################################### @@ -111,20 +111,20 @@ docker-build: use-main @echo "Building E2E Docker image..." @DOCKER_BUILDKIT=1 docker build -t skip-mev/feemarket-e2e -f contrib/images/feemarket.e2e.Dockerfile . -docker-build-integration: use-main - @echo "Building integration-test Docker image..." - @DOCKER_BUILDKIT=1 docker build -t feemarket-integration -f contrib/images/feemarket.integration.Dockerfile . +docker-build-e2e: use-main + @echo "Building e2e-test Docker image..." + @DOCKER_BUILDKIT=1 docker build -t feemarket-e2e -f contrib/images/feemarket.e2e.Dockerfile . ############################################################################### ### Tests ### ############################################################################### -TEST_INTEGRATION_DEPS = docker-build-integration use-integration -TEST_INTEGRATION_TAGS = integration +TEST_E2E_DEPS = docker-build-e2e use-e2e +TEST_E2E_TAGS = e2e -test-integration: $(TEST_INTEGRATION_DEPS) - @echo "Running integration tests..." - @go test ./tests/integration/integration_test.go -timeout 30m -p 1 -race -v -tags='$(TEST_INTEGRATION_TAGS)' +test-e2e: $(TEST_E2E_DEPS) + @echo "Running e2e tests..." + @go test ./tests/e2e/e2e_test.go -timeout 30m -p 1 -race -v -tags='$(TEST_E2E_TAGS)' test: @go test -v -race $(shell go list ./... | grep -v tests/) @@ -139,7 +139,7 @@ test-cover: @rm $(COVER_FILE) -.PHONY: test test-integration +.PHONY: test test-e2e ############################################################################### ### Protobuf ### diff --git a/contrib/images/feemarket.integration.Dockerfile b/contrib/images/feemarket.e2e.Dockerfile similarity index 100% rename from contrib/images/feemarket.integration.Dockerfile rename to contrib/images/feemarket.e2e.Dockerfile diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 3e04fe1..fd3216a 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -5,7 +5,6 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module/testutil" interchaintest "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" @@ -13,6 +12,7 @@ import ( ictestutil "github.com/strangelove-ventures/interchaintest/v7/testutil" "github.com/stretchr/testify/suite" + "github.com/skip-mev/feemarket/tests/e2e" feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" ) @@ -99,7 +99,7 @@ func MakeEncodingConfig() *testutil.TestEncodingConfig { return &cfg } -func TestIntegrationTestSuite(t *testing.T) { - s := integration.NewIntegrationTestSuiteFromSpec(spec) +func TestE2ETestSuite(t *testing.T) { + s := e2e.NewE2ETestSuiteFromSpec(spec) suite.Run(t, s) } diff --git a/tests/e2e/suite.go b/tests/e2e/suite.go index b6115c5..586fa60 100644 --- a/tests/e2e/suite.go +++ b/tests/e2e/suite.go @@ -40,7 +40,7 @@ type TestSuite struct { cdc codec.Codec } -func NewIntegrationTestSuiteFromSpec(spec *interchaintest.ChainSpec) *TestSuite { +func NewE2ETestSuiteFromSpec(spec *interchaintest.ChainSpec) *TestSuite { return &TestSuite{ spec: spec, denom: "stake", From afd8766bb651b585bebc4ac1aa973297ba3cca39 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 1 Dec 2023 17:04:25 -0500 Subject: [PATCH 23/53] sample --- testutils/sample/sample.go | 226 +++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 testutils/sample/sample.go diff --git a/testutils/sample/sample.go b/testutils/sample/sample.go new file mode 100644 index 0000000..7e065b3 --- /dev/null +++ b/testutils/sample/sample.go @@ -0,0 +1,226 @@ +// Package sample provides methods to initialize sample object of various types for test purposes +package sample + +import ( + "math/rand" + "strconv" + "testing" + "time" + + 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) + 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() +} From 1b32f1041ad760c37e69fd18809dd4d5dae3e93b Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 1 Dec 2023 17:04:36 -0500 Subject: [PATCH 24/53] encoding --- testutils/encoding/encoding.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 testutils/encoding/encoding.go diff --git a/testutils/encoding/encoding.go b/testutils/encoding/encoding.go new file mode 100644 index 0000000..636f883 --- /dev/null +++ b/testutils/encoding/encoding.go @@ -0,0 +1,28 @@ +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, + } +} From 50313e3281038c18455b26f09cfd908155959d68 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 1 Dec 2023 17:06:35 -0500 Subject: [PATCH 25/53] sample --- testutils/sample/sample.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testutils/sample/sample.go b/testutils/sample/sample.go index 7e065b3..5be5b79 100644 --- a/testutils/sample/sample.go +++ b/testutils/sample/sample.go @@ -2,6 +2,7 @@ package sample import ( + "github.com/cosmos/cosmos-sdk/x/group" "math/rand" "strconv" "testing" @@ -48,6 +49,7 @@ func InterfaceRegistry() codectypes.InterfaceRegistry { distrtypes.RegisterInterfaces(interfaceRegistry) vestingtypes.RegisterInterfaces(interfaceRegistry) feegrant.RegisterInterfaces(interfaceRegistry) + group.RegisterInterfaces(interfaceRegistry) govtypes.RegisterInterfaces(interfaceRegistry) evidencetypes.RegisterInterfaces(interfaceRegistry) crisistypes.RegisterInterfaces(interfaceRegistry) From 16854b21d42b7bd262723f5a6ed678f5c0668626 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Fri, 1 Dec 2023 17:09:18 -0500 Subject: [PATCH 26/53] use sample --- tests/e2e/setup.go | 15 ++------------- tests/e2e/suite.go | 9 +++++++++ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/e2e/setup.go b/tests/e2e/setup.go index dac5b1f..243c482 100644 --- a/tests/e2e/setup.go +++ b/tests/e2e/setup.go @@ -7,8 +7,8 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/skip-mev/feemarket/testutils/sample" "io" - "math/rand" "os" "path" "strconv" @@ -402,7 +402,7 @@ func (s *TestSuite) GetAndFundTestUserWithMnemonic( chain *cosmos.CosmosChain, ) (ibc.Wallet, error) { chainCfg := chain.Config() - keyName := fmt.Sprintf("%s-%s-%s", keyNamePrefix, chainCfg.ChainID, RandLowerCaseLetterString(3)) + keyName := fmt.Sprintf("%s-%s-%s", keyNamePrefix, chainCfg.ChainID, sample.AlphaString(r, 3)) user, err := chain.BuildWallet(ctx, keyName, mnemonic) if err != nil { return nil, fmt.Errorf("failed to get source user wallet: %w", err) @@ -470,14 +470,3 @@ func (s *TestSuite) ExecTx(ctx context.Context, chain *cosmos.CosmosChain, keyNa return string(stdout), nil } - -// RandLowerCaseLetterString returns a lowercase letter string of given length -func RandLowerCaseLetterString(length int) string { - chars := []byte("abcdefghijklmnopqrstuvwxyz") - - b := make([]byte, length) - for i := range b { - b[i] = chars[rand.Intn(len(chars))] - } - return string(b) -} diff --git a/tests/e2e/suite.go b/tests/e2e/suite.go index 586fa60..140773b 100644 --- a/tests/e2e/suite.go +++ b/tests/e2e/suite.go @@ -2,6 +2,7 @@ package e2e import ( "context" + "math/rand" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -17,6 +18,14 @@ const ( initBalance = 10000000000000 ) +var r *rand.Rand + +// initialize random generator with fixed seed for reproducibility +func init() { + s := rand.NewSource(1) + r = rand.New(s) +} + // TestSuite runs the feemarket e2e test-suite against a given interchaintest specification type TestSuite struct { suite.Suite From aaac5b0f729878bd7b71f099c6c6f0f08a4d2bb4 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 3 Dec 2023 18:18:44 -0500 Subject: [PATCH 27/53] add --- tests/e2e/setup.go | 3 +- testutils/keeper/bank.go | 21 ++++ testutils/keeper/bank_test.go | 38 ++++++++ testutils/keeper/initializer.go | 165 ++++++++++++++++++++++++++++++++ testutils/keeper/keeper.go | 96 +++++++++++++++++++ testutils/sample/sample.go | 8 +- 6 files changed, 329 insertions(+), 2 deletions(-) create mode 100644 testutils/keeper/bank.go create mode 100644 testutils/keeper/bank_test.go create mode 100644 testutils/keeper/initializer.go create mode 100644 testutils/keeper/keeper.go diff --git a/tests/e2e/setup.go b/tests/e2e/setup.go index 243c482..154c2f7 100644 --- a/tests/e2e/setup.go +++ b/tests/e2e/setup.go @@ -7,7 +7,6 @@ import ( "encoding/hex" "encoding/json" "fmt" - "github.com/skip-mev/feemarket/testutils/sample" "io" "os" "path" @@ -16,6 +15,8 @@ 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" diff --git a/testutils/keeper/bank.go b/testutils/keeper/bank.go new file mode 100644 index 0000000..ec5724f --- /dev/null +++ b/testutils/keeper/bank.go @@ -0,0 +1,21 @@ +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 new file mode 100644 index 0000000..d9eac16 --- /dev/null +++ b/testutils/keeper/bank_test.go @@ -0,0 +1,38 @@ +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 new file mode 100644 index 0000000..899775e --- /dev/null +++ b/testutils/keeper/initializer.go @@ -0,0 +1,165 @@ +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" + 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" +) + +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}, +} + +// 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(), + ) +} diff --git a/testutils/keeper/keeper.go b/testutils/keeper/keeper.go new file mode 100644 index 0000000..4712f86 --- /dev/null +++ b/testutils/keeper/keeper.go @@ -0,0 +1,96 @@ +// Package keeper provides methods to initialize SDK keepers with local storage for test purposes +package keeper + +import ( + "testing" + "time" + + "github.com/cometbft/cometbft/libs/log" + tmproto "github.com/cometbft/cometbft/proto/tendermint/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" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/stretchr/testify/require" +) + +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 +} + +// TestMsgServers holds all message servers used during keeper tests for all modules +type TestMsgServers struct { + T testing.TB +} + +// SetupOption represents an option that can be provided to NewTestSetup +type SetupOption func(*setupOptions) + +// setupOptions represents the set of SetupOption +type setupOptions struct { + LaunchHooksMock bool +} + +// 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) + } + + initializer := newInitializer() + + paramKeeper := initializer.Param() + authKeeper := initializer.Auth(paramKeeper) + bankKeeper := initializer.Bank(paramKeeper, authKeeper) + stakingKeeper := initializer.Staking(authKeeper, bankKeeper, paramKeeper) + distrKeeper := initializer.Distribution(authKeeper, bankKeeper, stakingKeeper) + require.NoError(t, initializer.StateStore.LoadLatestVersion()) + + // Create a context using a custom timestamp + ctx := sdk.NewContext(initializer.StateStore, tmproto.Header{ + Time: ExampleTimestamp, + Height: ExampleHeight, + }, false, log.NewNopLogger()) + + // Initialize community pool + distrKeeper.SetFeePool(ctx, distrtypes.InitialFeePool()) + + // Initialize params + err := distrKeeper.SetParams(ctx, distrtypes.DefaultParams()) + if err != nil { + panic(err) + } + err = stakingKeeper.SetParams(ctx, stakingtypes.DefaultParams()) + if err != nil { + panic(err) + } + + // set max shares - only set during app InitGenesis + return ctx, TestKeepers{ + T: t, + AccountKeeper: authKeeper, + BankKeeper: bankKeeper, + DistrKeeper: distrKeeper, + StakingKeeper: stakingKeeper, + }, TestMsgServers{ + T: t, + } +} diff --git a/testutils/sample/sample.go b/testutils/sample/sample.go index 5be5b79..744a4e0 100644 --- a/testutils/sample/sample.go +++ b/testutils/sample/sample.go @@ -2,12 +2,13 @@ package sample import ( - "github.com/cosmos/cosmos-sdk/x/group" "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" @@ -226,3 +227,8 @@ func Time(r *rand.Rand) time.Time { 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())) +} From 33298b96e2c21d1bd635256da0d437f140a4b80e Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 3 Dec 2023 18:44:04 -0500 Subject: [PATCH 28/53] network suite --- tests/integration/integration_test.go | 22 +++++++ tests/integration/network_test.go | 17 ++++++ testutils/network/network.go | 79 ++++++++++++++++++++++++++ testutils/networksuite/networksuite.go | 46 +++++++++++++++ 4 files changed, 164 insertions(+) create mode 100644 tests/integration/integration_test.go create mode 100644 tests/integration/network_test.go create mode 100644 testutils/network/network.go create mode 100644 testutils/networksuite/networksuite.go diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go new file mode 100644 index 0000000..dbc7e26 --- /dev/null +++ b/tests/integration/integration_test.go @@ -0,0 +1,22 @@ +package integration_test + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "testing" + + testkeeper "github.com/skip-mev/feemarket/testutils/keeper" +) + +func TestKeepers(t *testing.T) { + var ( + ctx, tk, _ = testkeeper.NewTestSetup(t) + wCtx = sdk.WrapSDKContext(ctx) + ) + + numIterations := 100 + + for i := 0; i < numIterations; i++ { + _ = tk + _ = wCtx + } +} diff --git a/tests/integration/network_test.go b/tests/integration/network_test.go new file mode 100644 index 0000000..44b8182 --- /dev/null +++ b/tests/integration/network_test.go @@ -0,0 +1,17 @@ +package integration_test + +import ( + "testing" + + "github.com/stretchr/testify/suite" +) + +// QueryTestSuite is a test suite for query tests +type NetworkTestSuite struct { + networksuite.NetworkTestSuite +} + +// TestQueryTestSuite runs test of the query suite +func TestNetworkTestSuite(t *testing.T) { + suite.Run(t, new(NetworkTestSuite)) +} diff --git a/testutils/network/network.go b/testutils/network/network.go new file mode 100644 index 0000000..de03cdd --- /dev/null +++ b/testutils/network/network.go @@ -0,0 +1,79 @@ +// Package network allows to programmatically spin up a local network for CLI tests +package network + +import ( + "fmt" + "testing" + "time" + + 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" + "github.com/skip-mev/feemarket/testutils" +) + +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 ( + cdc = testutils.CreateTestEncodingConfig() + chainID = "chain-" + tmrand.NewRand().Str(6) + ) + return network.Config{ + Codec: cdc.Codec, + TxConfig: cdc.TxConfig, + LegacyAmino: cdc.Amino, + InterfaceRegistry: cdc.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(cdc.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 new file mode 100644 index 0000000..ccba394 --- /dev/null +++ b/testutils/networksuite/networksuite.go @@ -0,0 +1,46 @@ +// Package networksuite provides a base test suite for tests that need a local network instance +package networksuite + +import ( + "math/rand" + + "github.com/cosmos/gogoproto/proto" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + "github.com/skip-mev/feemarket/testutils/network" + "github.com/skip-mev/feemarket/testutils/sample" + feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" +) + +// NetworkTestSuite is a test suite for query tests that initializes a network instance. +type NetworkTestSuite struct { + suite.Suite + Network *network.Network + FeeMarketState feemarkettypes.GenesisState +} + +// SetupSuite setups the local network with a genesis state. +func (nts *NetworkTestSuite) SetupSuite() { + var ( + r = sample.Rand() + cfg = network.DefaultConfig() + ) + + updateGenesisConfigState := func(moduleName string, moduleState proto.Message) { + buf, err := cfg.Codec.MarshalJSON(moduleState) + require.NoError(nts.T(), err) + cfg.GenesisState[moduleName] = buf + } + + // initialize fee market + require.NoError(nts.T(), cfg.Codec.UnmarshalJSON(cfg.GenesisState[feemarkettypes.ModuleName], &nts.FeeMarketState)) + nts.FeeMarketState = populateFeeMarket(r, nts.FeeMarketState) + updateGenesisConfigState(feemarkettypes.ModuleName, &nts.FeeMarketState) + + nts.Network = network.New(nts.T(), cfg) +} + +func populateFeeMarket(r *rand.Rand, feeMarketState feemarkettypes.GenesisState) feemarkettypes.GenesisState { + return feeMarketState +} From e6c2b6947c675ba12ffd52801093af4f83dc7d7b Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 3 Dec 2023 19:24:49 -0500 Subject: [PATCH 29/53] wip --- tests/integration/network_test.go | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/integration/network_test.go b/tests/integration/network_test.go index 44b8182..badcc08 100644 --- a/tests/integration/network_test.go +++ b/tests/integration/network_test.go @@ -1,9 +1,17 @@ package integration_test import ( + "fmt" + "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "strconv" "testing" + tmcli "github.com/cometbft/cometbft/libs/cli" "github.com/stretchr/testify/suite" + + "github.com/skip-mev/feemarket/testutils/networksuite" ) // QueryTestSuite is a test suite for query tests @@ -15,3 +23,57 @@ type NetworkTestSuite struct { func TestNetworkTestSuite(t *testing.T) { suite.Run(t, new(NetworkTestSuite)) } + +func (suite *NetworkTestSuite) TestShowGenesisAccount() { + ctx := suite.Network.Validators[0].ClientCtx + + common := []string{ + fmt.Sprintf("--%s=json", tmcli.OutputFlag), + } + for _, tc := range []struct { + desc string + idLaunchID string + idAddress string + + args []string + err error + obj types.GenesisAccount + }{ + { + desc: "should show an existing genesis account", + idLaunchID: strconv.Itoa(int(accs[0].LaunchID)), + idAddress: accs[0].Address, + + args: common, + obj: accs[0], + }, + { + desc: "should send error for a non existing genesis account", + idLaunchID: strconv.Itoa(100000), + idAddress: strconv.Itoa(100000), + + args: common, + err: status.Error(codes.NotFound, "not found"), + }, + } { + suite.T().Run(tc.desc, func(t *testing.T) { + args := []string{ + tc.idLaunchID, + tc.idAddress, + } + args = append(args, tc.args...) + out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowGenesisAccount(), args) + if tc.err != nil { + stat, ok := status.FromError(tc.err) + require.True(t, ok) + require.ErrorIs(t, stat.Err(), tc.err) + } else { + require.NoError(t, err) + var resp types.QueryGetGenesisAccountResponse + require.NoError(t, suite.Network.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) + require.NotNil(t, resp.GenesisAccount) + require.Equal(t, tc.obj, resp.GenesisAccount) + } + }) + } +} From f918b59d7dca2be22868238143e9c3ba0b925aee Mon Sep 17 00:00:00 2001 From: aljo242 Date: Sun, 3 Dec 2023 22:06:12 -0500 Subject: [PATCH 30/53] refactor --- .github/workflows/test.yml | 26 +++++++-- Makefile | 9 ++-- tests/integration/network_test.go | 87 ++++++++++++++++++++----------- 3 files changed, 84 insertions(+), 38 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ead0bbe..56f5d93 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,8 +5,6 @@ on: push: branches: - main - paths-ignore: - - tests/** permissions: contents: read @@ -16,7 +14,7 @@ concurrency: cancel-in-progress: true jobs: - test: + test-unit: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -35,4 +33,24 @@ jobs: - name: tests if: env.GIT_DIFF run: | - make test \ No newline at end of file + make test-unit + test-integration: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: 1.21.4 + cache: true + cache-dependency-path: go.sum + - uses: technote-space/get-diff-action@v6.1.2 + id: git_diff + with: + PATTERNS: | + **/*.go + go.mod + go.sum + - name: tests + if: env.GIT_DIFF + run: | + make test-integration \ No newline at end of file diff --git a/Makefile b/Makefile index 4186520..e835e5b 100644 --- a/Makefile +++ b/Makefile @@ -126,10 +126,12 @@ test-e2e: $(TEST_E2E_DEPS) @echo "Running e2e tests..." @go test ./tests/e2e/e2e_test.go -timeout 30m -p 1 -race -v -tags='$(TEST_E2E_TAGS)' -test: +test-unit: @go test -v -race $(shell go list ./... | grep -v tests/) -## test-cover: Run the unit tests and create a coverage html report +test-integration: + @go test -v -race ./tests/integration + test-cover: @echo Running unit tests and creating coverage report... @go test -mod=readonly -v -timeout 30m -coverprofile=$(COVER_FILE) -covermode=atomic $(shell go list ./... | grep -v tests/ | grep -v api/ | grep -v testutils/) @@ -138,8 +140,9 @@ test-cover: @go tool cover -html=$(COVER_FILE) -o $(COVER_HTML_FILE) @rm $(COVER_FILE) +test-all: test-unit test-integration test-e2e -.PHONY: test test-e2e +.PHONY: test-unit test-e2e test-integration test-cover test-all ############################################################################### ### Protobuf ### diff --git a/tests/integration/network_test.go b/tests/integration/network_test.go index badcc08..8fc148e 100644 --- a/tests/integration/network_test.go +++ b/tests/integration/network_test.go @@ -2,16 +2,17 @@ package integration_test import ( "fmt" - "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/stretchr/testify/require" - "google.golang.org/grpc/codes" - "strconv" "testing" tmcli "github.com/cometbft/cometbft/libs/cli" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "google.golang.org/grpc/status" "github.com/skip-mev/feemarket/testutils/networksuite" + "github.com/skip-mev/feemarket/x/feemarket/client/cli" + "github.com/skip-mev/feemarket/x/feemarket/types" ) // QueryTestSuite is a test suite for query tests @@ -24,55 +25,79 @@ func TestNetworkTestSuite(t *testing.T) { suite.Run(t, new(NetworkTestSuite)) } -func (suite *NetworkTestSuite) TestShowGenesisAccount() { - ctx := suite.Network.Validators[0].ClientCtx +func (s *NetworkTestSuite) TestGetParams() { + s.T().Parallel() + + ctx := s.Network.Validators[0].ClientCtx common := []string{ fmt.Sprintf("--%s=json", tmcli.OutputFlag), } for _, tc := range []struct { - desc string - idLaunchID string - idAddress string + name string args []string err error - obj types.GenesisAccount + obj types.Params }{ { - desc: "should show an existing genesis account", - idLaunchID: strconv.Itoa(int(accs[0].LaunchID)), - idAddress: accs[0].Address, - + name: "should return default params", args: common, - obj: accs[0], + obj: types.DefaultParams(), }, - { - desc: "should send error for a non existing genesis account", - idLaunchID: strconv.Itoa(100000), - idAddress: strconv.Itoa(100000), + } { + s.T().Run(tc.name, func(t *testing.T) { + tc := tc + out, err := clitestutil.ExecTestCLICmd(ctx, cli.GetParamsCmd(), tc.args) + if tc.err != nil { + stat, ok := status.FromError(tc.err) + require.True(t, ok) + require.ErrorIs(t, stat.Err(), tc.err) + } else { + require.NoError(t, err) + var resp types.ParamsResponse + require.NoError(t, s.Network.Config.Codec.UnmarshalJSON(out.Bytes(), &resp.Params)) + require.NotNil(t, resp.Params) + require.Equal(t, tc.obj, resp.Params) + } + }) + } +} + +func (s *NetworkTestSuite) TestGetState() { + s.T().Parallel() + + ctx := s.Network.Validators[0].ClientCtx + + common := []string{ + fmt.Sprintf("--%s=json", tmcli.OutputFlag), + } + for _, tc := range []struct { + name string + args []string + err error + obj types.State + }{ + { + name: "should return default state", args: common, - err: status.Error(codes.NotFound, "not found"), + obj: types.DefaultState(), }, } { - suite.T().Run(tc.desc, func(t *testing.T) { - args := []string{ - tc.idLaunchID, - tc.idAddress, - } - args = append(args, tc.args...) - out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowGenesisAccount(), args) + s.T().Run(tc.name, func(t *testing.T) { + tc := tc + out, err := clitestutil.ExecTestCLICmd(ctx, cli.GetStateCmd(), tc.args) if tc.err != nil { stat, ok := status.FromError(tc.err) require.True(t, ok) require.ErrorIs(t, stat.Err(), tc.err) } else { require.NoError(t, err) - var resp types.QueryGetGenesisAccountResponse - require.NoError(t, suite.Network.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) - require.NotNil(t, resp.GenesisAccount) - require.Equal(t, tc.obj, resp.GenesisAccount) + var resp types.StateResponse + require.NoError(t, s.Network.Config.Codec.UnmarshalJSON(out.Bytes(), &resp.State)) + require.NotNil(t, resp.State) + require.Equal(t, tc.obj, resp.State) } }) } From 1a410d81094d09c0fd830238f3c051ab5ad628c7 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 4 Dec 2023 07:49:14 -0500 Subject: [PATCH 31/53] add feemarket --- tests/integration/integration_test.go | 3 +- testutils/keeper/initializer.go | 17 ++++++++ testutils/keeper/keeper.go | 60 +++++++++++++++++---------- x/feemarket/keeper/keeper.go | 5 --- x/feemarket/keeper/keeper_test.go | 2 +- 5 files changed, 58 insertions(+), 29 deletions(-) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index dbc7e26..9dd0d4c 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -1,9 +1,10 @@ package integration_test import ( - sdk "github.com/cosmos/cosmos-sdk/types" "testing" + sdk "github.com/cosmos/cosmos-sdk/types" + testkeeper "github.com/skip-mev/feemarket/testutils/keeper" ) diff --git a/testutils/keeper/initializer.go b/testutils/keeper/initializer.go index 899775e..6865016 100644 --- a/testutils/keeper/initializer.go +++ b/testutils/keeper/initializer.go @@ -21,6 +21,9 @@ import ( upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper" + feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" + "github.com/skip-mev/feemarket/testutils/sample" ) @@ -163,3 +166,17 @@ func (i initializer) Distribution( 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(), + ) +} diff --git a/testutils/keeper/keeper.go b/testutils/keeper/keeper.go index 4712f86..6c90b0b 100644 --- a/testutils/keeper/keeper.go +++ b/testutils/keeper/keeper.go @@ -5,6 +5,9 @@ import ( "testing" "time" + feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper" + feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" + "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -27,25 +30,25 @@ var ( // 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 + T testing.TB + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.Keeper + DistrKeeper distrkeeper.Keeper + StakingKeeper *stakingkeeper.Keeper + FeeMarketKeeper *feemarketkeeper.Keeper } // TestMsgServers holds all message servers used during keeper tests for all modules type TestMsgServers struct { - T testing.TB + T testing.TB + 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 { - LaunchHooksMock bool -} +type setupOptions struct{} // 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) { @@ -62,6 +65,8 @@ func NewTestSetup(t testing.TB, options ...SetupOption) (sdk.Context, TestKeeper bankKeeper := initializer.Bank(paramKeeper, authKeeper) stakingKeeper := initializer.Staking(authKeeper, bankKeeper, paramKeeper) distrKeeper := initializer.Distribution(authKeeper, bankKeeper, stakingKeeper) + feeMarketKeeper := initializer.FeeMarket(authKeeper) + require.NoError(t, initializer.StateStore.LoadLatestVersion()) // Create a context using a custom timestamp @@ -70,10 +75,7 @@ func NewTestSetup(t testing.TB, options ...SetupOption) (sdk.Context, TestKeeper Height: ExampleHeight, }, false, log.NewNopLogger()) - // Initialize community pool - distrKeeper.SetFeePool(ctx, distrtypes.InitialFeePool()) - - // Initialize params + // initialize params err := distrKeeper.SetParams(ctx, distrtypes.DefaultParams()) if err != nil { panic(err) @@ -82,15 +84,29 @@ func NewTestSetup(t testing.TB, options ...SetupOption) (sdk.Context, TestKeeper if err != nil { panic(err) } + err = feeMarketKeeper.SetState(ctx, feemarkettypes.DefaultState()) + if err != nil { + panic(err) + } + err = feeMarketKeeper.SetParams(ctx, feemarkettypes.DefaultParams()) + if err != nil { + panic(err) + } + + // initialize msg servers + feeMarketMsgSrv := feemarketkeeper.NewMsgServer(*feeMarketKeeper) - // set max shares - only set during app InitGenesis - return ctx, TestKeepers{ - T: t, - AccountKeeper: authKeeper, - BankKeeper: bankKeeper, - DistrKeeper: distrKeeper, - StakingKeeper: stakingKeeper, - }, TestMsgServers{ - T: t, + return ctx, + TestKeepers{ + T: t, + AccountKeeper: authKeeper, + BankKeeper: bankKeeper, + DistrKeeper: distrKeeper, + StakingKeeper: stakingKeeper, + FeeMarketKeeper: feeMarketKeeper, + }, + TestMsgServers{ + T: t, + FeeMarketMsgServer: feeMarketMsgSrv, } } diff --git a/x/feemarket/keeper/keeper.go b/x/feemarket/keeper/keeper.go index 90a8cb7..8522d66 100644 --- a/x/feemarket/keeper/keeper.go +++ b/x/feemarket/keeper/keeper.go @@ -28,11 +28,6 @@ func NewKeeper( authKeeper types.AccountKeeper, authority string, ) *Keeper { - // ensure governance module account is set - if addr := authKeeper.GetModuleAddress(types.FeeCollectorName); addr == nil { - panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) - } - if _, err := sdk.AccAddressFromBech32(authority); err != nil { panic(fmt.Sprintf("invalid authority address: %s", authority)) } diff --git a/x/feemarket/keeper/keeper_test.go b/x/feemarket/keeper/keeper_test.go index 5343e35..f93868f 100644 --- a/x/feemarket/keeper/keeper_test.go +++ b/x/feemarket/keeper/keeper_test.go @@ -44,7 +44,7 @@ func (s *KeeperTestSuite) SetupTest() { s.authorityAccount = []byte("authority") s.accountKeeper = mocks.NewAccountKeeper(s.T()) - s.accountKeeper.On("GetModuleAddress", "feemarket-fee-collector").Return(sdk.AccAddress("feemarket-fee-collector")) + // s.accountKeeper.On("GetModuleAddress", "feemarket-fee-collector").Return(sdk.AccAddress("feemarket-fee-collector")) s.feemarketKeeper = keeper.NewKeeper( s.encCfg.Codec, From 3d5ac574beee6e44c0f84542eb007f1c54ef3a64 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 4 Dec 2023 08:04:50 -0500 Subject: [PATCH 32/53] init integration pkg --- tests/integration/integration_test.go | 96 ++++++++++++++++++++++++--- testutils/keeper/initializer.go | 44 ++++++++---- testutils/keeper/keeper.go | 10 ++- x/feemarket/keeper/keeper_test.go | 40 +++++++++++ 4 files changed, 163 insertions(+), 27 deletions(-) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 9dd0d4c..698a374 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -3,21 +3,97 @@ package integration_test import ( "testing" + "cosmossdk.io/math" + "github.com/stretchr/testify/suite" + + "github.com/skip-mev/feemarket/testutils" + "github.com/skip-mev/feemarket/x/feemarket/types" + sdk "github.com/cosmos/cosmos-sdk/types" testkeeper "github.com/skip-mev/feemarket/testutils/keeper" ) -func TestKeepers(t *testing.T) { - var ( - ctx, tk, _ = testkeeper.NewTestSetup(t) - wCtx = sdk.WrapSDKContext(ctx) - ) +type IntegrationTestSuite struct { + suite.Suite + + testKeepers testkeeper.TestKeepers + testMsgServers testkeeper.TestMsgServers + encCfg testutils.EncodingConfig + ctx sdk.Context + authorityAccount sdk.AccAddress +} + +func TestIntegrationTestSuite(t *testing.T) { + suite.Run(t, new(IntegrationTestSuite)) +} + +func (s *IntegrationTestSuite) SetupTest() { + s.encCfg = testutils.CreateTestEncodingConfig() + + 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) + s.Require().NoError(err) + + gotState, err := s.testKeepers.FeeMarketKeeper.GetState(s.ctx) + s.Require().NoError(err) + + s.Require().EqualValues(state, gotState) + }) + + s.Run("set and get aimd eip1559 state", func() { + state := types.DefaultAIMDState() + + err := s.testKeepers.FeeMarketKeeper.SetState(s.ctx, state) + s.Require().NoError(err) + + gotState, err := s.testKeepers.FeeMarketKeeper.GetState(s.ctx) + s.Require().NoError(err) + + s.Require().Equal(state, gotState) + }) +} + +func (s *IntegrationTestSuite) TestParams() { + s.Run("set and get default params", func() { + params := types.DefaultParams() + + err := s.testKeepers.FeeMarketKeeper.SetParams(s.ctx, params) + s.Require().NoError(err) + + gotParams, err := s.testKeepers.FeeMarketKeeper.GetParams(s.ctx) + s.Require().NoError(err) + + s.Require().EqualValues(params, gotParams) + }) + + s.Run("set and get custom params", func() { + params := types.Params{ + Alpha: math.LegacyMustNewDecFromStr("0.1"), + Beta: math.LegacyMustNewDecFromStr("0.1"), + Theta: math.LegacyMustNewDecFromStr("0.1"), + Delta: math.LegacyMustNewDecFromStr("0.1"), + MinBaseFee: math.NewInt(10), + MinLearningRate: math.LegacyMustNewDecFromStr("0.1"), + MaxLearningRate: math.LegacyMustNewDecFromStr("0.1"), + TargetBlockUtilization: 5, + MaxBlockUtilization: 10, + Window: 1, + Enabled: true, + } + + err := s.testKeepers.FeeMarketKeeper.SetParams(s.ctx, params) + s.Require().NoError(err) - numIterations := 100 + gotParams, err := s.testKeepers.FeeMarketKeeper.GetParams(s.ctx) + s.Require().NoError(err) - for i := 0; i < numIterations; i++ { - _ = tk - _ = wCtx - } + s.Require().EqualValues(params, gotParams) + }) } diff --git a/testutils/keeper/initializer.go b/testutils/keeper/initializer.go index 6865016..c09287c 100644 --- a/testutils/keeper/initializer.go +++ b/testutils/keeper/initializer.go @@ -12,6 +12,8 @@ import ( 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" @@ -21,18 +23,19 @@ import ( 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" - - "github.com/skip-mev/feemarket/testutils/sample" ) 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}, + 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 @@ -62,7 +65,7 @@ func ModuleAccountAddrs(maccPerms map[string][]string) map[string]bool { return modAccAddrs } -func (i initializer) Param() paramskeeper.Keeper { +func (i *initializer) Param() paramskeeper.Keeper { storeKey := sdk.NewKVStoreKey(paramstypes.StoreKey) tkeys := sdk.NewTransientStoreKey(paramstypes.TStoreKey) @@ -77,7 +80,7 @@ func (i initializer) Param() paramskeeper.Keeper { ) } -func (i initializer) Auth(paramKeeper paramskeeper.Keeper) authkeeper.AccountKeeper { +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) @@ -92,7 +95,7 @@ func (i initializer) Auth(paramKeeper paramskeeper.Keeper) authkeeper.AccountKee ) } -func (i initializer) Bank(paramKeeper paramskeeper.Keeper, authKeeper authkeeper.AccountKeeper) bankkeeper.Keeper { +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) @@ -113,7 +116,7 @@ type ProtocolVersionSetter struct{} func (vs ProtocolVersionSetter) SetProtocolVersion(uint64) {} -func (i initializer) Upgrade() *upgradekeeper.Keeper { +func (i *initializer) Upgrade() *upgradekeeper.Keeper { storeKey := sdk.NewKVStoreKey(upgradetypes.StoreKey) i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB) @@ -130,7 +133,7 @@ func (i initializer) Upgrade() *upgradekeeper.Keeper { ) } -func (i initializer) Staking( +func (i *initializer) Staking( authKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper, paramKeeper paramskeeper.Keeper, @@ -148,7 +151,7 @@ func (i initializer) Staking( ) } -func (i initializer) Distribution( +func (i *initializer) Distribution( authKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper, stakingKeeper *stakingkeeper.Keeper, @@ -167,7 +170,7 @@ func (i initializer) Distribution( ) } -func (i initializer) FeeMarket( +func (i *initializer) FeeMarket( authKeeper authkeeper.AccountKeeper, ) *feemarketkeeper.Keeper { storeKey := sdk.NewKVStoreKey(feemarkettypes.StoreKey) @@ -180,3 +183,16 @@ func (i initializer) FeeMarket( 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 6c90b0b..1eae498 100644 --- a/testutils/keeper/keeper.go +++ b/testutils/keeper/keeper.go @@ -5,9 +5,6 @@ import ( "testing" "time" - feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper" - feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" - "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -15,9 +12,13 @@ import ( 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" "github.com/stretchr/testify/require" + + feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper" + feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" ) var ( @@ -36,6 +37,7 @@ type TestKeepers struct { DistrKeeper distrkeeper.Keeper StakingKeeper *stakingkeeper.Keeper FeeMarketKeeper *feemarketkeeper.Keeper + FeeGrantKeeper feegrantkeeper.Keeper } // TestMsgServers holds all message servers used during keeper tests for all modules @@ -66,6 +68,7 @@ func NewTestSetup(t testing.TB, options ...SetupOption) (sdk.Context, TestKeeper stakingKeeper := initializer.Staking(authKeeper, bankKeeper, paramKeeper) distrKeeper := initializer.Distribution(authKeeper, bankKeeper, stakingKeeper) feeMarketKeeper := initializer.FeeMarket(authKeeper) + feeGrantKeeper := initializer.FeeGrant(authKeeper) require.NoError(t, initializer.StateStore.LoadLatestVersion()) @@ -104,6 +107,7 @@ func NewTestSetup(t testing.TB, options ...SetupOption) (sdk.Context, TestKeeper DistrKeeper: distrKeeper, StakingKeeper: stakingKeeper, FeeMarketKeeper: feeMarketKeeper, + FeeGrantKeeper: feeGrantKeeper, }, TestMsgServers{ T: t, diff --git a/x/feemarket/keeper/keeper_test.go b/x/feemarket/keeper/keeper_test.go index f93868f..16daac2 100644 --- a/x/feemarket/keeper/keeper_test.go +++ b/x/feemarket/keeper/keeper_test.go @@ -3,6 +3,8 @@ package keeper_test import ( "testing" + "cosmossdk.io/math" + storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -88,3 +90,41 @@ func (s *KeeperTestSuite) TestState() { s.Require().Equal(state, gotState) }) } + +func (s *KeeperTestSuite) TestParams() { + s.Run("set and get default params", func() { + params := types.DefaultParams() + + err := s.feemarketKeeper.SetParams(s.ctx, params) + s.Require().NoError(err) + + gotParams, err := s.feemarketKeeper.GetParams(s.ctx) + s.Require().NoError(err) + + s.Require().EqualValues(params, gotParams) + }) + + s.Run("set and get custom params", func() { + params := types.Params{ + Alpha: math.LegacyMustNewDecFromStr("0.1"), + Beta: math.LegacyMustNewDecFromStr("0.1"), + Theta: math.LegacyMustNewDecFromStr("0.1"), + Delta: math.LegacyMustNewDecFromStr("0.1"), + MinBaseFee: math.NewInt(10), + MinLearningRate: math.LegacyMustNewDecFromStr("0.1"), + MaxLearningRate: math.LegacyMustNewDecFromStr("0.1"), + TargetBlockUtilization: 5, + MaxBlockUtilization: 10, + Window: 1, + Enabled: true, + } + + err := s.feemarketKeeper.SetParams(s.ctx, params) + s.Require().NoError(err) + + gotParams, err := s.feemarketKeeper.GetParams(s.ctx) + s.Require().NoError(err) + + s.Require().EqualValues(params, gotParams) + }) +} From 9c41daaeaf93b986e0369a3a40e34249ab0a4c85 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 4 Dec 2023 08:17:51 -0500 Subject: [PATCH 33/53] update to latest commit --- go.mod | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 6f69bdf..b31f4f4 100644 --- a/go.mod +++ b/go.mod @@ -16,12 +16,12 @@ require ( github.com/cosmos/cosmos-sdk v0.47.6 github.com/cosmos/gogoproto v1.4.11 github.com/golang/protobuf v1.5.3 - github.com/golangci/golangci-lint v1.55.2 + github.com/golangci/golangci-lint v1.55.3-0.20231203192459-84442f26446b github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.17.0 github.com/stretchr/testify v1.8.4 - golang.org/x/tools v0.15.0 + golang.org/x/tools v0.16.0 google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 google.golang.org/grpc v1.59.0 google.golang.org/protobuf v1.31.0 @@ -44,13 +44,13 @@ require ( github.com/Abirdcfly/dupword v0.0.13 // indirect github.com/Antonboom/errname v0.1.12 // indirect github.com/Antonboom/nilnil v0.1.7 // indirect - github.com/Antonboom/testifylint v0.2.3 // indirect + github.com/Antonboom/testifylint v1.0.2 // indirect github.com/BurntSushi/toml v1.3.2 // indirect github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect github.com/GaijinEntertainment/go-exhaustruct/v3 v3.1.0 // indirect github.com/Masterminds/semver v1.5.0 // indirect - github.com/OpenPeeDeeP/depguard/v2 v2.1.0 // indirect + github.com/OpenPeeDeeP/depguard/v2 v2.2.0 // indirect github.com/alecthomas/go-check-sumtype v0.1.3 // indirect github.com/alexkohler/nakedret/v2 v2.0.2 // indirect github.com/alexkohler/prealloc v1.0.0 // indirect @@ -64,13 +64,13 @@ require ( github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect github.com/bkielbasa/cyclop v1.2.1 // indirect github.com/blizzy78/varnamelen v0.8.0 // indirect - github.com/bombsimon/wsl/v3 v3.4.0 // indirect + github.com/bombsimon/wsl/v4 v4.2.0 // indirect github.com/breml/bidichk v0.2.7 // indirect github.com/breml/errchkjson v0.3.6 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/butuzov/ireturn v0.2.2 // indirect github.com/butuzov/mirror v1.1.0 // indirect - github.com/catenacyber/perfsprint v0.2.0 // indirect + github.com/catenacyber/perfsprint v0.4.0 // indirect github.com/ccojocar/zxcvbn-go v1.0.1 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/cespare/xxhash v1.1.0 // indirect @@ -105,14 +105,14 @@ require ( github.com/dvsekhvalnov/jose2go v1.5.0 // indirect github.com/esimonov/ifshort v1.0.4 // indirect github.com/ettle/strcase v0.1.1 // indirect - github.com/fatih/color v1.15.0 // indirect + github.com/fatih/color v1.16.0 // indirect github.com/fatih/structtag v1.2.0 // indirect github.com/felixge/httpsnoop v1.0.2 // indirect github.com/firefart/nonamedreturns v1.0.4 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/fzipp/gocyclo v0.6.0 // indirect github.com/getsentry/sentry-go v0.25.0 // indirect - github.com/ghostiam/protogetter v0.2.3 // indirect + github.com/ghostiam/protogetter v0.3.3 // indirect github.com/go-critic/go-critic v0.9.0 // indirect github.com/go-kit/kit v0.12.0 // indirect github.com/go-kit/log v0.2.1 // indirect @@ -150,7 +150,7 @@ require ( github.com/google/uuid v1.3.1 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.1 // indirect github.com/googleapis/gax-go/v2 v2.12.0 // indirect - github.com/gordonklaus/ineffassign v0.0.0-20230610083614-0e73809eb601 // indirect + github.com/gordonklaus/ineffassign v0.1.0 // indirect github.com/gorilla/handlers v1.5.1 // indirect github.com/gorilla/mux v1.8.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect @@ -176,7 +176,7 @@ require ( github.com/huandu/skiplist v1.2.0 // indirect github.com/improbable-eng/grpc-web v0.15.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/jgautheron/goconst v1.6.0 // indirect + github.com/jgautheron/goconst v1.7.0 // indirect github.com/jingyugao/rowserrcheck v1.1.1 // indirect github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect @@ -218,7 +218,7 @@ require ( github.com/moricho/tparallel v0.3.1 // indirect github.com/mtibben/percent v0.2.1 // indirect github.com/nakabonne/nestif v0.3.1 // indirect - github.com/nishanths/exhaustive v0.11.0 // indirect + github.com/nishanths/exhaustive v0.12.0 // indirect github.com/nishanths/predeclared v0.2.2 // indirect github.com/nunnatsa/ginkgolinter v0.14.1 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect @@ -226,7 +226,7 @@ require ( github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/polyfloyd/go-errorlint v1.4.5 // indirect + github.com/polyfloyd/go-errorlint v1.4.6 // indirect github.com/prometheus/client_golang v1.17.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.45.0 // indirect @@ -268,7 +268,7 @@ require ( github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c // indirect github.com/tdakkota/asciicheck v0.2.0 // indirect github.com/tendermint/go-amino v0.16.0 // indirect - github.com/tetafro/godot v1.4.15 // indirect + github.com/tetafro/godot v1.4.16 // indirect github.com/tidwall/btree v1.7.0 // indirect github.com/timakin/bodyclose v0.0.0-20230421092635-574207250966 // indirect github.com/timonwong/loggercheck v0.9.4 // indirect @@ -276,31 +276,31 @@ require ( github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect github.com/ulikunitz/xz v0.5.11 // indirect github.com/ultraware/funlen v0.1.0 // indirect - github.com/ultraware/whitespace v0.0.5 // indirect + github.com/ultraware/whitespace v0.1.0 // indirect github.com/uudashr/gocognit v1.1.2 // indirect github.com/xen0n/gosmopolitan v1.2.2 // indirect github.com/yagipy/maintidx v1.0.0 // indirect github.com/yeya24/promlinter v0.2.0 // indirect - github.com/ykadowak/zerologlint v0.1.3 // indirect + github.com/ykadowak/zerologlint v0.1.5 // indirect github.com/zondax/hid v0.9.2 // indirect github.com/zondax/ledger-go v0.14.3 // indirect gitlab.com/bosi/decorder v0.4.1 // indirect - go-simpler.org/sloglint v0.1.2 // indirect + go-simpler.org/musttag v0.8.0 // indirect + go-simpler.org/sloglint v0.3.0 // indirect go.etcd.io/bbolt v1.3.7 // indirect go.opencensus.io v0.24.0 // indirect - go.tmz.dev/musttag v0.7.2 // indirect go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.10.0 // indirect go.uber.org/zap v1.24.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/exp/typeparams v0.0.0-20230307190834-24139beb5833 // 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/sync v0.5.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/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/api v0.143.0 // indirect From bcd4e1dc8c3ef835f10d37e98678c2fff717cc12 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 4 Dec 2023 08:17:56 -0500 Subject: [PATCH 34/53] go mod tidy --- go.sum | 88 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/go.sum b/go.sum index a1388f8..6c0fbd0 100644 --- a/go.sum +++ b/go.sum @@ -423,8 +423,8 @@ github.com/Antonboom/errname v0.1.12 h1:oh9ak2zUtsLp5oaEd/erjB4GPu9w19NyoIskZClD github.com/Antonboom/errname v0.1.12/go.mod h1:bK7todrzvlaZoQagP1orKzWXv59X/x0W0Io2XT1Ssro= github.com/Antonboom/nilnil v0.1.7 h1:ofgL+BA7vlA1K2wNQOsHzLJ2Pw5B5DpWRLdDAVvvTow= github.com/Antonboom/nilnil v0.1.7/go.mod h1:TP+ScQWVEq0eSIxqU8CbdT5DFWoHp0MbP+KMUO1BKYQ= -github.com/Antonboom/testifylint v0.2.3 h1:MFq9zyL+rIVpsvLX4vDPLojgN7qODzWsrnftNX2Qh60= -github.com/Antonboom/testifylint v0.2.3/go.mod h1:IYaXaOX9NbfAyO+Y04nfjGI8wDemC1rUyM/cYolz018= +github.com/Antonboom/testifylint v1.0.2 h1:WkSc4c6AcYAPrSqj/3MYrewhszk+mnwd07acH1NL9Vw= +github.com/Antonboom/testifylint v1.0.2/go.mod h1:tGEV9t6Th7DHXFVjd8oyLOBbIxXzs4CMEIAkbQ2RuC8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -446,8 +446,8 @@ github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEV github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/OpenPeeDeeP/depguard/v2 v2.1.0 h1:aQl70G173h/GZYhWf36aE5H0KaujXfVMnn/f1kSDVYY= -github.com/OpenPeeDeeP/depguard/v2 v2.1.0/go.mod h1:PUBgk35fX4i7JDmwzlJwJ+GMe6NfO1723wmJMgPThNQ= +github.com/OpenPeeDeeP/depguard/v2 v2.2.0 h1:vDfG60vDtIuf0MEOhmLlLLSzqaRM8EMcgJPdp74zmpA= +github.com/OpenPeeDeeP/depguard/v2 v2.2.0/go.mod h1:CIzddKRvLBC4Au5aYP/i3nyaWQ+ClszLIuVocRiCYFQ= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE= @@ -507,8 +507,8 @@ github.com/bkielbasa/cyclop v1.2.1 h1:AeF71HZDob1P2/pRm1so9cd1alZnrpyc4q2uP2l0gJ github.com/bkielbasa/cyclop v1.2.1/go.mod h1:K/dT/M0FPAiYjBgQGau7tz+3TMh4FWAEqlMhzFWCrgM= github.com/blizzy78/varnamelen v0.8.0 h1:oqSblyuQvFsW1hbBHh1zfwrKe3kcSj0rnXkKzsQ089M= github.com/blizzy78/varnamelen v0.8.0/go.mod h1:V9TzQZ4fLJ1DSrjVDfl89H7aMnTvKkApdHeyESmyR7k= -github.com/bombsimon/wsl/v3 v3.4.0 h1:RkSxjT3tmlptwfgEgTgU+KYKLI35p/tviNXNXiL2aNU= -github.com/bombsimon/wsl/v3 v3.4.0/go.mod h1:KkIB+TXkqy6MvK9BDZVbZxKNYsE1/oLRJbIFtf14qqo= +github.com/bombsimon/wsl/v4 v4.2.0 h1:dKK3o/Hk2aIt6t72CWg02ham2P5lnH9MBSW6cTU9xxU= +github.com/bombsimon/wsl/v4 v4.2.0/go.mod h1:1zaTbf/7ywOQtMdoUdTF2X1fbbBLiBUkajyuFAanT28= github.com/breml/bidichk v0.2.7 h1:dAkKQPLl/Qrk7hnP6P+E0xOodrq8Us7+U0o4UBOAlQY= github.com/breml/bidichk v0.2.7/go.mod h1:YodjipAGI9fGcYM7II6wFvGhdMYsC5pHDlGzqvEW3tQ= github.com/breml/errchkjson v0.3.6 h1:VLhVkqSBH96AvXEyclMR37rZslRrY2kcyq+31HCsVrA= @@ -526,8 +526,8 @@ github.com/butuzov/ireturn v0.2.2/go.mod h1:RfGHUvvAuFFxoHKf4Z8Yxuh6OjlCw1KvR2zM github.com/butuzov/mirror v1.1.0 h1:ZqX54gBVMXu78QLoiqdwpl2mgmoOJTk7s4p4o+0avZI= github.com/butuzov/mirror v1.1.0/go.mod h1:8Q0BdQU6rC6WILDiBM60DBfvV78OLJmMmixe7GF45AE= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= -github.com/catenacyber/perfsprint v0.2.0 h1:azOocHLscPjqXVJ7Mf14Zjlkn4uNua0+Hcg1wTR6vUo= -github.com/catenacyber/perfsprint v0.2.0/go.mod h1:/wclWYompEyjUD2FuIIDVKNkqz7IgBIWXIH3V0Zol50= +github.com/catenacyber/perfsprint v0.4.0 h1:ZwECTVWzrJ4oW94r2OEiNEO+RKWXSibEZBPd6HkrGl4= +github.com/catenacyber/perfsprint v0.4.0/go.mod h1:/wclWYompEyjUD2FuIIDVKNkqz7IgBIWXIH3V0Zol50= github.com/ccojocar/zxcvbn-go v1.0.1 h1:+sxrANSCj6CdadkcMnvde/GWU1vZiiXRbqYSCalV4/4= github.com/ccojocar/zxcvbn-go v1.0.1/go.mod h1:g1qkXtUSvHP8lhHp5GrSmTz6uWALGRMQdw6Qnz/hi60= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= @@ -689,8 +689,8 @@ github.com/esimonov/ifshort v1.0.4/go.mod h1:Pe8zjlRrJ80+q2CxHLfEOfTwxCZ4O+MuhcH github.com/ettle/strcase v0.1.1 h1:htFueZyVeE1XNnMEfbqp5r67qAN/4r6ya1ysq8Q+Zcw= github.com/ettle/strcase v0.1.1/go.mod h1:hzDLsPC7/lwKyBOywSHEP89nt2pDgdy+No1NBA9o9VY= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= -github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= +github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= @@ -713,8 +713,8 @@ github.com/fzipp/gocyclo v0.6.0/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlya github.com/getsentry/sentry-go v0.25.0 h1:q6Eo+hS+yoJlTO3uu/azhQadsD8V+jQn2D8VvX1eOyI= github.com/getsentry/sentry-go v0.25.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/ghostiam/protogetter v0.2.3 h1:qdv2pzo3BpLqezwqfGDLZ+nHEYmc5bUpIdsMbBVwMjw= -github.com/ghostiam/protogetter v0.2.3/go.mod h1:KmNLOsy1v04hKbvZs8EfGI1fk39AgTdRDxWNYPfXVc4= +github.com/ghostiam/protogetter v0.3.3 h1:EvOuzB/SEifg/c4aMnwcj033Qc1lHO7Yz4QnBDbmbik= +github.com/ghostiam/protogetter v0.3.3/go.mod h1:A0JgIhs0fgVnotGinjQiKaFVG3waItLJNwPmcMzDnvk= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= @@ -850,8 +850,8 @@ github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe h1:6RGUuS7EGotKx6 github.com/golangci/go-misc v0.0.0-20220329215616-d24fe342adfe/go.mod h1:gjqyPShc/m8pEMpk0a3SeagVb0kaqvhscv+i9jI5ZhQ= github.com/golangci/gofmt v0.0.0-20231018234816-f50ced29576e h1:ULcKCDV1LOZPFxGZaA6TlQbiM3J2GCPnkx/bGF6sX/g= github.com/golangci/gofmt v0.0.0-20231018234816-f50ced29576e/go.mod h1:Pm5KhLPA8gSnQwrQ6ukebRcapGb/BG9iUkdaiCcGHJM= -github.com/golangci/golangci-lint v1.55.2 h1:yllEIsSJ7MtlDBwDJ9IMBkyEUz2fYE0b5B8IUgO1oP8= -github.com/golangci/golangci-lint v1.55.2/go.mod h1:H60CZ0fuqoTwlTvnbyjhpZPWp7KmsjwV2yupIMiMXbM= +github.com/golangci/golangci-lint v1.55.3-0.20231203192459-84442f26446b h1:z3r/dMJX7RUKV8RAVYnu4tghQImjPksZzkncictRlT4= +github.com/golangci/golangci-lint v1.55.3-0.20231203192459-84442f26446b/go.mod h1:h6krrUw6/rso2L5KPuSLK3WGKdhYbEW4I0zPt4ckp3Y= github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0 h1:MfyDlzVjl1hoaPzPD4Gpb/QgoRfSBR0jdhwGyAWwMSA= github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0/go.mod h1:66R6K6P6VWk9I95jvqGxkqJxVWGFy9XlDwLwVz1RCFg= github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca h1:kNY3/svz5T29MYHubXix4aDDuE3RWHkPvopM/EDv/MA= @@ -940,8 +940,8 @@ github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qK github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gordonklaus/ineffassign v0.0.0-20230610083614-0e73809eb601 h1:mrEEilTAUmaAORhssPPkxj84TsHrPMLBGW2Z4SoTxm8= -github.com/gordonklaus/ineffassign v0.0.0-20230610083614-0e73809eb601/go.mod h1:Qcp2HIAYhR7mNUVSIxZww3Guk4it82ghYcEXIAk+QT0= +github.com/gordonklaus/ineffassign v0.1.0 h1:y2Gd/9I7MdY1oEIt+n+rowjBNDcLQq3RsH5hwJd0f9s= +github.com/gordonklaus/ineffassign v0.1.0/go.mod h1:Qcp2HIAYhR7mNUVSIxZww3Guk4it82ghYcEXIAk+QT0= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4= github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q= @@ -1043,8 +1043,8 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= -github.com/jgautheron/goconst v1.6.0 h1:gbMLWKRMkzAc6kYsQL6/TxaoBUg3Jm9LSF/Ih1ADWGA= -github.com/jgautheron/goconst v1.6.0/go.mod h1:aAosetZ5zaeC/2EfMeRswtxUFBpe2Hr7HzkgX4fanO4= +github.com/jgautheron/goconst v1.7.0 h1:cEqH+YBKLsECnRSd4F4TK5ri8t/aXtt/qoL0Ft252B0= +github.com/jgautheron/goconst v1.7.0/go.mod h1:aAosetZ5zaeC/2EfMeRswtxUFBpe2Hr7HzkgX4fanO4= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= github.com/jingyugao/rowserrcheck v1.1.1 h1:zibz55j/MJtLsjP1OF4bSdgXxwL1b+Vn7Tjzq7gFzUs= @@ -1209,8 +1209,8 @@ github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/nishanths/exhaustive v0.11.0 h1:T3I8nUGhl/Cwu5Z2hfc92l0e04D2GEW6e0l8pzda2l0= -github.com/nishanths/exhaustive v0.11.0/go.mod h1:RqwDsZ1xY0dNdqHho2z6X+bgzizwbLYOWnZbbl2wLB4= +github.com/nishanths/exhaustive v0.12.0 h1:vIY9sALmw6T/yxiASewa4TQcFsVYZQQRUQJhKRf3Swg= +github.com/nishanths/exhaustive v0.12.0/go.mod h1:mEZ95wPIZW+x8kC4TgC+9YCUgiST7ecevsVDTgc2obs= github.com/nishanths/predeclared v0.2.2 h1:V2EPdZPliZymNAn79T8RkNApBjMmVKh5XRpLm/w98Vk= github.com/nishanths/predeclared v0.2.2/go.mod h1:RROzoN6TnGQupbC+lqggsOlcgysk3LMK/HI84Mp280c= github.com/nunnatsa/ginkgolinter v0.14.1 h1:khx0CqR5U4ghsscjJ+lZVthp3zjIFytRXPTaQ/TMiyA= @@ -1287,8 +1287,8 @@ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qR github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polyfloyd/go-errorlint v1.4.5 h1:70YWmMy4FgRHehGNOUask3HtSFSOLKgmDn7ryNe7LqI= -github.com/polyfloyd/go-errorlint v1.4.5/go.mod h1:sIZEbFoDOCnTYYZoVkjc4hTnM459tuWA9H/EkdXwsKk= +github.com/polyfloyd/go-errorlint v1.4.6 h1:6E7ITe++G4eQ8+/ciIz9yONm+pDy+1LI/AZdZG0cP5Y= +github.com/polyfloyd/go-errorlint v1.4.6/go.mod h1:WGkLzUkLXGGr6BfD33l7yRidBa+T+8xB8TupCpId2ZE= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= @@ -1465,8 +1465,8 @@ github.com/tenntenn/modver v1.0.1 h1:2klLppGhDgzJrScMpkj9Ujy3rXPUspSjAcev9tSEBgA github.com/tenntenn/modver v1.0.1/go.mod h1:bePIyQPb7UeioSRkw3Q0XeMhYZSMx9B8ePqg6SAMGH0= github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpRQGxTSkNYKJ51yaw6ChIqO+Je8UqsTKN/cDag= github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3/go.mod h1:ON8b8w4BN/kE1EOhwT0o+d62W65a6aPw1nouo9LMgyY= -github.com/tetafro/godot v1.4.15 h1:QzdIs+XB8q+U1WmQEWKHQbKmCw06QuQM7gLx/dky2RM= -github.com/tetafro/godot v1.4.15/go.mod h1:2oVxTBSftRTh4+MVfUaUXR6bn2GDXCaMcOG4Dk3rfio= +github.com/tetafro/godot v1.4.16 h1:4ChfhveiNLk4NveAZ9Pu2AN8QZ2nkUGFuadM9lrr5D0= +github.com/tetafro/godot v1.4.16/go.mod h1:2oVxTBSftRTh4+MVfUaUXR6bn2GDXCaMcOG4Dk3rfio= github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= github.com/timakin/bodyclose v0.0.0-20230421092635-574207250966 h1:quvGphlmUVU+nhpFa4gg4yJyTRJ13reZMDHrKwYw53M= @@ -1490,8 +1490,8 @@ github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8= github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ultraware/funlen v0.1.0 h1:BuqclbkY6pO+cvxoq7OsktIXZpgBSkYTQtmwhAK81vI= github.com/ultraware/funlen v0.1.0/go.mod h1:XJqmOQja6DpxarLj6Jj1U7JuoS8PvL4nEqDaQhy22p4= -github.com/ultraware/whitespace v0.0.5 h1:hh+/cpIcopyMYbZNVov9iSxvJU3OYQg78Sfaqzi/CzI= -github.com/ultraware/whitespace v0.0.5/go.mod h1:aVMh/gQve5Maj9hQ/hg+F75lr/X5A89uZnzAmWSineA= +github.com/ultraware/whitespace v0.1.0 h1:O1HKYoh0kIeqE8sFqZf1o0qbORXUCOQFrlaQyZsczZw= +github.com/ultraware/whitespace v0.1.0/go.mod h1:/se4r3beMFNmewJ4Xmz0nMQ941GJt+qmSHGP9emHYe0= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/uudashr/gocognit v1.1.2 h1:l6BAEKJqQH2UpKAPKdMfZf5kE4W/2xk8pfU1OVLvniI= @@ -1504,8 +1504,8 @@ github.com/yagipy/maintidx v1.0.0 h1:h5NvIsCz+nRDapQ0exNv4aJ0yXSI0420omVANTv3GJM github.com/yagipy/maintidx v1.0.0/go.mod h1:0qNf/I/CCZXSMhsRsrEPDZ+DkekpKLXAJfsTACwgXLk= github.com/yeya24/promlinter v0.2.0 h1:xFKDQ82orCU5jQujdaD8stOHiv8UN68BSdn2a8u8Y3o= github.com/yeya24/promlinter v0.2.0/go.mod h1:u54lkmBOZrpEbQQ6gox2zWKKLKu2SGe+2KOiextY+IA= -github.com/ykadowak/zerologlint v0.1.3 h1:TLy1dTW3Nuc+YE3bYRPToG1Q9Ej78b5UUN6bjbGdxPE= -github.com/ykadowak/zerologlint v0.1.3/go.mod h1:KaUskqF3e/v59oPmdq1U1DnKcuHokl2/K1U4pmIELKg= +github.com/ykadowak/zerologlint v0.1.5 h1:Gy/fMz1dFQN9JZTPjv1hxEk+sRWm05row04Yoolgdiw= +github.com/ykadowak/zerologlint v0.1.5/go.mod h1:KaUskqF3e/v59oPmdq1U1DnKcuHokl2/K1U4pmIELKg= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -1519,10 +1519,12 @@ github.com/zondax/ledger-go v0.14.3 h1:wEpJt2CEcBJ428md/5MgSLsXLBos98sBOyxNmCjfU github.com/zondax/ledger-go v0.14.3/go.mod h1:IKKaoxupuB43g4NxeQmbLXv7T9AlQyie1UpHb342ycI= gitlab.com/bosi/decorder v0.4.1 h1:VdsdfxhstabyhZovHafFw+9eJ6eU0d2CkFNJcZz/NU4= gitlab.com/bosi/decorder v0.4.1/go.mod h1:jecSqWUew6Yle1pCr2eLWTensJMmsxHsBwt+PVbkAqA= -go-simpler.org/assert v0.6.0 h1:QxSrXa4oRuo/1eHMXSBFHKvJIpWABayzKldqZyugG7E= -go-simpler.org/assert v0.6.0/go.mod h1:74Eqh5eI6vCK6Y5l3PI8ZYFXG4Sa+tkr70OIPJAUr28= -go-simpler.org/sloglint v0.1.2 h1:IjdhF8NPxyn0Ckn2+fuIof7ntSnVUAqBFcQRrnG9AiM= -go-simpler.org/sloglint v0.1.2/go.mod h1:2LL+QImPfTslD5muNPydAEYmpXIj6o/WYcqnJjLi4o4= +go-simpler.org/assert v0.7.0 h1:OzWWZqfNxt8cLS+MlUp6Tgk1HjPkmgdKBq9qvy8lZsA= +go-simpler.org/assert v0.7.0/go.mod h1:74Eqh5eI6vCK6Y5l3PI8ZYFXG4Sa+tkr70OIPJAUr28= +go-simpler.org/musttag v0.8.0 h1:DR4UTgetNNhPRNo02rkK1hwDTRzAPotN+ZqYpdtEwWc= +go-simpler.org/musttag v0.8.0/go.mod h1:fiNdCkXt2S6je9Eblma3okjnlva9NT1Eg/WUt19rWu8= +go-simpler.org/sloglint v0.3.0 h1:E6TR0w4io+F1mkdvFaCRKEpf19S2+lnEYiDM2Z6bClk= +go-simpler.org/sloglint v0.3.0/go.mod h1:/RQr0TeTf89IyRjLJ9ogUbIp1Zs5zJJAj02pwQoDQdg= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ= go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= @@ -1540,8 +1542,6 @@ go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.15.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= -go.tmz.dev/musttag v0.7.2 h1:1J6S9ipDbalBSODNT5jCep8dhZyMr4ttnjQagmGYR5s= -go.tmz.dev/musttag v0.7.2/go.mod h1:m6q5NiiSKMnQYokefa2xGoyoXnrswCbJ0AWYzf4Zs28= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= @@ -1579,8 +1579,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/exp/typeparams v0.0.0-20220428152302-39d4317da171/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= @@ -1685,8 +1685,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= @@ -1841,8 +1841,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= @@ -1851,8 +1851,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= @@ -1952,8 +1952,8 @@ 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.5.0/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= 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= From 1b9f50c1505fdc90f1646500005d9b2f7e31aa57 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 4 Dec 2023 08:33:34 -0500 Subject: [PATCH 35/53] lint fix --- tests/integration/integration_test.go | 9 ++++----- testutils/networksuite/networksuite.go | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 698a374..6d732de 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -17,11 +17,10 @@ import ( type IntegrationTestSuite struct { suite.Suite - testKeepers testkeeper.TestKeepers - testMsgServers testkeeper.TestMsgServers - encCfg testutils.EncodingConfig - ctx sdk.Context - authorityAccount sdk.AccAddress + testKeepers testkeeper.TestKeepers + testMsgServers testkeeper.TestMsgServers + encCfg testutils.EncodingConfig + ctx sdk.Context } func TestIntegrationTestSuite(t *testing.T) { diff --git a/testutils/networksuite/networksuite.go b/testutils/networksuite/networksuite.go index ccba394..8f39766 100644 --- a/testutils/networksuite/networksuite.go +++ b/testutils/networksuite/networksuite.go @@ -41,6 +41,7 @@ func (nts *NetworkTestSuite) SetupSuite() { nts.Network = network.New(nts.T(), cfg) } -func populateFeeMarket(r *rand.Rand, feeMarketState feemarkettypes.GenesisState) feemarkettypes.GenesisState { +func populateFeeMarket(_ *rand.Rand, feeMarketState feemarkettypes.GenesisState) feemarkettypes.GenesisState { + // TODO intercept and populate state randomly if desired return feeMarketState } From bb349f9f178386c80ee2cda7c504c1ba8c3c57c7 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 4 Dec 2023 09:02:32 -0500 Subject: [PATCH 36/53] use encoding --- tests/integration/integration_test.go | 13 ++- testutils/network/network.go | 15 +-- testutils/testutils.go | 36 ------- x/feemarket/ante/suite/suite.go | 9 +- x/feemarket/keeper/feemarket_test.go | 122 ++++++++++++------------ x/feemarket/keeper/genesis_test.go | 16 ++-- x/feemarket/keeper/keeper_test.go | 37 ++++--- x/feemarket/keeper/msg_server_test.go | 2 +- x/feemarket/keeper/query_server_test.go | 20 ++-- 9 files changed, 117 insertions(+), 153 deletions(-) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 6d732de..8270681 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -4,14 +4,13 @@ import ( "testing" "cosmossdk.io/math" - "github.com/stretchr/testify/suite" - - "github.com/skip-mev/feemarket/testutils" - "github.com/skip-mev/feemarket/x/feemarket/types" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/suite" + appparams "github.com/skip-mev/feemarket/tests/app/params" + "github.com/skip-mev/feemarket/testutils/encoding" testkeeper "github.com/skip-mev/feemarket/testutils/keeper" + "github.com/skip-mev/feemarket/x/feemarket/types" ) type IntegrationTestSuite struct { @@ -19,7 +18,7 @@ type IntegrationTestSuite struct { testKeepers testkeeper.TestKeepers testMsgServers testkeeper.TestMsgServers - encCfg testutils.EncodingConfig + encCfg appparams.EncodingConfig ctx sdk.Context } @@ -28,7 +27,7 @@ func TestIntegrationTestSuite(t *testing.T) { } func (s *IntegrationTestSuite) SetupTest() { - s.encCfg = testutils.CreateTestEncodingConfig() + s.encCfg = encoding.MakeTestEncodingConfig() s.ctx, s.testKeepers, s.testMsgServers = testkeeper.NewTestSetup(s.T()) } diff --git a/testutils/network/network.go b/testutils/network/network.go index de03cdd..168f416 100644 --- a/testutils/network/network.go +++ b/testutils/network/network.go @@ -6,6 +6,8 @@ import ( "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" @@ -20,7 +22,6 @@ import ( "github.com/stretchr/testify/require" "github.com/skip-mev/feemarket/tests/app" - "github.com/skip-mev/feemarket/testutils" ) type ( @@ -41,14 +42,14 @@ func New(t *testing.T, cfg network.Config) *network.Network { // genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig func DefaultConfig() network.Config { var ( - cdc = testutils.CreateTestEncodingConfig() + encCfg = encoding.MakeTestEncodingConfig() chainID = "chain-" + tmrand.NewRand().Str(6) ) return network.Config{ - Codec: cdc.Codec, - TxConfig: cdc.TxConfig, - LegacyAmino: cdc.Amino, - InterfaceRegistry: cdc.InterfaceRegistry, + 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( @@ -62,7 +63,7 @@ func DefaultConfig() network.Config { baseapp.SetChainID(chainID), ) }, - GenesisState: app.ModuleBasics.DefaultGenesis(cdc.Codec), + GenesisState: app.ModuleBasics.DefaultGenesis(encCfg.Codec), TimeoutCommit: 2 * time.Second, ChainID: chainID, NumValidators: 1, diff --git a/testutils/testutils.go b/testutils/testutils.go index 2ed04ae..2777e78 100644 --- a/testutils/testutils.go +++ b/testutils/testutils.go @@ -3,52 +3,16 @@ package testutils import ( "math/rand" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx/signing" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" - "github.com/cosmos/cosmos-sdk/x/auth/tx" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" ) -type EncodingConfig struct { - InterfaceRegistry types.InterfaceRegistry - Codec codec.Codec - TxConfig client.TxConfig - Amino *codec.LegacyAmino -} - -func CreateTestEncodingConfig() EncodingConfig { - amino := codec.NewLegacyAmino() - interfaceRegistry := types.NewInterfaceRegistry() - - banktypes.RegisterInterfaces(interfaceRegistry) - authtypes.RegisterInterfaces(interfaceRegistry) - cryptocodec.RegisterInterfaces(interfaceRegistry) - feemarkettypes.RegisterInterfaces(interfaceRegistry) - stakingtypes.RegisterInterfaces(interfaceRegistry) - - cdc := codec.NewProtoCodec(interfaceRegistry) - - return EncodingConfig{ - InterfaceRegistry: interfaceRegistry, - Codec: cdc, - TxConfig: tx.NewTxConfig(cdc, tx.DefaultSignModes), - Amino: amino, - } -} - type Account struct { PrivKey cryptotypes.PrivKey PubKey cryptotypes.PubKey diff --git a/x/feemarket/ante/suite/suite.go b/x/feemarket/ante/suite/suite.go index 4151ee3..5477187 100644 --- a/x/feemarket/ante/suite/suite.go +++ b/x/feemarket/ante/suite/suite.go @@ -18,7 +18,8 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/skip-mev/feemarket/testutils" + appparams "github.com/skip-mev/feemarket/tests/app/params" + "github.com/skip-mev/feemarket/testutils/encoding" feemarketante "github.com/skip-mev/feemarket/x/feemarket/ante" "github.com/skip-mev/feemarket/x/feemarket/ante/mocks" "github.com/skip-mev/feemarket/x/feemarket/keeper" @@ -39,7 +40,7 @@ type TestSuite struct { FeemarketKeeper *keeper.Keeper BankKeeper *mocks.BankKeeper FeeGrantKeeper *mocks.FeeGrantKeeper - EncCfg testutils.EncodingConfig + EncCfg appparams.EncodingConfig Key *storetypes.KVStoreKey AuthorityAccount sdk.AccAddress } @@ -67,11 +68,11 @@ func (s *TestSuite) CreateTestAccounts(numAccs int) []TestAccount { return accounts } -// SetupTest setups a new test, with new app, context, and anteHandler. +// SetupTestSuite setups a new test, with new app, context, and anteHandler. func SetupTestSuite(t *testing.T) *TestSuite { s := &TestSuite{} - s.EncCfg = testutils.CreateTestEncodingConfig() + s.EncCfg = encoding.MakeTestEncodingConfig() s.Key = storetypes.NewKVStoreKey(types.StoreKey) tkey := storetypes.NewTransientStoreKey("transient_test_feemarket") testCtx := testutil.DefaultContextWithDB(t, s.Key, tkey) diff --git a/x/feemarket/keeper/feemarket_test.go b/x/feemarket/keeper/feemarket_test.go index ad5a600..2b94c69 100644 --- a/x/feemarket/keeper/feemarket_test.go +++ b/x/feemarket/keeper/feemarket_test.go @@ -13,13 +13,13 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { params := types.DefaultParams() s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) s.Require().Equal(fee, params.MinBaseFee) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) s.Require().Equal(math.LegacyMustNewDecFromStr("0.125"), lr) }) @@ -30,17 +30,17 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { params := types.DefaultParams() s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) // We expect the base fee to decrease by 1/8th. - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) factor := math.LegacyMustNewDecFromStr("0.875") expectedFee := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() s.Require().Equal(fee, expectedFee) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) s.Require().Equal(math.LegacyMustNewDecFromStr("0.125"), lr) }) @@ -56,14 +56,14 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { params := types.DefaultParams() s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) // We expect the base fee to decrease by 1/8th. - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) s.Require().Equal(fee, params.MinBaseFee) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) s.Require().Equal(math.LegacyMustNewDecFromStr("0.125"), lr) }) @@ -79,14 +79,14 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) // We expect the base fee to remain the same. - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) s.Require().Equal(fee, params.MinBaseFee) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) s.Require().Equal(math.LegacyMustNewDecFromStr("0.125"), lr) }) @@ -103,14 +103,14 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) // We expect the base fee to remain the same. - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) s.Require().Equal(state.BaseFee, fee) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) s.Require().Equal(math.LegacyMustNewDecFromStr("0.125"), lr) }) @@ -126,17 +126,17 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) // We expect the base fee to increase by 1/8th. - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) factor := math.LegacyMustNewDecFromStr("1.125") expectedFee := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() s.Require().Equal(fee, expectedFee) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) s.Require().Equal(math.LegacyMustNewDecFromStr("0.125"), lr) }) @@ -153,17 +153,17 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) // We expect the base fee to increase by 1/8th. - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) factor := math.LegacyMustNewDecFromStr("1.125") expectedFee := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() s.Require().Equal(fee, expectedFee) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) s.Require().Equal(math.LegacyMustNewDecFromStr("0.125"), lr) }) @@ -179,14 +179,14 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) // We expect the base fee to remain the same since it is at min base fee. - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) s.Require().Equal(fee, params.MinBaseFee) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) s.Require().Equal(math.LegacyMustNewDecFromStr("0.125"), lr) }) @@ -204,17 +204,17 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) // We expect the base fee to decrease by 1/8th * 1/2. - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) factor := math.LegacyMustNewDecFromStr("0.9375") expectedFee := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() s.Require().Equal(fee, expectedFee) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) s.Require().Equal(math.LegacyMustNewDecFromStr("0.125"), lr) }) @@ -230,17 +230,17 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) // We expect the base fee to increase by 1/8th * 1/2. - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) factor := math.LegacyMustNewDecFromStr("1.0625") expectedFee := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() s.Require().Equal(fee, expectedFee) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) s.Require().Equal(math.LegacyMustNewDecFromStr("0.125"), lr) }) @@ -257,17 +257,17 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) // We expect the base fee to increase by 1/8th * 1/2. - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) factor := math.LegacyMustNewDecFromStr("1.0625") expectedFee := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() s.Require().Equal(fee, expectedFee) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) s.Require().Equal(math.LegacyMustNewDecFromStr("0.125"), lr) }) @@ -277,13 +277,13 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { params := types.DefaultAIMDParams() s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) s.Require().Equal(fee, params.MinBaseFee) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) expectedLR := state.LearningRate.Add(params.Alpha) s.Require().Equal(expectedLR, lr) @@ -295,16 +295,16 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { params := types.DefaultAIMDParams() s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) // We expect the base fee to decrease by 1/8th and the learning rate to // increase by alpha. - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) expectedLR := state.LearningRate.Add(params.Alpha) s.Require().Equal(expectedLR, lr) - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) factor := math.LegacyOneDec().Add(math.LegacyMustNewDecFromStr("-1.0").Mul(lr)) expectedFee := state.BaseFee.ToLegacyDec().Mul(factor).TruncateInt() @@ -323,16 +323,16 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) expectedLR := state.LearningRate.Add(params.Alpha) s.Require().Equal(expectedLR, lr) // We expect the base fee to decrease by 1/8th and the learning rate to // increase by alpha. - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) s.Require().Equal(fee, params.MinBaseFee) }) @@ -349,15 +349,15 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) // We expect the base fee to remain the same and the learning rate to // remain at minimum. - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) s.Require().Equal(params.MinLearningRate, lr) - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) s.Require().Equal(state.BaseFee, fee) }) @@ -376,16 +376,16 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { s.setGenesisState(params, state) - s.Require().NoError(s.feemarketKeeper.UpdateFeeMarket(s.ctx)) + s.Require().NoError(s.feeMarketKeeper.UpdateFeeMarket(s.ctx)) // We expect the base fee to decrease by 1/8th and the learning rate to // decrease by lr * beta. - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) expectedLR := state.LearningRate.Mul(params.Beta) s.Require().Equal(expectedLR, lr) - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) s.Require().Equal(state.BaseFee, fee) }) @@ -394,18 +394,18 @@ func (s *KeeperTestSuite) TestUpdateFeeMarket() { func (s *KeeperTestSuite) TestGetBaseFee() { s.Run("can retrieve base fee with default eip-1559", func() { gs := types.DefaultGenesisState() - s.feemarketKeeper.InitGenesis(s.ctx, *gs) + s.feeMarketKeeper.InitGenesis(s.ctx, *gs) - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) s.Require().Equal(fee, gs.State.BaseFee) }) s.Run("can retrieve base fee with aimd eip-1559", func() { gs := types.DefaultAIMDGenesisState() - s.feemarketKeeper.InitGenesis(s.ctx, *gs) + s.feeMarketKeeper.InitGenesis(s.ctx, *gs) - fee, err := s.feemarketKeeper.GetBaseFee(s.ctx) + fee, err := s.feeMarketKeeper.GetBaseFee(s.ctx) s.Require().NoError(err) s.Require().Equal(fee, gs.State.BaseFee) }) @@ -414,18 +414,18 @@ func (s *KeeperTestSuite) TestGetBaseFee() { func (s *KeeperTestSuite) TestGetLearningRate() { s.Run("can retrieve learning rate with default eip-1559", func() { gs := types.DefaultGenesisState() - s.feemarketKeeper.InitGenesis(s.ctx, *gs) + s.feeMarketKeeper.InitGenesis(s.ctx, *gs) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) s.Require().Equal(lr, gs.State.LearningRate) }) s.Run("can retrieve learning rate with aimd eip-1559", func() { gs := types.DefaultAIMDGenesisState() - s.feemarketKeeper.InitGenesis(s.ctx, *gs) + s.feeMarketKeeper.InitGenesis(s.ctx, *gs) - lr, err := s.feemarketKeeper.GetLearningRate(s.ctx) + lr, err := s.feeMarketKeeper.GetLearningRate(s.ctx) s.Require().NoError(err) s.Require().Equal(lr, gs.State.LearningRate) }) @@ -434,22 +434,22 @@ func (s *KeeperTestSuite) TestGetLearningRate() { func (s *KeeperTestSuite) TestGetMinGasPrices() { s.Run("can retrieve min gas prices with default eip-1559", func() { gs := types.DefaultGenesisState() - s.feemarketKeeper.InitGenesis(s.ctx, *gs) + s.feeMarketKeeper.InitGenesis(s.ctx, *gs) expected := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, gs.State.BaseFee)) - mgp, err := s.feemarketKeeper.GetMinGasPrices(s.ctx) + mgp, err := s.feeMarketKeeper.GetMinGasPrices(s.ctx) s.Require().NoError(err) s.Require().Equal(expected, mgp) }) s.Run("can retrieve min gas prices with aimd eip-1559", func() { gs := types.DefaultAIMDGenesisState() - s.feemarketKeeper.InitGenesis(s.ctx, *gs) + s.feeMarketKeeper.InitGenesis(s.ctx, *gs) expected := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, gs.State.BaseFee)) - mgp, err := s.feemarketKeeper.GetMinGasPrices(s.ctx) + mgp, err := s.feeMarketKeeper.GetMinGasPrices(s.ctx) s.Require().NoError(err) s.Require().Equal(expected, mgp) }) @@ -458,6 +458,6 @@ func (s *KeeperTestSuite) TestGetMinGasPrices() { func (s *KeeperTestSuite) setGenesisState(params types.Params, state types.State) { gs := types.NewGenesisState(params, state) s.NotPanics(func() { - s.feemarketKeeper.InitGenesis(s.ctx, *gs) + s.feeMarketKeeper.InitGenesis(s.ctx, *gs) }) } diff --git a/x/feemarket/keeper/genesis_test.go b/x/feemarket/keeper/genesis_test.go index d56b461..ef5976b 100644 --- a/x/feemarket/keeper/genesis_test.go +++ b/x/feemarket/keeper/genesis_test.go @@ -7,13 +7,13 @@ import ( func (s *KeeperTestSuite) TestInitGenesis() { s.Run("default genesis should not panic", func() { s.Require().NotPanics(func() { - s.feemarketKeeper.InitGenesis(s.ctx, *types.DefaultGenesisState()) + s.feeMarketKeeper.InitGenesis(s.ctx, *types.DefaultGenesisState()) }) }) s.Run("default AIMD genesis should not panic", func() { s.Require().NotPanics(func() { - s.feemarketKeeper.InitGenesis(s.ctx, *types.DefaultAIMDGenesisState()) + s.feeMarketKeeper.InitGenesis(s.ctx, *types.DefaultAIMDGenesisState()) }) }) @@ -21,7 +21,7 @@ func (s *KeeperTestSuite) TestInitGenesis() { gs := types.DefaultGenesisState() gs.Params.Window = 0 s.Require().Panics(func() { - s.feemarketKeeper.InitGenesis(s.ctx, *gs) + s.feeMarketKeeper.InitGenesis(s.ctx, *gs) }) }) @@ -30,7 +30,7 @@ func (s *KeeperTestSuite) TestInitGenesis() { gs.Params.Window = 1 s.Require().Panics(func() { - s.feemarketKeeper.InitGenesis(s.ctx, *gs) + s.feeMarketKeeper.InitGenesis(s.ctx, *gs) }) }) } @@ -38,11 +38,11 @@ func (s *KeeperTestSuite) TestInitGenesis() { func (s *KeeperTestSuite) TestExportGenesis() { s.Run("export genesis should not panic for default eip-1559", func() { gs := types.DefaultGenesisState() - s.feemarketKeeper.InitGenesis(s.ctx, *gs) + s.feeMarketKeeper.InitGenesis(s.ctx, *gs) var exportedGenesis *types.GenesisState s.Require().NotPanics(func() { - exportedGenesis = s.feemarketKeeper.ExportGenesis(s.ctx) + exportedGenesis = s.feeMarketKeeper.ExportGenesis(s.ctx) }) s.Require().Equal(gs, exportedGenesis) @@ -50,11 +50,11 @@ func (s *KeeperTestSuite) TestExportGenesis() { s.Run("export genesis should not panic for default AIMD eip-1559", func() { gs := types.DefaultAIMDGenesisState() - s.feemarketKeeper.InitGenesis(s.ctx, *gs) + s.feeMarketKeeper.InitGenesis(s.ctx, *gs) var exportedGenesis *types.GenesisState s.Require().NotPanics(func() { - exportedGenesis = s.feemarketKeeper.ExportGenesis(s.ctx) + exportedGenesis = s.feeMarketKeeper.ExportGenesis(s.ctx) }) s.Require().Equal(gs, exportedGenesis) diff --git a/x/feemarket/keeper/keeper_test.go b/x/feemarket/keeper/keeper_test.go index 16daac2..53c8aac 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" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/suite" - "github.com/skip-mev/feemarket/testutils" + appparams "github.com/skip-mev/feemarket/tests/app/params" + "github.com/skip-mev/feemarket/testutils/encoding" "github.com/skip-mev/feemarket/x/feemarket/keeper" "github.com/skip-mev/feemarket/x/feemarket/types" "github.com/skip-mev/feemarket/x/feemarket/types/mocks" @@ -21,8 +20,8 @@ type KeeperTestSuite struct { suite.Suite accountKeeper *mocks.AccountKeeper - feemarketKeeper *keeper.Keeper - encCfg testutils.EncodingConfig + feeMarketKeeper *keeper.Keeper + encCfg appparams.EncodingConfig ctx sdk.Context key *storetypes.KVStoreKey authorityAccount sdk.AccAddress @@ -39,7 +38,7 @@ func TestKeeperTestSuite(t *testing.T) { } func (s *KeeperTestSuite) SetupTest() { - s.encCfg = testutils.CreateTestEncodingConfig() + s.encCfg = encoding.MakeTestEncodingConfig() s.key = storetypes.NewKVStoreKey(types.StoreKey) testCtx := testutil.DefaultContextWithDB(s.T(), s.key, storetypes.NewTransientStoreKey("transient_test")) s.ctx = testCtx.Ctx @@ -48,31 +47,31 @@ func (s *KeeperTestSuite) SetupTest() { s.accountKeeper = mocks.NewAccountKeeper(s.T()) // s.accountKeeper.On("GetModuleAddress", "feemarket-fee-collector").Return(sdk.AccAddress("feemarket-fee-collector")) - s.feemarketKeeper = keeper.NewKeeper( + s.feeMarketKeeper = keeper.NewKeeper( s.encCfg.Codec, s.key, s.accountKeeper, s.authorityAccount.String(), ) - err := s.feemarketKeeper.SetParams(s.ctx, types.DefaultParams()) + err := s.feeMarketKeeper.SetParams(s.ctx, types.DefaultParams()) s.Require().NoError(err) - err = s.feemarketKeeper.SetState(s.ctx, types.DefaultState()) + err = s.feeMarketKeeper.SetState(s.ctx, types.DefaultState()) s.Require().NoError(err) - s.msgServer = keeper.NewMsgServer(*s.feemarketKeeper) - s.queryServer = keeper.NewQueryServer(*s.feemarketKeeper) + s.msgServer = keeper.NewMsgServer(*s.feeMarketKeeper) + s.queryServer = keeper.NewQueryServer(*s.feeMarketKeeper) } func (s *KeeperTestSuite) TestState() { s.Run("set and get default eip1559 state", func() { state := types.DefaultState() - err := s.feemarketKeeper.SetState(s.ctx, state) + err := s.feeMarketKeeper.SetState(s.ctx, state) s.Require().NoError(err) - gotState, err := s.feemarketKeeper.GetState(s.ctx) + gotState, err := s.feeMarketKeeper.GetState(s.ctx) s.Require().NoError(err) s.Require().EqualValues(state, gotState) @@ -81,10 +80,10 @@ func (s *KeeperTestSuite) TestState() { s.Run("set and get aimd eip1559 state", func() { state := types.DefaultAIMDState() - err := s.feemarketKeeper.SetState(s.ctx, state) + err := s.feeMarketKeeper.SetState(s.ctx, state) s.Require().NoError(err) - gotState, err := s.feemarketKeeper.GetState(s.ctx) + gotState, err := s.feeMarketKeeper.GetState(s.ctx) s.Require().NoError(err) s.Require().Equal(state, gotState) @@ -95,10 +94,10 @@ func (s *KeeperTestSuite) TestParams() { s.Run("set and get default params", func() { params := types.DefaultParams() - err := s.feemarketKeeper.SetParams(s.ctx, params) + err := s.feeMarketKeeper.SetParams(s.ctx, params) s.Require().NoError(err) - gotParams, err := s.feemarketKeeper.GetParams(s.ctx) + gotParams, err := s.feeMarketKeeper.GetParams(s.ctx) s.Require().NoError(err) s.Require().EqualValues(params, gotParams) @@ -119,10 +118,10 @@ func (s *KeeperTestSuite) TestParams() { Enabled: true, } - err := s.feemarketKeeper.SetParams(s.ctx, params) + err := s.feeMarketKeeper.SetParams(s.ctx, params) s.Require().NoError(err) - gotParams, err := s.feemarketKeeper.GetParams(s.ctx) + gotParams, err := s.feeMarketKeeper.GetParams(s.ctx) s.Require().NoError(err) s.Require().EqualValues(params, gotParams) diff --git a/x/feemarket/keeper/msg_server_test.go b/x/feemarket/keeper/msg_server_test.go index 7e7f4b6..f503687 100644 --- a/x/feemarket/keeper/msg_server_test.go +++ b/x/feemarket/keeper/msg_server_test.go @@ -23,7 +23,7 @@ func (s *KeeperTestSuite) TestMsgParams() { s.Require().NoError(err) s.Require().NotNil(resp) - params, err := s.feemarketKeeper.GetParams(s.ctx) + params, err := s.feeMarketKeeper.GetParams(s.ctx) s.Require().NoError(err) s.Require().Equal(req.Params, params) }) diff --git a/x/feemarket/keeper/query_server_test.go b/x/feemarket/keeper/query_server_test.go index 37fe43b..23aac7c 100644 --- a/x/feemarket/keeper/query_server_test.go +++ b/x/feemarket/keeper/query_server_test.go @@ -15,7 +15,7 @@ func (s *KeeperTestSuite) TestParamsRequest() { s.Require().Equal(types.DefaultParams(), resp.Params) - params, err := s.feemarketKeeper.GetParams(s.ctx) + params, err := s.feeMarketKeeper.GetParams(s.ctx) s.Require().NoError(err) s.Require().Equal(resp.Params, params) @@ -35,7 +35,7 @@ func (s *KeeperTestSuite) TestParamsRequest() { Window: 1, Enabled: true, } - err := s.feemarketKeeper.SetParams(s.ctx, params) + err := s.feeMarketKeeper.SetParams(s.ctx, params) s.Require().NoError(err) req := &types.ParamsRequest{} @@ -45,7 +45,7 @@ func (s *KeeperTestSuite) TestParamsRequest() { s.Require().Equal(params, resp.Params) - params, err = s.feemarketKeeper.GetParams(s.ctx) + params, err = s.feeMarketKeeper.GetParams(s.ctx) s.Require().NoError(err) s.Require().Equal(resp.Params, params) @@ -61,7 +61,7 @@ func (s *KeeperTestSuite) TestStateRequest() { s.Require().Equal(types.DefaultState(), resp.State) - state, err := s.feemarketKeeper.GetState(s.ctx) + state, err := s.feeMarketKeeper.GetState(s.ctx) s.Require().NoError(err) s.Require().Equal(resp.State, state) @@ -74,7 +74,7 @@ func (s *KeeperTestSuite) TestStateRequest() { Window: []uint64{1}, Index: 0, } - err := s.feemarketKeeper.SetState(s.ctx, state) + err := s.feeMarketKeeper.SetState(s.ctx, state) s.Require().NoError(err) req := &types.StateRequest{} @@ -84,7 +84,7 @@ func (s *KeeperTestSuite) TestStateRequest() { s.Require().Equal(state, resp.State) - state, err = s.feemarketKeeper.GetState(s.ctx) + state, err = s.feeMarketKeeper.GetState(s.ctx) s.Require().NoError(err) s.Require().Equal(resp.State, state) @@ -98,7 +98,7 @@ func (s *KeeperTestSuite) TestBaseFeeRequest() { s.Require().NoError(err) s.Require().NotNil(resp) - fees, err := s.feemarketKeeper.GetMinGasPrices(s.ctx) + fees, err := s.feeMarketKeeper.GetMinGasPrices(s.ctx) s.Require().NoError(err) s.Require().Equal(resp.Fees, fees) @@ -108,13 +108,13 @@ func (s *KeeperTestSuite) TestBaseFeeRequest() { state := types.State{ BaseFee: math.OneInt(), } - err := s.feemarketKeeper.SetState(s.ctx, state) + err := s.feeMarketKeeper.SetState(s.ctx, state) s.Require().NoError(err) params := types.Params{ FeeDenom: "test", } - err = s.feemarketKeeper.SetParams(s.ctx, params) + err = s.feeMarketKeeper.SetParams(s.ctx, params) s.Require().NoError(err) req := &types.BaseFeeRequest{} @@ -122,7 +122,7 @@ func (s *KeeperTestSuite) TestBaseFeeRequest() { s.Require().NoError(err) s.Require().NotNil(resp) - fees, err := s.feemarketKeeper.GetMinGasPrices(s.ctx) + fees, err := s.feeMarketKeeper.GetMinGasPrices(s.ctx) s.Require().NoError(err) s.Require().Equal(resp.Fees, fees) From 36af52a8e259368dbdbd0f93c509540b8bf70de2 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Mon, 4 Dec 2023 09:17:03 -0500 Subject: [PATCH 37/53] init --- tests/integration/network_test.go | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/integration/network_test.go b/tests/integration/network_test.go index 8fc148e..22354c8 100644 --- a/tests/integration/network_test.go +++ b/tests/integration/network_test.go @@ -102,3 +102,45 @@ func (s *NetworkTestSuite) TestGetState() { }) } } + +func (s *NetworkTestSuite) TestSpamTx() { + s.T().Parallel() + + ctx := s.Network.Validators[0].ClientCtx + + common := []string{ + fmt.Sprintf("--%s=json", tmcli.OutputFlag), + } + for _, tc := range []struct { + name string + + args []string + err error + obj types.State + }{ + { + name: "should return default state", + args: common, + obj: types.DefaultState(), + }, + } { + + // TODO SPAM TX + + s.T().Run(tc.name, func(t *testing.T) { + tc := tc + out, err := clitestutil.ExecTestCLICmd(ctx, cli.GetStateCmd(), tc.args) + if tc.err != nil { + stat, ok := status.FromError(tc.err) + require.True(t, ok) + require.ErrorIs(t, stat.Err(), tc.err) + } else { + require.NoError(t, err) + var resp types.StateResponse + require.NoError(t, s.Network.Config.Codec.UnmarshalJSON(out.Bytes(), &resp.State)) + require.NotNil(t, resp.State) + require.Equal(t, tc.obj, resp.State) + } + }) + } +} From 460ffb4f127e3ef8dde3124d6a1eac4ab5d0dff1 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 5 Dec 2023 08:48:19 -0500 Subject: [PATCH 38/53] refactor --- x/feemarket/ante/expected_keepers.go | 3 +++ x/feemarket/ante/suite/suite.go | 14 +++++++------- x/feemarket/post/feegrant_test.go | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) 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 5477187..5ab6ab5 100644 --- a/x/feemarket/ante/suite/suite.go +++ b/x/feemarket/ante/suite/suite.go @@ -36,8 +36,8 @@ type TestSuite struct { ClientCtx client.Context TxBuilder client.TxBuilder - AccountKeeper authkeeper.AccountKeeper - FeemarketKeeper *keeper.Keeper + AccountKeeper feemarketante.AccountKeeper + FeeMarketKeeper feemarketante.FeeMarketKeeper BankKeeper *mocks.BankKeeper FeeGrantKeeper *mocks.FeeGrantKeeper EncCfg appparams.EncodingConfig @@ -96,17 +96,17 @@ func SetupTestSuite(t *testing.T) *TestSuite { s.EncCfg.Codec, authKey, authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix, s.AuthorityAccount.String(), ) - s.FeemarketKeeper = keeper.NewKeeper( + s.FeeMarketKeeper = keeper.NewKeeper( s.EncCfg.Codec, s.Key, s.AccountKeeper, s.AuthorityAccount.String(), ) - err = s.FeemarketKeeper.SetParams(s.Ctx, types.DefaultParams()) + err = s.FeeMarketKeeper.SetParams(s.Ctx, types.DefaultParams()) require.NoError(t, err) - err = s.FeemarketKeeper.SetState(s.Ctx, types.DefaultState()) + err = s.FeeMarketKeeper.SetState(s.Ctx, types.DefaultState()) require.NoError(t, err) s.BankKeeper = mocks.NewBankKeeper(t) @@ -119,7 +119,7 @@ func SetupTestSuite(t *testing.T) *TestSuite { anteDecorators := []sdk.AnteDecorator{ authante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first feemarketante.NewFeeMarketCheckDecorator( // fee market replaces fee deduct decorator - s.FeemarketKeeper, + s.FeeMarketKeeper, ), authante.NewSigGasConsumeDecorator(s.AccountKeeper, authante.DefaultSigVerificationGasConsumer), } @@ -132,7 +132,7 @@ func SetupTestSuite(t *testing.T) *TestSuite { s.AccountKeeper, s.BankKeeper, s.FeeGrantKeeper, - s.FeemarketKeeper, + s.FeeMarketKeeper, ), } diff --git a/x/feemarket/post/feegrant_test.go b/x/feemarket/post/feegrant_test.go index ae5a1fb..916b7d1 100644 --- a/x/feemarket/post/feegrant_test.go +++ b/x/feemarket/post/feegrant_test.go @@ -129,7 +129,7 @@ func TestDeductFeesNoDelegation(t *testing.T) { suite := antesuite.SetupTestSuite(t) protoTxCfg := tx.NewTxConfig(codec.NewProtoCodec(suite.EncCfg.InterfaceRegistry), tx.DefaultSignModes) // this just tests our handler - dfd := feemarketpost.NewFeeMarketDeductDecorator(suite.AccountKeeper, suite.BankKeeper, suite.FeeGrantKeeper, suite.FeemarketKeeper) + dfd := feemarketpost.NewFeeMarketDeductDecorator(suite.AccountKeeper, suite.BankKeeper, suite.FeeGrantKeeper, suite.FeeMarketKeeper) feePostHandler := sdk.ChainPostDecorators(dfd) signer, feeAcc := stc.malleate(suite) From 48656161c77338a892eaae8b0999c79419adac86 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 5 Dec 2023 10:41:59 -0500 Subject: [PATCH 39/53] clean --- x/feemarket/ante/suite/suite.go | 58 +++++++-------------------------- 1 file changed, 11 insertions(+), 47 deletions(-) diff --git a/x/feemarket/ante/suite/suite.go b/x/feemarket/ante/suite/suite.go index 5ab6ab5..400b050 100644 --- a/x/feemarket/ante/suite/suite.go +++ b/x/feemarket/ante/suite/suite.go @@ -1,18 +1,16 @@ package suite import ( + testkeeper "github.com/skip-mev/feemarket/testutils/keeper" "testing" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx/signing" authante "github.com/cosmos/cosmos-sdk/x/auth/ante" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/stretchr/testify/require" @@ -22,9 +20,7 @@ import ( "github.com/skip-mev/feemarket/testutils/encoding" feemarketante "github.com/skip-mev/feemarket/x/feemarket/ante" "github.com/skip-mev/feemarket/x/feemarket/ante/mocks" - "github.com/skip-mev/feemarket/x/feemarket/keeper" feemarketpost "github.com/skip-mev/feemarket/x/feemarket/post" - "github.com/skip-mev/feemarket/x/feemarket/types" ) type TestSuite struct { @@ -36,13 +32,11 @@ type TestSuite struct { ClientCtx client.Context TxBuilder client.TxBuilder - AccountKeeper feemarketante.AccountKeeper - FeeMarketKeeper feemarketante.FeeMarketKeeper - BankKeeper *mocks.BankKeeper - FeeGrantKeeper *mocks.FeeGrantKeeper - EncCfg appparams.EncodingConfig - Key *storetypes.KVStoreKey - AuthorityAccount sdk.AccAddress + AccountKeeper feemarketante.AccountKeeper + FeeMarketKeeper feemarketante.FeeMarketKeeper + BankKeeper *mocks.BankKeeper + FeeGrantKeeper *mocks.FeeGrantKeeper + EncCfg appparams.EncodingConfig } // TestAccount represents an account used in the tests in x/auth/ante. @@ -69,45 +63,15 @@ func (s *TestSuite) CreateTestAccounts(numAccs int) []TestAccount { } // SetupTestSuite setups a new test, with new app, context, and anteHandler. -func SetupTestSuite(t *testing.T) *TestSuite { +func SetupTestSuite(t *testing.T, isIntegration bool) *TestSuite { s := &TestSuite{} s.EncCfg = encoding.MakeTestEncodingConfig() - s.Key = storetypes.NewKVStoreKey(types.StoreKey) - tkey := storetypes.NewTransientStoreKey("transient_test_feemarket") - testCtx := testutil.DefaultContextWithDB(t, s.Key, tkey) - s.Ctx = testCtx.Ctx.WithIsCheckTx(false).WithBlockHeight(1) - cms, db := testCtx.CMS, testCtx.DB - - authKey := storetypes.NewKVStoreKey(authtypes.StoreKey) - tkey = storetypes.NewTransientStoreKey("transient_test_auth") - cms.MountStoreWithDB(authKey, storetypes.StoreTypeIAVL, db) - cms.MountStoreWithDB(tkey, storetypes.StoreTypeTransient, db) - err := cms.LoadLatestVersion() - require.NoError(t, err) - - maccPerms := map[string][]string{ - types.ModuleName: nil, - types.FeeCollectorName: {"burner"}, - } - - s.AuthorityAccount = authtypes.NewModuleAddress("gov") - s.AccountKeeper = authkeeper.NewAccountKeeper( - s.EncCfg.Codec, authKey, authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix, s.AuthorityAccount.String(), - ) - - s.FeeMarketKeeper = keeper.NewKeeper( - s.EncCfg.Codec, - s.Key, - s.AccountKeeper, - s.AuthorityAccount.String(), - ) - - err = s.FeeMarketKeeper.SetParams(s.Ctx, types.DefaultParams()) - require.NoError(t, err) + ctx, testKeepers, _ := testkeeper.NewTestSetup(t) + s.Ctx = ctx - err = s.FeeMarketKeeper.SetState(s.Ctx, types.DefaultState()) - require.NoError(t, err) + s.AccountKeeper = testKeepers.AccountKeeper + s.FeeMarketKeeper = testKeepers.FeeMarketKeeper s.BankKeeper = mocks.NewBankKeeper(t) s.FeeGrantKeeper = mocks.NewFeeGrantKeeper(t) From 4b7b95bfd787359140fad0a5ea6ff891b2ac7aff Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 5 Dec 2023 10:44:03 -0500 Subject: [PATCH 40/53] refactor --- x/feemarket/ante/fee_test.go | 2 +- x/feemarket/post/fee_test.go | 6 +++--- x/feemarket/post/feegrant_test.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x/feemarket/ante/fee_test.go b/x/feemarket/ante/fee_test.go index c8a4b4a..57317c2 100644 --- a/x/feemarket/ante/fee_test.go +++ b/x/feemarket/ante/fee_test.go @@ -57,7 +57,7 @@ func TestAnteHandle(t *testing.T) { for _, tc := range testCases { t.Run(fmt.Sprintf("Case %s", tc.Name), func(t *testing.T) { - s := antesuite.SetupTestSuite(t) + s := antesuite.SetupTestSuite(t, false) s.TxBuilder = s.ClientCtx.TxConfig.NewTxBuilder() args := tc.Malleate(s) diff --git a/x/feemarket/post/fee_test.go b/x/feemarket/post/fee_test.go index 10d7b8a..14f57cb 100644 --- a/x/feemarket/post/fee_test.go +++ b/x/feemarket/post/fee_test.go @@ -47,7 +47,7 @@ func TestDeductCoins(t *testing.T) { } for _, tc := range tests { t.Run(fmt.Sprintf("Case %s", tc.name), func(t *testing.T) { - s := antesuite.SetupTestSuite(t) + s := antesuite.SetupTestSuite(t, false) acc := s.CreateTestAccounts(1)[0] if !tc.invalidCoin { s.BankKeeper.On("SendCoinsFromAccountToModule", s.Ctx, acc.Account.GetAddress(), types.FeeCollectorName, tc.coins).Return(nil).Once() @@ -86,7 +86,7 @@ func TestSendTip(t *testing.T) { } for _, tc := range tests { t.Run(fmt.Sprintf("Case %s", tc.name), func(t *testing.T) { - s := antesuite.SetupTestSuite(t) + s := antesuite.SetupTestSuite(t, false) accs := s.CreateTestAccounts(2) if !tc.invalidCoin { s.BankKeeper.On("SendCoins", s.Ctx, mock.Anything, mock.Anything, tc.coins).Return(nil).Once() @@ -184,7 +184,7 @@ func TestPostHandle(t *testing.T) { for _, tc := range testCases { t.Run(fmt.Sprintf("Case %s", tc.Name), func(t *testing.T) { - s := antesuite.SetupTestSuite(t) + s := antesuite.SetupTestSuite(t, false) s.TxBuilder = s.ClientCtx.TxConfig.NewTxBuilder() args := tc.Malleate(s) diff --git a/x/feemarket/post/feegrant_test.go b/x/feemarket/post/feegrant_test.go index 916b7d1..2260cd5 100644 --- a/x/feemarket/post/feegrant_test.go +++ b/x/feemarket/post/feegrant_test.go @@ -126,7 +126,7 @@ func TestDeductFeesNoDelegation(t *testing.T) { for name, stc := range cases { tc := stc // to make scopelint happy t.Run(name, func(t *testing.T) { - suite := antesuite.SetupTestSuite(t) + suite := antesuite.SetupTestSuite(t, false) protoTxCfg := tx.NewTxConfig(codec.NewProtoCodec(suite.EncCfg.InterfaceRegistry), tx.DefaultSignModes) // this just tests our handler dfd := feemarketpost.NewFeeMarketDeductDecorator(suite.AccountKeeper, suite.BankKeeper, suite.FeeGrantKeeper, suite.FeeMarketKeeper) From b7bff5bc43676c46ace97c8f3802b3a99f2f219b Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 5 Dec 2023 10:51:06 -0500 Subject: [PATCH 41/53] refactor --- x/feemarket/ante/suite/suite.go | 21 +++++++------ x/feemarket/post/fee_test.go | 28 ++++++++--------- x/feemarket/post/feegrant_test.go | 52 +++++++++++++++---------------- 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/x/feemarket/ante/suite/suite.go b/x/feemarket/ante/suite/suite.go index 400b050..7859c9c 100644 --- a/x/feemarket/ante/suite/suite.go +++ b/x/feemarket/ante/suite/suite.go @@ -32,11 +32,11 @@ type TestSuite struct { ClientCtx client.Context TxBuilder client.TxBuilder - AccountKeeper feemarketante.AccountKeeper - FeeMarketKeeper feemarketante.FeeMarketKeeper - BankKeeper *mocks.BankKeeper - FeeGrantKeeper *mocks.FeeGrantKeeper - EncCfg appparams.EncodingConfig + AccountKeeper feemarketante.AccountKeeper + FeeMarketKeeper feemarketante.FeeMarketKeeper + MockBankKeeper *mocks.BankKeeper + MockFeeGrantKeeper *mocks.FeeGrantKeeper + EncCfg appparams.EncodingConfig } // TestAccount represents an account used in the tests in x/auth/ante. @@ -72,9 +72,12 @@ func SetupTestSuite(t *testing.T, isIntegration bool) *TestSuite { s.AccountKeeper = testKeepers.AccountKeeper s.FeeMarketKeeper = testKeepers.FeeMarketKeeper + s.MockBankKeeper = mocks.NewBankKeeper(t) + s.MockFeeGrantKeeper = mocks.NewFeeGrantKeeper(t) - s.BankKeeper = mocks.NewBankKeeper(t) - s.FeeGrantKeeper = mocks.NewFeeGrantKeeper(t) + if isIntegration { + + } s.ClientCtx = client.Context{}.WithTxConfig(s.EncCfg.TxConfig) s.TxBuilder = s.ClientCtx.TxConfig.NewTxBuilder() @@ -94,8 +97,8 @@ func SetupTestSuite(t *testing.T, isIntegration bool) *TestSuite { postDecorators := []sdk.PostDecorator{ feemarketpost.NewFeeMarketDeductDecorator( s.AccountKeeper, - s.BankKeeper, - s.FeeGrantKeeper, + s.MockBankKeeper, + s.MockFeeGrantKeeper, s.FeeMarketKeeper, ), } diff --git a/x/feemarket/post/fee_test.go b/x/feemarket/post/fee_test.go index 14f57cb..9f36a57 100644 --- a/x/feemarket/post/fee_test.go +++ b/x/feemarket/post/fee_test.go @@ -50,10 +50,10 @@ func TestDeductCoins(t *testing.T) { s := antesuite.SetupTestSuite(t, false) acc := s.CreateTestAccounts(1)[0] if !tc.invalidCoin { - s.BankKeeper.On("SendCoinsFromAccountToModule", s.Ctx, acc.Account.GetAddress(), types.FeeCollectorName, tc.coins).Return(nil).Once() + s.MockBankKeeper.On("SendCoinsFromAccountToModule", s.Ctx, acc.Account.GetAddress(), types.FeeCollectorName, tc.coins).Return(nil).Once() } - if err := post.DeductCoins(s.BankKeeper, s.Ctx, acc.Account, tc.coins); (err != nil) != tc.wantErr { + if err := post.DeductCoins(s.MockBankKeeper, s.Ctx, acc.Account, tc.coins); (err != nil) != tc.wantErr { s.Errorf(err, "DeductCoins() error = %v, wantErr %v", err, tc.wantErr) } }) @@ -89,10 +89,10 @@ func TestSendTip(t *testing.T) { s := antesuite.SetupTestSuite(t, false) accs := s.CreateTestAccounts(2) if !tc.invalidCoin { - s.BankKeeper.On("SendCoins", s.Ctx, mock.Anything, mock.Anything, tc.coins).Return(nil).Once() + s.MockBankKeeper.On("SendCoins", s.Ctx, mock.Anything, mock.Anything, tc.coins).Return(nil).Once() } - if err := post.SendTip(s.BankKeeper, s.Ctx, accs[0].Account.GetAddress(), accs[1].Account.GetAddress(), tc.coins); (err != nil) != tc.wantErr { + if err := post.SendTip(s.MockBankKeeper, s.Ctx, accs[0].Account.GetAddress(), accs[1].Account.GetAddress(), tc.coins); (err != nil) != tc.wantErr { s.Errorf(err, "SendTip() error = %v, wantErr %v", err, tc.wantErr) } }) @@ -110,9 +110,9 @@ func TestPostHandle(t *testing.T) { testCases := []antesuite.TestCase{ { Name: "signer has no funds", - Malleate: func(suite *antesuite.TestSuite) antesuite.TestCaseArgs { - accs := suite.CreateTestAccounts(1) - suite.BankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(sdkerrors.ErrInsufficientFunds) + Malleate: func(s *antesuite.TestSuite) antesuite.TestCaseArgs { + accs := s.CreateTestAccounts(1) + s.MockBankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(sdkerrors.ErrInsufficientFunds) return antesuite.TestCaseArgs{ Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())}, @@ -145,9 +145,9 @@ func TestPostHandle(t *testing.T) { }, { Name: "signer has enough funds, should pass, no tip", - Malleate: func(suite *antesuite.TestSuite) antesuite.TestCaseArgs { - accs := suite.CreateTestAccounts(1) - suite.BankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil) + Malleate: func(s *antesuite.TestSuite) antesuite.TestCaseArgs { + accs := s.CreateTestAccounts(1) + s.MockBankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil) return antesuite.TestCaseArgs{ Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())}, @@ -163,10 +163,10 @@ func TestPostHandle(t *testing.T) { }, { Name: "signer has enough funds, should pass with tip", - Malleate: func(suite *antesuite.TestSuite) antesuite.TestCaseArgs { - accs := suite.CreateTestAccounts(1) - suite.BankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil) - suite.BankKeeper.On("SendCoins", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once() + Malleate: func(s *antesuite.TestSuite) antesuite.TestCaseArgs { + accs := s.CreateTestAccounts(1) + s.MockBankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil) + s.MockBankKeeper.On("SendCoins", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once() return antesuite.TestCaseArgs{ Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())}, diff --git a/x/feemarket/post/feegrant_test.go b/x/feemarket/post/feegrant_test.go index 2260cd5..e9349d4 100644 --- a/x/feemarket/post/feegrant_test.go +++ b/x/feemarket/post/feegrant_test.go @@ -48,10 +48,10 @@ func TestDeductFeesNoDelegation(t *testing.T) { "paying with good funds": { fee: 24497000000, valid: true, - malleate: func(suite *antesuite.TestSuite) (antesuite.TestAccount, sdk.AccAddress) { - accs := suite.CreateTestAccounts(1) - suite.BankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil).Once() - suite.BankKeeper.On("SendCoins", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once() + malleate: func(s *antesuite.TestSuite) (antesuite.TestAccount, sdk.AccAddress) { + accs := s.CreateTestAccounts(1) + s.MockBankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[0].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil).Once() + s.MockBankKeeper.On("SendCoins", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once() return accs[0], nil }, @@ -75,11 +75,11 @@ func TestDeductFeesNoDelegation(t *testing.T) { // SetAccount for the grantee. fee: 36630000000, valid: true, - malleate: func(suite *antesuite.TestSuite) (antesuite.TestAccount, sdk.AccAddress) { - accs := suite.CreateTestAccounts(2) - suite.FeeGrantKeeper.On("UseGrantedFees", mock.Anything, accs[1].Account.GetAddress(), accs[0].Account.GetAddress(), mock.Anything, mock.Anything).Return(nil).Once() - suite.BankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[1].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil).Once() - suite.BankKeeper.On("SendCoins", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once() + malleate: func(s *antesuite.TestSuite) (antesuite.TestAccount, sdk.AccAddress) { + accs := s.CreateTestAccounts(2) + s.MockFeeGrantKeeper.On("UseGrantedFees", mock.Anything, accs[1].Account.GetAddress(), accs[0].Account.GetAddress(), mock.Anything, mock.Anything).Return(nil).Once() + s.MockBankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[1].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(nil).Once() + s.MockBankKeeper.On("SendCoins", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once() return accs[0], accs[1].Account.GetAddress() }, @@ -88,9 +88,9 @@ func TestDeductFeesNoDelegation(t *testing.T) { fee: 36630000000, valid: false, err: sdkerrors.ErrNotFound, - malleate: func(suite *antesuite.TestSuite) (antesuite.TestAccount, sdk.AccAddress) { - accs := suite.CreateTestAccounts(2) - suite.FeeGrantKeeper.On( + malleate: func(s *antesuite.TestSuite) (antesuite.TestAccount, sdk.AccAddress) { + accs := s.CreateTestAccounts(2) + s.MockFeeGrantKeeper.On( "UseGrantedFees", mock.Anything, accs[1].Account.GetAddress(), accs[0].Account.GetAddress(), mock.Anything, mock.Anything). Return(sdkerrors.ErrNotFound.Wrap("fee-grant not found")). Once() @@ -101,9 +101,9 @@ func TestDeductFeesNoDelegation(t *testing.T) { fee: 36630000000, valid: false, err: feegrant.ErrFeeLimitExceeded, - malleate: func(suite *antesuite.TestSuite) (antesuite.TestAccount, sdk.AccAddress) { - accs := suite.CreateTestAccounts(2) - suite.FeeGrantKeeper.On( + malleate: func(s *antesuite.TestSuite) (antesuite.TestAccount, sdk.AccAddress) { + accs := s.CreateTestAccounts(2) + s.MockFeeGrantKeeper.On( "UseGrantedFees", mock.Anything, accs[1].Account.GetAddress(), accs[0].Account.GetAddress(), mock.Anything, mock.Anything). Return(feegrant.ErrFeeLimitExceeded.Wrap("basic allowance")). Once() @@ -114,10 +114,10 @@ func TestDeductFeesNoDelegation(t *testing.T) { fee: 36630000000, valid: false, err: sdkerrors.ErrInsufficientFunds, - malleate: func(suite *antesuite.TestSuite) (antesuite.TestAccount, sdk.AccAddress) { - accs := suite.CreateTestAccounts(2) - suite.FeeGrantKeeper.On("UseGrantedFees", mock.Anything, accs[1].Account.GetAddress(), accs[0].Account.GetAddress(), mock.Anything, mock.Anything).Return(nil).Once() - suite.BankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[1].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(sdkerrors.ErrInsufficientFunds).Once() + malleate: func(s *antesuite.TestSuite) (antesuite.TestAccount, sdk.AccAddress) { + accs := s.CreateTestAccounts(2) + s.MockFeeGrantKeeper.On("UseGrantedFees", mock.Anything, accs[1].Account.GetAddress(), accs[0].Account.GetAddress(), mock.Anything, mock.Anything).Return(nil).Once() + s.MockBankKeeper.On("SendCoinsFromAccountToModule", mock.Anything, accs[1].Account.GetAddress(), types.FeeCollectorName, mock.Anything).Return(sdkerrors.ErrInsufficientFunds).Once() return accs[0], accs[1].Account.GetAddress() }, }, @@ -126,27 +126,27 @@ func TestDeductFeesNoDelegation(t *testing.T) { for name, stc := range cases { tc := stc // to make scopelint happy t.Run(name, func(t *testing.T) { - suite := antesuite.SetupTestSuite(t, false) - protoTxCfg := tx.NewTxConfig(codec.NewProtoCodec(suite.EncCfg.InterfaceRegistry), tx.DefaultSignModes) + s := antesuite.SetupTestSuite(t, false) + protoTxCfg := tx.NewTxConfig(codec.NewProtoCodec(s.EncCfg.InterfaceRegistry), tx.DefaultSignModes) // this just tests our handler - dfd := feemarketpost.NewFeeMarketDeductDecorator(suite.AccountKeeper, suite.BankKeeper, suite.FeeGrantKeeper, suite.FeeMarketKeeper) + dfd := feemarketpost.NewFeeMarketDeductDecorator(s.AccountKeeper, s.MockBankKeeper, s.MockFeeGrantKeeper, s.FeeMarketKeeper) feePostHandler := sdk.ChainPostDecorators(dfd) - signer, feeAcc := stc.malleate(suite) + signer, feeAcc := stc.malleate(s) fee := sdk.NewCoins(sdk.NewInt64Coin("stake", tc.fee)) msgs := []sdk.Msg{testdata.NewTestMsg(signer.Account.GetAddress())} - acc := suite.AccountKeeper.GetAccount(suite.Ctx, signer.Account.GetAddress()) + acc := s.AccountKeeper.GetAccount(s.Ctx, signer.Account.GetAddress()) privs, accNums, seqs := []cryptotypes.PrivKey{signer.Priv}, []uint64{0}, []uint64{0} if acc != nil { accNums, seqs = []uint64{acc.GetAccountNumber()}, []uint64{acc.GetSequence()} } var defaultGenTxGas uint64 = 10 - tx, err := genTxWithFeeGranter(protoTxCfg, msgs, fee, defaultGenTxGas, suite.Ctx.ChainID(), accNums, seqs, feeAcc, privs...) + tx, err := genTxWithFeeGranter(protoTxCfg, msgs, fee, defaultGenTxGas, s.Ctx.ChainID(), accNums, seqs, feeAcc, privs...) require.NoError(t, err) - _, err = feePostHandler(suite.Ctx, tx, false, true) // tests only feegrant post + _, err = feePostHandler(s.Ctx, tx, false, true) // tests only feegrant post if tc.valid { require.NoError(t, err) } else { From aa801df92b16cae62834eaab00e5b675e5b8b649 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 5 Dec 2023 11:44:21 -0500 Subject: [PATCH 42/53] refactor --- tests/integration/network_test.go | 1 - x/feemarket/ante/fee_test.go | 2 +- x/feemarket/ante/suite/suite.go | 39 ++++++++++++++++++++----------- x/feemarket/post/fee_test.go | 6 ++--- x/feemarket/post/feegrant_test.go | 2 +- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/tests/integration/network_test.go b/tests/integration/network_test.go index 22354c8..31fca8c 100644 --- a/tests/integration/network_test.go +++ b/tests/integration/network_test.go @@ -124,7 +124,6 @@ func (s *NetworkTestSuite) TestSpamTx() { obj: types.DefaultState(), }, } { - // TODO SPAM TX s.T().Run(tc.name, func(t *testing.T) { diff --git a/x/feemarket/ante/fee_test.go b/x/feemarket/ante/fee_test.go index 57317c2..34d6fea 100644 --- a/x/feemarket/ante/fee_test.go +++ b/x/feemarket/ante/fee_test.go @@ -57,7 +57,7 @@ func TestAnteHandle(t *testing.T) { for _, tc := range testCases { t.Run(fmt.Sprintf("Case %s", tc.Name), func(t *testing.T) { - s := antesuite.SetupTestSuite(t, false) + s := antesuite.SetupTestSuite(t, true) s.TxBuilder = s.ClientCtx.TxConfig.NewTxBuilder() args := tc.Malleate(s) diff --git a/x/feemarket/ante/suite/suite.go b/x/feemarket/ante/suite/suite.go index 7859c9c..36f92fb 100644 --- a/x/feemarket/ante/suite/suite.go +++ b/x/feemarket/ante/suite/suite.go @@ -1,16 +1,19 @@ package suite import ( - testkeeper "github.com/skip-mev/feemarket/testutils/keeper" "testing" + authante "github.com/cosmos/cosmos-sdk/x/auth/ante" + + testkeeper "github.com/skip-mev/feemarket/testutils/keeper" + feemarketpost "github.com/skip-mev/feemarket/x/feemarket/post" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx/signing" - 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/stretchr/testify/require" @@ -20,7 +23,6 @@ import ( "github.com/skip-mev/feemarket/testutils/encoding" feemarketante "github.com/skip-mev/feemarket/x/feemarket/ante" "github.com/skip-mev/feemarket/x/feemarket/ante/mocks" - feemarketpost "github.com/skip-mev/feemarket/x/feemarket/post" ) type TestSuite struct { @@ -32,8 +34,11 @@ type TestSuite struct { ClientCtx client.Context TxBuilder client.TxBuilder - AccountKeeper feemarketante.AccountKeeper - FeeMarketKeeper feemarketante.FeeMarketKeeper + AccountKeeper feemarketante.AccountKeeper + FeeMarketKeeper feemarketante.FeeMarketKeeper + BankKeeper feemarketante.BankKeeper + FeeGrantKeeper feemarketante.FeeGrantKeeper + MockBankKeeper *mocks.BankKeeper MockFeeGrantKeeper *mocks.FeeGrantKeeper EncCfg appparams.EncodingConfig @@ -63,7 +68,7 @@ func (s *TestSuite) CreateTestAccounts(numAccs int) []TestAccount { } // SetupTestSuite setups a new test, with new app, context, and anteHandler. -func SetupTestSuite(t *testing.T, isIntegration bool) *TestSuite { +func SetupTestSuite(t *testing.T, mock bool) *TestSuite { s := &TestSuite{} s.EncCfg = encoding.MakeTestEncodingConfig() @@ -75,13 +80,22 @@ func SetupTestSuite(t *testing.T, isIntegration bool) *TestSuite { s.MockBankKeeper = mocks.NewBankKeeper(t) s.MockFeeGrantKeeper = mocks.NewFeeGrantKeeper(t) - if isIntegration { - - } - s.ClientCtx = client.Context{}.WithTxConfig(s.EncCfg.TxConfig) s.TxBuilder = s.ClientCtx.TxConfig.NewTxBuilder() + s.SetupHandlers(mock) + s.SetT(t) + return s +} + +func (s *TestSuite) SetupHandlers(mock bool) { + bankKeeper := s.BankKeeper + feeGrantKeeper := s.FeeGrantKeeper + if mock { + bankKeeper = s.MockBankKeeper + feeGrantKeeper = s.MockFeeGrantKeeper + } + // create basic antehandler with the feemarket decorator anteDecorators := []sdk.AnteDecorator{ authante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first @@ -97,14 +111,13 @@ func SetupTestSuite(t *testing.T, isIntegration bool) *TestSuite { postDecorators := []sdk.PostDecorator{ feemarketpost.NewFeeMarketDeductDecorator( s.AccountKeeper, - s.MockBankKeeper, - s.MockFeeGrantKeeper, + bankKeeper, + feeGrantKeeper, s.FeeMarketKeeper, ), } s.PostHandler = sdk.ChainPostDecorators(postDecorators...) - return s } // TestCase represents a test case used in test tables. diff --git a/x/feemarket/post/fee_test.go b/x/feemarket/post/fee_test.go index 9f36a57..1f38b2c 100644 --- a/x/feemarket/post/fee_test.go +++ b/x/feemarket/post/fee_test.go @@ -47,7 +47,7 @@ func TestDeductCoins(t *testing.T) { } for _, tc := range tests { t.Run(fmt.Sprintf("Case %s", tc.name), func(t *testing.T) { - s := antesuite.SetupTestSuite(t, false) + s := antesuite.SetupTestSuite(t, true) acc := s.CreateTestAccounts(1)[0] if !tc.invalidCoin { s.MockBankKeeper.On("SendCoinsFromAccountToModule", s.Ctx, acc.Account.GetAddress(), types.FeeCollectorName, tc.coins).Return(nil).Once() @@ -86,7 +86,7 @@ func TestSendTip(t *testing.T) { } for _, tc := range tests { t.Run(fmt.Sprintf("Case %s", tc.name), func(t *testing.T) { - s := antesuite.SetupTestSuite(t, false) + s := antesuite.SetupTestSuite(t, true) accs := s.CreateTestAccounts(2) if !tc.invalidCoin { s.MockBankKeeper.On("SendCoins", s.Ctx, mock.Anything, mock.Anything, tc.coins).Return(nil).Once() @@ -184,7 +184,7 @@ func TestPostHandle(t *testing.T) { for _, tc := range testCases { t.Run(fmt.Sprintf("Case %s", tc.Name), func(t *testing.T) { - s := antesuite.SetupTestSuite(t, false) + s := antesuite.SetupTestSuite(t, true) s.TxBuilder = s.ClientCtx.TxConfig.NewTxBuilder() args := tc.Malleate(s) diff --git a/x/feemarket/post/feegrant_test.go b/x/feemarket/post/feegrant_test.go index e9349d4..ede5b9a 100644 --- a/x/feemarket/post/feegrant_test.go +++ b/x/feemarket/post/feegrant_test.go @@ -126,7 +126,7 @@ func TestDeductFeesNoDelegation(t *testing.T) { for name, stc := range cases { tc := stc // to make scopelint happy t.Run(name, func(t *testing.T) { - s := antesuite.SetupTestSuite(t, false) + s := antesuite.SetupTestSuite(t, true) protoTxCfg := tx.NewTxConfig(codec.NewProtoCodec(s.EncCfg.InterfaceRegistry), tx.DefaultSignModes) // this just tests our handler dfd := feemarketpost.NewFeeMarketDeductDecorator(s.AccountKeeper, s.MockBankKeeper, s.MockFeeGrantKeeper, s.FeeMarketKeeper) From 840d6a9442ae06fbbde78d2d76ad293a107f7270 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 5 Dec 2023 12:15:01 -0500 Subject: [PATCH 43/53] refactor clean --- x/feemarket/keeper/keeper_test.go | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/x/feemarket/keeper/keeper_test.go b/x/feemarket/keeper/keeper_test.go index ae63648..d944512 100644 --- a/x/feemarket/keeper/keeper_test.go +++ b/x/feemarket/keeper/keeper_test.go @@ -1,11 +1,13 @@ package keeper_test import ( + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + testkeeper "github.com/skip-mev/feemarket/testutils/keeper" "testing" "cosmossdk.io/math" storetypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/suite" @@ -39,27 +41,13 @@ func TestKeeperTestSuite(t *testing.T) { func (s *KeeperTestSuite) SetupTest() { s.encCfg = encoding.MakeTestEncodingConfig() - s.key = storetypes.NewKVStoreKey(types.StoreKey) - testCtx := testutil.DefaultContextWithDB(s.T(), s.key, storetypes.NewTransientStoreKey("transient_test")) - s.ctx = testCtx.Ctx - - s.authorityAccount = []byte("authority") + s.authorityAccount = authtypes.NewModuleAddress(govtypes.ModuleName) s.accountKeeper = mocks.NewAccountKeeper(s.T()) + ctx, tk, tm := testkeeper.NewTestSetup(s.T()) - s.feeMarketKeeper = keeper.NewKeeper( - s.encCfg.Codec, - s.key, - s.accountKeeper, - s.authorityAccount.String(), - ) - - err := s.feeMarketKeeper.SetParams(s.ctx, types.DefaultParams()) - s.Require().NoError(err) - - err = s.feeMarketKeeper.SetState(s.ctx, types.DefaultState()) - s.Require().NoError(err) - - s.msgServer = keeper.NewMsgServer(*s.feeMarketKeeper) + s.ctx = ctx + s.feeMarketKeeper = tk.FeeMarketKeeper + s.msgServer = tm.FeeMarketMsgServer s.queryServer = keeper.NewQueryServer(*s.feeMarketKeeper) } From 76229f79eedc54dd98ba6af11ea2538f5a868946 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 5 Dec 2023 12:17:33 -0500 Subject: [PATCH 44/53] format --- x/feemarket/ante/suite/suite.go | 8 +++----- x/feemarket/keeper/keeper_test.go | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/x/feemarket/ante/suite/suite.go b/x/feemarket/ante/suite/suite.go index 36f92fb..5278c45 100644 --- a/x/feemarket/ante/suite/suite.go +++ b/x/feemarket/ante/suite/suite.go @@ -3,17 +3,13 @@ package suite import ( "testing" - authante "github.com/cosmos/cosmos-sdk/x/auth/ante" - - testkeeper "github.com/skip-mev/feemarket/testutils/keeper" - feemarketpost "github.com/skip-mev/feemarket/x/feemarket/post" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx/signing" + 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/stretchr/testify/require" @@ -21,8 +17,10 @@ import ( appparams "github.com/skip-mev/feemarket/tests/app/params" "github.com/skip-mev/feemarket/testutils/encoding" + 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" + feemarketpost "github.com/skip-mev/feemarket/x/feemarket/post" ) type TestSuite struct { diff --git a/x/feemarket/keeper/keeper_test.go b/x/feemarket/keeper/keeper_test.go index d944512..f2841e1 100644 --- a/x/feemarket/keeper/keeper_test.go +++ b/x/feemarket/keeper/keeper_test.go @@ -1,18 +1,18 @@ package keeper_test import ( - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - testkeeper "github.com/skip-mev/feemarket/testutils/keeper" "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/stretchr/testify/suite" appparams "github.com/skip-mev/feemarket/tests/app/params" "github.com/skip-mev/feemarket/testutils/encoding" + testkeeper "github.com/skip-mev/feemarket/testutils/keeper" "github.com/skip-mev/feemarket/x/feemarket/keeper" "github.com/skip-mev/feemarket/x/feemarket/types" "github.com/skip-mev/feemarket/x/feemarket/types/mocks" From 55e22f0df13096d3daf9350f3293229bbab478d8 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 5 Dec 2023 16:10:29 -0500 Subject: [PATCH 45/53] use sample --- go.mod | 5 +- tests/e2e/setup.go | 3 +- testutils/encoding/encoding.go | 13 +- testutils/keeper/bank_test.go | 2 +- testutils/keeper/initializer.go | 2 +- testutils/networksuite/networksuite.go | 2 +- testutils/sample/sample.go | 234 ------------------------- 7 files changed, 18 insertions(+), 243 deletions(-) delete mode 100644 testutils/sample/sample.go 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())) -} From 14422789001ae033493a4dc4d2164c307f0c7e47 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 5 Dec 2023 16:33:34 -0500 Subject: [PATCH 46/53] encoding --- tests/integration/integration_test.go | 10 +++++--- testutils/encoding/encoding.go | 35 --------------------------- testutils/keeper/initializer.go | 7 +++++- testutils/network/network.go | 10 +++++--- x/feemarket/ante/suite/suite.go | 11 ++++++--- x/feemarket/keeper/keeper_test.go | 10 +++++--- 6 files changed, 32 insertions(+), 51 deletions(-) delete mode 100644 testutils/encoding/encoding.go diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 8270681..660337b 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -1,14 +1,14 @@ package integration_test import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/skip-mev/chaintestutil/encoding" "testing" "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/suite" - appparams "github.com/skip-mev/feemarket/tests/app/params" - "github.com/skip-mev/feemarket/testutils/encoding" testkeeper "github.com/skip-mev/feemarket/testutils/keeper" "github.com/skip-mev/feemarket/x/feemarket/types" ) @@ -18,7 +18,7 @@ type IntegrationTestSuite struct { testKeepers testkeeper.TestKeepers testMsgServers testkeeper.TestMsgServers - encCfg appparams.EncodingConfig + encCfg encoding.TestEncodingConfig ctx sdk.Context } @@ -27,7 +27,9 @@ func TestIntegrationTestSuite(t *testing.T) { } func (s *IntegrationTestSuite) SetupTest() { - s.encCfg = encoding.MakeTestEncodingConfig() + s.encCfg = encoding.MakeTestEncodingConfig(func(registry codectypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) + }) s.ctx, s.testKeepers, s.testMsgServers = testkeeper.NewTestSetup(s.T()) } diff --git a/testutils/encoding/encoding.go b/testutils/encoding/encoding.go deleted file mode 100644 index 301ba80..0000000 --- a/testutils/encoding/encoding.go +++ /dev/null @@ -1,35 +0,0 @@ -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" - feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" -) - -// MakeTestEncodingConfig creates a test EncodingConfig for a test configuration. -func MakeTestEncodingConfig() appparams.EncodingConfig { - amino := codec.NewLegacyAmino() - - addFeeMarket := func(ir codectypes.InterfaceRegistry) { - feemarkettypes.RegisterInterfaces(ir) - } - - interfaceRegistry := sample.InterfaceRegistry(addFeeMarket) - 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/initializer.go b/testutils/keeper/initializer.go index 740ac8f..0e53325 100644 --- a/testutils/keeper/initializer.go +++ b/testutils/keeper/initializer.go @@ -3,6 +3,7 @@ package keeper import ( tmdb "github.com/cometbft/cometbft-db" "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/store" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -48,9 +49,13 @@ type initializer struct { func newInitializer() initializer { db := tmdb.NewMemDB() + addFeeMarket := func(ir codectypes.InterfaceRegistry) { + feemarkettypes.RegisterInterfaces(ir) + } + return initializer{ DB: db, - Codec: sample.Codec(), + Codec: sample.Codec(addFeeMarket), StateStore: store.NewCommitMultiStore(db), } } diff --git a/testutils/network/network.go b/testutils/network/network.go index 168f416..766bf06 100644 --- a/testutils/network/network.go +++ b/testutils/network/network.go @@ -3,14 +3,14 @@ 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" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -19,9 +19,11 @@ import ( 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/skip-mev/chaintestutil/encoding" "github.com/stretchr/testify/require" "github.com/skip-mev/feemarket/tests/app" + feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" ) type ( @@ -42,7 +44,9 @@ func New(t *testing.T, cfg network.Config) *network.Network { // genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig func DefaultConfig() network.Config { var ( - encCfg = encoding.MakeTestEncodingConfig() + encCfg = encoding.MakeTestEncodingConfig(func(registry codectypes.InterfaceRegistry) { + feemarkettypes.RegisterInterfaces(registry) + }) chainID = "chain-" + tmrand.NewRand().Str(6) ) return network.Config{ diff --git a/x/feemarket/ante/suite/suite.go b/x/feemarket/ante/suite/suite.go index 5278c45..97d4db3 100644 --- a/x/feemarket/ante/suite/suite.go +++ b/x/feemarket/ante/suite/suite.go @@ -1,6 +1,9 @@ package suite import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/skip-mev/chaintestutil/encoding" + feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" "testing" "github.com/cosmos/cosmos-sdk/client" @@ -15,8 +18,6 @@ import ( "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" 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 +40,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 +70,9 @@ 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(func(registry codectypes.InterfaceRegistry) { + feemarkettypes.RegisterInterfaces(registry) + }) 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..391a3e4 100644 --- a/x/feemarket/keeper/keeper_test.go +++ b/x/feemarket/keeper/keeper_test.go @@ -4,14 +4,14 @@ import ( "testing" "cosmossdk.io/math" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" 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" 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,7 +23,7 @@ type KeeperTestSuite struct { accountKeeper *mocks.AccountKeeper feeMarketKeeper *keeper.Keeper - encCfg appparams.EncodingConfig + encCfg encoding.TestEncodingConfig ctx sdk.Context key *storetypes.KVStoreKey authorityAccount sdk.AccAddress @@ -40,7 +40,9 @@ func TestKeeperTestSuite(t *testing.T) { } func (s *KeeperTestSuite) SetupTest() { - s.encCfg = encoding.MakeTestEncodingConfig() + s.encCfg = encoding.MakeTestEncodingConfig(func(registry codectypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) + }) s.authorityAccount = authtypes.NewModuleAddress(govtypes.ModuleName) s.accountKeeper = mocks.NewAccountKeeper(s.T()) ctx, tk, tm := testkeeper.NewTestSetup(s.T()) From 7886bb117ecb10df1f0259a7c7917cdc13607e60 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Tue, 5 Dec 2023 17:49:13 -0500 Subject: [PATCH 47/53] remove network --- tests/integration/integration_test.go | 8 +-- testutils/network/network.go | 84 -------------------------- testutils/networksuite/networksuite.go | 33 +++++++++- x/feemarket/ante/suite/suite.go | 7 +-- 4 files changed, 35 insertions(+), 97 deletions(-) delete mode 100644 testutils/network/network.go diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 660337b..53dd132 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -1,12 +1,12 @@ package integration_test import ( - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/skip-mev/chaintestutil/encoding" + "github.com/skip-mev/feemarket/tests/app" "testing" "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/skip-mev/chaintestutil/encoding" "github.com/stretchr/testify/suite" testkeeper "github.com/skip-mev/feemarket/testutils/keeper" @@ -27,9 +27,7 @@ func TestIntegrationTestSuite(t *testing.T) { } func (s *IntegrationTestSuite) SetupTest() { - s.encCfg = encoding.MakeTestEncodingConfig(func(registry codectypes.InterfaceRegistry) { - types.RegisterInterfaces(registry) - }) + s.encCfg = encoding.MakeTestEncodingConfig(app.ModuleBasics.RegisterInterfaces) s.ctx, s.testKeepers, s.testMsgServers = testkeeper.NewTestSetup(s.T()) } diff --git a/testutils/network/network.go b/testutils/network/network.go deleted file mode 100644 index 766bf06..0000000 --- a/testutils/network/network.go +++ /dev/null @@ -1,84 +0,0 @@ -// Package network allows to programmatically spin up a local network for CLI tests -package network - -import ( - "fmt" - - "testing" - "time" - - tmdb "github.com/cometbft/cometbft-db" - tmrand "github.com/cometbft/cometbft/libs/rand" - "github.com/cosmos/cosmos-sdk/baseapp" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "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/skip-mev/chaintestutil/encoding" - "github.com/stretchr/testify/require" - - "github.com/skip-mev/feemarket/tests/app" - feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" -) - -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(func(registry codectypes.InterfaceRegistry) { - feemarkettypes.RegisterInterfaces(registry) - }) - 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 72f1d41..104aba5 100644 --- a/testutils/networksuite/networksuite.go +++ b/testutils/networksuite/networksuite.go @@ -4,18 +4,45 @@ 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" + sdknetwork "github.com/cosmos/cosmos-sdk/testutil/network" + 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/chaintestutil/sample" - "github.com/skip-mev/feemarket/testutils/network" + "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 sdknetwork.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 +51,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/x/feemarket/ante/suite/suite.go b/x/feemarket/ante/suite/suite.go index 97d4db3..49c2d8c 100644 --- a/x/feemarket/ante/suite/suite.go +++ b/x/feemarket/ante/suite/suite.go @@ -1,9 +1,8 @@ package suite import ( - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/skip-mev/chaintestutil/encoding" - feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" + "github.com/skip-mev/feemarket/tests/app" "testing" "github.com/cosmos/cosmos-sdk/client" @@ -70,9 +69,7 @@ func (s *TestSuite) CreateTestAccounts(numAccs int) []TestAccount { func SetupTestSuite(t *testing.T, mock bool) *TestSuite { s := &TestSuite{} - s.EncCfg = encoding.MakeTestEncodingConfig(func(registry codectypes.InterfaceRegistry) { - feemarkettypes.RegisterInterfaces(registry) - }) + s.EncCfg = encoding.MakeTestEncodingConfig(app.ModuleBasics.RegisterInterfaces) ctx, testKeepers, _ := testkeeper.NewTestSetup(t) s.Ctx = ctx From 76331f1ad3798ffcd92c8aeee9b3165532681a19 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 6 Dec 2023 09:20:58 -0500 Subject: [PATCH 48/53] refactor keeper --- testutils/keeper/bank.go | 21 ---- testutils/keeper/bank_test.go | 38 ------ testutils/keeper/initializer.go | 203 -------------------------------- testutils/keeper/keeper.go | 131 ++++++++------------- 4 files changed, 51 insertions(+), 342 deletions(-) delete mode 100644 testutils/keeper/bank.go delete mode 100644 testutils/keeper/bank_test.go delete mode 100644 testutils/keeper/initializer.go 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 2daa847..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/skip-mev/chaintestutil/sample" - "github.com/stretchr/testify/require" - - testkeeper "github.com/skip-mev/feemarket/testutils/keeper" -) - -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 0e53325..0000000 --- a/testutils/keeper/initializer.go +++ /dev/null @@ -1,203 +0,0 @@ -package keeper - -import ( - tmdb "github.com/cometbft/cometbft-db" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "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/chaintestutil/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() - addFeeMarket := func(ir codectypes.InterfaceRegistry) { - feemarkettypes.RegisterInterfaces(ir) - } - - return initializer{ - DB: db, - Codec: sample.Codec(addFeeMarket), - 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..bc8a24d 100644 --- a/testutils/keeper/keeper.go +++ b/testutils/keeper/keeper.go @@ -2,115 +2,86 @@ package keeper import ( - "testing" - "time" - "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "github.com/cosmos/cosmos-sdk/store/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" "github.com/stretchr/testify/require" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/skip-mev/chaintestutil/keeper" 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 + keeper.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 + keeper.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 ...keeper.SetupOption) (sdk.Context, TestKeepers, TestMsgServers) { + options = append(options, keeper.WithAdditionalModuleAccounts(additionalMaccPerms)) - initializer := newInitializer() + _, tk, tms := keeper.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: keeper.ExampleTimestamp, + Height: keeper.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, - } +func FeeMarket( + initializer *keeper.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(), + ) } From 52add38141129d0f8f570e0e559c6010e6d0ff18 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 6 Dec 2023 09:34:47 -0500 Subject: [PATCH 49/53] fix --- tests/integration/integration_test.go | 3 ++- testutils/keeper/keeper.go | 25 +++++++++++++------------ x/feemarket/ante/suite/suite.go | 4 +++- x/feemarket/keeper/keeper_test.go | 2 -- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 53dd132..4f685b4 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -1,9 +1,10 @@ package integration_test import ( - "github.com/skip-mev/feemarket/tests/app" "testing" + "github.com/skip-mev/feemarket/tests/app" + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/skip-mev/chaintestutil/encoding" diff --git a/testutils/keeper/keeper.go b/testutils/keeper/keeper.go index bc8a24d..7aaabad 100644 --- a/testutils/keeper/keeper.go +++ b/testutils/keeper/keeper.go @@ -2,17 +2,17 @@ package keeper import ( + "testing" + "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" 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" - "testing" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/skip-mev/chaintestutil/keeper" feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper" feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types" @@ -20,13 +20,13 @@ import ( // TestKeepers holds all keepers used during keeper tests for all modules type TestKeepers struct { - keeper.TestKeepers + testkeeper.TestKeepers FeeMarketKeeper *feemarketkeeper.Keeper } // TestMsgServers holds all message servers used during keeper tests for all modules type TestMsgServers struct { - keeper.TestMsgServers + testkeeper.TestMsgServers FeeMarketMsgServer feemarkettypes.MsgServer } @@ -36,10 +36,10 @@ var additionalMaccPerms = map[string][]string{ } // NewTestSetup returns initialized instances of all the keepers and message servers of the modules -func NewTestSetup(t testing.TB, options ...keeper.SetupOption) (sdk.Context, TestKeepers, TestMsgServers) { - options = append(options, keeper.WithAdditionalModuleAccounts(additionalMaccPerms)) +func NewTestSetup(t testing.TB, options ...testkeeper.SetupOption) (sdk.Context, TestKeepers, TestMsgServers) { + options = append(options, testkeeper.WithAdditionalModuleAccounts(additionalMaccPerms)) - _, tk, tms := keeper.NewTestSetup(t, options...) + _, tk, tms := testkeeper.NewTestSetup(t, options...) // initialize extra keeper feeMarketKeeper := FeeMarket(tk.Initializer, tk.AccountKeeper) @@ -49,8 +49,8 @@ func NewTestSetup(t testing.TB, options ...keeper.SetupOption) (sdk.Context, Tes feeMarketMsgSrv := feemarketkeeper.NewMsgServer(*feeMarketKeeper) ctx := sdk.NewContext(tk.Initializer.StateStore, tmproto.Header{ - Time: keeper.ExampleTimestamp, - Height: keeper.ExampleHeight, + Time: testkeeper.ExampleTimestamp, + Height: testkeeper.ExampleHeight, }, false, log.NewNopLogger()) err := feeMarketKeeper.SetState(ctx, feemarkettypes.DefaultState()) @@ -71,8 +71,9 @@ func NewTestSetup(t testing.TB, options ...keeper.SetupOption) (sdk.Context, Tes return ctx, testKeepers, testMsgServers } +// FeeMarket initializes func FeeMarket( - initializer *keeper.Initializer, + initializer *testkeeper.Initializer, authKeeper authkeeper.AccountKeeper, ) *feemarketkeeper.Keeper { storeKey := sdk.NewKVStoreKey(feemarkettypes.StoreKey) diff --git a/x/feemarket/ante/suite/suite.go b/x/feemarket/ante/suite/suite.go index 49c2d8c..a8355f6 100644 --- a/x/feemarket/ante/suite/suite.go +++ b/x/feemarket/ante/suite/suite.go @@ -1,9 +1,11 @@ package suite import ( + "testing" + "github.com/skip-mev/chaintestutil/encoding" + "github.com/skip-mev/feemarket/tests/app" - "testing" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" diff --git a/x/feemarket/keeper/keeper_test.go b/x/feemarket/keeper/keeper_test.go index 391a3e4..b28be5f 100644 --- a/x/feemarket/keeper/keeper_test.go +++ b/x/feemarket/keeper/keeper_test.go @@ -5,7 +5,6 @@ import ( "cosmossdk.io/math" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - 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" @@ -25,7 +24,6 @@ type KeeperTestSuite struct { feeMarketKeeper *keeper.Keeper encCfg encoding.TestEncodingConfig ctx sdk.Context - key *storetypes.KVStoreKey authorityAccount sdk.AccAddress // Message server variables From dbdcc3fb389ba1c86bafe3178dae1b898526f6ed Mon Sep 17 00:00:00 2001 From: aljo242 Date: Wed, 6 Dec 2023 10:16:03 -0500 Subject: [PATCH 50/53] clean --- tests/e2e/go.mod | 12 +++++++----- tests/e2e/go.sum | 20 ++++++++++---------- tests/integration/integration_test.go | 3 +-- x/feemarket/ante/suite/suite.go | 6 ++---- x/feemarket/keeper/keeper_test.go | 6 ++---- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/tests/e2e/go.mod b/tests/e2e/go.mod index 14ecba2..194968c 100644 --- a/tests/e2e/go.mod +++ b/tests/e2e/go.mod @@ -10,6 +10,7 @@ replace ( github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.8 github.com/cosmos/iavl => github.com/cosmos/iavl v0.20.0 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 + github.com/skip-mev/chaintestutil => ../../../chaintestutil github.com/skip-mev/feemarket => ../../ github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/vedhavyas/go-subkey => github.com/strangelove-ventures/go-subkey v1.0.7 @@ -19,6 +20,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-00010101000000-000000000000 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 +216,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..311256b 100644 --- a/tests/e2e/go.sum +++ b/tests/e2e/go.sum @@ -1374,8 +1374,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 +1472,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 +1622,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 +1632,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 +1719,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/integration/integration_test.go b/tests/integration/integration_test.go index 4f685b4..95e1374 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -3,13 +3,12 @@ package integration_test import ( "testing" - "github.com/skip-mev/feemarket/tests/app" - "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/skip-mev/chaintestutil/encoding" "github.com/stretchr/testify/suite" + "github.com/skip-mev/feemarket/tests/app" testkeeper "github.com/skip-mev/feemarket/testutils/keeper" "github.com/skip-mev/feemarket/x/feemarket/types" ) diff --git a/x/feemarket/ante/suite/suite.go b/x/feemarket/ante/suite/suite.go index a8355f6..bc55a16 100644 --- a/x/feemarket/ante/suite/suite.go +++ b/x/feemarket/ante/suite/suite.go @@ -3,10 +3,6 @@ package suite import ( "testing" - "github.com/skip-mev/chaintestutil/encoding" - - "github.com/skip-mev/feemarket/tests/app" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -16,9 +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" + "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" diff --git a/x/feemarket/keeper/keeper_test.go b/x/feemarket/keeper/keeper_test.go index b28be5f..e7c64d4 100644 --- a/x/feemarket/keeper/keeper_test.go +++ b/x/feemarket/keeper/keeper_test.go @@ -4,13 +4,13 @@ import ( "testing" "cosmossdk.io/math" - codectypes "github.com/cosmos/cosmos-sdk/codec/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" + "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" @@ -38,9 +38,7 @@ func TestKeeperTestSuite(t *testing.T) { } func (s *KeeperTestSuite) SetupTest() { - s.encCfg = encoding.MakeTestEncodingConfig(func(registry codectypes.InterfaceRegistry) { - types.RegisterInterfaces(registry) - }) + 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()) From c0586a4ede629ecd71a75781bf43e1bf3c409165 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 7 Dec 2023 11:19:04 -0500 Subject: [PATCH 51/53] use repo --- go.mod | 4 ++-- go.sum | 2 ++ tests/e2e/go.mod | 2 +- tests/integration/integration_test.go | 26 +++++++++++++------------- tests/integration/network_test.go | 4 ++-- testutils/keeper/keeper.go | 2 +- testutils/networksuite/networksuite.go | 3 +-- 7 files changed, 22 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index c6a6310..2a1667d 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +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/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 @@ -330,4 +330,4 @@ replace ( golang.org/x/exp => golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2 ) -replace github.com/skip-mev/chaintestutil => ../chaintestutil +// replace github.com/skip-mev/chaintestutil => ../chaintestutil 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 194968c..f218d38 100644 --- a/tests/e2e/go.mod +++ b/tests/e2e/go.mod @@ -20,7 +20,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-00010101000000-000000000000 + 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 diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 95e1374..9e33cf3 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -15,11 +15,11 @@ import ( type IntegrationTestSuite struct { suite.Suite + testkeeper.TestKeepers + testkeeper.TestMsgServers - testKeepers testkeeper.TestKeepers - testMsgServers testkeeper.TestMsgServers - encCfg encoding.TestEncodingConfig - ctx sdk.Context + encCfg encoding.TestEncodingConfig + ctx sdk.Context } func TestIntegrationTestSuite(t *testing.T) { @@ -29,17 +29,17 @@ func TestIntegrationTestSuite(t *testing.T) { func (s *IntegrationTestSuite) SetupTest() { 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/keeper/keeper.go b/testutils/keeper/keeper.go index 7aaabad..a8c069a 100644 --- a/testutils/keeper/keeper.go +++ b/testutils/keeper/keeper.go @@ -71,7 +71,7 @@ func NewTestSetup(t testing.TB, options ...testkeeper.SetupOption) (sdk.Context, return ctx, testKeepers, testMsgServers } -// FeeMarket initializes +// FeeMarket initializes the fee market module using the testkeepers intializer. func FeeMarket( initializer *testkeeper.Initializer, authKeeper authkeeper.AccountKeeper, diff --git a/testutils/networksuite/networksuite.go b/testutils/networksuite/networksuite.go index 104aba5..64b82bb 100644 --- a/testutils/networksuite/networksuite.go +++ b/testutils/networksuite/networksuite.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" servertypes "github.com/cosmos/cosmos-sdk/server/types" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" - sdknetwork "github.com/cosmos/cosmos-sdk/testutil/network" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/gogoproto/proto" @@ -25,7 +24,7 @@ import ( var ( chainID = "chain-" + tmrand.NewRand().Str(6) - DefaultAppConstructor = func(val sdknetwork.ValidatorI) servertypes.Application { + DefaultAppConstructor = func(val network.ValidatorI) servertypes.Application { return app.New( val.GetCtx().Logger, tmdb.NewMemDB(), From 4ccdce900197efb6984b574d172eae74fd32f123 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 7 Dec 2023 12:13:11 -0500 Subject: [PATCH 52/53] remove --- go.mod | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.mod b/go.mod index 2a1667d..749b552 100644 --- a/go.mod +++ b/go.mod @@ -329,5 +329,3 @@ 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 From 29a87fbe5ee715df11b69db93c2a7b74b7c37673 Mon Sep 17 00:00:00 2001 From: aljo242 Date: Thu, 7 Dec 2023 12:52:56 -0500 Subject: [PATCH 53/53] clean --- tests/e2e/go.mod | 1 - tests/e2e/go.sum | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/e2e/go.mod b/tests/e2e/go.mod index f218d38..813f117 100644 --- a/tests/e2e/go.mod +++ b/tests/e2e/go.mod @@ -10,7 +10,6 @@ replace ( github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.8 github.com/cosmos/iavl => github.com/cosmos/iavl v0.20.0 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/skip-mev/chaintestutil => ../../../chaintestutil github.com/skip-mev/feemarket => ../../ github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/vedhavyas/go-subkey => github.com/strangelove-ventures/go-subkey v1.0.7 diff --git a/tests/e2e/go.sum b/tests/e2e/go.sum index 311256b..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=