Search Apps Documentation Source Content File Folder Download Copy Actions Download

z6aa_timeout_filetest.gno

12.13 Kb · 362 lines
  1// PKGPATH: gno.land/r/aib/main
  2package main
  3
  4import (
  5	"encoding/hex"
  6	"testing"
  7	"time"
  8
  9	"gno.land/p/aib/ibc/lightclient/tendermint"
 10	tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
 11	"gno.land/p/aib/ibc/types"
 12	"gno.land/p/aib/ics23"
 13	appstesting "gno.land/r/aib/ibc/apps/testing"
 14	"gno.land/r/aib/ibc/core"
 15)
 16
 17// Timeout success with authorized relayer
 18func main(cur realm) {
 19	core.SetAdmin(cross(cur), "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")
 20	core.AddRelayer(cross(cur), "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")
 21	var (
 22		chainID       = "atomone-1"
 23		trustedHeight = types.NewHeight(1, 2)
 24		clientState   = tmtesting.NewClientState(chainID, trustedHeight)
 25		apphash       = tmtesting.Hash("apphash-1")
 26		// priv=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==
 27		val1 = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=",
 28			"VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 1)
 29		// priv=nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
 30		val2 = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=",
 31			"NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 1)
 32		trustedValset  = tendermint.NewValset(val1, val2)
 33		consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
 34		counterpartyID = "07-tendermint-42"
 35	)
 36	clientID := core.CreateClient(cross(cur), clientState, consensusState)
 37	core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, counterpartyID)
 38	// Register app
 39	var (
 40		app       = appstesting.NewApp(cross(cur))
 41		appPortID = "app"
 42	)
 43	core.RegisterApp(cross(cur), appPortID, app)
 44	// Send a packet
 45	sendPacket := types.MsgSendPacket{
 46		SourceClient:     clientID,
 47		TimeoutTimestamp: uint64(time.Now().Add(10 * time.Minute).Unix()),
 48		Payloads: []types.Payload{{
 49			SourcePort:      appPortID,
 50			DestinationPort: "destinationPort",
 51			Encoding:        "application/json",
 52			Value:           []byte("{}"),
 53			Version:         "v1",
 54		}},
 55	}
 56	sequence := core.SendPacket(cross(cur), sendPacket)
 57	// Change block time to after the timeout
 58	ctx := testing.GetContext()
 59	ctx.Time = time.Now().Add(12 * time.Minute)
 60	testing.SetContext(ctx)
 61	// Update client with a block created after the timeout
 62	// NOTE code generated by:
 63	// go run -C ./cmd/gen-block-signatures . -apphash-hex=82ea91f259352674360c621c4b0a1975cc076e3792b6d22a8bfbe8e7f7d0d2d7 -chainid=atomone-1 -header-time-shift=12 -height=12 -privkeys=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==,nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
 64	// NOTE this apphash was provided by the gen-proof command below.
 65	apphash, _ = hex.DecodeString("82ea91f259352674360c621c4b0a1975cc076e3792b6d22a8bfbe8e7f7d0d2d7")
 66	trustedHeight = clientState.LatestHeight
 67	var (
 68		newHeight       = uint64(12)
 69		commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
 70		newTimestamp    = consensusState.Timestamp.Add(time.Minute * time.Duration(12))
 71		valset          = tendermint.NewValset(val1, val2)
 72		nextValset      = tendermint.NewValset(val1, val2)
 73
 74		signatures = []tendermint.CommitSig{
 75			{
 76				BlockIDFlag:      tendermint.BlockIDFlagCommit,
 77				ValidatorAddress: valset.Validators[0].Address,
 78				Timestamp:        commitTimestamp,
 79				Signature:        []byte("\x90\x76\xf4\x27\xaf\x23\xd0\xcb\x97\xb1\x6d\xfa\x86\xae\x6d\x46\xe9\xe4\x65\x76\xf2\x6a\x1d\x5f\x83\xa6\x9e\x4a\x28\x55\x6e\x74\x84\x02\xff\x15\xc0\x41\xed\x15\xb7\xef\x3a\x3f\xe1\xe6\xa0\x8f\x34\x83\x9c\x2e\x27\x26\x69\x00\x73\x45\x87\xd2\x3c\xe6\x12\x07"),
 80			},
 81			{
 82				BlockIDFlag:      tendermint.BlockIDFlagCommit,
 83				ValidatorAddress: valset.Validators[1].Address,
 84				Timestamp:        commitTimestamp,
 85				Signature:        []byte("\x45\x61\x3b\x34\x58\xa1\xf5\x75\x16\x6f\xb3\xad\xda\x12\xa8\xef\xb6\x64\x3f\x6b\x80\x73\x74\xe3\x15\x6f\xe1\x3b\x3f\x50\xed\x0d\xbc\xa7\x54\x11\x72\xe3\x71\x22\x95\xec\x77\x93\x45\x03\x67\xa5\x00\x4c\x84\x3b\x1c\xa4\xf7\x0e\x95\xd1\xe2\x04\xb6\x91\x63\x09"),
 86			},
 87		}
 88
 89		msgHeader = tmtesting.NewMsgHeader(
 90			chainID, newTimestamp, apphash, newHeight, trustedHeight, valset,
 91			nextValset, trustedValset, signatures,
 92		)
 93	)
 94	core.UpdateClient(cross(cur), clientID, msgHeader)
 95
 96	// Timeout the packet
 97	// Generate the proof that no RecvPacket have been received by the
 98	// counterparty chain.
 99	specs := ics23.IavlSpec()
100	// NOTE code generated by:
101	// go run -C ./cmd/gen-proof . 'prefix2' '07-tendermint-42' 'receipt'
102	proof := []ics23.CommitmentProof{
103
104		// iavl proof
105		ics23.CommitmentProof_Nonexist{
106			Nonexist: &ics23.NonExistenceProof{
107				Key: []byte("\x70\x72\x65\x66\x69\x78\x32\x30\x37\x2d\x74\x65\x6e\x64\x65\x72\x6d\x69\x6e\x74\x2d\x34\x32\x02\x00\x00\x00\x00\x00\x00\x00\x01"),
108				Left: &ics23.ExistenceProof{
109					Key:   []byte("\x50"),
110					Value: []byte("\x50"),
111					Leaf: &ics23.LeafOp{
112						Hash:         specs.LeafSpec.Hash,
113						PrehashKey:   specs.LeafSpec.PrehashKey,
114						PrehashValue: specs.LeafSpec.PrehashValue,
115						Length:       specs.LeafSpec.Length,
116						Prefix:       []byte("\x00\x02\x02"),
117					},
118					Path: []*ics23.InnerOp{
119						{
120							Hash:   specs.InnerSpec.Hash,
121							Prefix: []byte("\x04\x06\x02\x20"),
122							Suffix: []byte("\x20\x79\x8e\x2c\xaa\x96\xfd\xfb\xa3\x76\xdd\xeb\x47\x99\x99\x54\xd2\xf4\x7e\x65\x16\x22\x64\xb0\x53\x6a\xb5\xdf\xf7\xfc\x0a\x2e\x07"),
123						},
124						{
125							Hash:   specs.InnerSpec.Hash,
126							Prefix: []byte("\x06\x0a\x02\x20\x9a\xf3\x7d\xd5\x95\xa0\x19\x08\x03\xb5\xe0\x5a\xae\xf4\x2a\xe3\xfa\xd4\x99\xe4\xfb\xe3\x7f\x7c\xd3\x1c\xad\xff\x22\xa9\xee\x74\x20"),
127							Suffix: []byte(""),
128						},
129					},
130				},
131				Right: &ics23.ExistenceProof{
132					Key:   []byte("\x72"),
133					Value: []byte("\x72"),
134					Leaf: &ics23.LeafOp{
135						Hash:         specs.LeafSpec.Hash,
136						PrehashKey:   specs.LeafSpec.PrehashKey,
137						PrehashValue: specs.LeafSpec.PrehashValue,
138						Length:       specs.LeafSpec.Length,
139						Prefix:       []byte("\x00\x02\x02"),
140					},
141					Path: []*ics23.InnerOp{
142						{
143							Hash:   specs.InnerSpec.Hash,
144							Prefix: []byte("\x02\x04\x02\x20"),
145							Suffix: []byte("\x20\xa3\x03\x93\x0c\xa8\x83\x16\x18\xac\x7e\x4d\xdd\x10\x54\x6c\xfc\x36\x6f\xb7\x30\xd6\x63\x0c\x03\x0a\x97\x22\x6b\xbe\xfc\x69\x35"),
146						},
147						{
148							Hash:   specs.InnerSpec.Hash,
149							Prefix: []byte("\x04\x06\x02\x20\x35\xf8\xea\x80\x53\x90\xe0\x84\x85\x4f\x39\x9b\x42\xcc\xde\xae\xa3\x3a\x1d\xed\xc1\x15\x63\x8a\xc4\x8d\x06\x00\x63\x7d\xba\x1f\x20"),
150							Suffix: []byte(""),
151						},
152						{
153							Hash:   specs.InnerSpec.Hash,
154							Prefix: []byte("\x06\x0a\x02\x20\x9a\xf3\x7d\xd5\x95\xa0\x19\x08\x03\xb5\xe0\x5a\xae\xf4\x2a\xe3\xfa\xd4\x99\xe4\xfb\xe3\x7f\x7c\xd3\x1c\xad\xff\x22\xa9\xee\x74\x20"),
155							Suffix: []byte(""),
156						},
157					},
158				},
159			},
160		},
161
162		// rootmulti proof
163		ics23.CommitmentProof_Exist{
164			Exist: &ics23.ExistenceProof{
165				Key:   []byte("\x69\x61\x76\x6c\x53\x74\x6f\x72\x65\x4b\x65\x79"),
166				Value: []byte("\x38\x22\xf3\x2f\x21\x66\x53\x63\x29\x4f\x96\xed\xda\x15\xa7\x81\x1a\x67\x6c\x2b\xa9\xdd\xcc\xec\x46\x63\x64\xf1\x00\x69\x82\x7d"),
167				Leaf: &ics23.LeafOp{
168					Hash:         specs.LeafSpec.Hash,
169					PrehashKey:   specs.LeafSpec.PrehashKey,
170					PrehashValue: specs.LeafSpec.PrehashValue,
171					Length:       specs.LeafSpec.Length,
172					Prefix:       []byte("\x00"),
173				},
174				Path: []*ics23.InnerOp{},
175			},
176		},
177	}
178
179	timeoutPacket := types.MsgTimeout{
180		Packet: types.Packet{
181			Sequence:          sequence,
182			SourceClient:      clientID,
183			DestinationClient: counterpartyID,
184			TimeoutTimestamp:  sendPacket.TimeoutTimestamp,
185			Payloads:          sendPacket.Payloads,
186		},
187		ProofUnreceived: proof,
188		ProofHeight:     msgHeader.GetHeight(),
189	}
190
191	res := core.Timeout(cross(cur), timeoutPacket)
192
193	println("res:", res)
194	println("\n----------- assert render clients/07-tendermint-1/packet_commitments")
195	println(core.Render("clients/" + clientID + "/packet_commitments"))
196	println("----------- assert render clients/07-tendermint-1/packet_commitments/1 (cleared)")
197	println(core.Render("clients/" + clientID + "/packet_commitments/1"))
198	println("\n----------- app report")
199	println(app.Report())
200
201	// assert NOOP response (res=1) if timeout is resubmitted
202	res = core.Timeout(cross(cur), timeoutPacket)
203
204	println("res:", res)
205	println("\n----------- app report")
206	println(app.Report())
207}
208
209// Output:
210// res: (2 gno.land/p/aib/ibc/types.ResponseResultType)
211//
212// ----------- assert render clients/07-tendermint-1/packet_commitments
213// {"items":[],"page":1,"total":1}
214// ----------- assert render clients/07-tendermint-1/packet_commitments/1 (cleared)
215// {"error":"sequence 1 not found"}
216//
217// ----------- app report
218// OnSendPacket (1)
219// - sourceClient: 07-tendermint-1
220// - destinationClient: 07-tendermint-42
221// - sequence: 1
222// - payload:
223//   - sourcePort: app
224//   - destinationPort: destinationPort
225//   - version: v1
226//   - encoding: application/json
227//   - value: {}
228//
229// OnRecvPacket (0)
230// OnTimeoutPacket (1)
231// - sourceClient: 07-tendermint-1
232// - destinationClient: 07-tendermint-42
233// - sequence: 1
234// - payload:
235//   - sourcePort: app
236//   - destinationPort: destinationPort
237//   - version: v1
238//   - encoding: application/json
239//   - value: {}
240//
241// OnAcknowledgementPacket (0)
242//
243// res: (1 gno.land/p/aib/ibc/types.ResponseResultType)
244//
245// ----------- app report
246// OnSendPacket (1)
247// - sourceClient: 07-tendermint-1
248// - destinationClient: 07-tendermint-42
249// - sequence: 1
250// - payload:
251//   - sourcePort: app
252//   - destinationPort: destinationPort
253//   - version: v1
254//   - encoding: application/json
255//   - value: {}
256//
257// OnRecvPacket (0)
258// OnTimeoutPacket (1)
259// - sourceClient: 07-tendermint-1
260// - destinationClient: 07-tendermint-42
261// - sequence: 1
262// - payload:
263//   - sourcePort: app
264//   - destinationPort: destinationPort
265//   - version: v1
266//   - encoding: application/json
267//   - value: {}
268//
269// OnAcknowledgementPacket (0)
270
271// Events:
272// [
273//   {
274//     "type": "create_client",
275//     "attrs": [
276//       {
277//         "key": "client_id",
278//         "value": "07-tendermint-1"
279//       },
280//       {
281//         "key": "client_type",
282//         "value": "07-tendermint"
283//       },
284//       {
285//         "key": "consensus_heights",
286//         "value": "1/2"
287//       }
288//     ],
289//     "pkg_path": "gno.land/r/aib/ibc/core"
290//   },
291//   {
292//     "type": "send_packet",
293//     "attrs": [
294//       {
295//         "key": "packet_source_client",
296//         "value": "07-tendermint-1"
297//       },
298//       {
299//         "key": "packet_dest_client",
300//         "value": "07-tendermint-42"
301//       },
302//       {
303//         "key": "packet_sequence",
304//         "value": "1"
305//       },
306//       {
307//         "key": "packet_timeout_timestamp",
308//         "value": "1234568490"
309//       },
310//       {
311//         "key": "encoded_packet_hex",
312//         "value": "0801120f30372d74656e6465726d696e742d311a1030372d74656e6465726d696e742d343220aa8ad8cc042a300a03617070120f64657374696e6174696f6e506f72741a02763122106170706c69636174696f6e2f6a736f6e2a027b7d"
313//       }
314//     ],
315//     "pkg_path": "gno.land/r/aib/ibc/core"
316//   },
317//   {
318//     "type": "update_client",
319//     "attrs": [
320//       {
321//         "key": "client_id",
322//         "value": "07-tendermint-1"
323//       },
324//       {
325//         "key": "client_type",
326//         "value": "07-tendermint"
327//       },
328//       {
329//         "key": "consensus_heights",
330//         "value": "1/12"
331//       }
332//     ],
333//     "pkg_path": "gno.land/r/aib/ibc/core"
334//   },
335//   {
336//     "type": "timeout_packet",
337//     "attrs": [
338//       {
339//         "key": "packet_source_client",
340//         "value": "07-tendermint-1"
341//       },
342//       {
343//         "key": "packet_dest_client",
344//         "value": "07-tendermint-42"
345//       },
346//       {
347//         "key": "packet_sequence",
348//         "value": "1"
349//       },
350//       {
351//         "key": "packet_timeout_timestamp",
352//         "value": "1234568490"
353//       },
354//       {
355//         "key": "encoded_packet_hex",
356//         "value": "0801120f30372d74656e6465726d696e742d311a1030372d74656e6465726d696e742d343220aa8ad8cc042a300a03617070120f64657374696e6174696f6e506f72741a02763122106170706c69636174696f6e2f6a736f6e2a027b7d"
357//       }
358//     ],
359//     "pkg_path": "gno.land/r/aib/ibc/core"
360//   }
361// ]
362