Search Apps Documentation Source Content File Folder Download Copy Actions Download

z6d_timeout_filetest.gno

2.05 Kb · 74 lines
 1// PKGPATH: gno.land/r/aib/main
 2package main
 3
 4import (
 5	"testing"
 6	"time"
 7
 8	tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
 9	"gno.land/p/aib/ibc/types"
10	"gno.land/p/aib/ics23"
11	appstesting "gno.land/r/aib/ibc/apps/testing"
12	"gno.land/r/aib/ibc/core"
13)
14
15// Timeout client expired
16func main(cur realm) {
17	var (
18		chainID        = "chain-id-2"
19		trustedHeight  = types.NewHeight(2, 2)
20		clientState    = tmtesting.NewClientState(chainID, trustedHeight)
21		apphash        = tmtesting.Hash("apphash")
22		trustedValset  = tmtesting.GenValset()
23		consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
24		counterpartyID = "07-tendermint-42"
25	)
26	clientID := core.CreateClient(cross(cur), clientState, consensusState)
27	core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, counterpartyID)
28	// Register app
29	var (
30		app       = appstesting.NewApp(cross(cur))
31		appPortID = "app"
32	)
33	core.RegisterApp(cross(cur), appPortID, app)
34	// Send a packet
35	sendPacket := types.MsgSendPacket{
36		SourceClient:     clientID,
37		TimeoutTimestamp: uint64(time.Now().Add(time.Hour).Unix()),
38		Payloads: []types.Payload{{
39			SourcePort:      appPortID,
40			DestinationPort: "destinationPort",
41			Encoding:        "application/json",
42			Value:           []byte("{}"),
43			Version:         "v1",
44		}},
45	}
46	sequence := core.SendPacket(cross(cur), sendPacket)
47
48	// Change block time to expire the lightclient
49	ctx := testing.GetContext()
50	ctx.Time = time.Now().Add(clientState.TrustingPeriod)
51	testing.SetContext(ctx)
52
53	// Timeout the packet
54	timeoutPacket := types.MsgTimeout{
55		Packet: types.Packet{
56			Sequence:          sequence,
57			SourceClient:      clientID,
58			DestinationClient: counterpartyID,
59			TimeoutTimestamp:  1,
60			Payloads:          sendPacket.Payloads,
61		},
62		ProofUnreceived: []ics23.CommitmentProof{
63			ics23.CommitmentProof_Nonexist{
64				Nonexist: &ics23.NonExistenceProof{},
65			},
66		},
67		ProofHeight: trustedHeight,
68	}
69
70	core.Timeout(cross(cur), timeoutPacket)
71}
72
73// Error:
74// client (07-tendermint-1) status is Expired