Skip to content

Commit

Permalink
cover halted queries
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaubennassar committed Oct 31, 2024
1 parent 296daab commit 55da82b
Show file tree
Hide file tree
Showing 8 changed files with 467 additions and 11 deletions.
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ github.com/0xPolygon/zkevm-ethtx-manager v0.2.0 h1:QWE6nKBBHkMEiza723hJk0+oZbLSd
github.com/0xPolygon/zkevm-ethtx-manager v0.2.0/go.mod h1:lqQmzSo2OXEZItD0R4Cd+lqKFxphXEWgqHefVcGDZZc=
github.com/0xPolygonHermez/zkevm-data-streamer v0.2.7 h1:73sYxRQ9cOmtYBEyHePgEwrVULR+YruSQxVXCt/SmzU=
github.com/0xPolygonHermez/zkevm-data-streamer v0.2.7/go.mod h1:7nM7Ihk+fTG1TQPwdZoGOYd3wprqqyIyjtS514uHzWE=
github.com/0xPolygonHermez/zkevm-synchronizer-l1 v1.0.4 h1:+ZbyEpaBZu88jWtov/7iBWvwgBMu5cxlvAFDxsPrnGQ=
github.com/0xPolygonHermez/zkevm-synchronizer-l1 v1.0.4/go.mod h1:X4Su/M/+hSISqdl9yomKlRsbTyuZHsRohporyHsP8gg=
github.com/0xPolygonHermez/zkevm-synchronizer-l1 v1.0.5 h1:YmnhuCl349MoNASN0fMeGKU1o9HqJhiZkfMsA/1cTRA=
github.com/0xPolygonHermez/zkevm-synchronizer-l1 v1.0.5/go.mod h1:X4Su/M/+hSISqdl9yomKlRsbTyuZHsRohporyHsP8gg=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
Expand Down
259 changes: 259 additions & 0 deletions l1infotreesync/cover.out

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions l1infotreesync/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"testing"

"github.com/0xPolygon/cdk-contracts-tooling/contracts/banana/polygonzkevmglobalexitrootv2"
mocks_l1infotreesync "github.com/0xPolygon/cdk/l1infotreesync/mocks"
"github.com/0xPolygon/cdk/l1infotreesync/mocks"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

func TestBuildAppenderErrorOnBadContractAddr(t *testing.T) {
l1Client := mocks_l1infotreesync.NewEthClienter(t)
l1Client := mocks.NewEthClienter(t)
globalExitRoot := common.HexToAddress("0x1")
rollupManager := common.HexToAddress("0x2")
l1Client.EXPECT().CallContract(mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("test-error"))
Expand All @@ -25,7 +25,7 @@ func TestBuildAppenderErrorOnBadContractAddr(t *testing.T) {
}

func TestBuildAppenderBypassBadContractAddr(t *testing.T) {
l1Client := mocks_l1infotreesync.NewEthClienter(t)
l1Client := mocks.NewEthClienter(t)
globalExitRoot := common.HexToAddress("0x1")
rollupManager := common.HexToAddress("0x2")
l1Client.EXPECT().CallContract(mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("test-error"))
Expand All @@ -35,7 +35,7 @@ func TestBuildAppenderBypassBadContractAddr(t *testing.T) {
}

func TestBuildAppenderVerifiedContractAddr(t *testing.T) {
l1Client := mocks_l1infotreesync.NewEthClienter(t)
l1Client := mocks.NewEthClienter(t)
globalExitRoot := common.HexToAddress("0x1")
rollupManager := common.HexToAddress("0x2")

Expand Down
3 changes: 2 additions & 1 deletion l1infotreesync/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
cdktypes "github.com/0xPolygon/cdk/config/types"
"github.com/0xPolygon/cdk/etherman"
"github.com/0xPolygon/cdk/l1infotreesync"
"github.com/0xPolygon/cdk/l1infotreesync/mocks"
"github.com/0xPolygon/cdk/log"
"github.com/0xPolygon/cdk/reorgdetector"
"github.com/0xPolygon/cdk/test/contracts/verifybatchesmock"
Expand Down Expand Up @@ -60,7 +61,7 @@ func TestE2E(t *testing.T) {
ctx, cancelCtx := context.WithCancel(context.Background())
dbPath := path.Join(t.TempDir(), "file::memory:?cache=shared")

rdm := l1infotreesync.NewReorgDetectorMock(t)
rdm := mocks.NewReorgDetectorMock(t)
rdm.On("Subscribe", mock.Anything).Return(&reorgdetector.Subscription{}, nil)
rdm.On("AddBlockToTrack", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)

Expand Down
198 changes: 198 additions & 0 deletions l1infotreesync/l1infotreesync_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
package l1infotreesync

import (
"context"
"errors"
"testing"

"github.com/0xPolygon/cdk/sync"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)

func TestGetL1InfoTreeMerkleProof(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, _, err := s.GetL1InfoTreeMerkleProof(context.Background(), 0)
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetRollupExitTreeMerkleProof(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetRollupExitTreeMerkleProof(context.Background(), 0, common.Hash{})
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetLatestInfoUntilBlock(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetLatestInfoUntilBlock(context.Background(), 0)
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetInfoByIndex(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetInfoByIndex(context.Background(), 0)
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetL1InfoTreeRootByIndex(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetL1InfoTreeRootByIndex(context.Background(), 0)
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetLastRollupExitRoot(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetLastRollupExitRoot(context.Background())
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetLastL1InfoTreeRoot(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetLastL1InfoTreeRoot(context.Background())
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetLastProcessedBlock(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetLastProcessedBlock(context.Background())
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetLocalExitRoot(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetLocalExitRoot(context.Background(), 0, common.Hash{})
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetLastVerifiedBatches(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetLastVerifiedBatches(0)
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetFirstVerifiedBatches(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetFirstVerifiedBatches(0)
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetFirstVerifiedBatchesAfterBlock(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetFirstVerifiedBatchesAfterBlock(0, 0)
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetFirstL1InfoWithRollupExitRoot(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetFirstL1InfoWithRollupExitRoot(common.Hash{})
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetLastInfo(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetLastInfo()
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetFirstInfo(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetFirstInfo()
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetFirstInfoAfterBlock(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetFirstInfoAfterBlock(0)
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}

func TestGetL1InfoTreeMerkleProofFromIndexToRoot(t *testing.T) {
s := L1InfoTreeSync{
processor: &processor{
halted: true,
},
}
_, err := s.GetL1InfoTreeMerkleProofFromIndexToRoot(context.Background(), 0, common.Hash{})
require.Error(t, err)
require.True(t, errors.Is(err, sync.ErrInconsistentState))
}
2 changes: 1 addition & 1 deletion l1infotreesync/mocks/eth_clienter.go

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

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

4 changes: 2 additions & 2 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ generate-mocks-rpc: ## Generates mocks for rpc, using mockery tool
.PHONY: generate-mocks-l1infotreesync
generate-mocks-l1infotreesync: ## Generates mocks for l1infotreesync, using mockery tool
rm -Rf ../l1infotreesync/mocks
export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --all --case snake --dir ../l1infotreesync --output ../l1infotreesync/mocks --outpkg mocks_l1infotreesync ${COMMON_MOCKERY_PARAMS}
export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=ReorgDetector --dir=../sync --output=../l1infotreesync --outpkg=l1infotreesync --structname=ReorgDetectorMock --filename=mock_reorgdetector_test.go
export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --all --case snake --dir ../l1infotreesync --output ../l1infotreesync/mocks --outpkg mocks ${COMMON_MOCKERY_PARAMS}
export "GOROOT=$$(go env GOROOT)" && $$(go env GOPATH)/bin/mockery --name=ReorgDetector --dir=../sync --output=../l1infotreesync/mocks --outpkg=mocks --structname=ReorgDetectorMock --filename=mock_reorgdetector.go

.PHONY: generate-mocks-aggoracle
generate-mocks-helpers: ## Generates mocks for helpers , using mockery tool
Expand Down

0 comments on commit 55da82b

Please sign in to comment.