Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Naohiro Yoshida <[email protected]>
  • Loading branch information
Naohiro Yoshida committed Sep 6, 2023
1 parent 4f7f8a9 commit 2554144
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions tool/testdata/internal/create_update_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
},
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 2554144

Please sign in to comment.