eth, catalyst: fix flaky tests (#26153)

* eth/catalyst: fix time-dependent (flaky) test

* eth: increase timeout on TestTransactionPropagation
pull/26164/head
Martin Holst Swende 2 years ago committed by GitHub
parent c539bda166
commit ea65edaa28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      eth/catalyst/api_test.go
  2. 2
      eth/handler_eth_test.go

@ -567,42 +567,56 @@ func TestNewPayloadOnInvalidChain(t *testing.T) {
var ( var (
api = NewConsensusAPI(ethservice) api = NewConsensusAPI(ethservice)
parent = ethservice.BlockChain().CurrentBlock() parent = ethservice.BlockChain().CurrentBlock()
signer = types.LatestSigner(ethservice.BlockChain().Config())
// This EVM code generates a log when the contract is created. // This EVM code generates a log when the contract is created.
logCode = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00") logCode = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00")
) )
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
statedb, _ := ethservice.BlockChain().StateAt(parent.Root()) statedb, _ := ethservice.BlockChain().StateAt(parent.Root())
nonce := statedb.GetNonce(testAddr) tx := types.MustSignNewTx(testKey, signer, &types.LegacyTx{
tx, _ := types.SignTx(types.NewContractCreation(nonce, new(big.Int), 1000000, big.NewInt(2*params.InitialBaseFee), logCode), types.LatestSigner(ethservice.BlockChain().Config()), testKey) Nonce: statedb.GetNonce(testAddr),
ethservice.TxPool().AddLocal(tx) Value: new(big.Int),
Gas: 1000000,
params := beacon.PayloadAttributesV1{ GasPrice: big.NewInt(2 * params.InitialBaseFee),
Data: logCode,
})
ethservice.TxPool().AddRemotesSync([]*types.Transaction{tx})
var (
params = beacon.PayloadAttributesV1{
Timestamp: parent.Time() + 1, Timestamp: parent.Time() + 1,
Random: crypto.Keccak256Hash([]byte{byte(i)}), Random: crypto.Keccak256Hash([]byte{byte(i)}),
SuggestedFeeRecipient: parent.Coinbase(), SuggestedFeeRecipient: parent.Coinbase(),
} }
fcState = beacon.ForkchoiceStateV1{
fcState := beacon.ForkchoiceStateV1{
HeadBlockHash: parent.Hash(), HeadBlockHash: parent.Hash(),
SafeBlockHash: common.Hash{}, SafeBlockHash: common.Hash{},
FinalizedBlockHash: common.Hash{}, FinalizedBlockHash: common.Hash{},
} }
resp, err := api.ForkchoiceUpdatedV1(fcState, &params) payload *beacon.ExecutableDataV1
if err != nil { resp beacon.ForkChoiceResponse
err error
)
for i := 0; ; i++ {
if resp, err = api.ForkchoiceUpdatedV1(fcState, &params); err != nil {
t.Fatalf("error preparing payload, err=%v", err) t.Fatalf("error preparing payload, err=%v", err)
} }
if resp.PayloadStatus.Status != beacon.VALID { if resp.PayloadStatus.Status != beacon.VALID {
t.Fatalf("error preparing payload, invalid status: %v", resp.PayloadStatus.Status) t.Fatalf("error preparing payload, invalid status: %v", resp.PayloadStatus.Status)
} }
// give the payload some time to be built // give the payload some time to be built
time.Sleep(100 * time.Millisecond) time.Sleep(50 * time.Millisecond)
payload, err := api.GetPayloadV1(*resp.PayloadID) if payload, err = api.GetPayloadV1(*resp.PayloadID); err != nil {
if err != nil {
t.Fatalf("can't get payload: %v", err) t.Fatalf("can't get payload: %v", err)
} }
if len(payload.Transactions) == 0 { if len(payload.Transactions) > 0 {
break
}
// No luck this time we need to update the params and try again.
params.Timestamp = params.Timestamp + 1
if i > 10 {
t.Fatalf("payload should not be empty") t.Fatalf("payload should not be empty")
} }
}
execResp, err := api.NewPayloadV1(*payload) execResp, err := api.NewPayloadV1(*payload)
if err != nil { if err != nil {
t.Fatalf("can't execute payload: %v", err) t.Fatalf("can't execute payload: %v", err)

@ -451,7 +451,7 @@ func testTransactionPropagation(t *testing.T, protocol uint) {
select { select {
case event := <-txChs[i]: case event := <-txChs[i]:
arrived += len(event.Txs) arrived += len(event.Txs)
case <-time.After(time.Second): case <-time.After(2 * time.Second):
t.Errorf("sink %d: transaction propagation timed out: have %d, want %d", i, arrived, len(txs)) t.Errorf("sink %d: transaction propagation timed out: have %d, want %d", i, arrived, len(txs))
timeout = true timeout = true
} }

Loading…
Cancel
Save