From b5d302a07fa7eeb8f4302f8ae7a4bdc027c4f922 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 31 Oct 2023 20:19:53 +0800 Subject: [PATCH] test: update tests --- bindings/encoding/input_test.go | 2 -- prover/proof_submitter/proof_contester.go | 2 +- prover/proof_submitter/proof_contester_test.go | 6 ++++-- prover/proof_submitter/proof_submitter.go | 4 ++-- prover/proof_submitter/transaction/builder.go | 4 ++-- .../proof_submitter/transaction/builder_test.go | 17 ++++++++++++----- prover/prover.go | 17 +++++++++++++---- prover/prover_test.go | 2 +- 8 files changed, 35 insertions(+), 19 deletions(-) diff --git a/bindings/encoding/input_test.go b/bindings/encoding/input_test.go index 8a3e18371..d006fd78f 100644 --- a/bindings/encoding/input_test.go +++ b/bindings/encoding/input_test.go @@ -5,8 +5,6 @@ import ( "os" "testing" - "testing" - "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" diff --git a/prover/proof_submitter/proof_contester.go b/prover/proof_submitter/proof_contester.go index 95bf476e0..14163cbd0 100644 --- a/prover/proof_submitter/proof_contester.go +++ b/prover/proof_submitter/proof_contester.go @@ -124,7 +124,7 @@ func (c *ProofContester) SubmitContest( }, Tier: transitionProvedEvent.Tier, }, - c.txBuilder.BuildForNormalProofSubmission( + c.txBuilder.Build( ctx, transitionProvedEvent.BlockId, &blockProposedEvent.Meta, diff --git a/prover/proof_submitter/proof_contester_test.go b/prover/proof_submitter/proof_contester_test.go index d4a042e2b..2d0661bdf 100644 --- a/prover/proof_submitter/proof_contester_test.go +++ b/prover/proof_submitter/proof_contester_test.go @@ -14,8 +14,10 @@ func (s *ProofSubmitterTestSuite) TestSubmitContestNoTransition() { context.Background(), &bindings.TaikoL1ClientBlockProposed{}, &bindings.TaikoL1ClientTransitionProved{ - BlockId: common.Big256, - ParentHash: testutils.RandomHash(), + BlockId: common.Big256, + Tran: bindings.TaikoDataTransition{ + ParentHash: testutils.RandomHash(), + }, }, ), ) diff --git a/prover/proof_submitter/proof_submitter.go b/prover/proof_submitter/proof_submitter.go index 24aec6b68..415be26d4 100644 --- a/prover/proof_submitter/proof_submitter.go +++ b/prover/proof_submitter/proof_submitter.go @@ -206,13 +206,13 @@ func (s *ProofSubmitter) SubmitProof( return fmt.Errorf("failed to fetch anchor transaction receipt: %w", err) } - txBuilder := s.txBuilder.BuildForNormalProofSubmission( + txBuilder := s.txBuilder.Build( ctx, proofWithHeader.BlockID, proofWithHeader.Meta, &bindings.TaikoDataTransition{ ParentHash: proofWithHeader.Header.ParentHash, - BlockHash: proofWithHeader.Header.Hash(), + BlockHash: proofWithHeader.Opts.BlockHash, SignalRoot: proofWithHeader.Opts.SignalRoot, Graffiti: s.graffiti, }, diff --git a/prover/proof_submitter/transaction/builder.go b/prover/proof_submitter/transaction/builder.go index ff5a472ef..725b54710 100644 --- a/prover/proof_submitter/transaction/builder.go +++ b/prover/proof_submitter/transaction/builder.go @@ -49,8 +49,8 @@ func NewProveBlockTxBuilder( } } -// BuildForNormalProofSubmission creates a new TaikoL1.ProveBlock transaction with the given nonce. -func (a *ProveBlockTxBuilder) BuildForNormalProofSubmission( +// Build creates a new TaikoL1.ProveBlock transaction with the given nonce. +func (a *ProveBlockTxBuilder) Build( ctx context.Context, blockID *big.Int, meta *bindings.TaikoDataBlockMetadata, diff --git a/prover/proof_submitter/transaction/builder_test.go b/prover/proof_submitter/transaction/builder_test.go index 1070648fb..55023536b 100644 --- a/prover/proof_submitter/transaction/builder_test.go +++ b/prover/proof_submitter/transaction/builder_test.go @@ -5,7 +5,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/taikoxyz/taiko-client/bindings" - "github.com/taikoxyz/taiko-client/testutils" ) func (s *TransactionTestSuite) TestGetProveBlocksTxOpts() { @@ -19,15 +18,23 @@ func (s *TransactionTestSuite) TestGetProveBlocksTxOpts() { } func (s *TransactionTestSuite) TestBuildTxs() { - _, err := s.builder.BuildForNormalProofSubmission( - context.Background(), common.Big256, testutils.RandomBytes(1024), + _, err := s.builder.Build( + context.Background(), + common.Big256, + &bindings.TaikoDataBlockMetadata{}, + &bindings.TaikoDataTransition{}, + &bindings.TaikoDataTierProof{}, + false, )(common.Big256) s.NotNil(err) - _, err = s.builder.BuildForGuardianProofSubmission( + _, err = s.builder.Build( context.Background(), common.Big256, - &bindings.TaikoDataBlockEvidence{}, + &bindings.TaikoDataBlockMetadata{}, + &bindings.TaikoDataTransition{}, + &bindings.TaikoDataTierProof{}, + true, )(common.Big256) s.NotNil(err) } diff --git a/prover/prover.go b/prover/prover.go index 9f0335477..c5bfb81e3 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -652,13 +652,22 @@ func (p *Prover) onTransitionContested(ctx context.Context, e *bindings.TaikoL1C return nil } + contestedTransition, err := p.rpc.TaikoL1.GetTransition( + &bind.CallOpts{Context: ctx}, + e.BlockId.Uint64(), + e.Tran.ParentHash, + ) + if err != nil { + return err + } + // Compare the contested transition to the block in local L2 canonical chain. isValidProof, err := p.isValidProof( ctx, e.BlockId, e.Tran.ParentHash, - e.Tran.BlockHash, - e.Tran.SignalRoot, + contestedTransition.BlockHash, + contestedTransition.SignalRoot, ) if err != nil { return err @@ -668,8 +677,8 @@ func (p *Prover) onTransitionContested(ctx context.Context, e *bindings.TaikoL1C "Contested transition is valid to local canonical chain, ignore the contest", "blockID", e.BlockId, "parentHash", common.Bytes2Hex(e.Tran.ParentHash[:]), - "hash", common.Bytes2Hex(e.Tran.BlockHash[:]), - "signalRoot", common.BytesToHash(e.Tran.SignalRoot[:]), + "hash", common.Bytes2Hex(contestedTransition.BlockHash[:]), + "signalRoot", common.BytesToHash(contestedTransition.SignalRoot[:]), "contester", e.Contester, "bond", e.ContestBond, ) diff --git a/prover/prover_test.go b/prover/prover_test.go index 668a9e304..1a772f20b 100644 --- a/prover/prover_test.go +++ b/prover/prover_test.go @@ -257,7 +257,7 @@ func (s *ProverTestSuite) TestContestWrongBlocks() { contestedEvent := <-contestedSink s.Equal(header.Number.Uint64(), contestedEvent.BlockId.Uint64()) - s.Equal(common.BytesToHash(proofWithHeader.Opts.BlockHash[:]), common.BytesToHash(contestedEvent.Tran.BlockHash[:])) + s.Equal(header.Hash(), common.BytesToHash(contestedEvent.Tran.BlockHash[:])) s.Equal(header.ParentHash, common.BytesToHash(contestedEvent.Tran.ParentHash[:])) s.Nil(s.p.onTransitionContested(context.Background(), contestedEvent))