Skip to content

Commit

Permalink
Merge branch 'ics29-fee-middleware' into damian/760-effecient-storage
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan authored Feb 21, 2022
2 parents e3bd5c5 + c14d2b4 commit 83719ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 70 deletions.
40 changes: 0 additions & 40 deletions modules/apps/29-fee/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ package fee_test
import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"

"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"
transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
Expand All @@ -25,27 +23,11 @@ type FeeTestSuite struct {
path *ibctesting.Path
}

// TODO: remove and rename 'SetupMockTest' to 'SetupTest'
func (suite *FeeTestSuite) SetupTest() {
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2)
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1))
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2))

path := ibctesting.NewPath(suite.chainA, suite.chainB)
feeTransferVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: transfertypes.Version}))
path.EndpointA.ChannelConfig.Version = feeTransferVersion
path.EndpointB.ChannelConfig.Version = feeTransferVersion
path.EndpointA.ChannelConfig.PortID = transfertypes.PortID
path.EndpointB.ChannelConfig.PortID = transfertypes.PortID
suite.path = path
}

// TODO: rename to 'SetupTest' when the above function is removed
func (suite *FeeTestSuite) SetupMockTest() {
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2)
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1))
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2))

path := ibctesting.NewPath(suite.chainA, suite.chainB)
mockFeeVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: ibcmock.Version}))
path.EndpointA.ChannelConfig.Version = mockFeeVersion
Expand All @@ -59,28 +41,6 @@ func TestIBCFeeTestSuite(t *testing.T) {
suite.Run(t, new(FeeTestSuite))
}

// TODO: remove
func (suite *FeeTestSuite) CreateICS20Packet(coin sdk.Coin) channeltypes.Packet {

fungibleTokenPacket := transfertypes.NewFungibleTokenPacketData(
coin.Denom,
sdk.NewInt(100).String(),
suite.chainA.SenderAccount.GetAddress().String(),
suite.chainB.SenderAccount.GetAddress().String(),
)

return channeltypes.NewPacket(
fungibleTokenPacket.GetBytes(),
suite.chainA.SenderAccount.GetSequence(),
suite.path.EndpointA.ChannelConfig.PortID,
suite.path.EndpointA.ChannelID,
suite.path.EndpointB.ChannelConfig.PortID,
suite.path.EndpointB.ChannelID,
clienttypes.NewHeight(0, 100),
0,
)
}

func (suite *FeeTestSuite) CreateMockPacket() channeltypes.Packet {
return channeltypes.NewPacket(
ibcmock.MockPacketData,
Expand Down
14 changes: 7 additions & 7 deletions modules/apps/29-fee/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (suite *FeeTestSuite) TestOnChanOpenInit() {

suite.Run(tc.name, func() {
// reset suite
suite.SetupMockTest()
suite.SetupTest()
suite.coordinator.SetupConnections(suite.path)

// setup mock callback
Expand Down Expand Up @@ -150,7 +150,7 @@ func (suite *FeeTestSuite) TestOnChanOpenTry() {

suite.Run(tc.name, func() {
// reset suite
suite.SetupMockTest()
suite.SetupTest()
suite.coordinator.SetupConnections(suite.path)
suite.path.EndpointB.ChanOpenInit()

Expand Down Expand Up @@ -255,7 +255,7 @@ func (suite *FeeTestSuite) TestOnChanOpenAck() {
for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
suite.SetupMockTest()
suite.SetupTest()
suite.coordinator.SetupConnections(suite.path)

// setup mock callback
Expand Down Expand Up @@ -337,7 +337,7 @@ func (suite *FeeTestSuite) TestOnChanCloseInit() {
for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
suite.SetupMockTest()
suite.SetupTest()
suite.coordinator.Setup(suite.path) // setup channel

origBal := suite.chainA.GetSimApp().BankKeeper.GetAllBalances(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress())
Expand Down Expand Up @@ -415,7 +415,7 @@ func (suite *FeeTestSuite) TestOnChanCloseConfirm() {
for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
suite.SetupMockTest()
suite.SetupTest()
suite.coordinator.Setup(suite.path) // setup channel

origBal := suite.chainA.GetSimApp().BankKeeper.GetAllBalances(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress())
Expand Down Expand Up @@ -481,7 +481,7 @@ func (suite *FeeTestSuite) TestOnRecvPacket() {
for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
suite.SetupMockTest()
suite.SetupTest()
suite.coordinator.Setup(suite.path)

// set up a different channel to make sure that the test will error if the destination channel of the packet is not fee enabled
Expand Down Expand Up @@ -723,7 +723,7 @@ func (suite *FeeTestSuite) TestOnTimeoutPacket() {
for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
suite.SetupMockTest()
suite.SetupTest()
suite.coordinator.Setup(suite.path)
packet := suite.CreateMockPacket()

Expand Down
23 changes: 0 additions & 23 deletions modules/apps/29-fee/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/stretchr/testify/suite"

"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"
transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
ibcmock "github.com/cosmos/ibc-go/v3/testing/mock"
Expand All @@ -34,31 +33,11 @@ type KeeperTestSuite struct {
queryClient types.QueryClient
}

// TODO: remove and rename 'SetupMockTest' to 'SetupTest'
func (suite *KeeperTestSuite) SetupTest() {
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2)
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1))
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2))

path := ibctesting.NewPath(suite.chainA, suite.chainB)
feeTransferVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: transfertypes.Version}))
path.EndpointA.ChannelConfig.Version = feeTransferVersion
path.EndpointB.ChannelConfig.Version = feeTransferVersion
path.EndpointA.ChannelConfig.PortID = transfertypes.PortID
path.EndpointB.ChannelConfig.PortID = transfertypes.PortID
suite.path = path

queryHelper := baseapp.NewQueryServerTestHelper(suite.chainA.GetContext(), suite.chainA.GetSimApp().InterfaceRegistry())
types.RegisterQueryServer(queryHelper, suite.chainA.GetSimApp().IBCFeeKeeper)
suite.queryClient = types.NewQueryClient(queryHelper)
}

// TODO: rename to 'SetupTest' when the above function is removed
func (suite *KeeperTestSuite) SetupMockTest() {
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2)
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1))
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2))

path := ibctesting.NewPath(suite.chainA, suite.chainB)
mockFeeVersion := string(types.ModuleCdc.MustMarshalJSON(&types.Metadata{FeeVersion: types.Version, AppVersion: ibcmock.Version}))
path.EndpointA.ChannelConfig.Version = mockFeeVersion
Expand All @@ -77,7 +56,6 @@ func TestKeeperTestSuite(t *testing.T) {
}

func (suite *KeeperTestSuite) TestFeeInEscrow() {
suite.SetupMockTest()
suite.coordinator.Setup(suite.path)

fee := types.Fee{RecvFee: defaultReceiveFee, AckFee: defaultAckFee, TimeoutFee: defaultTimeoutFee}
Expand Down Expand Up @@ -119,7 +97,6 @@ func (suite *KeeperTestSuite) TestDisableAllChannels() {
}

func (suite *KeeperTestSuite) TestGetAllIdentifiedPacketFees() {
suite.SetupMockTest()
suite.coordinator.Setup(suite.path)

// escrow a fee
Expand Down

0 comments on commit 83719ee

Please sign in to comment.