Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
test(driver): add depositsRoot tests (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored May 20, 2023
1 parent 2128ddc commit fc1d43e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
11 changes: 11 additions & 0 deletions driver/chain_syncer/calldata/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ func (s *CalldataSyncerTestSuite) TestHandleReorgToNoneGenesis() {
s.Greater(s.s.lastInsertedBlockID.Uint64(), uint64(1))
}

func (s *CalldataSyncerTestSuite) TestWithdrawRootCalculation() {
events := testutils.ProposeAndInsertEmptyBlocks(&s.ClientTestSuite, s.p, s.s)

for _, e := range events {
header, err := s.s.rpc.L2.HeaderByNumber(context.Background(), e.Id)
s.Nil(err)
s.NotEmpty(e.Meta.DepositsRoot)
s.Equal(common.BytesToHash(e.Meta.DepositsRoot[:]), *header.WithdrawalsHash)
}
}

func TestCalldataSyncerTestSuite(t *testing.T) {
suite.Run(t, new(CalldataSyncerTestSuite))
}
25 changes: 25 additions & 0 deletions testutils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"math/big"
"math/rand"
"os"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -65,13 +67,19 @@ func ProposeAndInsertEmptyBlocks(
CacheTxListInfo: 0,
}, encoded, 0))

DepositEtherToL2(s)
ProposeInvalidTxListBytes(s, proposer)

// Zero byte txList
DepositEtherToL2(s)
s.Nil(proposer.ProposeEmptyBlockOp(context.Background()))

events = append(events, []*bindings.TaikoL1ClientBlockProposed{<-sink, <-sink, <-sink}...)

for _, e := range events {
s.NotEmpty(e.Meta.DepositsRoot)
}

_, isPending, err := s.RpcClient.L1.TransactionByHash(context.Background(), events[len(events)-1].Raw.TxHash)
s.Nil(err)
s.False(isPending)
Expand Down Expand Up @@ -166,6 +174,23 @@ func ProposeAndInsertValidBlock(
return event
}

func DepositEtherToL2(s *ClientTestSuite) {
config, err := s.RpcClient.TaikoL1.GetConfig(nil)
s.Nil(err)

l1ProverPrivKey, err := crypto.ToECDSA(common.Hex2Bytes(os.Getenv("L1_PROVER_PRIVATE_KEY")))
s.Nil(err)

opts, err := bind.NewKeyedTransactorWithChainID(l1ProverPrivKey, s.RpcClient.L1ChainID)
s.Nil(err)
opts.Value = config.MinEthDepositAmount

for i := 0; i < int(config.MinEthDepositsPerBlock); i++ {
_, err = s.RpcClient.TaikoL1.DepositEtherToL2(opts)
s.Nil(err)
}
}

// RandomHash generates a random blob of data and returns it as a hash.
func RandomHash() common.Hash {
var hash common.Hash
Expand Down

0 comments on commit fc1d43e

Please sign in to comment.