core, ethclient/gethclient: improve flaky tests (#25918)

* ethclient/gethclient: improve time-sensitive flaky test

* eth/catalyst: fix (?) flaky test

* core: stop blockchains in tests after use

* core: fix dangling blockchain instances

* core: rm whitespace

* eth/gasprice, eth/tracers, consensus/clique: stop dangling blockchains in tests

* all: address review concerns

* core: goimports

* eth/catalyst: fix another time-sensitive test

* consensus/clique: add snapshot test run function

* core: rename stop() to stopWithoutSaving()

Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
Martin Holst Swende
2022-10-06 13:39:20 +02:00
committed by GitHub
co-authored by Felix Lange
parent deead99731
commit 067bac3f24
12 changed files with 265 additions and 158 deletions
+28 -10
View File
@@ -92,12 +92,21 @@ func TestEth2AssembleBlock(t *testing.T) {
blockParams := beacon.PayloadAttributesV1{
Timestamp: blocks[9].Time() + 5,
}
execData, err := assembleBlock(api, blocks[9].Hash(), &blockParams)
if err != nil {
t.Fatalf("error producing block, err=%v", err)
// This test is a bit time-sensitive, the miner needs to pick up on the
// txs in the pool. Therefore, we retry once if it fails on the first attempt.
var testErr error
for retries := 2; retries > 0; retries-- {
if execData, err := assembleBlock(api, blocks[9].Hash(), &blockParams); err != nil {
t.Fatalf("error producing block, err=%v", err)
} else if have, want := len(execData.Transactions), 1; have != want {
testErr = fmt.Errorf("invalid number of transactions, have %d want %d", have, want)
} else {
testErr = nil
break
}
}
if len(execData.Transactions) != 1 {
t.Fatalf("invalid number of transactions %d != 1", len(execData.Transactions))
if testErr != nil {
t.Fatal(testErr)
}
}
@@ -113,12 +122,21 @@ func TestEth2AssembleBlockWithAnotherBlocksTxs(t *testing.T) {
blockParams := beacon.PayloadAttributesV1{
Timestamp: blocks[8].Time() + 5,
}
execData, err := assembleBlock(api, blocks[8].Hash(), &blockParams)
if err != nil {
t.Fatalf("error producing block, err=%v", err)
// This test is a bit time-sensitive, the miner needs to pick up on the
// txs in the pool. Therefore, we retry once if it fails on the first attempt.
var testErr error
for retries := 2; retries > 0; retries-- {
if execData, err := assembleBlock(api, blocks[8].Hash(), &blockParams); err != nil {
t.Fatalf("error producing block, err=%v", err)
} else if have, want := len(execData.Transactions), blocks[9].Transactions().Len(); have != want {
testErr = fmt.Errorf("invalid number of transactions, have %d want %d", have, want)
} else {
testErr = nil
break
}
}
if len(execData.Transactions) != blocks[9].Transactions().Len() {
t.Fatalf("invalid number of transactions %d != 1", len(execData.Transactions))
if testErr != nil {
t.Fatal(testErr)
}
}