Search Apps Documentation Source Content File Folder Download Copy Actions Download

z3i_send_packet_filetest.gno

1.48 Kb · 51 lines
 1// PKGPATH: gno.land/r/aib/main
 2package main
 3
 4import (
 5	"errors"
 6	"time"
 7
 8	tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
 9	"gno.land/p/aib/ibc/types"
10	appstesting "gno.land/r/aib/ibc/apps/testing"
11	"gno.land/r/aib/ibc/core"
12)
13
14// SendPacket fails app returns an error
15func main(cur realm) {
16	var (
17		chainID        = "chain-id-2"
18		clientState    = tmtesting.NewClientState(chainID, types.NewHeight(2, 2))
19		apphash        = tmtesting.Hash("apphash")
20		trustedValset  = tmtesting.GenValset()
21		consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
22	)
23	clientID := core.CreateClient(cross(cur), clientState, consensusState)
24	core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, "07-tendermint-2")
25
26	println("next sequence:", core.Render("clients/"+clientID+"/next_sequence_send"))
27	// Register app
28	var (
29		app       = appstesting.NewApp(cross(cur))
30		appPortID = "app1"
31	)
32	app.SetOnSendPacketReturn(errors.New("app error"))
33	core.RegisterApp(cross(cur), appPortID, app)
34
35	packet := 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
47	core.SendPacket(cross(cur), packet)
48}
49
50// Error:
51// send packet failed for payload #0 app "app1": app error