Skip to content

Commit

Permalink
all: replace t.Log(); t.FailNow() with t.Fatal() (ethereum#19849)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Jan 4, 2025
1 parent 33b2a9c commit 14ad750
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 39 deletions.
23 changes: 8 additions & 15 deletions accounts/abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"log"
"math/big"
"reflect"
"strings"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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]
Expand All @@ -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) {
Expand All @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions consensus/tests/engine_v2_tests/forensics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package engine_v2_tests
import (
"crypto/ecdsa"
"encoding/json"
"errors"
"math/big"
"testing"
"time"
Expand All @@ -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")

Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
3 changes: 1 addition & 2 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 4 additions & 8 deletions core/txpool/lending_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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%
Expand All @@ -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)
Expand Down
14 changes: 5 additions & 9 deletions core/types/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
}
}

Expand Down

0 comments on commit 14ad750

Please sign in to comment.