@@ -23,6 +23,7 @@ type QueryMsg struct {
23
23
// ibc2 contract response type
24
24
type State struct {
25
25
IBC2PacketReceiveCounter uint32 `json:"ibc2_packet_receive_counter"`
26
+ IBC2PacketTimeoutCounter uint32 `json:"ibc2_packet_timeout_counter"`
26
27
LastChannelID string `json:"last_channel_id"`
27
28
LastPacketSeq uint64 `json:"last_packet_seq"`
28
29
}
@@ -33,7 +34,7 @@ type IbcPayload struct {
33
34
SendAsyncAckForPrevMsg bool `json:"send_async_ack_for_prev_msg"`
34
35
}
35
36
36
- func TestIBC2SendMsg (t * testing.T ) {
37
+ func TestIBC2SendReceiveMsg (t * testing.T ) {
37
38
coord := wasmibctesting .NewCoordinator (t , 2 )
38
39
chainA := wasmibctesting .NewWasmTestChain (coord .GetChain (ibctesting .GetChainID (1 )))
39
40
chainB := wasmibctesting .NewWasmTestChain (coord .GetChain (ibctesting .GetChainID (2 )))
@@ -105,3 +106,59 @@ func TestIBC2SendMsg(t *testing.T) {
105
106
require .Equal (t , uint32 (i ), response .IBC2PacketReceiveCounter )
106
107
}
107
108
}
109
+
110
+ func TestIBC2TimeoutMsg (t * testing.T ) {
111
+ coord := wasmibctesting .NewCoordinator (t , 2 )
112
+ chainA := wasmibctesting .NewWasmTestChain (coord .GetChain (ibctesting .GetChainID (1 )))
113
+ chainB := wasmibctesting .NewWasmTestChain (coord .GetChain (ibctesting .GetChainID (2 )))
114
+ contractCodeA := chainA .StoreCodeFile ("./testdata/ibc2.wasm" ).CodeID
115
+ contractAddrA := chainA .InstantiateContract (contractCodeA , []byte (`{}` ))
116
+ contractPortA := wasmkeeper .PortIDForContractV2 (contractAddrA )
117
+ require .NotEmpty (t , contractAddrA )
118
+
119
+ contractCodeB := chainB .StoreCodeFile ("./testdata/ibc2.wasm" ).CodeID
120
+ // Skip initial contract address to not overlap with ChainA
121
+ _ = chainB .InstantiateContract (contractCodeB , []byte (`{}` ))
122
+ contractAddrB := chainB .InstantiateContract (contractCodeB , []byte (`{}` ))
123
+ contractPortB := wasmkeeper .PortIDForContractV2 (contractAddrB )
124
+ require .NotEmpty (t , contractAddrB )
125
+
126
+ path := wasmibctesting .NewWasmPath (chainA , chainB )
127
+ path .EndpointA .ChannelConfig = & ibctesting.ChannelConfig {
128
+ PortID : contractPortA ,
129
+ Version : ibctransfertypes .V1 ,
130
+ Order : channeltypes .UNORDERED ,
131
+ }
132
+ path .EndpointB .ChannelConfig = & ibctesting.ChannelConfig {
133
+ PortID : contractPortB ,
134
+ Version : ibctransfertypes .V1 ,
135
+ Order : channeltypes .UNORDERED ,
136
+ }
137
+
138
+ path .Path .SetupV2 ()
139
+
140
+ // IBC v2 Payload from contract on Chain B to contract on Chain A
141
+ payload := mockv2 .NewMockPayload (contractPortB , contractPortA )
142
+ var err error
143
+ payload .Value , err = json .Marshal (IbcPayload {ResponseWithoutAck : false , SendAsyncAckForPrevMsg : false })
144
+ require .NoError (t , err )
145
+
146
+ // Message timeout
147
+ timeoutTimestamp := uint64 (chainB .GetContext ().BlockTime ().Add (time .Minute ).Unix ())
148
+
149
+ _ , err = path .EndpointB .MsgSendPacket (timeoutTimestamp , payload )
150
+ require .NoError (t , err )
151
+
152
+ // First message send through test
153
+ err = wasmibctesting .RelayPendingPacketsV2 (path )
154
+ require .NoError (t , err )
155
+
156
+ // Check that timeout message is sent to the contract
157
+ err = wasmibctesting .TimeoutPendingPacketsV2 (coord , path )
158
+ require .NoError (t , err )
159
+
160
+ var response State
161
+ err = chainA .SmartQuery (contractAddrA .String (), QueryMsg {QueryState : struct {}{}}, & response )
162
+ require .NoError (t , err )
163
+ require .Equal (t , uint32 (1 ), response .IBC2PacketTimeoutCounter )
164
+ }
0 commit comments