z6j_timeout_filetest.gno
4.52 Kb · 113 lines
1// PKGPATH: gno.land/r/aib/main
2package main
3
4import (
5 "testing"
6 "time"
7
8 "gno.land/p/aib/ibc/lightclient/tendermint"
9 tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
10 "gno.land/p/aib/ibc/types"
11 "gno.land/p/aib/ics23"
12 appstesting "gno.land/r/aib/ibc/apps/testing"
13 "gno.land/r/aib/ibc/core"
14)
15
16// Timeout wrong number of proofs compared to specs
17func main(cur realm) {
18 var (
19 chainID = "atomone-1"
20 trustedHeight = types.NewHeight(1, 2)
21 clientState = tmtesting.NewClientState(chainID, trustedHeight)
22 apphash = tmtesting.Hash("apphash-1")
23 // priv=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==
24 val1 = tendermint.NewValidator("9DIBYr64rywKO3Kk6+743xDHcEU=",
25 "VMpO0RzmZu4OMVvsniYdeO/2eP+h1xeoAcHBTZC7Gfw=", 1)
26 // priv=nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
27 val2 = tendermint.NewValidator("y+naL3ubs9q1bXrY9+uRxY9c+J8=",
28 "NeGV1CqewGUTpH5SxVRfkgYOMCVX84MyCslqtw9Ouvo=", 1)
29 trustedValset = tendermint.NewValset(val1, val2)
30 consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
31 counterpartyID = "07-tendermint-42"
32 )
33 clientID := core.CreateClient(cross(cur), clientState, consensusState)
34 core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, counterpartyID)
35 // Register app
36 var (
37 app = appstesting.NewApp(cross(cur))
38 appPortID = "app"
39 )
40 core.RegisterApp(cross(cur), appPortID, app)
41 // Send a packet
42 sendPacket := types.MsgSendPacket{
43 SourceClient: clientID,
44 TimeoutTimestamp: uint64(time.Now().Add(10 * time.Minute).Unix()),
45 Payloads: []types.Payload{{
46 SourcePort: appPortID,
47 DestinationPort: "destinationPort",
48 Encoding: "application/json",
49 Value: []byte("{}"),
50 Version: "v1",
51 }},
52 }
53 sequence := core.SendPacket(cross(cur), sendPacket)
54 // Change block time to after the timeout
55 ctx := testing.GetContext()
56 ctx.Time = time.Now().Add(12 * time.Minute)
57 testing.SetContext(ctx)
58 // Update client with a block created after the timeout
59 // NOTE code generated by:
60 // go run -C ./cmd/gen-block-signatures . -apphash-seed=apphash-5 -chainid=atomone-1 -header-time-shift=12 -height=12 -privkeys=8a6cAbQSpDbebmcTEhCMPhhr/SkL/2pizo60yzHRkN9Uyk7RHOZm7g4xW+yeJh147/Z4/6HXF6gBwcFNkLsZ/A==,nWg6ETc62tyxd94lh8fFaQnZKaAW6vlS0L/4lfseJuI14ZXUKp7AZROkflLFVF+SBg4wJVfzgzIKyWq3D066+g==
61 apphash = tmtesting.Hash("apphash-5")
62 trustedHeight = clientState.LatestHeight
63 var (
64 newHeight = uint64(12)
65 commitTimestamp = tmtesting.ToTime("2025-09-25T07:55:57.306746166Z")
66 newTimestamp = consensusState.Timestamp.Add(time.Minute * time.Duration(12))
67 valset = tendermint.NewValset(val1, val2)
68 nextValset = tendermint.NewValset(val1, val2)
69
70 signatures = []tendermint.CommitSig{
71 {
72 BlockIDFlag: tendermint.BlockIDFlagCommit,
73 ValidatorAddress: valset.Validators[0].Address,
74 Timestamp: commitTimestamp,
75 Signature: []byte("\x5b\xc5\x2d\x89\x50\xb1\x29\xbc\x19\x17\x8f\x8f\x35\xcc\xa8\x28\xa8\xa8\xb5\x88\x6c\x51\x15\x01\x70\x7b\x04\xa3\x5e\xf9\x50\x5d\xfa\x6e\x56\xa4\x54\x72\x70\x04\x14\x6c\x26\x8e\xae\xd5\x95\x33\x51\x18\x3a\x07\x26\x93\x4f\x97\x99\x7d\x28\x84\x4d\xea\x0a\x07"),
76 },
77 {
78 BlockIDFlag: tendermint.BlockIDFlagCommit,
79 ValidatorAddress: valset.Validators[1].Address,
80 Timestamp: commitTimestamp,
81 Signature: []byte("\x02\x55\x68\xb1\x0d\xda\x0a\x17\x3e\xd8\xa7\x23\x1b\x02\x7e\x54\x7a\x17\x35\x79\x13\xc6\x6b\xd8\xcb\xf1\xe8\xb5\xfd\x1a\x38\xea\x0c\x1a\x04\xea\x72\x45\x54\x62\x7c\x9b\xab\xaf\x03\x63\x13\x86\x6c\x54\x56\x83\xd2\x39\x71\x15\xe5\x27\x51\x6a\x3f\x26\x0d\x0a"),
82 },
83 }
84
85 msgHeader = tmtesting.NewMsgHeader(
86 chainID, newTimestamp, apphash, newHeight, trustedHeight, valset,
87 nextValset, trustedValset, signatures,
88 )
89 )
90 core.UpdateClient(cross(cur), clientID, msgHeader)
91
92 // Timeout the packet
93 timeoutPacket := types.MsgTimeout{
94 Packet: types.Packet{
95 Sequence: sequence,
96 SourceClient: clientID,
97 DestinationClient: counterpartyID,
98 TimeoutTimestamp: sendPacket.TimeoutTimestamp,
99 Payloads: sendPacket.Payloads,
100 },
101 ProofUnreceived: []ics23.CommitmentProof{
102 ics23.CommitmentProof_Nonexist{
103 Nonexist: &ics23.NonExistenceProof{},
104 },
105 },
106 ProofHeight: msgHeader.GetHeight(),
107 }
108
109 core.Timeout(cross(cur), timeoutPacket)
110}
111
112// Error:
113// failed packet receipt absence verification for client (07-tendermint-1): length of specs: 2 not equal to length of proof: 1