Skip to content

Commit b4f0e6e

Browse files
committed
all: replace t.Log(); t.FailNow() with t.Fatal() (ethereum#19849)
1 parent fd10210 commit b4f0e6e

File tree

5 files changed

+26
-39
lines changed

5 files changed

+26
-39
lines changed

accounts/abi/abi_test.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"encoding/hex"
2222
"errors"
2323
"fmt"
24-
"log"
2524
"math/big"
2625
"reflect"
2726
"strings"
@@ -105,8 +104,7 @@ func TestReader(t *testing.T) {
105104
func TestTestNumbers(t *testing.T) {
106105
abi, err := JSON(strings.NewReader(jsondata2))
107106
if err != nil {
108-
t.Error(err)
109-
t.FailNow()
107+
t.Fatal(err)
110108
}
111109

112110
if _, err := abi.Pack("balance"); err != nil {
@@ -143,8 +141,7 @@ func TestTestNumbers(t *testing.T) {
143141
func TestTestString(t *testing.T) {
144142
abi, err := JSON(strings.NewReader(jsondata2))
145143
if err != nil {
146-
t.Error(err)
147-
t.FailNow()
144+
t.Fatal(err)
148145
}
149146

150147
if _, err := abi.Pack("string", "hello world"); err != nil {
@@ -155,8 +152,7 @@ func TestTestString(t *testing.T) {
155152
func TestTestBool(t *testing.T) {
156153
abi, err := JSON(strings.NewReader(jsondata2))
157154
if err != nil {
158-
t.Error(err)
159-
t.FailNow()
155+
t.Fatal(err)
160156
}
161157

162158
if _, err := abi.Pack("bool", true); err != nil {
@@ -167,8 +163,7 @@ func TestTestBool(t *testing.T) {
167163
func TestTestSlice(t *testing.T) {
168164
abi, err := JSON(strings.NewReader(jsondata2))
169165
if err != nil {
170-
t.Error(err)
171-
t.FailNow()
166+
t.Fatal(err)
172167
}
173168

174169
slice := make([]uint64, 2)
@@ -224,8 +219,7 @@ func TestMethodSignature(t *testing.T) {
224219
func TestMultiPack(t *testing.T) {
225220
abi, err := JSON(strings.NewReader(jsondata2))
226221
if err != nil {
227-
t.Error(err)
228-
t.FailNow()
222+
t.Fatal(err)
229223
}
230224

231225
sig := crypto.Keccak256([]byte("bar(uint32,uint16)"))[:4]
@@ -235,8 +229,7 @@ func TestMultiPack(t *testing.T) {
235229

236230
packed, err := abi.Pack("bar", uint32(10), uint16(11))
237231
if err != nil {
238-
t.Error(err)
239-
t.FailNow()
232+
t.Fatal(err)
240233
}
241234

242235
if !bytes.Equal(packed, sig) {
@@ -249,11 +242,11 @@ func ExampleJSON() {
249242

250243
abi, err := JSON(strings.NewReader(definition))
251244
if err != nil {
252-
log.Fatalln(err)
245+
panic(err)
253246
}
254247
out, err := abi.Pack("isBar", common.HexToAddress("01"))
255248
if err != nil {
256-
log.Fatalln(err)
249+
panic(err)
257250
}
258251

259252
fmt.Printf("%x\n", out)

consensus/tests/engine_v2_tests/forensics_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package engine_v2_tests
33
import (
44
"crypto/ecdsa"
55
"encoding/json"
6+
"errors"
67
"math/big"
78
"testing"
89
"time"
@@ -16,6 +17,8 @@ import (
1617
"github.com/stretchr/testify/assert"
1718
)
1819

20+
var errTimeoutAfter5Seconds = errors.New("timeout after 5 seconds")
21+
1922
func TestProcessQcShallSetForensicsCommittedQc(t *testing.T) {
2023
t.Skip("Skipping this test for now as we disable forensics")
2124

@@ -200,7 +203,7 @@ func TestForensicsMonitoringNotOnSameChainButHaveSameRoundQC(t *testing.T) {
200203
assert.Equal(t, 5, len(content.LargerRoundInfo.SignerAddresses))
201204
return
202205
case <-time.After(5 * time.Second):
203-
t.FailNow()
206+
t.Fatal(errTimeoutAfter5Seconds)
204207
}
205208
}
206209
}
@@ -262,7 +265,7 @@ func TestForensicsMonitoringNotOnSameChainDoNotHaveSameRoundQC(t *testing.T) {
262265
assert.Equal(t, 2, len(content.LargerRoundInfo.SignerAddresses))
263266
return
264267
case <-time.After(5 * time.Second):
265-
t.FailNow()
268+
t.Fatal(errTimeoutAfter5Seconds)
266269
}
267270
}
268271
}
@@ -327,7 +330,7 @@ func TestForensicsAcrossEpoch(t *testing.T) {
327330
assert.Equal(t, 2, len(content.LargerRoundInfo.SignerAddresses))
328331
return
329332
case <-time.After(5 * time.Second):
330-
t.FailNow()
333+
t.Fatal(errTimeoutAfter5Seconds)
331334
}
332335
}
333336
}
@@ -395,7 +398,7 @@ func TestVoteEquivocationSameRound(t *testing.T) {
395398
assert.Equal(t, types.Round(5), content.LargerRoundVote.ProposedBlockInfo.Round)
396399
return
397400
case <-time.After(5 * time.Second):
398-
t.FailNow()
401+
t.Fatal(errTimeoutAfter5Seconds)
399402
}
400403
}
401404
}
@@ -452,7 +455,7 @@ func TestVoteEquivocationDifferentRound(t *testing.T) {
452455
assert.Equal(t, acc1Addr, content.Signer)
453456
return
454457
case <-time.After(5 * time.Second):
455-
t.FailNow()
458+
t.Fatal(errTimeoutAfter5Seconds)
456459
}
457460
}
458461
}

core/blockchain_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ func testHeaderChainImport(chain []*types.Header, blockchain *BlockChain) error
157157
func insertChain(done chan bool, blockchain *BlockChain, chain types.Blocks, t *testing.T) {
158158
_, err := blockchain.InsertChain(chain)
159159
if err != nil {
160-
fmt.Println(err)
161-
t.FailNow()
160+
t.Fatal(err)
162161
}
163162
done <- true
164163
}

core/txpool/lending_pool_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ func TestSendLending(t *testing.T) {
177177
}
178178
nonce, err := getLendingNonce(crypto.PubkeyToAddress(privateKey.PublicKey))
179179
if err != nil {
180-
t.Error("fail to get nonce")
181-
t.FailNow()
180+
t.Fatal("fail to get nonce")
182181
}
183182

184183
for {
@@ -249,8 +248,7 @@ func TestCancelLending(t *testing.T) {
249248
}
250249
nonce, err := getLendingNonce(crypto.PubkeyToAddress(privateKey.PublicKey))
251250
if err != nil {
252-
t.Error("fail to get nonce")
253-
t.FailNow()
251+
t.Fatal("fail to get nonce")
254252
}
255253

256254
// 10%
@@ -272,16 +270,14 @@ func TestRecallLending(t *testing.T) {
272270
}
273271
nonce, err := getLendingNonce(crypto.PubkeyToAddress(privateKey.PublicKey))
274272
if err != nil {
275-
t.Error("fail to get nonce")
276-
t.FailNow()
273+
t.Fatal("fail to get nonce")
277274
}
278275
interestRate := 10 * common.BaseLendingInterest.Uint64()
279276
testSendLending(key, nonce, USDAddress, common.Address{}, new(big.Int).Mul(_1E8, big.NewInt(1000)), interestRate, lendingstate.Investing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
280277
time.Sleep(2 * time.Second)
281278
nonce, err = getLendingNonce(crypto.PubkeyToAddress(privateKey.PublicKey))
282279
if err != nil {
283-
t.Error("fail to get nonce")
284-
t.FailNow()
280+
t.Fatal("fail to get nonce")
285281
}
286282
testSendLending(key, nonce, USDAddress, common.XDCNativeAddressBinary, new(big.Int).Mul(_1E8, big.NewInt(1000)), interestRate, lendingstate.Borrowing, lendingstate.LendingStatusNew, true, 0, 0, common.Hash{}, "")
287283
time.Sleep(2 * time.Second)

core/types/transaction_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,12 @@ func TestRecipientEmpty(t *testing.T) {
230230
_, addr := defaultTestKey()
231231
tx, err := decodeTx(common.Hex2Bytes("f8498080808080011ca09b16de9d5bdee2cf56c28d16275a4da68cd30273e2525f3959f5d62557489921a0372ebd8fb3345f7db7b5a86d42e24d36e983e259b0664ceb8c227ec9af572f3d"))
232232
if err != nil {
233-
t.Error(err)
234-
t.FailNow()
233+
t.Fatal(err)
235234
}
236235

237236
from, err := Sender(HomesteadSigner{}, tx)
238237
if err != nil {
239-
t.Error(err)
240-
t.FailNow()
238+
t.Fatal(err)
241239
}
242240
if addr != from {
243241
t.Error("derived address doesn't match")
@@ -249,18 +247,16 @@ func TestRecipientNormal(t *testing.T) {
249247

250248
tx, err := decodeTx(common.Hex2Bytes("f85d80808094000000000000000000000000000000000000000080011ca0527c0d8f5c63f7b9f41324a7c8a563ee1190bcbf0dac8ab446291bdbf32f5c79a0552c4ef0a09a04395074dab9ed34d3fbfb843c2f2546cc30fe89ec143ca94ca6"))
251249
if err != nil {
252-
t.Error(err)
253-
t.FailNow()
250+
t.Fatal(err)
254251
}
255252

256253
from, err := Sender(HomesteadSigner{}, tx)
257254
if err != nil {
258-
t.Error(err)
259-
t.FailNow()
255+
t.Fatal(err)
260256
}
261257

262258
if addr != from {
263-
t.Error("derived address doesn't match")
259+
t.Fatal("derived address doesn't match")
264260
}
265261
}
266262

0 commit comments

Comments
 (0)