Search Apps Documentation Source Content File Folder Download Copy Actions Download

zz_update_client_example_filetest.gno

4.11 Kb · 120 lines
  1// PKGPATH: gno.land/r/aib/main
  2package main
  3
  4import (
  5	"time"
  6
  7	"gno.land/p/aib/ibc/lightclient/tendermint"
  8	tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing"
  9	"gno.land/p/aib/ibc/types"
 10	"gno.land/r/aib/ibc/core"
 11)
 12
 13func main(cur realm) {
 14	var (
 15		clientID  = "07-tendermint-1"         // XXX update
 16		chainID   = "chain-id-2"              // XXX update
 17		timestamp = time.Now()                // XXX update
 18		height    = types.Height{2, 5}        // XXX update
 19		valset    = &tendermint.ValidatorSet{ // XXX update
 20			Validators: []*tendermint.Validator{
 21				{
 22					Address:     tmtesting.GenAddr("val1"),
 23					PubKey:      tmtesting.GenPubkey("val1_pubkey"),
 24					VotingPower: 2,
 25				},
 26				{
 27					Address:     tmtesting.GenAddr("val2"),
 28					PubKey:      tmtesting.GenPubkey("val2_pubkey"),
 29					VotingPower: 3,
 30				},
 31			},
 32			Proposer: &tendermint.Validator{
 33				Address:     tmtesting.GenAddr("val1"),
 34				PubKey:      tmtesting.GenPubkey("val1_pubkey"),
 35				VotingPower: 2,
 36			},
 37			TotalVotingPower: 5,
 38		}
 39		trustedHeight = types.Height{2, 2}        // XXX update
 40		trustedValset = &tendermint.ValidatorSet{ // XXX update
 41			Validators: []*tendermint.Validator{
 42				{
 43					Address:     tmtesting.GenAddr("val1"),
 44					PubKey:      tmtesting.GenPubkey("val1_pubkey"),
 45					VotingPower: 2,
 46				},
 47				{
 48					Address:     tmtesting.GenAddr("val2"),
 49					PubKey:      tmtesting.GenPubkey("val2_pubkey"),
 50					VotingPower: 3,
 51				},
 52			},
 53			Proposer: &tendermint.Validator{
 54				Address:     tmtesting.GenAddr("val1"),
 55				PubKey:      tmtesting.GenPubkey("val1_pubkey"),
 56				VotingPower: 2,
 57			},
 58			TotalVotingPower: 5,
 59		}
 60		msgHeader = &tendermint.MsgHeader{
 61			Header: &tendermint.Header{
 62				Version: tendermint.Consensus{
 63					Block: tendermint.BlockProtocol,
 64					App:   1, //NOTE no idea what to put there, sounds unused
 65				},
 66				ChainID: chainID,
 67				Height:  height.RevisionHeight,
 68				Time:    timestamp,
 69				LastBlockID: tendermint.BlockID{
 70					Hash: tmtesting.Hash("last_block_hash"),
 71					PartSetHeader: tendermint.PartSetHeader{
 72						Total: 2,
 73						Hash:  tmtesting.Hash("last_block_partset_header_hash"),
 74					},
 75				},
 76				LastCommitHash:     tmtesting.Hash("last_commit_hash"), //XXX update
 77				DataHash:           tmtesting.Hash("data_hash"),        //XXX update
 78				ValidatorsHash:     valset.Hash(),
 79				NextValidatorsHash: valset.Hash(),
 80				ConsensusHash:      tmtesting.Hash("consensus_hash"),    // XXX update
 81				AppHash:            tmtesting.Hash("app_hash"),          // XXX update
 82				LastResultsHash:    tmtesting.Hash("last_results_hash"), //XXX update
 83				EvidenceHash:       tmtesting.Hash("evidence_hash"),     //XXX update
 84				ProposerAddress:    tmtesting.GenAddr("proposer"),       // XXX update
 85			},
 86			Commit: &tendermint.Commit{
 87				Height: height.RevisionHeight,
 88				Round:  1,
 89				BlockID: tendermint.BlockID{
 90					Hash: tmtesting.Hash("last_block_partset_header_hash"), //XXX update
 91					PartSetHeader: tendermint.PartSetHeader{
 92						Total: 5,
 93						Hash:  tmtesting.Hash("last_block_partset_header_hash"), //XXX update
 94					},
 95				},
 96				Signatures: []tendermint.CommitSig{
 97					{
 98						BlockIDFlag:      tendermint.BlockIDFlagCommit,
 99						ValidatorAddress: tmtesting.GenAddr("val1"),                          // XXX update
100						Signature:        tmtesting.GenSignature("valsign1"),                 // XXX update
101						Timestamp:        tmtesting.ToTime("2025-09-25T07:55:57.306746166Z"), //XXX update
102					},
103					{
104						BlockIDFlag:      tendermint.BlockIDFlagCommit,
105						ValidatorAddress: tmtesting.GenAddr("val2"),                          // XXX update
106						Signature:        tmtesting.GenSignature("valsign2"),                 // XXX update
107						Timestamp:        tmtesting.ToTime("2025-09-25T07:55:57.306746166Z"), //XXX update
108					},
109				},
110			},
111			ValidatorSet:      valset,
112			TrustedHeight:     trustedHeight,
113			TrustedValidators: trustedValset,
114		}
115	)
116	core.UpdateClient(cross(cur), clientID, msgHeader)
117}
118
119// Error:
120// expected BlockID#Hash and Header#Hash to be the same, got "b40edd05fbc1dba702520fbf71142c39ebe97400a1806a842a7c54f6d97fb519" != "fb33f6107d92ab1b8e8d3b2ad622f64a06bff39d10f2cb7257b3cc327fa7107e"