-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/3518 use generic eth client for l2 #3519
Changes from all commits
70c772e
4d2c48f
4490897
3a4fa3f
7443e41
39a489c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import ( | |
"math/big" | ||
"testing" | ||
|
||
rpctypes "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"github.com/0xPolygonHermez/zkevm-node/state" | ||
"github.com/0xPolygonHermez/zkevm-node/synchronizer/actions" | ||
mock_syncinterfaces "github.com/0xPolygonHermez/zkevm-node/synchronizer/common/syncinterfaces/mocks" | ||
|
@@ -19,7 +18,7 @@ import ( | |
type CheckL2BlocksTestData struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. } |
||
sut *actions.CheckL2BlockHash | ||
mockState *mock_syncinterfaces.StateFullInterface | ||
zKEVMClient *mock_syncinterfaces.ZKEVMClientInterface | ||
zKEVMClient *mock_syncinterfaces.ZKEVMClientEthereumCompatibleInterface | ||
} | ||
|
||
func TestCheckL2BlockHash_GetMinimumL2BlockToCheck(t *testing.T) { | ||
|
@@ -57,7 +56,7 @@ func TestCheckL2BlockHashNotEnoughBlocksToCheck(t *testing.T) { | |
func newCheckL2BlocksTestData(t *testing.T, initialL2Block, modulus uint64) CheckL2BlocksTestData { | ||
res := CheckL2BlocksTestData{ | ||
mockState: mock_syncinterfaces.NewStateFullInterface(t), | ||
zKEVMClient: mock_syncinterfaces.NewZKEVMClientInterface(t), | ||
zKEVMClient: mock_syncinterfaces.NewZKEVMClientEthereumCompatibleInterface(t), | ||
} | ||
res.sut = actions.NewCheckL2BlockHash(res.mockState, res.zKEVMClient, initialL2Block, modulus) | ||
return res | ||
|
@@ -97,18 +96,23 @@ func TestCheckL2BlockHashMatch(t *testing.T) { | |
|
||
data.mockState.EXPECT().GetLastL2BlockNumber(mock.Anything, mock.Anything).Return(lastL2Block, nil) | ||
data.mockState.EXPECT().GetL2BlockByNumber(mock.Anything, lastL2Block, mock.Anything).Return(stateBlock, nil) | ||
l2blockHash := stateBlock.Hash() | ||
rpcL2Block := rpctypes.Block{ | ||
Hash: &l2blockHash, | ||
Number: rpctypes.ArgUint64(lastL2Block), | ||
} | ||
//l2blockHash := stateBlock.Hash() | ||
// rpcL2Block := rpctypes.Block{ | ||
// Hash: &l2blockHash, | ||
// Number: rpctypes.ArgUint64(lastL2Block), | ||
// } | ||
// create a types.Block object | ||
|
||
rpcL2Block := types.NewBlock(&types.Header{ | ||
Number: big.NewInt(int64(lastL2Block)), | ||
}, nil, nil, nil, nil) | ||
|
||
data.zKEVMClient.EXPECT().BlockByNumber(mock.Anything, lastL2BlockBigInt).Return(&rpcL2Block, nil) | ||
data.zKEVMClient.EXPECT().BlockByNumber(mock.Anything, lastL2BlockBigInt).Return(rpcL2Block, nil) | ||
err := data.sut.CheckL2Block(context.Background(), nil) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestCheckL2BlockHashMissmatch(t *testing.T) { | ||
func TestCheckL2BlockHashMismatch(t *testing.T) { | ||
data := newCheckL2BlocksTestData(t, 1, 10) | ||
lastL2Block := uint64(14) | ||
lastL2BlockBigInt := big.NewInt(int64(lastL2Block)) | ||
|
@@ -119,13 +123,14 @@ func TestCheckL2BlockHashMissmatch(t *testing.T) { | |
|
||
data.mockState.EXPECT().GetLastL2BlockNumber(mock.Anything, mock.Anything).Return(lastL2Block, nil) | ||
data.mockState.EXPECT().GetL2BlockByNumber(mock.Anything, lastL2Block, mock.Anything).Return(stateBlock, nil) | ||
l2blockHash := common.HexToHash("0x1234") | ||
rpcL2Block := rpctypes.Block{ | ||
Hash: &l2blockHash, | ||
Number: rpctypes.ArgUint64(lastL2Block), | ||
} | ||
//l2blockHash := common.HexToHash("0x1234") | ||
|
||
rpcL2Block := types.NewBlock(&types.Header{ | ||
Number: big.NewInt(int64(lastL2Block)), | ||
ParentHash: common.HexToHash("0x1234"), | ||
}, nil, nil, nil, nil) | ||
|
||
data.zKEVMClient.EXPECT().BlockByNumber(mock.Anything, lastL2BlockBigInt).Return(&rpcL2Block, nil) | ||
data.zKEVMClient.EXPECT().BlockByNumber(mock.Anything, lastL2BlockBigInt).Return(rpcL2Block, nil) | ||
err := data.sut.CheckL2Block(context.Background(), nil) | ||
require.Error(t, err) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package syncinterfaces | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
// ZKEVMClientEthereumCompatibleInterface contains the methods required to interact with zkEVM-RPC as a ethereum-API compatible | ||
// | ||
// Reason behind: the zkEVMClient have some extensions to ethereum-API that are not compatible with all nodes. So if you need to maximize | ||
// the compatibility the idea is to use a regular ethereum-API compatible client | ||
type ZKEVMClientEthereumCompatibleInterface interface { | ||
ZKEVMClientEthereumCompatibleL2BlockGetter | ||
} | ||
|
||
// ZKEVMClientEthereumCompatibleL2BlockGetter contains the methods required to interact with zkEVM-RPC as a ethereum-API compatible for obtain Block information | ||
type ZKEVMClientEthereumCompatibleL2BlockGetter interface { | ||
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.