Skip to content

Commit

Permalink
Add NewTransferPath in testing. (cosmos#4164)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim authored Jul 25, 2023
1 parent 6b0bd37 commit 3bd0044
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 53 deletions.
12 changes: 2 additions & 10 deletions modules/apps/27-interchain-accounts/host/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
{
"interchain account successfully executes transfertypes.MsgTransfer",
func(encoding string) {
transferPath := ibctesting.NewPath(suite.chainB, suite.chainC)
transferPath.EndpointA.ChannelConfig.PortID = ibctesting.TransferPort
transferPath.EndpointB.ChannelConfig.PortID = ibctesting.TransferPort
transferPath.EndpointA.ChannelConfig.Version = transfertypes.Version
transferPath.EndpointB.ChannelConfig.Version = transfertypes.Version
transferPath := ibctesting.NewTransferPath(suite.chainB, suite.chainC)

suite.coordinator.Setup(transferPath)

Expand Down Expand Up @@ -702,11 +698,7 @@ func (suite *KeeperTestSuite) TestJSONOnRecvPacket() {
{
"interchain account successfully executes transfertypes.MsgTransfer",
func(icaAddress string) {
transferPath := ibctesting.NewPath(suite.chainB, suite.chainC)
transferPath.EndpointA.ChannelConfig.PortID = ibctesting.TransferPort
transferPath.EndpointB.ChannelConfig.PortID = ibctesting.TransferPort
transferPath.EndpointA.ChannelConfig.Version = transfertypes.Version
transferPath.EndpointB.ChannelConfig.Version = transfertypes.Version
transferPath := ibctesting.NewTransferPath(suite.chainB, suite.chainC)

suite.coordinator.Setup(transferPath)

Expand Down
6 changes: 3 additions & 3 deletions modules/apps/transfer/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (suite *TransferTestSuite) TestOnChanOpenInit() {

suite.Run(tc.name, func() {
suite.SetupTest() // reset
path = NewTransferPath(suite.chainA, suite.chainB)
path = ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.SetupConnections(path)
path.EndpointA.ChannelID = ibctesting.FirstChannelID

Expand Down Expand Up @@ -151,7 +151,7 @@ func (suite *TransferTestSuite) TestOnChanOpenTry() {
suite.Run(tc.name, func() {
suite.SetupTest() // reset

path = NewTransferPath(suite.chainA, suite.chainB)
path = ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.SetupConnections(path)
path.EndpointA.ChannelID = ibctesting.FirstChannelID

Expand Down Expand Up @@ -215,7 +215,7 @@ func (suite *TransferTestSuite) TestOnChanOpenAck() {
suite.Run(tc.name, func() {
suite.SetupTest() // reset

path := NewTransferPath(suite.chainA, suite.chainB)
path := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.SetupConnections(path)
path.EndpointA.ChannelID = ibctesting.FirstChannelID
counterpartyVersion = types.Version
Expand Down
3 changes: 2 additions & 1 deletion modules/apps/transfer/keeper/invariants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
)

func (suite *KeeperTestSuite) TestTotalEscrowPerDenomInvariant() {
Expand Down Expand Up @@ -36,7 +37,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowPerDenomInvariant() {

suite.Run(tc.name, func() {
suite.SetupTest() // reset
path := NewTransferPath(suite.chainA, suite.chainB)
path := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)

amount := sdkmath.NewInt(100)
Expand Down
10 changes: 0 additions & 10 deletions modules/apps/transfer/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ func (suite *KeeperTestSuite) SetupTest() {
types.RegisterQueryServer(queryHelper, suite.chainA.GetSimApp().TransferKeeper)
}

func NewTransferPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path {
path := ibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig.PortID = ibctesting.TransferPort
path.EndpointB.ChannelConfig.PortID = ibctesting.TransferPort
path.EndpointA.ChannelConfig.Version = types.Version
path.EndpointB.ChannelConfig.Version = types.Version

return path
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/transfer/keeper/mbt_relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ func (suite *KeeperTestSuite) TestModelBasedRelay() {
}

suite.SetupTest()
pathAtoB := NewTransferPath(suite.chainA, suite.chainB)
pathBtoC := NewTransferPath(suite.chainB, suite.chainC)
pathAtoB := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
pathBtoC := ibctesting.NewTransferPath(suite.chainB, suite.chainC)
suite.coordinator.Setup(pathAtoB)
suite.coordinator.Setup(pathBtoC)

Expand Down
4 changes: 2 additions & 2 deletions modules/apps/transfer/keeper/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (suite *KeeperTestSuite) TestMigrateTotalEscrowForDenom() {
"success: one native denom escrowed in two channels",
func() {
denom = sdk.DefaultBondDenom
extraPath := NewTransferPath(suite.chainA, suite.chainB)
extraPath := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(extraPath)

escrowAddress1 := transfertypes.GetEscrowAddress(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
Expand Down Expand Up @@ -221,7 +221,7 @@ func (suite *KeeperTestSuite) TestMigrateTotalEscrowForDenom() {
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
suite.SetupTest() // reset

path = NewTransferPath(suite.chainA, suite.chainB)
path = ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)

tc.malleate() // explicitly fund escrow account
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (suite *KeeperTestSuite) TestMsgTransfer() {
suite.Run(tc.name, func() {
suite.SetupTest()

path := NewTransferPath(suite.chainA, suite.chainB)
path := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)

coin := sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100))
Expand Down
24 changes: 12 additions & 12 deletions modules/apps/transfer/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
suite.Run(tc.name, func() {
suite.SetupTest() // reset

path = NewTransferPath(suite.chainA, suite.chainB)
path = ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)

coin = sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100))
Expand Down Expand Up @@ -191,10 +191,10 @@ func (suite *KeeperTestSuite) TestSendTransferSetsTotalEscrowAmountForSourceIBCT

// set up
// 2 transfer channels between chain A and chain B
path1 := NewTransferPath(suite.chainA, suite.chainB)
path1 := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path1)

path2 := NewTransferPath(suite.chainA, suite.chainB)
path2 := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path2)

// create IBC token on chain B with denom trace "transfer/channel-0/stake"
Expand Down Expand Up @@ -341,7 +341,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
suite.SetupTest() // reset

path := NewTransferPath(suite.chainA, suite.chainB)
path := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)
receiver = suite.chainB.SenderAccount.GetAddress().String() // must be explicitly changed in malleate

Expand Down Expand Up @@ -442,10 +442,10 @@ func (suite *KeeperTestSuite) TestOnRecvPacketSetsTotalEscrowAmountForSourceIBCT

// setup
// 2 transfer channels between chain A and chain B
path1 := NewTransferPath(suite.chainA, suite.chainB)
path1 := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path1)

path2 := NewTransferPath(suite.chainA, suite.chainB)
path2 := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path2)

// denomTrace path: {transfer/channel-1/transfer/channel-0}
Expand Down Expand Up @@ -570,7 +570,7 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacket() {

suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
suite.SetupTest() // reset
path = NewTransferPath(suite.chainA, suite.chainB)
path = ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)
amount = sdkmath.NewInt(100) // must be explicitly changed
expEscrowAmount = sdkmath.ZeroInt()
Expand Down Expand Up @@ -639,10 +639,10 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacketSetsTotalEscrowAmountFo

// set up
// 2 transfer channels between chain A and chain B
path1 := NewTransferPath(suite.chainA, suite.chainB)
path1 := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path1)

path2 := NewTransferPath(suite.chainA, suite.chainB)
path2 := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path2)

// fund escrow account for transfer and channel-1 on chain B
Expand Down Expand Up @@ -770,7 +770,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() {
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
suite.SetupTest() // reset

path = NewTransferPath(suite.chainA, suite.chainB)
path = ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)
amount = sdkmath.NewInt(100) // must be explicitly changed
sender = suite.chainA.SenderAccount.GetAddress().String()
Expand Down Expand Up @@ -834,10 +834,10 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacketSetsTotalEscrowAmountForSourceI

// set up
// 2 transfer channels between chain A and chain B
path1 := NewTransferPath(suite.chainA, suite.chainB)
path1 := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path1)

path2 := NewTransferPath(suite.chainA, suite.chainB)
path2 := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path2)

// fund escrow account for transfer and channel-1 on chain B
Expand Down
14 changes: 2 additions & 12 deletions modules/apps/transfer/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ func (suite *TransferTestSuite) SetupTest() {
suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(3))
}

func NewTransferPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path {
path := ibctesting.NewPath(chainA, chainB)
path.EndpointA.ChannelConfig.PortID = ibctesting.TransferPort
path.EndpointB.ChannelConfig.PortID = ibctesting.TransferPort
path.EndpointA.ChannelConfig.Version = types.Version
path.EndpointB.ChannelConfig.Version = types.Version

return path
}

// Constructs the following sends based on the established channels/connections
// 1 - from chainA to chainB
// 2 - from chainB to chainC
Expand All @@ -51,7 +41,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() {
// NOTE:
// pathAtoB.EndpointA = endpoint on chainA
// pathAtoB.EndpointB = endpoint on chainB
pathAtoB := NewTransferPath(suite.chainA, suite.chainB)
pathAtoB := ibctesting.NewTransferPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(pathAtoB)

originalBalance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom)
Expand Down Expand Up @@ -88,7 +78,7 @@ func (suite *TransferTestSuite) TestHandleMsgTransfer() {
// NOTE:
// pathBtoC.EndpointA = endpoint on chainB
// pathBtoC.EndpointB = endpoint on chainC
pathBtoC := NewTransferPath(suite.chainB, suite.chainC)
pathBtoC := ibctesting.NewTransferPath(suite.chainB, suite.chainC)
suite.coordinator.Setup(pathBtoC)

// send from chainB to chainC
Expand Down
13 changes: 13 additions & 0 deletions testing/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
)

Expand All @@ -31,6 +32,18 @@ func NewPath(chainA, chainB *TestChain) *Path {
}
}

// NewTransferPath constructs a new path between each chain suitable for use with
// the transfer module.
func NewTransferPath(chainA, chainB *TestChain) *Path {
path := NewPath(chainA, chainB)
path.EndpointA.ChannelConfig.PortID = TransferPort
path.EndpointB.ChannelConfig.PortID = TransferPort
path.EndpointA.ChannelConfig.Version = transfertypes.Version
path.EndpointB.ChannelConfig.Version = transfertypes.Version

return path
}

// SetChannelOrdered sets the channel order for both endpoints to ORDERED.
func (path *Path) SetChannelOrdered() {
path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED
Expand Down

0 comments on commit 3bd0044

Please sign in to comment.