From 8c95b0ec9c638292f8611ecb1714a5570b46138f Mon Sep 17 00:00:00 2001 From: marcello33 Date: Wed, 13 Nov 2024 14:54:52 +0100 Subject: [PATCH] cgh: fix rpc blockNumber and bash warnings --- helper/call.go | 22 +++++++++++++++++++++- integration-tests/bor_health.sh | 4 ++-- integration-tests/smoke_test.sh | 14 +++++++------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/helper/call.go b/helper/call.go index 4f1a84a66..2acbf72c1 100644 --- a/helper/call.go +++ b/helper/call.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "github.com/ethereum/go-ethereum/common/hexutil" "math/big" "strings" "time" @@ -465,7 +466,11 @@ func (c *ContractCaller) GetMaticChainBlock(blockNum *big.Int) (header *ethTypes var latestBlock *ethTypes.Header if c.MaticGrpcFlag { - latestBlock, err = c.MaticGrpcClient.HeaderByNumber(ctx, blockNum.Uint64()) + if blockNum == nil { + latestBlock, err = c.MaticGrpcClient.HeaderByNumber(ctx, uint64(rpc.LatestBlockNumber.Int64())) + } else { + latestBlock, err = c.MaticGrpcClient.HeaderByNumber(ctx, blockNum.Uint64()) + } } else { latestBlock, err = c.MaticChainClient.HeaderByNumber(ctx, blockNum) } @@ -1016,3 +1021,18 @@ func chooseContractCallerABI(contractCallerObj *ContractCaller, abi string) (*ab func getABI(data string) (abi.ABI, error) { return abi.JSON(strings.NewReader(data)) } + +func toBlockNumArg(number *big.Int) string { + if number == nil { + return "latest" + } + if number.Sign() >= 0 { + return hexutil.EncodeBig(number) + } + // It's negative. + if number.IsInt64() { + return rpc.BlockNumber(number.Int64()).String() + } + // It's negative and large, which is invalid. + return fmt.Sprintf("", number) +} diff --git a/integration-tests/bor_health.sh b/integration-tests/bor_health.sh index 0791d415f..469992098 100644 --- a/integration-tests/bor_health.sh +++ b/integration-tests/bor_health.sh @@ -11,5 +11,5 @@ do fi done -echo $peers -echo $block +echo "$peers" +echo "$block" diff --git a/integration-tests/smoke_test.sh b/integration-tests/smoke_test.sh index 4541ec5d4..f5354ffde 100644 --- a/integration-tests/smoke_test.sh +++ b/integration-tests/smoke_test.sh @@ -18,8 +18,8 @@ do exit 1 fi - if (( $balance > $balanceInit )); then - if [ $stateSyncFound != "true" ]; then + if (( balance > balanceInit )); then + if [ "$stateSyncFound" != "true" ]; then stateSyncTime=$(( SECONDS - start_time )) stateSyncFound="true" fi @@ -27,18 +27,18 @@ do checkpointID=$(curl -sL http://localhost:1317/checkpoints/latest | jq .result.id) - if [ $checkpointID != "null" ]; then - if [ $checkpointFound != "true" ]; then + if [ "$checkpointID" != "null" ]; then + if [ "$checkpointFound" != "true" ]; then checkpointTime=$(( SECONDS - start_time )) checkpointFound="true" fi fi - if [ $stateSyncFound == "true" ] && [ $checkpointFound == "true" ]; then + if [ "$stateSyncFound" == "true" ] && [ "$checkpointFound" == "true" ]; then break fi done echo "Both state sync and checkpoint went through. All tests have passed!" -echo "Time taken for state sync: $(printf '%02dm:%02ds\n' $(($stateSyncTime%3600/60)) $(($stateSyncTime%60)))" -echo "Time taken for checkpoint: $(printf '%02dm:%02ds\n' $(($checkpointTime%3600/60)) $(($checkpointTime%60)))" +echo "Time taken for state sync: $(printf '%02dm:%02ds\n' $((stateSyncTime%3600/60)) $((stateSyncTime%60)))" +echo "Time taken for checkpoint: $(printf '%02dm:%02ds\n' $((checkpointTime%3600/60)) $((checkpointTime%60)))"