Skip to content

Commit

Permalink
Add unittest for multi-fork support (#25)
Browse files Browse the repository at this point in the history
- Add unittest for new code under sequencesender/txbuilder (> 80%)
- Improved contracts base clase and is no longer needed Contract()
- Removed param sender for txBuilder.BuildSequenceBatchesTx because it use the From from bind.TransactOpts variable
- Require just 1 verified batch to pass e2e
  • Loading branch information
joanestebanr authored Aug 1, 2024
1 parent 880bccb commit 12d1e3f
Show file tree
Hide file tree
Showing 58 changed files with 4,413 additions and 249 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ stop: ## Stops all services
.PHONY: test
test:
trap '$(STOP)' EXIT; MallocNanoZone=0 go test -count=1 -short -race -p 1 -covermode=atomic -coverprofile=../coverage.out -coverpkg ./... -timeout 200s ./...

.PHONY: test-seq_sender
test-seq_sender:
trap '$(STOP)' EXIT; MallocNanoZone=0 go test -count=1 -short -race -p 1 -covermode=atomic -coverprofile=../coverage.out -timeout 200s ./sequencesender/...


.PHONY: install-linter
install-linter: ## Installs the linter
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.54.2
Expand Down
27 changes: 21 additions & 6 deletions aggoracle/mock_ethtxmanager_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ func newTxBuilder(cfg config.Config, ethman *etherman.Client) (txbuilder.TxBuild
switch contracts.VersionType(cfg.Common.ContractVersions) {
case contracts.VersionBanana:
if cfg.Common.IsValidiumMode {
txBuilder = txbuilder.NewTxBuilderBananaValidium(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, da, *auth, auth.From, cfg.SequenceSender.MaxBatchesForL1)
txBuilder = txbuilder.NewTxBuilderBananaValidium(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, da, *auth, cfg.SequenceSender.MaxBatchesForL1)
} else {
txBuilder = txbuilder.NewTxBuilderBananaZKEVM(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, *auth, auth.From, cfg.SequenceSender.MaxTxSizeForL1)
txBuilder = txbuilder.NewTxBuilderBananaZKEVM(ethman.Contracts.Banana.Rollup, ethman.Contracts.Banana.GlobalExitRoot, *auth, cfg.SequenceSender.MaxTxSizeForL1)
}
case contracts.VersionElderberry:
if cfg.Common.IsValidiumMode {
txBuilder = txbuilder.NewTxBuilderElderberryValidium(ethman.Contracts.Elderberry.Rollup, da, *auth, auth.From, cfg.SequenceSender.MaxBatchesForL1)
txBuilder = txbuilder.NewTxBuilderElderberryValidium(ethman.Contracts.Elderberry.Rollup, da, *auth, cfg.SequenceSender.MaxBatchesForL1)
} else {
txBuilder = txbuilder.NewTxBuilderElderberryZKEVM(ethman.Contracts.Elderberry.Rollup, *auth, auth.From, cfg.SequenceSender.MaxTxSizeForL1)
txBuilder = txbuilder.NewTxBuilderElderberryZKEVM(ethman.Contracts.Elderberry.Rollup, *auth, cfg.SequenceSender.MaxTxSizeForL1)
}
default:
err = fmt.Errorf("unknown contract version: %s", cfg.Common.ContractVersions)
Expand Down
4 changes: 2 additions & 2 deletions dataavailability/dataavailability.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func New(backend DABackender) (*DataAvailability, error) {
return da, da.backend.Init()
}

func (d *DataAvailability) PostSequence(ctx context.Context, sequenceBanana etherman.SequenceBanana) ([]byte, error) {
return d.backend.PostSequence(ctx, sequenceBanana)
func (d *DataAvailability) PostSequenceBanana(ctx context.Context, sequenceBanana etherman.SequenceBanana) ([]byte, error) {
return d.backend.PostSequenceBanana(ctx, sequenceBanana)
}

func (d *DataAvailability) PostSequenceElderberry(ctx context.Context, batchesData [][]byte) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion dataavailability/datacommittee/datacommittee.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (d *Backend) PostSequenceElderberry(ctx context.Context, batchesData [][]by
return collectSignatures(committee, ch, cancelSignatureCollection)
}

func (d *Backend) PostSequence(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) {
func (d *Backend) PostSequenceBanana(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error) {
// Get current committee
committee, err := d.getCurrentDataCommittee()
if err != nil {
Expand Down
12 changes: 7 additions & 5 deletions dataavailability/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ type DABackender interface {

// SequenceSender is used to send provided sequence of batches
type SequenceSender interface {
SequenceSenderElderberry
SequenceSenderBanana
}

type SequenceSenderElderberry interface {
// PostSequence sends the sequence data to the data availability backend, and returns the dataAvailabilityMessage
// as expected by the contract
PostSequence(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error)
// PostSequenceElderberry sends the sequence data to the data availability backend, and returns the dataAvailabilityMessage
// as expected by the contract
PostSequenceElderberry(ctx context.Context, batchesData [][]byte) ([]byte, error)
}

type SequenceSenderElderberry interface {
type SequenceSenderBanana interface {
// PostSequence sends the sequence data to the data availability backend, and returns the dataAvailabilityMessage
// as expected by the contract
PostSequenceElderberry(ctx context.Context, batchesData [][]byte) ([]byte, error)
PostSequenceBanana(ctx context.Context, sequence etherman.SequenceBanana) ([]byte, error)
}

// SequenceRetriever is used to retrieve batch data
Expand Down
96 changes: 96 additions & 0 deletions dataavailability/mocks_da/batch_data_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 12d1e3f

Please sign in to comment.