From 2554144827184aad91450a70bae57aaf290344b2 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Wed, 6 Sep 2023 18:44:31 +0900 Subject: [PATCH] refactor Signed-off-by: Naohiro Yoshida --- .../testdata/internal/create_update_client.go | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/tool/testdata/internal/create_update_client.go b/tool/testdata/internal/create_update_client.go index 82352eb..bc0316b 100644 --- a/tool/testdata/internal/create_update_client.go +++ b/tool/testdata/internal/create_update_client.go @@ -8,6 +8,7 @@ import ( "github.com/datachainlab/ibc-parlia-relay/module/constant" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/rlp" "github.com/hyperledger-labs/yui-relayer/core" "github.com/spf13/cobra" "log" @@ -67,6 +68,41 @@ func updateClientErrorCmd() *cobra.Command { Use: "error", Short: "create updateClient testdata for error", RunE: func(cmd *cobra.Command, args []string) error { + prover, chain, err := createMainnetProver() + if err != nil { + return err + } + latest, err := chain.LatestHeight() + if err != nil { + return err + } + header, err := prover.GetLatestFinalizedHeaderByLatestHeight(latest.GetRevisionHeight()) + if err != nil { + return err + } + target, err := header.(*module.Header).DecodedTarget() + if err != nil { + return err + } + updating, _ := prover.SetupHeadersForUpdateByLatestHeight(types.NewHeight(header.GetHeight().GetRevisionNumber(), target.Number.Uint64()-1), header.(*module.Header)) + target.Root = common.Hash{} + rlpTarget, err := rlp.EncodeToBytes(target) + updating[0].(*module.Header).Target = &module.ETHHeader{Header: rlpTarget} + pack, err := types.PackClientMessage(updating[0]) + if err != nil { + return err + } + marshal, err := pack.Marshal() + if err != nil { + return err + } + log.Println("header", common.Bytes2Hex(marshal)) + log.Println("height", header.GetHeight().GetRevisionHeight()) + log.Println("trustedHeight", header.(*module.Header).TrustedHeight.GetRevisionHeight()) + epochCount := header.GetHeight().GetRevisionHeight() / constant.BlocksPerEpoch + log.Println("currentEpochHeight", epochCount*constant.BlocksPerEpoch) + log.Println("targetValidatorHash", common.Bytes2Hex(crypto.Keccak256(header.(*module.Header).TargetValidators...))) + log.Println("targetValidatorSize", len(header.(*module.Header).TargetValidators)) return nil }, } @@ -114,8 +150,8 @@ func printMainnetHeader(prover *module.Prover, height uint64) error { log.Println("currentEpochHeight", epochCount*constant.BlocksPerEpoch) // validators hash - log.Println("target_validator_size", len(header.TargetValidators)) - log.Println("target_validator_hash", common.Bytes2Hex(crypto.Keccak256(header.TargetValidators...))) + log.Println("targetValidatorSize", len(header.TargetValidators)) + log.Println("targetValidatorHash", common.Bytes2Hex(crypto.Keccak256(header.TargetValidators...))) if target.Number.Uint64()%constant.BlocksPerEpoch == 0 { newValidators, err := module.ExtractValidatorSet(target) if err != nil { @@ -124,8 +160,8 @@ func printMainnetHeader(prover *module.Prover, height uint64) error { if len(newValidators) != MainNetValidatorSize { return fmt.Errorf("invalid validator size for test") } - log.Println("new_validator_hash", common.Bytes2Hex(crypto.Keccak256(newValidators...))) - log.Println("new_validator_size", len(newValidators)) + log.Println("newValidatorHash", common.Bytes2Hex(crypto.Keccak256(newValidators...))) + log.Println("newValidatorSize", len(newValidators)) } return nil }