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

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Oct 31, 2023
1 parent 76b9768 commit b5d302a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 19 deletions.
2 changes: 0 additions & 2 deletions bindings/encoding/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"os"
"testing"

"testing"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"

Expand Down
2 changes: 1 addition & 1 deletion prover/proof_submitter/proof_contester.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (c *ProofContester) SubmitContest(
},
Tier: transitionProvedEvent.Tier,
},
c.txBuilder.BuildForNormalProofSubmission(
c.txBuilder.Build(
ctx,
transitionProvedEvent.BlockId,
&blockProposedEvent.Meta,
Expand Down
6 changes: 4 additions & 2 deletions prover/proof_submitter/proof_contester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
},
),
)
Expand Down
4 changes: 2 additions & 2 deletions prover/proof_submitter/proof_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
4 changes: 2 additions & 2 deletions prover/proof_submitter/transaction/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 12 additions & 5 deletions prover/proof_submitter/transaction/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
}
17 changes: 13 additions & 4 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion prover/prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit b5d302a

Please sign in to comment.