Skip to content

Commit

Permalink
test(driver): add more tests about withdrawals && treasury (taikoxyz#236
Browse files Browse the repository at this point in the history
)
  • Loading branch information
davidtaikocha authored May 22, 2023
1 parent c6e3ea9 commit 1390a68
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 14 deletions.
95 changes: 93 additions & 2 deletions driver/chain_syncer/calldata/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package calldata

import (
"context"
"math/big"
"math/rand"
"os"
"testing"
Expand Down Expand Up @@ -147,14 +148,104 @@ func (s *CalldataSyncerTestSuite) TestHandleReorgToNoneGenesis() {
}

func (s *CalldataSyncerTestSuite) TestWithdrawRootCalculation() {
events := testutils.ProposeAndInsertEmptyBlocks(&s.ClientTestSuite, s.p, s.s)
depositReceiptPrivKey, err := crypto.ToECDSA(
common.Hex2Bytes("2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6"),
)
s.Nil(err)

depositReceipt := crypto.PubkeyToAddress(depositReceiptPrivKey.PublicKey)
balance, err := s.RpcClient.L2.BalanceAt(context.Background(), depositReceipt, nil)
s.Nil(err)

testutils.DepositEtherToL2(&s.ClientTestSuite, depositReceiptPrivKey)

for _, e := range events {
for _, e := range testutils.ProposeAndInsertEmptyBlocks(&s.ClientTestSuite, s.p, s.s) {
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)

for _, deposit := range e.Meta.DepositsProcessed {
if depositReceipt == deposit.Recipient {
balance = new(big.Int).Add(balance, deposit.Amount)
}
}
}

balanceAfter, err := s.RpcClient.L2.BalanceAt(context.Background(), depositReceipt, nil)
s.Nil(err)

s.Zero(balanceAfter.Cmp(balance))
}

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

balance, err := s.RpcClient.L2.BalanceAt(context.Background(), treasury, nil)
s.Nil(err)

headBefore, err := s.RpcClient.L2.BlockNumber(context.Background())
s.Nil(err)

testutils.ProposeAndInsertEmptyBlocks(&s.ClientTestSuite, s.p, s.s)

headAfter, err := s.RpcClient.L2.BlockNumber(context.Background())
s.Nil(err)

balanceAfter, err := s.RpcClient.L2.BalanceAt(context.Background(), treasury, nil)
s.Nil(err)

s.Greater(headAfter, headBefore)
s.Zero(balanceAfter.Cmp(balance))
}

func (s *CalldataSyncerTestSuite) TestTreasuryIncome() {
treasury := common.HexToAddress(os.Getenv("TREASURY"))
s.NotZero(treasury.Big().Uint64())

balance, err := s.RpcClient.L2.BalanceAt(context.Background(), treasury, nil)
s.Nil(err)

headBefore, err := s.RpcClient.L2.BlockNumber(context.Background())
s.Nil(err)

testutils.ProposeAndInsertEmptyBlocks(&s.ClientTestSuite, s.p, s.s)
testutils.ProposeAndInsertValidBlock(&s.ClientTestSuite, s.p, s.s)

headAfter, err := s.RpcClient.L2.BlockNumber(context.Background())
s.Nil(err)

balanceAfter, err := s.RpcClient.L2.BalanceAt(context.Background(), treasury, nil)
s.Nil(err)

s.Greater(headAfter, headBefore)
s.True(balanceAfter.Cmp(balance) > 0)

var hasNoneAnchorTxs bool
for i := headBefore + 1; i <= headAfter; i++ {
block, err := s.RpcClient.L2.BlockByNumber(context.Background(), new(big.Int).SetUint64(i))
s.Nil(err)
s.GreaterOrEqual(block.Transactions().Len(), 1)
s.Greater(block.BaseFee().Uint64(), uint64(0))

for j, tx := range block.Transactions() {
if j == 0 {
continue
}

hasNoneAnchorTxs = true
receipt, err := s.RpcClient.L2.TransactionReceipt(context.Background(), tx.Hash())
s.Nil(err)

fee := new(big.Int).Mul(block.BaseFee(), new(big.Int).SetUint64(receipt.GasUsed))

balance = new(big.Int).Add(balance, fee)
}
}

s.True(hasNoneAnchorTxs)
s.Zero(balanceAfter.Cmp(balance))
}

func TestCalldataSyncerTestSuite(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions integration_test/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ if [ "$RUN_TESTS" == "true" ]; then
L1_PROPOSER_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
L2_SUGGESTED_FEE_RECIPIENT=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
L1_PROVER_PRIVATE_KEY=59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d \
TREASURY=0x1000777700000000000000000000000000000001 \
JWT_SECRET=$DIR/nodes/jwt.hex \
go test -v -p=1 ./$PACKAGE -coverprofile=coverage.out -covermode=atomic -timeout=300s
else
Expand Down
2 changes: 1 addition & 1 deletion integration_test/nodes/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cd $TAIKO_MONO_DIR/packages/protocol &&
ORACLE_PROVER=0x70997970C51812dc3A010C7d01b50e0d17dc79C8 \
SOLO_PROPOSER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
OWNER=0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC \
TREASURY=0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC \
TREASURY=0x1000777700000000000000000000000000000001 \
INITIAL_PROOF_TIME_TARGET=101 \
TAIKO_L2_ADDRESS=0x1000777700000000000000000000000000000001 \
L2_SIGNAL_SERVICE=0x1000777700000000000000000000000000000007 \
Expand Down
6 changes: 3 additions & 3 deletions prover/proof_producer/zkevm_rpcd_producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
)

func TestNewZkevmRpcdProducer(t *testing.T) {
dummpyZkevmRpcdProducer, err := NewZkevmRpcdProducer("http://localhost:18545", "", "", "", false, 0)
dummyZkevmRpcdProducer, err := NewZkevmRpcdProducer("http://localhost:18545", "", "", "", false, 0)
require.Nil(t, err)

dummpyZkevmRpcdProducer.CustomProofHook = func() ([]byte, uint64, error) {
dummyZkevmRpcdProducer.CustomProofHook = func() ([]byte, uint64, error) {
return []byte{0}, CircuitsDegree10Txs, nil
}

Expand All @@ -38,7 +38,7 @@ func TestNewZkevmRpcdProducer(t *testing.T) {
MixDigest: randHash(),
Nonce: types.BlockNonce{},
}
require.Nil(t, dummpyZkevmRpcdProducer.RequestProof(
require.Nil(t, dummyZkevmRpcdProducer.RequestProof(
context.Background(),
&ProofRequestOptions{},
blockID,
Expand Down
11 changes: 3 additions & 8 deletions testutils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package testutils

import (
"context"
"crypto/ecdsa"
"math/big"
"math/rand"
"os"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -67,11 +67,9 @@ 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}...)
Expand Down Expand Up @@ -174,14 +172,11 @@ func ProposeAndInsertValidBlock(
return event
}

func DepositEtherToL2(s *ClientTestSuite) {
func DepositEtherToL2(s *ClientTestSuite, depositerPrivKey *ecdsa.PrivateKey) {
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)
opts, err := bind.NewKeyedTransactorWithChainID(depositerPrivKey, s.RpcClient.L1ChainID)
s.Nil(err)
opts.Value = config.MinEthDepositAmount

Expand Down

0 comments on commit 1390a68

Please sign in to comment.