From fe10930ea986d2d718d96d3115fe57872a89dbeb Mon Sep 17 00:00:00 2001 From: David Zhou Date: Fri, 9 May 2025 11:06:56 -0400 Subject: [PATCH] TEST: Basic test file for block flushing --- eth/tracers/firehose.go | 12 +++++----- eth/tracers/firehose_concurrency_test.go | 28 +++++++++++++++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/eth/tracers/firehose.go b/eth/tracers/firehose.go index 7ca1b01e12..a1be26f862 100644 --- a/eth/tracers/firehose.go +++ b/eth/tracers/firehose.go @@ -496,12 +496,12 @@ func (f *Firehose) OnBlockEnd(err error) { } f.ensureInBlockAndNotInTrx() - - job := &blockPrintJob{ - block: f.block, - finality: f.blockFinality, - } - f.blockPrintQueue <- job + f.printBlockToFirehose(f.block, f.blockFinality) + //job := &blockPrintJob{ + // block: f.block, + // finality: f.blockFinality, + //} + //f.blockPrintQueue <- job } else { // An error occurred, could have happen in transaction/call context, we must not check if in trx/call, only check in block diff --git a/eth/tracers/firehose_concurrency_test.go b/eth/tracers/firehose_concurrency_test.go index ace16035f4..04338baf12 100644 --- a/eth/tracers/firehose_concurrency_test.go +++ b/eth/tracers/firehose_concurrency_test.go @@ -1,9 +1,35 @@ package tracers import ( + "encoding/hex" + "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/params" + "github.com/stretchr/testify/require" "testing" ) -func TestFirehoseBlockPrintingOrder(t *testing.T) { +func TestFirehose_BlockPrintsToFirehose(t *testing.T) { + f := NewFirehose(&FirehoseConfig{ + ApplyBackwardCompatibility: ptr(false), + private: &privateFirehoseConfig{ + FlushToTestBuffer: true, + }, + }) + f.OnBlockchainInit(params.AllEthashProtocolChanges) + + f.OnBlockStart(blockEvent(123)) + blockHash := hex.EncodeToString(f.block.Hash) // Store the block hash before it gets reset + f.onTxStart(txEvent(), hex2Hash("ABCD"), from, to) + f.OnCallEnter(0, byte(vm.CALL), from, to, nil, 0, nil) + f.OnBalanceChange(from, b(100), b(50), 0) + f.OnCallExit(0, nil, 0, nil, false) + f.OnTxEnd(txReceiptEvent(0), nil) + f.OnBlockEnd(nil) + + output := f.InternalTestingBuffer().String() + + require.Contains(t, output, "FIRE BLOCK", "expected FIRE BLOCK output not found") + require.Contains(t, output, "123", "expected block number not found in output") + require.Contains(t, output, blockHash, "expected block hash not found in output") }