From 226c57613b2da39d1fcebbcd4a726e79558e4dc0 Mon Sep 17 00:00:00 2001 From: rian Date: Thu, 7 Nov 2024 14:08:36 +0200 Subject: [PATCH] update tests and make Hash func private --- blockchain/blockchain_test.go | 15 +++------------ rpc/l1.go | 4 ++-- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/blockchain/blockchain_test.go b/blockchain/blockchain_test.go index 21ecb1a72e..d1094da539 100644 --- a/blockchain/blockchain_test.go +++ b/blockchain/blockchain_test.go @@ -239,11 +239,6 @@ func TestStore(t *testing.T) { got0Update, err := chain.StateUpdateByHash(block0.Hash) require.NoError(t, err) assert.Equal(t, stateUpdate0, got0Update) - - nonExistentMsgHash := common.HexToHash("0xcoffeebabe") - hash, err := chain.L1HandlerTxnHash(&nonExistentMsgHash) - require.Nil(t, hash) - require.Equal(t, db.ErrKeyNotFound, err) }) t.Run("add block to non-empty blockchain", func(t *testing.T) { @@ -272,21 +267,17 @@ func TestStore(t *testing.T) { got1Update, err := chain.StateUpdateByNumber(1) require.NoError(t, err) assert.Equal(t, stateUpdate1, got1Update) - - nonExistentMsgHash := common.HexToHash("0xcoffeebabe") - hash, err := chain.L1HandlerTxnHash(&nonExistentMsgHash) - require.Nil(t, hash) - require.Equal(t, db.ErrKeyNotFound, err) }) +} +func TestStoreL1HandlerTxnHash(t *testing.T) { t.Run("add block with L1 Handler Txn", func(t *testing.T) { client := feeder.NewTestClient(t, &utils.Sepolia) gw := adaptfeeder.New(client) chain := blockchain.New(pebble.NewMemTest(t), &utils.Sepolia) - var block *core.Block var stateUpdate *core.StateUpdate for i := range uint64(7) { - block, err = gw.BlockByNumber(context.Background(), i) + block, err := gw.BlockByNumber(context.Background(), i) require.NoError(t, err) stateUpdate, err = gw.StateUpdate(context.Background(), i) require.NoError(t, err) diff --git a/rpc/l1.go b/rpc/l1.go index 77d29e5834..e603a0db2b 100644 --- a/rpc/l1.go +++ b/rpc/l1.go @@ -25,7 +25,7 @@ type LogMessageToL2 struct { Fee *big.Int } -func (l *LogMessageToL2) HashMessage() *common.Hash { +func (l *LogMessageToL2) hashMessage() *common.Hash { hash := sha3.NewLegacyKeccak256() writeUint256 := func(value *big.Int) { @@ -108,7 +108,7 @@ func (h *Handler) messageToL2Logs(ctx context.Context, txHash *common.Hash) ([]* selector := new(big.Int).SetBytes(vLog.Topics[3].Bytes()) event.FromAddress = &fromAddress event.Selector = selector - messageHashes = append(messageHashes, event.HashMessage()) + messageHashes = append(messageHashes, event.hashMessage()) } return messageHashes, nil }