Skip to content

Commit

Permalink
Extend unit test to check receipt meta-information
Browse files Browse the repository at this point in the history
  • Loading branch information
HerbertJordan committed Nov 28, 2024
1 parent b0e9760 commit 48ffb69
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions tests/block_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ func testBlockHeadersOnNetwork(t *testing.T, net *IntegrationTestNet) {
testHeaders_TransactionRootMatchesBlockTxsHash(t, headers, client)
})

t.Run("TransactionReceiptReferencesCorrectContext", func(t *testing.T) {
testHeaders_TransactionReceiptReferencesCorrectContext(t, headers, client)
})

t.Run("ReceiptBlockHashMatchesBlockHash", func(t *testing.T) {
testHeaders_ReceiptBlockHashMatchesBlockHash(t, headers, client)
})

t.Run("ReceiptRootMatchesBlockReceipts", func(t *testing.T) {
testHeaders_ReceiptRootMatchesBlockReceipts(t, headers, client)
})
Expand Down Expand Up @@ -266,15 +274,50 @@ func testHeaders_BaseFeeEvolutionFollowsPricingRules(t *testing.T, headers []*ty
func testHeaders_TransactionRootMatchesBlockTxsHash(t *testing.T, headers []*types.Header, client *ethclient.Client) {
require := require.New(t)

for _, header := range headers {
for i, header := range headers {
block, err := client.BlockByNumber(context.Background(), header.Number)
require.NoError(err, "failed to get block receipts")
require.NoError(err, "failed to get block %d", i)

txsHash := types.DeriveSha(block.Transactions(), trie.NewStackTrie(nil))
require.Equal(header.TxHash, txsHash, "transaction root hash mismatch")
}
}

func testHeaders_TransactionReceiptReferencesCorrectContext(
t *testing.T, headers []*types.Header, client *ethclient.Client,
) {
require := require.New(t)

for i, header := range headers {
block, err := client.BlockByNumber(context.Background(), header.Number)
require.NoError(err, "failed to get block %d", i)

for j, tx := range block.Transactions() {
receipt, err := client.TransactionReceipt(context.Background(), tx.Hash())
require.NoError(err, "failed to get transaction receipt")

require.Equal(tx.Hash(), receipt.TxHash, "transaction hash mismatch")
require.Equal(i, int(receipt.BlockNumber.Uint64()), "block number mismatch")
require.Equal(j, int(receipt.TransactionIndex), "transaction index mismatch")
require.Equal(header.Hash(), receipt.BlockHash, "block hash mismatch")
}
}
}

func testHeaders_ReceiptBlockHashMatchesBlockHash(t *testing.T, headers []*types.Header, client *ethclient.Client) {
require := require.New(t)

for _, header := range headers {
receipts, err := client.BlockReceipts(context.Background(),
rpc.BlockNumberOrHashWithHash(header.Hash(), false))
require.NoError(err, "failed to get block receipts")

for _, receipt := range receipts {
require.Equal(header.Hash(), receipt.BlockHash, "receipt block hash mismatch")
}
}
}

func testHeaders_ReceiptRootMatchesBlockReceipts(t *testing.T, headers []*types.Header, client *ethclient.Client) {
require := require.New(t)

Expand Down Expand Up @@ -536,6 +579,7 @@ func testHeaders_CanRetrieveLogEvents(t *testing.T, headers []*types.Header, cli
require.NoError(err, "failed to get block receipts")

for _, receipt := range receipts {
require.Equal(blockHash, receipt.BlockHash, "block hash mismatch")
for _, log := range receipt.Logs {
allLogs = append(allLogs, *log)

Expand Down Expand Up @@ -621,6 +665,7 @@ func testHeaders_CounterStateIsVerifiable(
receipts, err := client.BlockReceipts(context.Background(), rpc.BlockNumberOrHashWithHash(header.Hash(), false))
require.NoError(err, "failed to get block receipts")
for _, receipt := range receipts {
require.Equal(header.Hash(), receipt.BlockHash, "block hash mismatch")
for _, log := range receipt.Logs {
event, err := counter.ParseCount(*log)
if err != nil {
Expand Down

0 comments on commit 48ffb69

Please sign in to comment.