Search Apps Documentation Source Content File Folder Download Copy Actions Download

z2c_on_ack_packet_filetest.gno

4.40 Kb · 115 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: invalid AppAcknowledgements
 18func main(cur realm) {
 19	var (
 20		chainID        = "chain-id-2"
 21		trustedHeight  = types.NewHeight(2, 2)
 22		clientState    = tmtesting.NewClientState(chainID, trustedHeight)
 23		apphash, _     = hex.DecodeString("e0e3b9fff6b7dae2afc0e430b6765483deeb42489187280bf0e8779515a779bb")
 24		trustedValset  = tmtesting.GenValset()
 25		consensusState = tmtesting.GenConsensusState(time.Now(), apphash[:], trustedValset.Hash())
 26		counterpartyID = "07-tendermint-42"
 27	)
 28	clientID := core.CreateClient(cross(cur), clientState, consensusState)
 29	core.RegisterCounterparty(cross(cur), clientID, [][]byte{[]byte("iavlStoreKey"), []byte("prefix2")}, counterpartyID)
 30
 31	// Transfer the 100ugnot we want to ack
 32	testing.SetRealm(testing.NewUserRealm("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"))
 33	testing.SetOriginSend(chain.NewCoins(chain.NewCoin("ugnot", 100)))
 34	println("----------- assert render total_escrow/ugnot before Transfer")
 35	println(transfer.Render("total_escrow/ugnot"))
 36	sendPacket, sequence := transfer.Transfer(cross(cur), clientID, "atone1user", "ugnot", 100, uint64(time.Now().Add(time.Hour).Unix()), "")
 37	println("----------- assert render total_escrow/ugnot after Transfer")
 38	println(transfer.Render("total_escrow/ugnot"))
 39
 40	// Acknowledge the packet
 41	specs := ics23.IavlSpec()
 42	// Generate the proof of acknowledgement written during the RecvPacket of the
 43	// counterparty client.
 44	// NOTE proof generated by ./cmd/gen-proof 'prefix2' '07-tendermint-42' 'acknowledgement' 'not json'
 45	proofAcked := []ics23.CommitmentProof{
 46
 47		// iavl proof
 48		ics23.CommitmentProof_Exist{
 49			Exist: &ics23.ExistenceProof{
 50				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"),
 51				Value: []byte("\x6a\x1b\x58\x87\x05\x25\xf5\x0a\x67\xe0\xf0\x59\x58\x70\x50\x5a\x1e\x82\x07\xac\xfb\xfe\x5f\xe7\xf6\x40\x45\x13\xa3\x57\xd3\xc3"),
 52				Leaf: &ics23.LeafOp{
 53					Hash:         specs.LeafSpec.Hash,
 54					PrehashKey:   specs.LeafSpec.PrehashKey,
 55					PrehashValue: specs.LeafSpec.PrehashValue,
 56					Length:       specs.LeafSpec.Length,
 57					Prefix:       []byte("\x00\x02\x02"),
 58				},
 59				Path: []*ics23.InnerOp{
 60					{
 61						Hash:   specs.InnerSpec.Hash,
 62						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"),
 63						Suffix: []byte(""),
 64					},
 65					{
 66						Hash:   specs.InnerSpec.Hash,
 67						Prefix: []byte("\x04\x08\x02\x20"),
 68						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"),
 69					},
 70					{
 71						Hash:   specs.InnerSpec.Hash,
 72						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"),
 73						Suffix: []byte(""),
 74					},
 75				},
 76			},
 77		},
 78
 79		// rootmulti proof
 80		ics23.CommitmentProof_Exist{
 81			Exist: &ics23.ExistenceProof{
 82				Key:   []byte("\x69\x61\x76\x6c\x53\x74\x6f\x72\x65\x4b\x65\x79"),
 83				Value: []byte("\x87\x64\x71\x03\x02\xf7\x2c\xad\x01\x9e\x20\x71\xeb\xf2\x56\xc4\xeb\xe6\xe6\x9e\xba\xb5\xb2\x9e\xe1\xaf\x39\x51\xca\x17\x01\xd7"),
 84				Leaf: &ics23.LeafOp{
 85					Hash:         specs.LeafSpec.Hash,
 86					PrehashKey:   specs.LeafSpec.PrehashKey,
 87					PrehashValue: specs.LeafSpec.PrehashValue,
 88					Length:       specs.LeafSpec.Length,
 89					Prefix:       []byte("\x00"),
 90				},
 91				Path: []*ics23.InnerOp{},
 92			},
 93		},
 94	}
 95
 96	ackPacket := types.MsgAcknowledgement{
 97		Packet: types.Packet{
 98			Sequence:          sequence,
 99			SourceClient:      clientID,
100			DestinationClient: counterpartyID,
101			TimeoutTimestamp:  sendPacket.TimeoutTimestamp,
102			Payloads:          sendPacket.Payloads,
103		},
104		Acknowledgement: types.Acknowledgement{
105			AppAcknowledgements: [][]byte{[]byte(`not json`)},
106		},
107		ProofAcked:  proofAcked,
108		ProofHeight: trustedHeight,
109	}
110
111	core.Acknowledgement(cross(cur), ackPacket)
112}
113
114// Error:
115// acknowledgement packet failed for payload #0 app "transfer": cannot unmarshal ICS-20 transfer packet acknowledgement: invalid token