Search Apps Documentation Source Content File Folder Download Copy Actions Download

z5d_acknowledgement_filetest.gno

2.15 Kb · 77 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// Acknowledgement status not active
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	// Acknowledge the packet
54	ackPacket := types.MsgAcknowledgement{
55		Packet: types.Packet{
56			Sequence:          sequence,
57			SourceClient:      clientID,
58			DestinationClient: counterpartyID,
59			TimeoutTimestamp:  1,
60			Payloads:          sendPacket.Payloads,
61		},
62		Acknowledgement: types.Acknowledgement{
63			AppAcknowledgements: [][]byte{[]byte("ack")},
64		},
65		ProofAcked: []ics23.CommitmentProof{
66			ics23.CommitmentProof_Exist{
67				Exist: &ics23.ExistenceProof{},
68			},
69		},
70		ProofHeight: trustedHeight,
71	}
72
73	core.Acknowledgement(cross(cur), ackPacket)
74}
75
76// Error:
77// client (07-tendermint-1) status is Expired