Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaubennassar committed Nov 13, 2024
1 parent 05f8290 commit 3aef4be
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 99 deletions.
4 changes: 2 additions & 2 deletions aggoracle/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (

gerContractL1 "github.com/0xPolygon/cdk-contracts-tooling/contracts/manual/globalexitrootnopush0"
"github.com/0xPolygon/cdk/aggoracle"
"github.com/0xPolygon/cdk/test/aggoraclehelpers"
"github.com/0xPolygon/cdk/test/helpers"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/stretchr/testify/require"
)

func TestEVM(t *testing.T) {
env := aggoraclehelpers.SetupAggoracleWithEVMChain(t)
env := helpers.NewE2EEnvWithEVML2(t)
runTest(t, env.GERL1Contract, env.AggOracleSender, env.L1Client, env.AuthL1)
}

Expand Down
35 changes: 10 additions & 25 deletions bridgesync/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,19 @@ import (
"context"
"fmt"
"math/big"
"path"
"testing"
"time"

"github.com/0xPolygon/cdk/bridgesync"
"github.com/0xPolygon/cdk/etherman"
"github.com/0xPolygon/cdk/reorgdetector"
"github.com/0xPolygon/cdk/test/helpers"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
)

func TestBridgeEventE2E(t *testing.T) {
env := helpers.NewE2EEnvWithEVML2(t)
ctx := context.Background()
dbPathSyncer := path.Join(t.TempDir(), "file::memory:?cache=shared")
dbPathReorg := path.Join(t.TempDir(), "file::memory:?cache=shared")

client, setup := helpers.SimulatedBackend(t, nil, 0)
rd, err := reorgdetector.New(client.Client(), reorgdetector.Config{DBPath: dbPathReorg})
require.NoError(t, err)

go rd.Start(ctx) //nolint:errcheck

testClient := helpers.TestClient{ClientRenamed: client.Client()}
syncer, err := bridgesync.NewL1(ctx, dbPathSyncer, setup.EBZkevmBridgeAddr, 10, etherman.LatestBlock, rd, testClient, 0, time.Millisecond*10, 0, 0, 1)
require.NoError(t, err)

go syncer.Start(ctx)

// Send bridge txs
expectedBridges := []bridgesync.Bridge{}
Expand All @@ -46,31 +30,32 @@ func TestBridgeEventE2E(t *testing.T) {
DestinationAddress: common.HexToAddress("f00"),
Metadata: []byte{},
}
tx, err := setup.EBZkevmBridgeContract.BridgeAsset(
setup.UserAuth,
tx, err := env.BridgeL1Contract.BridgeAsset(
env.AuthL1,
bridge.DestinationNetwork,
bridge.DestinationAddress,
bridge.Amount,
bridge.OriginAddress,
false, nil,
)
require.NoError(t, err)
client.Commit()
receipt, err := client.Client().TransactionReceipt(ctx, tx.Hash())
env.L1Client.Commit()
receipt, err := env.L1Client.Client().TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
require.Equal(t, receipt.Status, types.ReceiptStatusSuccessful)
expectedBridges = append(expectedBridges, bridge)
}

// TODO: replace wait with the one in package helpers once merged
// Wait for syncer to catch up
syncerUpToDate := false

var errMsg string
lb, err := client.Client().BlockNumber(ctx)
lb, err := env.L1Client.Client().BlockNumber(ctx)
require.NoError(t, err)

for i := 0; i < 10; i++ {
lpb, err := syncer.GetLastProcessedBlock(ctx)
lpb, err := env.BridgeL1Sync.GetLastProcessedBlock(ctx)
require.NoError(t, err)
if lpb == lb {
syncerUpToDate = true
Expand All @@ -84,9 +69,9 @@ func TestBridgeEventE2E(t *testing.T) {
require.True(t, syncerUpToDate, errMsg)

// Get bridges
lastBlock, err := client.Client().BlockNumber(ctx)
lastBlock, err := env.L1Client.Client().BlockNumber(ctx)
require.NoError(t, err)
actualBridges, err := syncer.GetBridges(ctx, 0, lastBlock)
actualBridges, err := env.BridgeL1Sync.GetBridges(ctx, 0, lastBlock)
require.NoError(t, err)

// Assert bridges
Expand Down
11 changes: 3 additions & 8 deletions bridgesync/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,10 @@ type Event struct {
Claim *Claim
}

type BridgeContractor interface {
LastUpdatedDepositCount(ctx context.Context, BlockNumber uint64) (uint32, error)
}

type processor struct {
db *sql.DB
exitTree *tree.AppendOnlyTree
log *log.Logger
bridgeContract BridgeContractor
db *sql.DB
exitTree *tree.AppendOnlyTree
log *log.Logger
}

func newProcessor(dbPath, loggerPrefix string) (*processor, error) {
Expand Down
9 changes: 0 additions & 9 deletions bridgesync/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,15 +773,6 @@ func TestInsertAndGetClaim(t *testing.T) {
require.Equal(t, testClaim, &claims[0])
}

type mockBridgeContract struct {
lastUpdatedDepositCount uint32
err error
}

func (m *mockBridgeContract) LastUpdatedDepositCount(ctx context.Context, blockNumber uint64) (uint32, error) {
return m.lastUpdatedDepositCount, m.err
}

func TestGetBridgesPublished(t *testing.T) {
t.Parallel()

Expand Down
5 changes: 2 additions & 3 deletions claimsponsor/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/0xPolygon/cdk/claimsponsor"
"github.com/0xPolygon/cdk/etherman"
"github.com/0xPolygon/cdk/log"
"github.com/0xPolygon/cdk/test/aggoraclehelpers"
"github.com/0xPolygon/cdk/test/helpers"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -23,10 +22,10 @@ import (
func TestE2EL1toEVML2(t *testing.T) {
// start other needed components
ctx := context.Background()
env := aggoraclehelpers.SetupAggoracleWithEVMChain(t)
env := helpers.NewE2EEnvWithEVML2(t)
dbPathBridgeSyncL1 := path.Join(t.TempDir(), "file::memory:?cache=shared")
testClient := helpers.TestClient{ClientRenamed: env.L1Client.Client()}
bridgeSyncL1, err := bridgesync.NewL1(ctx, dbPathBridgeSyncL1, env.BridgeL1Addr, 10, etherman.LatestBlock, env.ReorgDetector, testClient, 0, time.Millisecond*10, 0, 0, 1)
bridgeSyncL1, err := bridgesync.NewL1(ctx, dbPathBridgeSyncL1, env.BridgeL1Addr, 10, etherman.LatestBlock, env.ReorgDetectorL1, testClient, 0, time.Millisecond*10, 0, 0, 1)
require.NoError(t, err)
go bridgeSyncL1.Start(ctx)

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ require (
)

require (
github.com/0xPolygonHermez/zkevm-data-streamer v0.2.7 // indirect
github.com/DataDog/zstd v1.5.6 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
Expand Down
11 changes: 2 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ github.com/0xPolygon/cdk-rpc v0.0.0-20241004114257-6c3cb6eebfb6 h1:FXL/rcO7/GtZ3
github.com/0xPolygon/cdk-rpc v0.0.0-20241004114257-6c3cb6eebfb6/go.mod h1:2scWqMMufrQXu7TikDgQ3BsyaKoX8qP26D6E262vSOg=
github.com/0xPolygon/zkevm-ethtx-manager v0.2.1 h1:2Yb+KdJFMpVrS9LIkd658XiWuN+MCTs7SgeWaopXScg=
github.com/0xPolygon/zkevm-ethtx-manager v0.2.1/go.mod h1:lqQmzSo2OXEZItD0R4Cd+lqKFxphXEWgqHefVcGDZZc=
github.com/0xPolygonHermez/zkevm-data-streamer v0.2.7/go.mod h1:7nM7Ihk+fTG1TQPwdZoGOYd3wprqqyIyjtS514uHzWE=
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 Expand Up @@ -481,18 +480,15 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ=
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE=
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo=
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand All @@ -512,8 +508,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -575,9 +569,8 @@ golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapK
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o=
golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q=
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
6 changes: 3 additions & 3 deletions lastgersync/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import (

"github.com/0xPolygon/cdk/etherman"
"github.com/0xPolygon/cdk/lastgersync"
"github.com/0xPolygon/cdk/test/aggoraclehelpers"
"github.com/0xPolygon/cdk/test/helpers"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)

func TestE2E(t *testing.T) {
ctx := context.Background()
env := aggoraclehelpers.SetupAggoracleWithEVMChain(t)
env := helpers.NewE2EEnvWithEVML2(t)
dbPathSyncer := path.Join(t.TempDir(), "file::memory:?cache=shared")
syncer, err := lastgersync.New(
ctx,
dbPathSyncer,
env.ReorgDetector,
env.ReorgDetectorL1,
env.L2Client.Client(),
env.GERL2Addr,
env.L1InfoTreeSync,
Expand Down
8 changes: 4 additions & 4 deletions reorgdetector/reorgdetector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"time"

cdktypes "github.com/0xPolygon/cdk/config/types"
"github.com/0xPolygon/cdk/test/helpers"
common "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/stretchr/testify/require"
)

Expand All @@ -19,7 +19,7 @@ func Test_ReorgDetector(t *testing.T) {
ctx := context.Background()

// Simulated L1
clientL1, _ := helpers.SimulatedBackend(t, nil, 0)
clientL1 := simulated.NewBackend(nil, simulated.WithBlockGasLimit(10000000))

// Create test DB dir
testDir := path.Join(t.TempDir(), "file::memory:?cache=shared")
Expand Down Expand Up @@ -74,7 +74,7 @@ func Test_ReorgDetector(t *testing.T) {
}

func TestGetTrackedBlocks(t *testing.T) {
clientL1, _ := helpers.SimulatedBackend(t, nil, 0)
clientL1 := simulated.NewBackend(nil, simulated.WithBlockGasLimit(10000000))
testDir := path.Join(t.TempDir(), "file::memory:?cache=shared")
reorgDetector, err := New(clientL1.Client(), Config{DBPath: testDir, CheckReorgsInterval: cdktypes.NewDuration(time.Millisecond * 100)})
require.NoError(t, err)
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestGetTrackedBlocks(t *testing.T) {
}

func TestNotSubscribed(t *testing.T) {
clientL1, _ := helpers.SimulatedBackend(t, nil, 0)
clientL1 := simulated.NewBackend(nil, simulated.WithBlockGasLimit(10000000))
testDir := path.Join(t.TempDir(), "file::memory:?cache=shared")
reorgDetector, err := New(clientL1.Client(), Config{DBPath: testDir, CheckReorgsInterval: cdktypes.NewDuration(time.Millisecond * 100)})
require.NoError(t, err)
Expand Down
Loading

0 comments on commit 3aef4be

Please sign in to comment.