Search Apps Documentation Source Content File Folder Download Copy Actions Download

z7d_recv_packet_filetest.gno

1.59 Kb · 59 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	"gno.land/r/aib/ibc/core"
12)
13
14// RecvPacket fails client not active
15func main(cur realm) {
16	var (
17		chainID        = "chain-id-2"
18		trustedHeight  = types.NewHeight(2, 2)
19		clientState    = tmtesting.NewClientState(chainID, trustedHeight)
20		apphash        = tmtesting.Hash("apphash")
21		trustedValset  = tmtesting.GenValset()
22		consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
23	)
24	clientID := core.CreateClient(cross(cur), clientState, consensusState)
25	core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, "07-tendermint-2")
26
27	// Change block time to expire the lightclient
28	ctx := testing.GetContext()
29	ctx.Time = time.Now().Add(clientState.TrustingPeriod)
30	testing.SetContext(ctx)
31
32	// Receive the packet
33	recvPacket := types.MsgRecvPacket{
34		Packet: types.Packet{
35			Sequence:          1,
36			SourceClient:      "source",
37			DestinationClient: clientID,
38			TimeoutTimestamp:  1,
39			Payloads: []types.Payload{{
40				SourcePort:      "appID",
41				DestinationPort: "destinationPort",
42				Encoding:        "application/json",
43				Value:           []byte("{}"),
44				Version:         "v1",
45			}},
46		},
47		ProofCommitment: []ics23.CommitmentProof{
48			ics23.CommitmentProof_Exist{
49				Exist: &ics23.ExistenceProof{},
50			},
51		},
52		ProofHeight: trustedHeight,
53	}
54
55	core.RecvPacket(cross(cur), recvPacket)
56}
57
58// Error:
59// client (07-tendermint-1) status is Expired