diff --git a/testutil/test_helpers.go b/testutil/test_helpers.go index 906839be3..be42ec829 100644 --- a/testutil/test_helpers.go +++ b/testutil/test_helpers.go @@ -13,6 +13,7 @@ import ( wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" abcit "github.com/cometbft/cometbft/abci/types" tmrand "github.com/cometbft/cometbft/libs/rand" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -547,7 +548,7 @@ func (suite *IBCConnectionTestSuite) SendMsgsNoCheck(chain *ibctesting.TestChain return nil, err } - //chain.commitBlock(resp) + commitBlock(chain, resp) suite.Coordinator.IncrementTime() @@ -563,6 +564,33 @@ func (suite *IBCConnectionTestSuite) SendMsgsNoCheck(chain *ibctesting.TestChain return txResult, nil } +func commitBlock(chain *ibctesting.TestChain, res *cometbfttypes.ResponseFinalizeBlock) { + _, err := chain.App.Commit() + require.NoError(chain.TB, err) + + // set the last header to the current header + // use nil trusted fields + chain.LastHeader = chain.CurrentTMClientHeader() + + // val set changes returned from previous block get applied to the next validators + // of this block. See tendermint spec for details. + chain.Vals = chain.NextVals + chain.NextVals = ibctesting.ApplyValSetChanges(chain, chain.Vals, res.ValidatorUpdates) + + // increment the current header + chain.CurrentHeader = cmtproto.Header{ + ChainID: chain.ChainID, + Height: chain.App.LastBlockHeight() + 1, + AppHash: chain.App.LastCommitID().Hash, + // NOTE: the time is increased by the coordinator to maintain time synchrony amongst + // chains. + Time: chain.CurrentHeader.Time, + ValidatorsHash: chain.Vals.Hash(), + NextValidatorsHash: chain.NextVals.Hash(), + ProposerAddress: chain.CurrentHeader.ProposerAddress, + } +} + // SignAndDeliver signs and delivers a transaction without asserting the results. This overrides the function // from ibctesting func SignAndDeliver( @@ -575,7 +603,7 @@ func SignAndDeliver( blockTime time.Time, nextValHash []byte, priv ...cryptotypes.PrivKey, -) (res *abcit.ResponseFinalizeBlock, err error) { +) (res *cometbfttypes.ResponseFinalizeBlock, err error) { tb.Helper() tx, err := simtestutil.GenSignedMockTx( rand.New(rand.NewSource(time.Now().UnixNano())), diff --git a/x/ibc-rate-limit/ibc_middleware_test.go b/x/ibc-rate-limit/ibc_middleware_test.go index d862c9ee6..2353ca8ba 100644 --- a/x/ibc-rate-limit/ibc_middleware_test.go +++ b/x/ibc-rate-limit/ibc_middleware_test.go @@ -9,10 +9,11 @@ import ( sdkmath "cosmossdk.io/math" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - "github.com/neutron-org/neutron/v4/testutil" "github.com/stretchr/testify/require" "golang.org/x/exp/slices" + "github.com/neutron-org/neutron/v4/testutil" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" abci "github.com/cometbft/cometbft/abci/types" @@ -24,6 +25,7 @@ import ( "github.com/stretchr/testify/suite" sdktypes "github.com/cosmos/cosmos-sdk/types" + "github.com/neutron-org/neutron/v4/x/ibc-rate-limit/types" ) @@ -70,8 +72,8 @@ func (suite *MiddlewareTestSuite) MessageFromAToB(denom string, amount sdkmath.I func (suite *MiddlewareTestSuite) MessageFromBToA(denom string, amount sdkmath.Int) sdk.Msg { coin := sdk.NewCoin(denom, amount) - port := suite.Path.EndpointB.ChannelConfig.PortID - channel := suite.Path.EndpointB.ChannelID + port := suite.TransferPath.EndpointB.ChannelConfig.PortID + channel := suite.TransferPath.EndpointB.ChannelID accountFrom := suite.ChainB.SenderAccount.GetAddress().String() accountTo := suite.ChainA.SenderAccount.GetAddress().String() timeoutHeight := clienttypes.NewHeight(10, 100) @@ -89,8 +91,8 @@ func (suite *MiddlewareTestSuite) MessageFromBToA(denom string, amount sdkmath.I //func (suite *MiddlewareTestSuite) MessageFromAToC(denom string, amount sdkmath.Int) sdk.Msg { // coin := sdk.NewCoin(denom, amount) -// port := suite.PathAC.EndpointA.ChannelConfig.PortID -// channel := suite.PathAC.EndpointA.ChannelID +// port := suite.TransferPathAC.EndpointA.ChannelConfig.PortID +// channel := suite.TransferPathAC.EndpointA.ChannelID // accountFrom := suite.ChainA.SenderAccount.GetAddress().String() // accountTo := suite.ChainC.SenderAccount.GetAddress().String() // timeoutHeight := clienttypes.NewHeight(10, 100) @@ -210,12 +212,12 @@ func (suite *MiddlewareTestSuite) FullSendAToB(msg sdk.Msg) (*abci.ExecTxResult, // return nil, "", err // } // -// err = suite.PathAC.EndpointB.UpdateClient() +// err = suite.TransferPathAC.EndpointB.UpdateClient() // if err != nil { // return nil, "", err // } // -// res, err := suite.PathAC.EndpointB.RecvPacketWithResult(packet) +// res, err := suite.TransferPathAC.EndpointB.RecvPacketWithResult(packet) // if err != nil { // return nil, "", err // } @@ -225,11 +227,11 @@ func (suite *MiddlewareTestSuite) FullSendAToB(msg sdk.Msg) (*abci.ExecTxResult, // return nil, "", err // } // -// err = suite.PathAC.EndpointA.UpdateClient() +// err = suite.TransferPathAC.EndpointA.UpdateClient() // if err != nil { // return nil, "", err // } -// err = suite.PathAC.EndpointB.UpdateClient() +// err = suite.TransferPathAC.EndpointB.UpdateClient() // if err != nil { // return nil, "", err // } @@ -498,8 +500,8 @@ func (suite *MiddlewareTestSuite) TestFailedSendTransfer() { // Use the whole quota coins := sdk.NewCoin(sdk.DefaultBondDenom, quota) - port := suite.Path.EndpointA.ChannelConfig.PortID - channel := suite.Path.EndpointA.ChannelID + port := suite.TransferPath.EndpointA.ChannelConfig.PortID + channel := suite.TransferPath.EndpointA.ChannelID accountFrom := suite.ChainA.SenderAccount.GetAddress().String() timeoutHeight := clienttypes.NewHeight(10, 100) msg := transfertypes.NewMsgTransfer(port, channel, coins, accountFrom, "INVALID", timeoutHeight, 0, "") @@ -520,9 +522,9 @@ func (suite *MiddlewareTestSuite) TestFailedSendTransfer() { suite.ChainA.Coordinator.IncrementTime() // Update both clients - err = suite.Path.EndpointA.UpdateClient() + err = suite.TransferPath.EndpointA.UpdateClient() suite.Require().NoError(err) - err = suite.Path.EndpointB.UpdateClient() + err = suite.TransferPath.EndpointB.UpdateClient() suite.Require().NoError(err) // Execute the acknowledgement from chain B in chain A @@ -532,7 +534,7 @@ func (suite *MiddlewareTestSuite) TestFailedSendTransfer() { suite.Require().NoError(err) // recv in chain b - newRes, err := suite.Path.EndpointB.RecvPacketWithResult(packet) + newRes, err := suite.TransferPath.EndpointB.RecvPacketWithResult(packet) suite.Require().NoError(err) // get the ack from the chain b's response @@ -540,7 +542,7 @@ func (suite *MiddlewareTestSuite) TestFailedSendTransfer() { suite.Require().NoError(err) // manually relay it to chain a - err = suite.Path.EndpointA.AcknowledgePacket(packet, ack) + err = suite.TransferPath.EndpointA.AcknowledgePacket(packet, ack) suite.Require().NoError(err) // We should be able to send again because the packet that exceeded the quota failed and has been reverted @@ -598,7 +600,7 @@ func (suite *MiddlewareTestSuite) TestUnsetRateLimitingContract() { // // denom := sdk.DefaultBondDenom // sendAmount := sdkmath.NewInt(1000) -// acceptedChannel := suite.Path.EndpointA.ChannelID +// acceptedChannel := suite.TransferPath.EndpointA.ChannelID // // // Successfully send a denom before any restrictions are added. // _, err := suite.AssertSend(true, suite.MessageFromAToB(denom, sendAmount))