Skip to content

Commit

Permalink
Tests for MoveTheHead
Browse files Browse the repository at this point in the history
  • Loading branch information
mskrzypkows committed Jun 14, 2024
1 parent 3a1f631 commit 41fe9c2
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/taiko-client/driver/chain_syncer/blob/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"net/url"
"time"

"golang.org/x/exp/slog"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/beacon/engine"
Expand Down Expand Up @@ -524,12 +526,17 @@ func (s *Syncer) insertNewHeadUsingDecodedTxList(

// Insert the anchor transaction at the head of the transactions list
txList = append([]*types.Transaction{anchorTx}, txList...)

slog.Debug("Transaction List", "txList", txList)

var txListBytes []byte
if txListBytes, err = rlp.EncodeToBytes(txList); err != nil {
log.Error("Encode txList error", "blockID", l1Origin.BlockID /* event.BlockId, */, "error", err)
return err
}

slog.Debug("txListBytes length", "length", len(txListBytes))

payload, err := s.createExecutionPayloads(
ctx,
nil,
Expand Down Expand Up @@ -586,7 +593,7 @@ func (s *Syncer) createExecutionPayloads(
BlockMetadata: &engine.BlockMetadata{
HighestBlockID: headBlockID,
Beneficiary: common.Address{},
GasLimit: 0,
GasLimit: 240000000 + consensus.AnchorGasLimit, //TODO: replace constant with value from config
Timestamp: 0,
TxList: txListBytes,
MixHash: common.Hash{},
Expand Down Expand Up @@ -614,6 +621,12 @@ func (s *Syncer) createExecutionPayloads(
L1Origin: l1Origin,
}

log.Debug(
"Event GasLimit and Consensus AnchorGasLimit",
"eventGasLimit", event.Meta.GasLimit,
"consensusAnchorGasLimit", consensus.AnchorGasLimit,
)

log.Debug(
"PayloadAttributes",
"blockID", event.BlockId,
Expand Down Expand Up @@ -673,6 +686,8 @@ func (s *Syncer) createExecutionPayloads(
return nil, fmt.Errorf("unexpected NewPayload response status: %s", execStatus.Status)
}

log.Debug("Payload has been created successfully", "payloadID", fcRes.PayloadID, "blockNumber", payload.Number, "blockHash", payload.BlockHash)

return payload, nil
}

Expand Down
60 changes: 60 additions & 0 deletions packages/taiko-client/driver/chain_syncer/blob/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package blob

import (
"context"
"golang.org/x/exp/slog"
"math/big"
"os"
"testing"
Expand All @@ -10,6 +11,7 @@ import (
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/suite"

Expand Down Expand Up @@ -119,6 +121,64 @@ func (s *BlobSyncerTestSuite) TestInsertNewHead() {
s.Nil(err)
}

func (s *BlobSyncerTestSuite) TestInsertNewHeadUsingDecodedTxList() {
parent, err := s.s.rpc.L2.HeaderByNumber(context.Background(), nil)
s.Nil(err)
l1Head, err := s.s.rpc.L1.BlockByNumber(context.Background(), nil)
s.Nil(err)
txList := []*types.Transaction{
types.NewTransaction(0, common.BytesToAddress(testutils.RandomBytes(20)), big.NewInt(0), 21000, big.NewInt(1), nil),
}
err = s.s.insertNewHeadUsingDecodedTxList(
context.Background(),
parent,
common.Big1,
txList,
&rawdb.L1Origin{
BlockID: common.Big1,
L1BlockHeight: common.Big1,
L1BlockHash: l1Head.Hash(),
},
)
s.Nil(err)
}

func (s *BlobSyncerTestSuite) TestMoveTheHead() {
parent, err := s.s.rpc.L2.HeaderByNumber(context.Background(), nil)
s.Nil(err)
txList := []*types.Transaction{
types.NewTransaction(0, common.BytesToAddress(testutils.RandomBytes(20)), big.NewInt(0), 0, big.NewInt(1), nil),
}

err = s.s.MoveTheHead(
context.Background(),
txList,
)
s.Nil(err)

// Verify that the head has moved by checking the latest block header
newParent, err := s.s.rpc.L2.HeaderByNumber(context.Background(), nil)
s.Nil(err)
s.Greater(newParent.Number.Uint64(), parent.Number.Uint64())

// Verify that the transactions were included in the new head block
block, err := s.s.rpc.L2.BlockByHash(context.Background(), newParent.Hash())
s.Nil(err)
_ = block
slog.Info(
"New head block",
"number", newParent.Number,
"hash", newParent.Hash(),
"transactions", block.Transactions(),
)

// s.Equal(len(txList), len(block.Transactions()))
// for i, tx := range txList {
// s.Equal(tx.Hash(), block.Transactions()[i].Hash())
// }
}


func (s *BlobSyncerTestSuite) TestTreasuryIncomeAllAnchors() {
treasury := common.HexToAddress(os.Getenv("TREASURY"))
s.NotZero(treasury.Big().Uint64())
Expand Down

0 comments on commit 41fe9c2

Please sign in to comment.