Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(taiko-client): cleanup pre-ontake tests #18647

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions packages/taiko-client/driver/chain_syncer/blob/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ func (s *BlobSyncerTestSuite) TestProcessL1BlocksReorg() {
func (s *BlobSyncerTestSuite) TestOnBlockProposed() {
s.Nil(s.s.onBlockProposed(
context.Background(),
&metadata.TaikoDataBlockMetadataLegacy{TaikoDataBlockMetadata: bindings.TaikoDataBlockMetadata{Id: 0}},
&metadata.TaikoDataBlockMetadataOntake{TaikoDataBlockMetadataV2: bindings.TaikoDataBlockMetadataV2{Id: 0}},
func() {},
))
s.NotNil(s.s.onBlockProposed(
context.Background(),
&metadata.TaikoDataBlockMetadataLegacy{TaikoDataBlockMetadata: bindings.TaikoDataBlockMetadata{Id: 1}},
&metadata.TaikoDataBlockMetadataOntake{TaikoDataBlockMetadataV2: bindings.TaikoDataBlockMetadataV2{Id: 1}},
func() {},
))
}
Expand All @@ -80,18 +80,21 @@ func (s *BlobSyncerTestSuite) TestInsertNewHead() {
s.Nil(err)
l1Head, err := s.s.rpc.L1.BlockByNumber(context.Background(), nil)
s.Nil(err)
protocolConfigs, err := s.s.rpc.TaikoL1.GetConfig(nil)
s.Nil(err)
_, err = s.s.insertNewHead(
context.Background(),
&metadata.TaikoDataBlockMetadataLegacy{
TaikoDataBlockMetadata: bindings.TaikoDataBlockMetadata{
Id: 1,
L1Height: l1Head.NumberU64(),
L1Hash: l1Head.Hash(),
Coinbase: common.BytesToAddress(testutils.RandomBytes(1024)),
BlobHash: testutils.RandomHash(),
Difficulty: testutils.RandomHash(),
GasLimit: utils.RandUint32(nil),
Timestamp: uint64(time.Now().Unix()),
&metadata.TaikoDataBlockMetadataOntake{
TaikoDataBlockMetadataV2: bindings.TaikoDataBlockMetadataV2{
Id: 1,
AnchorBlockId: l1Head.NumberU64(),
AnchorBlockHash: l1Head.Hash(),
Coinbase: common.BytesToAddress(testutils.RandomBytes(1024)),
BlobHash: testutils.RandomHash(),
Difficulty: testutils.RandomHash(),
GasLimit: utils.RandUint32(nil),
Timestamp: uint64(time.Now().Unix()),
BaseFeeConfig: protocolConfigs.BaseFeeConfig,
},
Log: types.Log{
BlockNumber: l1Head.Number().Uint64(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func rlpEncodedTransactionBytes(l int, signed bool) []byte {
var tx *types.Transaction
if signed {
txData := &types.LegacyTx{Nonce: 1, To: &testAddr, GasPrice: common.Big256, Value: common.Big1, Gas: 10}

tx = types.MustSignNewTx(testKey, types.LatestSigner(&params.ChainConfig{ChainID: chainID}), txData)
} else {
tx = types.NewTransaction(1, testAddr, common.Big1, 10, new(big.Int).SetUint64(10*params.GWei), nil)
Expand Down
73 changes: 16 additions & 57 deletions packages/taiko-client/internal/testutils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,14 @@ func (s *ClientTestSuite) ProposeAndInsertEmptyBlocks(
l1Head, err := s.RPCClient.L1.HeaderByNumber(context.Background(), nil)
s.Nil(err)

sink := make(chan *bindings.TaikoL1ClientBlockProposed)
sub, err := s.RPCClient.TaikoL1.WatchBlockProposed(nil, sink, nil, nil)
sink := make(chan *bindings.TaikoL1ClientBlockProposedV2)
sub, err := s.RPCClient.TaikoL1.WatchBlockProposedV2(nil, sink, nil)
s.Nil(err)
defer func() {
sub.Unsubscribe()
close(sink)
}()

sink2 := make(chan *bindings.TaikoL1ClientBlockProposedV2)
sub2, err := s.RPCClient.TaikoL1.WatchBlockProposedV2(nil, sink2, nil)
s.Nil(err)
defer func() {
sub2.Unsubscribe()
close(sink2)
}()

// RLP encoded empty list
s.Nil(proposer.ProposeTxLists(context.Background(), []types.Transactions{{}}))
s.Nil(blobSyncer.ProcessL1Blocks(context.Background()))
Expand All @@ -64,14 +56,9 @@ func (s *ClientTestSuite) ProposeAndInsertEmptyBlocks(

var txHash common.Hash
for i := 0; i < 3; i++ {
select {
case event := <-sink:
metadataList = append(metadataList, metadata.NewTaikoDataBlockMetadataLegacy(event))
txHash = event.Raw.TxHash
case event := <-sink2:
metadataList = append(metadataList, metadata.NewTaikoDataBlockMetadataOntake(event))
txHash = event.Raw.TxHash
}
event := <-sink
metadataList = append(metadataList, metadata.NewTaikoDataBlockMetadataOntake(event))
txHash = event.Raw.TxHash
}

_, isPending, err := s.RPCClient.L1.TransactionByHash(context.Background(), txHash)
Expand All @@ -97,19 +84,13 @@ func (s *ClientTestSuite) ProposeAndInsertValidBlock(
s.Nil(err)

// Propose txs in L2 execution engine's mempool
sink := make(chan *bindings.TaikoL1ClientBlockProposed)
sub, err := s.RPCClient.TaikoL1.WatchBlockProposed(nil, sink, nil, nil)
s.Nil(err)

sink2 := make(chan *bindings.TaikoL1ClientBlockProposedV2)
sub2, err := s.RPCClient.TaikoL1.WatchBlockProposedV2(nil, sink2, nil)
sink := make(chan *bindings.TaikoL1ClientBlockProposedV2)
sub, err := s.RPCClient.TaikoL1.WatchBlockProposedV2(nil, sink, nil)
s.Nil(err)

defer func() {
sub.Unsubscribe()
sub2.Unsubscribe()
close(sink)
close(sink2)
}()

nonce, err := s.RPCClient.L2.PendingNonceAt(context.Background(), s.TestAddr)
Expand All @@ -130,18 +111,10 @@ func (s *ClientTestSuite) ProposeAndInsertValidBlock(
s.Nil(proposer.ProposeOp(context.Background()))

var (
txHash common.Hash
meta metadata.TaikoBlockMetaData
)
select {
case event := <-sink:
txHash = event.Raw.TxHash
meta = metadata.NewTaikoDataBlockMetadataLegacy(event)
case event := <-sink2:
event = <-sink
txHash = event.Raw.TxHash
meta = metadata.NewTaikoDataBlockMetadataOntake(event)
}

meta = metadata.NewTaikoDataBlockMetadataOntake(event)
)
_, isPending, err := s.RPCClient.L1.TransactionByHash(context.Background(), txHash)
s.Nil(err)
s.False(isPending)
Expand All @@ -157,9 +130,7 @@ func (s *ClientTestSuite) ProposeAndInsertValidBlock(
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

s.Nil(backoff.Retry(func() error {
return blobSyncer.ProcessL1Blocks(ctx)
}, backoff.NewExponentialBackOff()))
s.Nil(backoff.Retry(func() error { return blobSyncer.ProcessL1Blocks(ctx) }, backoff.NewExponentialBackOff()))

s.Nil(s.RPCClient.WaitTillL2ExecutionEngineSynced(context.Background()))

Expand All @@ -182,20 +153,12 @@ func (s *ClientTestSuite) ProposeValidBlock(
s.Nil(err)

// Propose txs in L2 execution engine's mempool
sink := make(chan *bindings.TaikoL1ClientBlockProposed)
sink2 := make(chan *bindings.TaikoL1ClientBlockProposedV2)

sub, err := s.RPCClient.TaikoL1.WatchBlockProposed(nil, sink, nil, nil)
s.Nil(err)

sub2, err := s.RPCClient.TaikoL1.WatchBlockProposedV2(nil, sink2, nil)
sink := make(chan *bindings.TaikoL1ClientBlockProposedV2)
sub, err := s.RPCClient.TaikoL1.WatchBlockProposedV2(nil, sink, nil)
s.Nil(err)

defer func() {
sub.Unsubscribe()
sub2.Unsubscribe()
close(sink)
close(sink2)
}()

ontakeForkHeight, err := s.RPCClient.TaikoL2.OntakeForkHeight(nil)
Expand Down Expand Up @@ -231,14 +194,10 @@ func (s *ClientTestSuite) ProposeValidBlock(

s.Nil(proposer.ProposeOp(context.Background()))

var txHash common.Hash
select {
case event := <-sink:
txHash = event.Raw.TxHash
case event := <-sink2:
var (
event = <-sink
txHash = event.Raw.TxHash
}

)
_, isPending, err := s.RPCClient.L1.TransactionByHash(context.Background(), txHash)
s.Nil(err)
s.False(isPending)
Expand Down
82 changes: 4 additions & 78 deletions packages/taiko-client/proposer/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,17 @@ import (
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/rlp"
"github.com/stretchr/testify/suite"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/encoding"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/metadata"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/driver/chain_syncer/beaconsync"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/driver/chain_syncer/blob"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/driver/state"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/internal/testutils"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/config"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/jwt"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/rpc"
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/utils"
builder "github.com/taikoxyz/taiko-mono/packages/taiko-client/proposer/transaction_builder"
)

type ProposerTestSuite struct {
Expand Down Expand Up @@ -244,58 +238,6 @@ func (s *ProposerTestSuite) TestTxPoolContentWithMinTip() {
s.Nil(s.s.ProcessL1Blocks(context.Background()))
}

func (s *ProposerTestSuite) TestProposeTxLists() {
p := s.p
ctx := p.ctx
cfg := s.p.Config

txBuilder := builder.NewBlobTransactionBuilder(
p.rpc,
p.L1ProposerPrivKey,
cfg.TaikoL1Address,
cfg.ProverSetAddress,
cfg.L2SuggestedFeeRecipient,
cfg.ProposeBlockTxGasLimit,
cfg.ExtraData,
config.NewChainConfig(s.p.protocolConfigs),
false,
)

emptyTxListBytes, err := rlp.EncodeToBytes(types.Transactions{})
s.Nil(err)
txListsBytes := [][]byte{emptyTxListBytes}
txCandidates := make([]txmgr.TxCandidate, len(txListsBytes))
for i, txListBytes := range txListsBytes {
compressedTxListBytes, err := utils.Compress(txListBytes)
if err != nil {
log.Warn("Failed to compress transactions list", "index", i, "error", err)
break
}

candidate, err := txBuilder.BuildLegacy(
p.ctx,
p.IncludeParentMetaHash,
compressedTxListBytes,
)
if err != nil {
log.Warn("Failed to build TaikoL1.proposeBlock transaction", "error", err)
break
}

// trigger the error
candidate.GasLimit = 10_000_000

txCandidates[i] = *candidate
}

for _, txCandidate := range txCandidates {
txMgr, _ := p.txmgrSelector.Select()
receipt, err := txMgr.Send(ctx, txCandidate)
s.Nil(err)
s.Nil(encoding.TryParsingCustomErrorFromReceipt(ctx, p.rpc.L1, p.proposerAddress, receipt))
}
}

func (s *ProposerTestSuite) TestProposeOpNoEmptyBlock() {
// TODO: Temporarily skip this test case when using l2_reth node.
if os.Getenv("L2_NODE") == "l2_reth" {
Expand Down Expand Up @@ -363,40 +305,24 @@ func (s *ProposerTestSuite) TestName() {

func (s *ProposerTestSuite) TestProposeOp() {
// Propose txs in L2 execution engine's mempool
sink := make(chan *bindings.TaikoL1ClientBlockProposed)

sub, err := s.p.rpc.TaikoL1.WatchBlockProposed(nil, sink, nil, nil)
sink := make(chan *bindings.TaikoL1ClientBlockProposedV2)
sub, err := s.p.rpc.TaikoL1.WatchBlockProposedV2(nil, sink, nil)
s.Nil(err)
defer func() {
sub.Unsubscribe()
close(sink)
}()

sink2 := make(chan *bindings.TaikoL1ClientBlockProposedV2)

sub2, err := s.p.rpc.TaikoL1.WatchBlockProposedV2(nil, sink2, nil)
s.Nil(err)
defer func() {
sub2.Unsubscribe()
close(sink2)
}()

to := common.BytesToAddress(testutils.RandomBytes(32))
_, err = testutils.SendDynamicFeeTx(s.p.rpc.L2, s.TestAddrPrivKey, &to, common.Big1, nil)
s.Nil(err)

s.Nil(s.p.ProposeOp(context.Background()))

var (
meta metadata.TaikoBlockMetaData
event = <-sink
meta = metadata.NewTaikoDataBlockMetadataOntake(event)
)
select {
case event := <-sink:
meta = metadata.NewTaikoDataBlockMetadataLegacy(event)
case event := <-sink2:
meta = metadata.NewTaikoDataBlockMetadataOntake(event)
}

s.Equal(meta.GetCoinbase(), s.p.L2SuggestedFeeRecipient)

_, isPending, err := s.p.rpc.L1.TransactionByHash(context.Background(), meta.GetTxHash())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestDummyProducerRequestProof(t *testing.T) {
res, err := producer.RequestProof(
&ProofRequestOptions{},
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
&metadata.TaikoDataBlockMetadataOntake{},
header,
tier,
time.Now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestGuardianProducerRequestProof(t *testing.T) {
context.Background(),
&ProofRequestOptions{},
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
&metadata.TaikoDataBlockMetadataOntake{},
header,
time.Now(),
)
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestGuardianProducerRequestProofReturnLivenessBond(t *testing.T) {
context.Background(),
&ProofRequestOptions{},
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
&metadata.TaikoDataBlockMetadataOntake{},
header,
time.Now(),
)
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestMinorityRequestProof(t *testing.T) {
context.Background(),
&ProofRequestOptions{},
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
&metadata.TaikoDataBlockMetadataOntake{},
header,
time.Now(),
)
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestRequestMinorityProofReturnLivenessBond(t *testing.T) {
context.Background(),
&ProofRequestOptions{},
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
&metadata.TaikoDataBlockMetadataOntake{},
header,
time.Now(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestOptimisticRequestProof(t *testing.T) {
context.Background(),
&ProofRequestOptions{},
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
&metadata.TaikoDataBlockMetadataOntake{},
header,
time.Now(),
)
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestProofCancel(t *testing.T) {
context.Background(),
&ProofRequestOptions{},
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
&metadata.TaikoDataBlockMetadataOntake{},
header,
time.Now(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestSGXProducerRequestProof(t *testing.T) {
context.Background(),
&ProofRequestOptions{},
blockID,
&metadata.TaikoDataBlockMetadataLegacy{},
&metadata.TaikoDataBlockMetadataOntake{},
header,
time.Now(),
)
Expand Down
Loading
Loading