Skip to content

Commit

Permalink
test: bridge e2e testing (#57)
Browse files Browse the repository at this point in the history
* tests: PoC bridge testing with bats
* Run bats in e2e
* Remove unused make lines
* test: Send EOA and deploy contract E2E tests using Bats (#69)
* feat: add helper functions for contract deployment and sending transactions using cast commands
* feat: send EOA transaction test basic
* feat: deploy ERC20Mock contract E2E test

---------

Co-authored-by: Stefan Negovanović <[email protected]>
  • Loading branch information
vcastellm and Stefan-Ethernal committed Sep 17, 2024
1 parent 3dbaa84 commit 44e71ff
Show file tree
Hide file tree
Showing 49 changed files with 1,251 additions and 179 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@v3
- name: Lint
run: |
make install-linter
make lint
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61
args: --timeout=30m
4 changes: 4 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ jobs:
repository: 0xPolygon/kurtosis-cdk
path: "kurtosis-cdk"

- name: Setup Bats and bats libs
uses: bats-core/[email protected]

- name: Test
run: make test-e2e-${{ matrix.e2e-group }}
working-directory: test
env:
KURTOSIS_FOLDER: ${{ github.workspace }}/kurtosis-cdk
BATS_LIB_PATH: /usr/lib/
86 changes: 41 additions & 45 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,65 @@
run:
timeout: 3m
tests: true
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
skip-dirs:
- tests
- aggregator/db/migrations

service:
golangci-lint-version: 1.59.1
golangci-lint-version: 1.61.0

linters:
disable-all: true
enable:
- whitespace # Tool for detection of leading and trailing whitespace
# - wsl # Forces you to use empty lines
- wastedassign # Finds wasted assignment statements
- unconvert # Unnecessary type conversions
- tparallel # Detects inappropriate usage of t.Parallel() method in your Go test codes
- thelper # Detects golang test helpers without t.Helper() call and checks the consistency of test helpers
- stylecheck # Stylecheck is a replacement for golint
- prealloc # Finds slice declarations that could potentially be pre-allocated
- predeclared # Finds code that shadows one of Go's predeclared identifiers
- nolintlint # Ill-formed or insufficient nolint directives
# - nlreturn # Checks for a new line before return and branch statements to increase code clarity
- misspell # Misspelled English words in comments
- makezero # Finds slice declarations with non-zero initial length
- lll # Long lines
- importas # Enforces consistent import aliases
- gosec # Security problems
- gofmt # Whether the code was gofmt-ed
- goimports # Unused imports
- goconst # Repeated strings that could be replaced by a constant
- forcetypeassert # Finds forced type assertions
- dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
- dupl # Code clone detection
- errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13
- gocritic # gocritic is a Go source code linter that maintains checks that are not in other linters
- errcheck # Errcheck is a go lint rule for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
# - godox # Godox is a linter for TODOs and FIXMEs left in the code
- gci # Gci is a linter for checking the consistency of the code with the go code style guide
- gomnd # Gomnd is a linter for magic numbers
# - revive
- unparam # Unparam is a linter for unused function parameters
- whitespace # Tool for detection of leading and trailing whitespace
# - wsl # Forces you to use empty lines
- wastedassign # Finds wasted assignment statements
- unconvert # Unnecessary type conversions
- tparallel # Detects inappropriate usage of t.Parallel() method in your Go test codes
- thelper # Detects golang test helpers without t.Helper() call and checks the consistency of test helpers
- stylecheck # Stylecheck is a replacement for golint
- prealloc # Finds slice declarations that could potentially be pre-allocated
- predeclared # Finds code that shadows one of Go's predeclared identifiers
- nolintlint # Ill-formed or insufficient nolint directives
# - nlreturn # Checks for a new line before return and branch statements to increase code clarity
- misspell # Misspelled English words in comments
- makezero # Finds slice declarations with non-zero initial length
- lll # Long lines
- importas # Enforces consistent import aliases
- gosec # Security problems
- gofmt # Whether the code was gofmt-ed
- goimports # Unused imports
- goconst # Repeated strings that could be replaced by a constant
- forcetypeassert # Finds forced type assertions
- dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
- dupl # Code clone detection
- errname # Checks that sentinel errors are prefixed with Err and error types are suffixed with Error
- errorlint # Error wrapping introduced in Go 1.13
- gocritic # gocritic is a Go source code linter that maintains checks that are not in other linters
- errcheck # Errcheck is a go lint rule for checking for unchecked errors
# - godox # Linter for TODOs and FIXMEs left in the code
- gci # Gci checks the consistency of the code with the Go code style guide
- mnd # mnd is a linter for magic numbers
# - revive
- unparam # Unused function parameters

linters-settings:
gofmt:
simplify: true
gocritic:
enabled-checks:
- ruleguard
# settings:
# ruleguard:
# rules: "./gorules/rules.go"
revive:
rules:
- name: exported
arguments:
- disableStutteringCheck
- name: exported
arguments:
- disableStutteringCheck
goconst:
min-len: 3
min-occurrences: 3
gosec:
excludes:
- G115 # Potential integer overflow when converting between integer types

issues:
# new-from-rev: origin/develop # report only new issues with reference to develop branch
whole-files: true
exclude-rules:
- path: '(_test\.go|^test/.*)'
Expand All @@ -78,9 +72,11 @@ issues:
- path: 'etherman/contracts/contracts_(banana|elderberry)\.go'
linters:
- dupl
exclude-dirs:
- tests
- aggregator/db/migrations
include:
- EXC0012 # Exported (.+) should have comment( \(or a comment on this block\))? or be unexported
- EXC0013 # Package comment should be of the form "(.+)...
- EXC0014 # Comment on exported (.+) should be of the form "(.+)..."
- EXC0015 # Should have a package comment

20 changes: 0 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ LDFLAGS += -X 'github.com/0xPolygon/cdk.GitRev=$(GITREV)'
LDFLAGS += -X 'github.com/0xPolygon/cdk.GitBranch=$(GITBRANCH)'
LDFLAGS += -X 'github.com/0xPolygon/cdk.BuildDate=$(DATE)'

# Variables
VENV = .venv
VENV_PYTHON = $(VENV)/bin/python
SYSTEM_PYTHON = $(or $(shell which python3), $(shell which python))
PYTHON = $(or $(wildcard $(VENV_PYTHON)), "install_first_venv")
GENERATE_SCHEMA_DOC = $(VENV)/bin/generate-schema-doc
GENERATE_DOC_PATH = "docs/config-file/"
GENERATE_DOC_TEMPLATES_PATH = "docs/config-file/templates/"

# Check dependencies
# Check for Go
.PHONY: check-go
Expand Down Expand Up @@ -87,22 +78,11 @@ test-unit:
.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

.PHONY: lint
lint: ## Runs the linter
export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/golangci-lint run --timeout 5m

$(VENV_PYTHON):
rm -rf $(VENV)
$(SYSTEM_PYTHON) -m venv $(VENV)

venv: $(VENV_PYTHON)

.PHONY: generate-code-from-proto
generate-code-from-proto: ## Generates code from proto files
cd proto/src/proto/aggregator/v1 && protoc --proto_path=. --proto_path=../../../../include --go_out=../../../../../aggregator/prover --go-grpc_out=../../../../../aggregator/prover --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative aggregator.proto
Expand Down
9 changes: 6 additions & 3 deletions aggoracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ func (a *AggOracle) Start(ctx context.Context) {
case <-a.ticker.C:
blockNumToFetch, gerToInject, err = a.getLastFinalisedGER(ctx, blockNumToFetch)
if err != nil {
if errors.Is(err, l1infotreesync.ErrBlockNotProcessed) {
switch {
case errors.Is(err, l1infotreesync.ErrBlockNotProcessed):
a.logger.Debugf("syncer is not ready for the block %d", blockNumToFetch)
} else if errors.Is(err, l1infotreesync.ErrNotFound) {

case errors.Is(err, l1infotreesync.ErrNotFound):
blockNumToFetch = 0
a.logger.Debugf("syncer has not found any GER until block %d", blockNumToFetch)
} else {

default:
a.logger.Error("error calling getLastFinalisedGER: ", err)
}

Expand Down
18 changes: 12 additions & 6 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func (a *Aggregator) handleReorg(reorgData synchronizer.ReorgExecutionResult) {
"Halting the aggregator due to a L1 reorg. " +
"Reorged data has been deleted, so it is safe to manually restart the aggregator.",
)
time.Sleep(10 * time.Second) //nolint:gomnd
time.Sleep(10 * time.Second) //nolint:mnd
}
}

Expand Down Expand Up @@ -377,6 +377,7 @@ func (a *Aggregator) handleRollbackBatches(rollbackData synchronizer.RollbackBat
}

marshalledBookMark, err = proto.Marshal(bookMark)
//nolint:gocritic
if err != nil {
a.logger.Error("failed to marshal bookmark: %v", err)
} else {
Expand Down Expand Up @@ -405,7 +406,7 @@ func (a *Aggregator) handleRollbackBatches(rollbackData synchronizer.RollbackBat
a.halted.Store(true)
for {
a.logger.Errorf("Halting the aggregator due to an error handling rollback batches event: %v", err)
time.Sleep(10 * time.Second) //nolint:gomnd
time.Sleep(10 * time.Second) //nolint:mnd
}
}
}
Expand Down Expand Up @@ -1149,6 +1150,7 @@ func (a *Aggregator) validateEligibleFinalProof(
batchNumberToVerify := lastVerifiedBatchNum + 1

if proof.BatchNumber != batchNumberToVerify {
//nolint:gocritic
if proof.BatchNumber < batchNumberToVerify &&
proof.BatchNumberFinal >= batchNumberToVerify {
// We have a proof that contains some batches below the last batch verified, anyway can be eligible as final proof
Expand Down Expand Up @@ -1728,8 +1730,9 @@ func (a *Aggregator) buildInputProver(
l1InfoTreeData := map[uint32]*prover.L1Data{}
forcedBlockhashL1 := common.Hash{}
l1InfoRoot := batchToVerify.L1InfoRoot.Bytes()
//nolint:gocritic
if !isForcedBatch {
tree, err := l1infotree.NewL1InfoTree(a.logger, 32, [][32]byte{}) //nolint:gomnd
tree, err := l1infotree.NewL1InfoTree(a.logger, 32, [][32]byte{}) //nolint:mnd
if err != nil {
return nil, err
}
Expand All @@ -1741,7 +1744,10 @@ func (a *Aggregator) buildInputProver(

aLeaves := make([][32]byte, len(leaves))
for i, leaf := range leaves {
aLeaves[i] = l1infotree.HashLeafData(leaf.GlobalExitRoot, leaf.PreviousBlockHash, uint64(leaf.Timestamp.Unix()))
aLeaves[i] = l1infotree.HashLeafData(
leaf.GlobalExitRoot,
leaf.PreviousBlockHash,
uint64(leaf.Timestamp.Unix()))
}

for _, l2blockRaw := range batchRawData.Blocks {
Expand Down Expand Up @@ -1836,7 +1842,7 @@ func (a *Aggregator) buildInputProver(
return inputProver, nil
}

func (a *Aggregator) getWitness(batchNumber uint64, URL string, fullWitness bool) ([]byte, error) {
func (a *Aggregator) getWitness(batchNumber uint64, url string, fullWitness bool) ([]byte, error) {
var (
witness string
response rpc.Response
Expand All @@ -1850,7 +1856,7 @@ func (a *Aggregator) getWitness(batchNumber uint64, URL string, fullWitness bool

a.logger.Infof("Requesting witness for batch %d of type %s", batchNumber, witnessType)

response, err = rpc.JSONRPCCall(URL, "zkevm_getBatchWitness", batchNumber, witnessType)
response, err = rpc.JSONRPCCall(url, "zkevm_getBatchWitness", batchNumber, witnessType)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions aggregator/profitabilitychecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ func NewTxProfitabilityCheckerBase(

// IsProfitable checks pol collateral with min reward
func (pc *TxProfitabilityCheckerBase) IsProfitable(ctx context.Context, polCollateral *big.Int) (bool, error) {
//if pc.IntervalAfterWhichBatchSentAnyway != 0 {
// if pc.IntervalAfterWhichBatchSentAnyway != 0 {
// ok, err := isConsolidatedBatchAppeared(ctx, pc.State, pc.IntervalAfterWhichBatchSentAnyway)
// if err != nil {
// return false, err
// }
// if ok {
// return true, nil
// }
//}
// }
return polCollateral.Cmp(pc.MinReward) >= 0, nil
}

Expand All @@ -64,20 +64,20 @@ func NewTxProfitabilityCheckerAcceptAll(state stateInterface, interval time.Dura

// IsProfitable validate batch anyway and don't check anything
func (pc *TxProfitabilityCheckerAcceptAll) IsProfitable(ctx context.Context, polCollateral *big.Int) (bool, error) {
//if pc.IntervalAfterWhichBatchSentAnyway != 0 {
// if pc.IntervalAfterWhichBatchSentAnyway != 0 {
// ok, err := isConsolidatedBatchAppeared(ctx, pc.State, pc.IntervalAfterWhichBatchSentAnyway)
// if err != nil {
// return false, err
// }
// if ok {
// return true, nil
// }
//}
// }
return true, nil
}

// TODO: now it's impossible to check, when batch got consolidated, bcs it's not saved
//func isConsolidatedBatchAppeared(ctx context.Context, state stateInterface,
// func isConsolidatedBatchAppeared(ctx context.Context, state stateInterface,
// intervalAfterWhichBatchConsolidatedAnyway time.Duration) (bool, error) {
// batch, err := state.GetLastVerifiedBatch(ctx, nil)
// if err != nil {
Expand All @@ -89,4 +89,4 @@ func (pc *TxProfitabilityCheckerAcceptAll) IsProfitable(ctx context.Context, pol
// }
//
// return false, err
//}
// }
14 changes: 7 additions & 7 deletions aggregator/prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,13 @@ func fea2scalar(v []uint64) *big.Int {
return big.NewInt(0)
}
res := new(big.Int).SetUint64(v[0])
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[1]), 32)) //nolint:gomnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[2]), 64)) //nolint:gomnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[3]), 96)) //nolint:gomnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[4]), 128)) //nolint:gomnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[5]), 160)) //nolint:gomnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[6]), 192)) //nolint:gomnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[7]), 224)) //nolint:gomnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[1]), 32)) //nolint:mnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[2]), 64)) //nolint:mnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[3]), 96)) //nolint:mnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[4]), 128)) //nolint:mnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[5]), 160)) //nolint:mnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[6]), 192)) //nolint:mnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[7]), 224)) //nolint:mnd

return res
}
10 changes: 7 additions & 3 deletions claimsponsor/claimsponsor.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,19 @@ func (c *ClaimSponsor) AddClaimToQueue(ctx context.Context, claim *Claim) error

var queuePosition uint64
lastQueuePosition, _, err := getLastQueueIndex(tx)
if errors.Is(err, ErrNotFound) {
switch {
case errors.Is(err, ErrNotFound):
queuePosition = 0
} else if err != nil {

case err != nil:
tx.Rollback()

return err
} else {

default:
queuePosition = lastQueuePosition + 1
}

err = tx.Put(queueTable, dbCommon.Uint64ToBytes(queuePosition), claim.Key())
if err != nil {
tx.Rollback()
Expand Down
1 change: 1 addition & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func start(cliCtx *cli.Context) error {
// start aggregator in a goroutine, checking for errors
go func() {
if err := aggregator.Start(); err != nil {
aggregator.Stop()
log.Fatal(err)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion config/types/duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestDurationUnmarshal(t *testing.T) {
err = json.Unmarshal(input, &d)

if testCase.expectedResult != nil {
require.Equal(t, (*testCase.expectedResult).Nanoseconds(), d.Nanoseconds())
require.Equal(t, testCase.expectedResult.Nanoseconds(), d.Nanoseconds())
}

if err != nil {
Expand Down
Loading

0 comments on commit 44e71ff

Please sign in to comment.