Search Apps Documentation Source Content File Folder Download Copy Actions Download

z2b_on_ack_packet_filetest.gno

4.47 Kb · 117 lines
  1// PKGPATH: gno.land/r/aib/main
  2package main
  3
  4import (
  5	"chain"
  6	"encoding/hex"
  7	"testing"
  8	"time"
  9
 10	tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
 11	"gno.land/p/aib/ibc/types"
 12	"gno.land/p/aib/ics23"
 13	"gno.land/r/aib/ibc/apps/transfer"
 14	"gno.land/r/aib/ibc/core"
 15)
 16
 17// OnAcknowledgementPacket: cannot pass custom ack error in IBCv2
 18func main(cur realm) {
 19	var (
 20		chainID       = "chain-id-2"
 21		trustedHeight = types.NewHeight(2, 2)
 22		clientState   = tmtesting.NewClientState(chainID, trustedHeight)
 23		// NOTE this apphash was provided by the gen-proof command below.
 24		apphash, _     = hex.DecodeString("fa470da3647704716eab0024c8bcb7530760de45c6cc94c040900a3379c7747c")
 25		trustedValset  = tmtesting.GenValset()
 26		consensusState = tmtesting.GenConsensusState(time.Now(), apphash, trustedValset.Hash())
 27		counterpartyID = "07-tendermint-42"
 28	)
 29	clientID := core.CreateClient(cross(cur), clientState, consensusState)
 30	core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, counterpartyID)
 31
 32	// Transfer the 100ugnot we want to ack
 33	testing.SetRealm(testing.NewUserRealm("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))
 34	testing.SetOriginSend(chain.NewCoins(chain.NewCoin("ugnot", 100)))
 35	println("----------- assert render total_escrow/ugnot before Transfer")
 36	println(transfer.Render("total_escrow/ugnot"))
 37	sendPacket, sequence := transfer.Transfer(cross(cur), clientID, "atone1user", "ugnot", 100, uint64(time.Now().Add(time.Hour).Unix()), "")
 38	println("----------- assert render total_escrow/ugnot after Transfer")
 39	println(transfer.Render("total_escrow/ugnot"))
 40
 41	// Acknowledge the packet
 42	// Generate the proof of acknowledgement written during the RecvPacket of the
 43	// counterparty client.
 44	specs := ics23.IavlSpec()
 45	// NOTE code generated by:
 46	// go run -C ./cmd/gen-proof . 'prefix2' '07-tendermint-42' 'acknowledgement' '{"error":"oups"}'
 47	proof := []ics23.CommitmentProof{
 48
 49		// iavl proof
 50		ics23.CommitmentProof_Exist{
 51			Exist: &ics23.ExistenceProof{
 52				Key:   []byte("\x70\x72\x65\x66\x69\x78\x32\x30\x37\x2d\x74\x65\x6e\x64\x65\x72\x6d\x69\x6e\x74\x2d\x34\x32\x03\x00\x00\x00\x00\x00\x00\x00\x01"),
 53				Value: []byte("\x50\xad\x5e\xb3\xd3\x8f\x27\x0b\x52\xd4\xc9\xbf\x0f\x2d\x2c\xba\xfb\xbf\x33\xb7\x9a\xee\x80\x01\x34\x9d\x09\x14\x1a\xd0\xa3\x53"),
 54				Leaf: &ics23.LeafOp{
 55					Hash:         specs.LeafSpec.Hash,
 56					PrehashKey:   specs.LeafSpec.PrehashKey,
 57					PrehashValue: specs.LeafSpec.PrehashValue,
 58					Length:       specs.LeafSpec.Length,
 59					Prefix:       []byte("\x00\x02\x02"),
 60				},
 61				Path: []*ics23.InnerOp{
 62					{
 63						Hash:   specs.InnerSpec.Hash,
 64						Prefix: []byte("\x02\x04\x02\x20\x35\xf8\xea\x80\x53\x90\xe0\x84\x85\x4f\x39\x9b\x42\xcc\xde\xae\xa3\x3a\x1d\xed\xc1\x15\x63\x8a\xc4\x8d\x06\x00\x63\x7d\xba\x1f\x20"),
 65						Suffix: []byte(""),
 66					},
 67					{
 68						Hash:   specs.InnerSpec.Hash,
 69						Prefix: []byte("\x04\x08\x02\x20"),
 70						Suffix: []byte("\x20\x79\x8e\x2c\xaa\x96\xfd\xfb\xa3\x76\xdd\xeb\x47\x99\x99\x54\xd2\xf4\x7e\x65\x16\x22\x64\xb0\x53\x6a\xb5\xdf\xf7\xfc\x0a\x2e\x07"),
 71					},
 72					{
 73						Hash:   specs.InnerSpec.Hash,
 74						Prefix: []byte("\x06\x0c\x02\x20\x9a\xf3\x7d\xd5\x95\xa0\x19\x08\x03\xb5\xe0\x5a\xae\xf4\x2a\xe3\xfa\xd4\x99\xe4\xfb\xe3\x7f\x7c\xd3\x1c\xad\xff\x22\xa9\xee\x74\x20"),
 75						Suffix: []byte(""),
 76					},
 77				},
 78			},
 79		},
 80
 81		// rootmulti proof
 82		ics23.CommitmentProof_Exist{
 83			Exist: &ics23.ExistenceProof{
 84				Key:   []byte("\x69\x61\x76\x6c\x53\x74\x6f\x72\x65\x4b\x65\x79"),
 85				Value: []byte("\x84\x9a\xa5\x45\x77\x3c\x81\x87\xfc\xb9\x95\x2a\x35\x68\xfa\x9d\x24\xcd\x38\x4e\xcf\x85\x3e\xee\xb9\xdb\xe1\x00\x34\x4c\xcc\x4f"),
 86				Leaf: &ics23.LeafOp{
 87					Hash:         specs.LeafSpec.Hash,
 88					PrehashKey:   specs.LeafSpec.PrehashKey,
 89					PrehashValue: specs.LeafSpec.PrehashValue,
 90					Length:       specs.LeafSpec.Length,
 91					Prefix:       []byte("\x00"),
 92				},
 93				Path: []*ics23.InnerOp{},
 94			},
 95		},
 96	}
 97
 98	ackPacket := types.MsgAcknowledgement{
 99		Packet: types.Packet{
100			Sequence:          sequence,
101			SourceClient:      clientID,
102			DestinationClient: counterpartyID,
103			TimeoutTimestamp:  sendPacket.TimeoutTimestamp,
104			Payloads:          sendPacket.Payloads,
105		},
106		Acknowledgement: types.Acknowledgement{
107			AppAcknowledgements: [][]byte{[]byte(`{"error":"oups"}`)},
108		},
109		ProofAcked:  proof,
110		ProofHeight: trustedHeight,
111	}
112
113	core.Acknowledgement(cross(cur), ackPacket)
114}
115
116// Error:
117// acknowledgement packet failed for payload #0 app "transfer": cannot pass in a custom error acknowledgement with IBC v2