-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate the
aggoracle
contracts (#244)
* integrate new contracts for the aggoracle (wip) * feat: integrate the GlobalExitRootManager L2 sovereign chain * fix: backport changes from fep-type1 branch * chore: remove empty test/e2e.go * test: update the aggoracle e2e test * fix: logs * refactor: rely only on single L1 bridge syncer in the e2e, cleanup logs, handle context cancellation * refactor: simulated backend so that it correctly initializes bridge contract * fix: tests * fix: bridge balance logs * add extract rpc error data helper function * extract L1SetupResult and L2SetupResult * some more cleanups * fix: update import paths for l2-sovereign-chain contracts and use the Shanghai spec * refactor: rename waitTxToBeSuccessOrFail to waitForTxResult and update logging messages * chore: update cdk-contracts-tooling dependency to v0.0.1 * fix: remove duplicated recipes in test/makefile * test: chaingersender ut * test: IsGERInjected unit test * remove removal of mock files * rename
- Loading branch information
1 parent
6e5bd04
commit 52770bf
Showing
58 changed files
with
3,912 additions
and
649 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package chaingersender | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"math/big" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/0xPolygon/cdk/aggoracle/mocks" | ||
"github.com/0xPolygon/cdk/log" | ||
"github.com/0xPolygon/zkevm-ethtx-manager/types" | ||
"github.com/ethereum/go-ethereum/accounts/abi" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestEVMChainGERSender_InjectGER(t *testing.T) { | ||
insertGERFuncABI := `[{ | ||
"inputs": [ | ||
{ | ||
"internalType": "bytes32", | ||
"name": "_newRoot", | ||
"type": "bytes32" | ||
} | ||
], | ||
"name": "insertGlobalExitRoot", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}]` | ||
l2GERManagerAddr := common.HexToAddress("0x123") | ||
l2GERManagerAbi, err := abi.JSON(strings.NewReader(insertGERFuncABI)) | ||
require.NoError(t, err) | ||
|
||
ger := common.HexToHash("0x456") | ||
txID := common.HexToHash("0x789") | ||
|
||
tests := []struct { | ||
name string | ||
addReturnTxID common.Hash | ||
addReturnErr error | ||
resultReturn types.MonitoredTxResult | ||
resultReturnErr error | ||
expectedErr string | ||
}{ | ||
{ | ||
name: "successful injection", | ||
addReturnTxID: txID, | ||
addReturnErr: nil, | ||
resultReturn: types.MonitoredTxResult{Status: types.MonitoredTxStatusMined, MinedAtBlockNumber: big.NewInt(123)}, | ||
resultReturnErr: nil, | ||
expectedErr: "", | ||
}, | ||
{ | ||
name: "injection fails due to transaction failure", | ||
addReturnTxID: txID, | ||
addReturnErr: nil, | ||
resultReturn: types.MonitoredTxResult{Status: types.MonitoredTxStatusFailed}, | ||
resultReturnErr: nil, | ||
expectedErr: "inject GER tx", | ||
}, | ||
{ | ||
name: "injection fails due to Add method error", | ||
addReturnTxID: common.Hash{}, | ||
addReturnErr: errors.New("add error"), | ||
resultReturn: types.MonitoredTxResult{}, | ||
resultReturnErr: nil, | ||
expectedErr: "add error", | ||
}, | ||
{ | ||
name: "injection fails due to Result method error", | ||
addReturnTxID: txID, | ||
addReturnErr: nil, | ||
resultReturn: types.MonitoredTxResult{}, | ||
resultReturnErr: errors.New("result error"), | ||
expectedErr: "result error", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ctx, cancelFn := context.WithTimeout(context.Background(), time.Millisecond*500) | ||
defer cancelFn() | ||
|
||
ethTxMan := new(mocks.EthTxManagerMock) | ||
ethTxMan. | ||
On("Add", ctx, &l2GERManagerAddr, common.Big0, mock.Anything, mock.Anything, mock.Anything). | ||
Return(tt.addReturnTxID, tt.addReturnErr) | ||
ethTxMan. | ||
On("Result", ctx, tt.addReturnTxID). | ||
Return(tt.resultReturn, tt.resultReturnErr) | ||
|
||
sender := &EVMChainGERSender{ | ||
logger: log.GetDefaultLogger(), | ||
l2GERManagerAddr: l2GERManagerAddr, | ||
l2GERManagerAbi: &l2GERManagerAbi, | ||
ethTxMan: ethTxMan, | ||
waitPeriodMonitorTx: time.Millisecond * 10, | ||
} | ||
|
||
err := sender.InjectGER(ctx, ger) | ||
if tt.expectedErr == "" { | ||
require.NoError(t, err) | ||
} else { | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), tt.expectedErr) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestEVMChainGERSender_IsGERInjected(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
mockReturn *big.Int | ||
mockError error | ||
expectedResult bool | ||
expectedErrMsg string | ||
}{ | ||
{ | ||
name: "GER is injected", | ||
mockReturn: big.NewInt(1), | ||
mockError: nil, | ||
expectedResult: true, | ||
expectedErrMsg: "", | ||
}, | ||
{ | ||
name: "GER is not injected", | ||
mockReturn: big.NewInt(0), | ||
mockError: nil, | ||
expectedResult: false, | ||
expectedErrMsg: "", | ||
}, | ||
{ | ||
name: "Error checking GER injection", | ||
mockReturn: nil, | ||
mockError: errors.New("some error"), | ||
expectedResult: false, | ||
expectedErrMsg: "failed to check if global exit root is injected", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
mockL2GERManager := new(mocks.L2GERManagerMock) | ||
mockL2GERManager.On("GlobalExitRootMap", mock.Anything, mock.Anything). | ||
Return(tt.mockReturn, tt.mockError) | ||
|
||
evmChainGERSender := &EVMChainGERSender{ | ||
l2GERManager: mockL2GERManager, | ||
} | ||
|
||
ger := common.HexToHash("0x12345") | ||
result, err := evmChainGERSender.IsGERInjected(ger) | ||
if tt.expectedErrMsg != "" { | ||
require.ErrorContains(t, err, tt.expectedErrMsg) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
require.Equal(t, tt.expectedResult, result) | ||
|
||
mockL2GERManager.AssertExpectations(t) | ||
}) | ||
} | ||
} |
Oops, something went wrong.