From b4f0e6e33ffeaf6c0da26d2b3ff3cbef46182ae0 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Mon, 6 Jan 2025 09:12:27 +0800 Subject: [PATCH] all: replace t.Log(); t.FailNow() with t.Fatal() (#19849) --- accounts/abi/abi_test.go | 23 +++++++------------ .../tests/engine_v2_tests/forensics_test.go | 13 +++++++---- core/blockchain_test.go | 3 +-- core/txpool/lending_pool_test.go | 12 ++++------ core/types/transaction_test.go | 14 ++++------- 5 files changed, 26 insertions(+), 39 deletions(-) diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index 52d73992eb647..efdfc03645f42 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -21,7 +21,6 @@ import ( "encoding/hex" "errors" "fmt" - "log" "math/big" "reflect" "strings" @@ -105,8 +104,7 @@ func TestReader(t *testing.T) { func TestTestNumbers(t *testing.T) { abi, err := JSON(strings.NewReader(jsondata2)) if err != nil { - t.Error(err) - t.FailNow() + t.Fatal(err) } if _, err := abi.Pack("balance"); err != nil { @@ -143,8 +141,7 @@ func TestTestNumbers(t *testing.T) { func TestTestString(t *testing.T) { abi, err := JSON(strings.NewReader(jsondata2)) if err != nil { - t.Error(err) - t.FailNow() + t.Fatal(err) } if _, err := abi.Pack("string", "hello world"); err != nil { @@ -155,8 +152,7 @@ func TestTestString(t *testing.T) { func TestTestBool(t *testing.T) { abi, err := JSON(strings.NewReader(jsondata2)) if err != nil { - t.Error(err) - t.FailNow() + t.Fatal(err) } if _, err := abi.Pack("bool", true); err != nil { @@ -167,8 +163,7 @@ func TestTestBool(t *testing.T) { func TestTestSlice(t *testing.T) { abi, err := JSON(strings.NewReader(jsondata2)) if err != nil { - t.Error(err) - t.FailNow() + t.Fatal(err) } slice := make([]uint64, 2) @@ -224,8 +219,7 @@ func TestMethodSignature(t *testing.T) { func TestMultiPack(t *testing.T) { abi, err := JSON(strings.NewReader(jsondata2)) if err != nil { - t.Error(err) - t.FailNow() + t.Fatal(err) } sig := crypto.Keccak256([]byte("bar(uint32,uint16)"))[:4] @@ -235,8 +229,7 @@ func TestMultiPack(t *testing.T) { packed, err := abi.Pack("bar", uint32(10), uint16(11)) if err != nil { - t.Error(err) - t.FailNow() + t.Fatal(err) } if !bytes.Equal(packed, sig) { @@ -249,11 +242,11 @@ func ExampleJSON() { abi, err := JSON(strings.NewReader(definition)) if err != nil { - log.Fatalln(err) + panic(err) } out, err := abi.Pack("isBar", common.HexToAddress("01")) if err != nil { - log.Fatalln(err) + panic(err) } fmt.Printf("%x\n", out) diff --git a/consensus/tests/engine_v2_tests/forensics_test.go b/consensus/tests/engine_v2_tests/forensics_test.go index dd9ad913db018..a5a77d93eb70a 100644 --- a/consensus/tests/engine_v2_tests/forensics_test.go +++ b/consensus/tests/engine_v2_tests/forensics_test.go @@ -3,6 +3,7 @@ package engine_v2_tests import ( "crypto/ecdsa" "encoding/json" + "errors" "math/big" "testing" "time" @@ -16,6 +17,8 @@ import ( "github.com/stretchr/testify/assert" ) +var errTimeoutAfter5Seconds = errors.New("timeout after 5 seconds") + func TestProcessQcShallSetForensicsCommittedQc(t *testing.T) { t.Skip("Skipping this test for now as we disable forensics") @@ -200,7 +203,7 @@ func TestForensicsMonitoringNotOnSameChainButHaveSameRoundQC(t *testing.T) { assert.Equal(t, 5, len(content.LargerRoundInfo.SignerAddresses)) return case <-time.After(5 * time.Second): - t.FailNow() + t.Fatal(errTimeoutAfter5Seconds) } } } @@ -262,7 +265,7 @@ func TestForensicsMonitoringNotOnSameChainDoNotHaveSameRoundQC(t *testing.T) { assert.Equal(t, 2, len(content.LargerRoundInfo.SignerAddresses)) return case <-time.After(5 * time.Second): - t.FailNow() + t.Fatal(errTimeoutAfter5Seconds) } } } @@ -327,7 +330,7 @@ func TestForensicsAcrossEpoch(t *testing.T) { assert.Equal(t, 2, len(content.LargerRoundInfo.SignerAddresses)) return case <-time.After(5 * time.Second): - t.FailNow() + t.Fatal(errTimeoutAfter5Seconds) } } } @@ -395,7 +398,7 @@ func TestVoteEquivocationSameRound(t *testing.T) { assert.Equal(t, types.Round(5), content.LargerRoundVote.ProposedBlockInfo.Round) return case <-time.After(5 * time.Second): - t.FailNow() + t.Fatal(errTimeoutAfter5Seconds) } } } @@ -452,7 +455,7 @@ func TestVoteEquivocationDifferentRound(t *testing.T) { assert.Equal(t, acc1Addr, content.Signer) return case <-time.After(5 * time.Second): - t.FailNow() + t.Fatal(errTimeoutAfter5Seconds) } } } diff --git a/core/blockchain_test.go b/core/blockchain_test.go index ae6217b29b047..b61cfb88b1dcb 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -157,8 +157,7 @@ func testHeaderChainImport(chain []*types.Header, blockchain *BlockChain) error func insertChain(done chan bool, blockchain *BlockChain, chain types.Blocks, t *testing.T) { _, err := blockchain.InsertChain(chain) if err != nil { - fmt.Println(err) - t.FailNow() + t.Fatal(err) } done <- true } diff --git a/core/txpool/lending_pool_test.go b/core/txpool/lending_pool_test.go index ceb6970b7ade6..fff43d190c704 100644 --- a/core/txpool/lending_pool_test.go +++ b/core/txpool/lending_pool_test.go @@ -177,8 +177,7 @@ func TestSendLending(t *testing.T) { } nonce, err := getLendingNonce(crypto.PubkeyToAddress(privateKey.PublicKey)) if err != nil { - t.Error("fail to get nonce") - t.FailNow() + t.Fatal("fail to get nonce") } for { @@ -249,8 +248,7 @@ func TestCancelLending(t *testing.T) { } nonce, err := getLendingNonce(crypto.PubkeyToAddress(privateKey.PublicKey)) if err != nil { - t.Error("fail to get nonce") - t.FailNow() + t.Fatal("fail to get nonce") } // 10% @@ -272,16 +270,14 @@ func TestRecallLending(t *testing.T) { } nonce, err := getLendingNonce(crypto.PubkeyToAddress(privateKey.PublicKey)) if err != nil { - t.Error("fail to get nonce") - t.FailNow() + t.Fatal("fail to get nonce") } interestRate := 10 * common.BaseLendingInterest.Uint64() testSendLending(key, nonce, USDAddress, common.Address{}, new(big.Int).Mul(_1E8, big.NewInt(1000)), interestRate, lendingstate.Investing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "") time.Sleep(2 * time.Second) nonce, err = getLendingNonce(crypto.PubkeyToAddress(privateKey.PublicKey)) if err != nil { - t.Error("fail to get nonce") - t.FailNow() + t.Fatal("fail to get nonce") } testSendLending(key, nonce, USDAddress, common.XDCNativeAddressBinary, new(big.Int).Mul(_1E8, big.NewInt(1000)), interestRate, lendingstate.Borrowing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "") time.Sleep(2 * time.Second) diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go index e43e55f79bec6..e0d46bd8d6525 100644 --- a/core/types/transaction_test.go +++ b/core/types/transaction_test.go @@ -230,14 +230,12 @@ func TestRecipientEmpty(t *testing.T) { _, addr := defaultTestKey() tx, err := decodeTx(common.Hex2Bytes("f8498080808080011ca09b16de9d5bdee2cf56c28d16275a4da68cd30273e2525f3959f5d62557489921a0372ebd8fb3345f7db7b5a86d42e24d36e983e259b0664ceb8c227ec9af572f3d")) if err != nil { - t.Error(err) - t.FailNow() + t.Fatal(err) } from, err := Sender(HomesteadSigner{}, tx) if err != nil { - t.Error(err) - t.FailNow() + t.Fatal(err) } if addr != from { t.Error("derived address doesn't match") @@ -249,18 +247,16 @@ func TestRecipientNormal(t *testing.T) { tx, err := decodeTx(common.Hex2Bytes("f85d80808094000000000000000000000000000000000000000080011ca0527c0d8f5c63f7b9f41324a7c8a563ee1190bcbf0dac8ab446291bdbf32f5c79a0552c4ef0a09a04395074dab9ed34d3fbfb843c2f2546cc30fe89ec143ca94ca6")) if err != nil { - t.Error(err) - t.FailNow() + t.Fatal(err) } from, err := Sender(HomesteadSigner{}, tx) if err != nil { - t.Error(err) - t.FailNow() + t.Fatal(err) } if addr != from { - t.Error("derived address doesn't match") + t.Fatal("derived address doesn't match") } }