9
9
"github.com/cosmos/ibc-go/modules/apps/transfer/types"
10
10
clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types"
11
11
channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types"
12
- "github.com/cosmos/ibc-go/modules/core/exported"
13
12
ibctesting "github.com/cosmos/ibc-go/testing"
14
13
)
15
14
@@ -31,90 +30,102 @@ func (suite *TransferTestSuite) SetupTest() {
31
30
suite .chainC = suite .coordinator .GetChain (ibctesting .GetChainID (2 ))
32
31
}
33
32
33
+ func NewTransferPath (chainA , chainB * ibctesting.TestChain ) * ibctesting.Path {
34
+ path := ibctesting .NewPath (chainA , chainB )
35
+ path .EndpointA .ChannelConfig .PortID = ibctesting .TransferPort
36
+ path .EndpointB .ChannelConfig .PortID = ibctesting .TransferPort
37
+
38
+ return path
39
+ }
40
+
34
41
// constructs a send from chainA to chainB on the established channel/connection
35
42
// and sends the same coin back from chainB to chainA.
36
43
func (suite * TransferTestSuite ) TestHandleMsgTransfer () {
37
44
// setup between chainA and chainB
38
- clientA , clientB , connA , connB := suite .coordinator .SetupClientConnections (suite .chainA , suite .chainB , exported .Tendermint )
39
- channelA , channelB := suite .coordinator .CreateTransferChannels (suite .chainA , suite .chainB , connA , connB , channeltypes .UNORDERED )
40
- // originalBalance := suite.chainA.App.BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom)
45
+ path := NewTransferPath (suite .chainA , suite .chainB )
46
+ suite .coordinator .Setup (path )
47
+
48
+ // originalBalance := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), sdk.DefaultBondDenom)
41
49
timeoutHeight := clienttypes .NewHeight (0 , 110 )
42
50
43
51
coinToSendToB := sdk .NewCoin (sdk .DefaultBondDenom , sdk .NewInt (100 ))
44
52
45
53
// send from chainA to chainB
46
- msg := types .NewMsgTransfer (channelA . PortID , channelA . ID , coinToSendToB , suite .chainA .SenderAccount .GetAddress ().String (), suite .chainB .SenderAccount .GetAddress ().String (), timeoutHeight , 0 )
54
+ msg := types .NewMsgTransfer (path . EndpointA . ChannelConfig . PortID , path . EndpointA . ChannelID , coinToSendToB , suite .chainA .SenderAccount .GetAddress ().String (), suite .chainB .SenderAccount .GetAddress ().String (), timeoutHeight , 0 )
47
55
48
- err := suite .coordinator . SendMsg ( suite . chainA , suite . chainB , clientB , msg )
56
+ _ , err := suite .chainA . SendMsgs ( msg )
49
57
suite .Require ().NoError (err ) // message committed
50
58
51
59
// relay send
52
60
fungibleTokenPacket := types .NewFungibleTokenPacketData (coinToSendToB .Denom , coinToSendToB .Amount .Uint64 (), suite .chainA .SenderAccount .GetAddress ().String (), suite .chainB .SenderAccount .GetAddress ().String ())
53
- packet := channeltypes .NewPacket (fungibleTokenPacket .GetBytes (), 1 , channelA . PortID , channelA . ID , channelB . PortID , channelB . ID , timeoutHeight , 0 )
61
+ packet := channeltypes .NewPacket (fungibleTokenPacket .GetBytes (), 1 , path . EndpointA . ChannelConfig . PortID , path . EndpointA . ChannelID , path . EndpointB . ChannelConfig . PortID , path . EndpointB . ChannelID , timeoutHeight , 0 )
54
62
ack := channeltypes .NewResultAcknowledgement ([]byte {byte (1 )})
55
- err = suite . coordinator . RelayPacket (suite . chainA , suite . chainB , clientA , clientB , packet , ack .Acknowledgement ())
63
+ err = path . RelayPacket (packet , ack .Acknowledgement ())
56
64
suite .Require ().NoError (err ) // relay committed
57
65
58
66
// check that voucher exists on chain B
59
67
voucherDenomTrace := types .ParseDenomTrace (types .GetPrefixedDenom (packet .GetDestPort (), packet .GetDestChannel (), sdk .DefaultBondDenom ))
60
- balance := suite .chainB .App .BankKeeper .GetBalance (suite .chainB .GetContext (), suite .chainB .SenderAccount .GetAddress (), voucherDenomTrace .IBCDenom ())
68
+ balance := suite .chainB .GetSimApp () .BankKeeper .GetBalance (suite .chainB .GetContext (), suite .chainB .SenderAccount .GetAddress (), voucherDenomTrace .IBCDenom ())
61
69
62
- coinSentFromAToB := types .GetTransferCoin (channelB . PortID , channelB . ID , sdk .DefaultBondDenom , 100 )
70
+ coinSentFromAToB := types .GetTransferCoin (path . EndpointB . ChannelConfig . PortID , path . EndpointB . ChannelID , sdk .DefaultBondDenom , 100 )
63
71
suite .Require ().Equal (coinSentFromAToB , balance )
64
72
65
73
// setup between chainB to chainC
66
- clientOnBForC , clientOnCForB , connOnBForC , connOnCForB := suite .coordinator .SetupClientConnections (suite .chainB , suite .chainC , exported .Tendermint )
67
- channelOnBForC , channelOnCForB := suite .coordinator .CreateTransferChannels (suite .chainB , suite .chainC , connOnBForC , connOnCForB , channeltypes .UNORDERED )
74
+ // NOTE:
75
+ // pathBtoC.EndpointA = endpoint on chainB
76
+ // pathBtoC.EndpointB = endpoint on chainC
77
+ pathBtoC := NewTransferPath (suite .chainB , suite .chainC )
78
+ suite .coordinator .Setup (pathBtoC )
68
79
69
80
// send from chainB to chainC
70
- msg = types .NewMsgTransfer (channelOnBForC . PortID , channelOnBForC . ID , coinSentFromAToB , suite .chainB .SenderAccount .GetAddress ().String (), suite .chainC .SenderAccount .GetAddress ().String (), timeoutHeight , 0 )
81
+ msg = types .NewMsgTransfer (pathBtoC . EndpointA . ChannelConfig . PortID , pathBtoC . EndpointA . ChannelID , coinSentFromAToB , suite .chainB .SenderAccount .GetAddress ().String (), suite .chainC .SenderAccount .GetAddress ().String (), timeoutHeight , 0 )
71
82
72
- err = suite .coordinator . SendMsg ( suite . chainB , suite . chainC , clientOnCForB , msg )
83
+ _ , err = suite .chainB . SendMsgs ( msg )
73
84
suite .Require ().NoError (err ) // message committed
74
85
75
86
// relay send
76
87
// NOTE: fungible token is prefixed with the full trace in order to verify the packet commitment
77
- fullDenomPath := types .GetPrefixedDenom (channelOnCForB . PortID , channelOnCForB . ID , voucherDenomTrace .GetFullDenomPath ())
88
+ fullDenomPath := types .GetPrefixedDenom (pathBtoC . EndpointB . ChannelConfig . PortID , pathBtoC . EndpointB . ChannelID , voucherDenomTrace .GetFullDenomPath ())
78
89
fungibleTokenPacket = types .NewFungibleTokenPacketData (voucherDenomTrace .GetFullDenomPath (), coinSentFromAToB .Amount .Uint64 (), suite .chainB .SenderAccount .GetAddress ().String (), suite .chainC .SenderAccount .GetAddress ().String ())
79
- packet = channeltypes .NewPacket (fungibleTokenPacket .GetBytes (), 1 , channelOnBForC . PortID , channelOnBForC . ID , channelOnCForB . PortID , channelOnCForB . ID , timeoutHeight , 0 )
80
- err = suite . coordinator . RelayPacket (suite . chainB , suite . chainC , clientOnBForC , clientOnCForB , packet , ack .Acknowledgement ())
90
+ packet = channeltypes .NewPacket (fungibleTokenPacket .GetBytes (), 1 , pathBtoC . EndpointA . ChannelConfig . PortID , pathBtoC . EndpointA . ChannelID , pathBtoC . EndpointB . ChannelConfig . PortID , pathBtoC . EndpointB . ChannelID , timeoutHeight , 0 )
91
+ err = pathBtoC . RelayPacket (packet , ack .Acknowledgement ())
81
92
suite .Require ().NoError (err ) // relay committed
82
93
83
94
coinSentFromBToC := sdk .NewInt64Coin (types .ParseDenomTrace (fullDenomPath ).IBCDenom (), 100 )
84
- balance = suite .chainC .App .BankKeeper .GetBalance (suite .chainC .GetContext (), suite .chainC .SenderAccount .GetAddress (), coinSentFromBToC .Denom )
95
+ balance = suite .chainC .GetSimApp () .BankKeeper .GetBalance (suite .chainC .GetContext (), suite .chainC .SenderAccount .GetAddress (), coinSentFromBToC .Denom )
85
96
86
97
// check that the balance is updated on chainC
87
98
suite .Require ().Equal (coinSentFromBToC , balance )
88
99
89
100
// check that balance on chain B is empty
90
- balance = suite .chainB .App .BankKeeper .GetBalance (suite .chainB .GetContext (), suite .chainB .SenderAccount .GetAddress (), coinSentFromBToC .Denom )
101
+ balance = suite .chainB .GetSimApp () .BankKeeper .GetBalance (suite .chainB .GetContext (), suite .chainB .SenderAccount .GetAddress (), coinSentFromBToC .Denom )
91
102
suite .Require ().Zero (balance .Amount .Int64 ())
92
103
93
104
// send from chainC back to chainB
94
- msg = types .NewMsgTransfer (channelOnCForB . PortID , channelOnCForB . ID , coinSentFromBToC , suite .chainC .SenderAccount .GetAddress ().String (), suite .chainB .SenderAccount .GetAddress ().String (), timeoutHeight , 0 )
105
+ msg = types .NewMsgTransfer (pathBtoC . EndpointB . ChannelConfig . PortID , pathBtoC . EndpointB . ChannelID , coinSentFromBToC , suite .chainC .SenderAccount .GetAddress ().String (), suite .chainB .SenderAccount .GetAddress ().String (), timeoutHeight , 0 )
95
106
96
- err = suite .coordinator . SendMsg ( suite . chainC , suite . chainB , clientOnBForC , msg )
107
+ _ , err = suite .chainC . SendMsgs ( msg )
97
108
suite .Require ().NoError (err ) // message committed
98
109
99
110
// relay send
100
111
// NOTE: fungible token is prefixed with the full trace in order to verify the packet commitment
101
112
fungibleTokenPacket = types .NewFungibleTokenPacketData (fullDenomPath , coinSentFromBToC .Amount .Uint64 (), suite .chainC .SenderAccount .GetAddress ().String (), suite .chainB .SenderAccount .GetAddress ().String ())
102
- packet = channeltypes .NewPacket (fungibleTokenPacket .GetBytes (), 1 , channelOnCForB . PortID , channelOnCForB . ID , channelOnBForC . PortID , channelOnBForC . ID , timeoutHeight , 0 )
103
- err = suite . coordinator . RelayPacket (suite . chainC , suite . chainB , clientOnCForB , clientOnBForC , packet , ack .Acknowledgement ())
113
+ packet = channeltypes .NewPacket (fungibleTokenPacket .GetBytes (), 1 , pathBtoC . EndpointB . ChannelConfig . PortID , pathBtoC . EndpointB . ChannelID , pathBtoC . EndpointA . ChannelConfig . PortID , pathBtoC . EndpointA . ChannelID , timeoutHeight , 0 )
114
+ err = pathBtoC . RelayPacket (packet , ack .Acknowledgement ())
104
115
suite .Require ().NoError (err ) // relay committed
105
116
106
- balance = suite .chainB .App .BankKeeper .GetBalance (suite .chainB .GetContext (), suite .chainB .SenderAccount .GetAddress (), coinSentFromAToB .Denom )
117
+ balance = suite .chainB .GetSimApp () .BankKeeper .GetBalance (suite .chainB .GetContext (), suite .chainB .SenderAccount .GetAddress (), coinSentFromAToB .Denom )
107
118
108
119
// check that the balance on chainA returned back to the original state
109
120
suite .Require ().Equal (coinSentFromAToB , balance )
110
121
111
122
// check that module account escrow address is empty
112
123
escrowAddress := types .GetEscrowAddress (packet .GetDestPort (), packet .GetDestChannel ())
113
- balance = suite .chainB .App .BankKeeper .GetBalance (suite .chainB .GetContext (), escrowAddress , sdk .DefaultBondDenom )
124
+ balance = suite .chainB .GetSimApp () .BankKeeper .GetBalance (suite .chainB .GetContext (), escrowAddress , sdk .DefaultBondDenom )
114
125
suite .Require ().Equal (sdk .NewCoin (sdk .DefaultBondDenom , sdk .ZeroInt ()), balance )
115
126
116
127
// check that balance on chain B is empty
117
- balance = suite .chainC .App .BankKeeper .GetBalance (suite .chainC .GetContext (), suite .chainC .SenderAccount .GetAddress (), voucherDenomTrace .IBCDenom ())
128
+ balance = suite .chainC .GetSimApp () .BankKeeper .GetBalance (suite .chainC .GetContext (), suite .chainC .SenderAccount .GetAddress (), voucherDenomTrace .IBCDenom ())
118
129
suite .Require ().Zero (balance .Amount .Int64 ())
119
130
}
120
131
0 commit comments