Skip to content

Commit

Permalink
update tests and make Hash func private
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Nov 7, 2024
1 parent b9d107c commit 226c576
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
15 changes: 3 additions & 12 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions rpc/l1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

0 comments on commit 226c576

Please sign in to comment.