From 398777c4a60bbd2a95860567af97455ad75db18e Mon Sep 17 00:00:00 2001 From: Rachit Sonthalia Date: Tue, 26 Mar 2024 16:05:17 +0530 Subject: [PATCH] cr fix --- interop/executor.go | 13 ++-- interop/executor_test.go | 88 +++++------------------- mocks/db.generated.go | 2 +- mocks/eth_tx_manager.generated.go | 2 +- mocks/etherman.generated.go | 2 +- mocks/etherman_client.generated.go | 2 +- mocks/zk_evm_client.generated.go | 2 +- mocks/zk_evm_client_creator.generated.go | 2 +- 8 files changed, 28 insertions(+), 85 deletions(-) diff --git a/interop/executor.go b/interop/executor.go index 6c18d336..75d83d09 100644 --- a/interop/executor.go +++ b/interop/executor.go @@ -163,15 +163,14 @@ func (e *Executor) Execute(ctx context.Context, signedTx tx.SignedTx) error { } log.Debugf("get batch by number: %v", batch) - if batch == nil && (signedTx.Tx.ZKP.NewStateRoot != common.Hash{} || signedTx.Tx.ZKP.NewLocalExitRoot != common.Hash{}) { + if batch == nil { return fmt.Errorf( - "Mismatch detected, expected local exit root: %s actual: %s. expected state root: %s actual: %s", - signedTx.Tx.ZKP.NewLocalExitRoot.Hex(), - common.Hash{}.Hex(), - signedTx.Tx.ZKP.NewStateRoot.Hex(), - common.Hash{}.Hex(), + "unable to perform soundness check because batch number %v is undefined", + signedTx.Tx.NewVerifiedBatch, ) - } else if batch != nil && (batch.StateRoot != signedTx.Tx.ZKP.NewStateRoot || batch.LocalExitRoot != signedTx.Tx.ZKP.NewLocalExitRoot) { + } + + if batch.StateRoot != signedTx.Tx.ZKP.NewStateRoot || batch.LocalExitRoot != signedTx.Tx.ZKP.NewLocalExitRoot { return fmt.Errorf( "Mismatch detected, expected local exit root: %s actual: %s. expected state root: %s actual: %s", signedTx.Tx.ZKP.NewLocalExitRoot.Hex(), diff --git a/interop/executor_test.go b/interop/executor_test.go index 7638c4f8..120cdc31 100644 --- a/interop/executor_test.go +++ b/interop/executor_test.go @@ -166,6 +166,19 @@ func TestExecutor_VerifySignature(t *testing.T) { func TestExecutor_Execute(t *testing.T) { t.Parallel() + // Create a sample signed transaction for testing + signedTx := tx.SignedTx{ + Tx: tx.Tx{ + LastVerifiedBatch: 0, + NewVerifiedBatch: 1, + ZKP: tx.ZKP{ + NewStateRoot: common.BytesToHash([]byte("sampleNewStateRoot")), + NewLocalExitRoot: common.BytesToHash([]byte("sampleNewLocalExitRoot")), + Proof: []byte("sampleProof"), + }, + }, + } + t.Run("Batch is not nil and roots match", func(t *testing.T) { t.Parallel() @@ -176,19 +189,6 @@ func TestExecutor_Execute(t *testing.T) { executor := New(log.WithFields("test", "test"), cfg, interopAdminAddr, etherman, ethTxManager) - // Create a sample signed transaction for testing - signedTx := tx.SignedTx{ - Tx: tx.Tx{ - LastVerifiedBatch: 0, - NewVerifiedBatch: 1, - ZKP: tx.ZKP{ - NewStateRoot: common.BytesToHash([]byte("sampleNewStateRoot")), - NewLocalExitRoot: common.BytesToHash([]byte("sampleNewLocalExitRoot")), - Proof: []byte("sampleProof"), - }, - }, - } - // Mock the ZkEVMClientCreator.NewClient method mockZkEVMClientCreator := mocks.NewZkEVMClientClientCreatorMock(t) mockZkEVMClient := mocks.NewZkEVMClientMock(t) @@ -210,7 +210,7 @@ func TestExecutor_Execute(t *testing.T) { mockZkEVMClient.AssertExpectations(t) }) - t.Run("Returns expected error when Batch is nil and roots do not match", func(t *testing.T) { + t.Run("Returns expected error when Batch is nil", func(t *testing.T) { t.Parallel() cfg := &config.Config{} @@ -220,19 +220,6 @@ func TestExecutor_Execute(t *testing.T) { executor := New(log.WithFields("test", "test"), cfg, interopAdminAddr, etherman, ethTxManager) - // Create a sample signed transaction for testing - signedTx := tx.SignedTx{ - Tx: tx.Tx{ - LastVerifiedBatch: 0, - NewVerifiedBatch: 1, - ZKP: tx.ZKP{ - NewStateRoot: common.BytesToHash([]byte("sampleNewStateRoot")), - NewLocalExitRoot: common.BytesToHash([]byte("sampleNewLocalExitRoot")), - Proof: []byte("sampleProof"), - }, - }, - } - // Mock the ZkEVMClientCreator.NewClient method mockZkEVMClientCreator := mocks.NewZkEVMClientClientCreatorMock(t) mockZkEVMClient := mocks.NewZkEVMClientMock(t) @@ -247,56 +234,13 @@ func TestExecutor_Execute(t *testing.T) { err := executor.Execute(context.Background(), signedTx) require.Error(t, err) expectedError := fmt.Sprintf( - "Mismatch detected, expected local exit root: %s actual: %s. expected state root: %s actual: %s", - signedTx.Tx.ZKP.NewLocalExitRoot.Hex(), - common.Hash{}.Hex(), - signedTx.Tx.ZKP.NewStateRoot.Hex(), - common.Hash{}.Hex(), + "unable to perform soundness check because batch number %v is undefined", + signedTx.Tx.NewVerifiedBatch, ) assert.Contains(t, err.Error(), expectedError) mockZkEVMClientCreator.AssertExpectations(t) mockZkEVMClient.AssertExpectations(t) }) - - t.Run("Batch is nil and roots match", func(t *testing.T) { - t.Parallel() - - cfg := &config.Config{} - interopAdminAddr := common.HexToAddress("0x1234567890abcdef") - etherman := mocks.NewEthermanMock(t) - ethTxManager := mocks.NewEthTxManagerMock(t) - - executor := New(log.WithFields("test", "test"), cfg, interopAdminAddr, etherman, ethTxManager) - - // Create a sample signed transaction for testing - signedTx := tx.SignedTx{ - Tx: tx.Tx{ - LastVerifiedBatch: 0, - NewVerifiedBatch: 1, - ZKP: tx.ZKP{ - NewStateRoot: common.Hash{}, - NewLocalExitRoot: common.Hash{}, - Proof: []byte("sampleProof"), - }, - }, - } - - // Mock the ZkEVMClientCreator.NewClient method - mockZkEVMClientCreator := mocks.NewZkEVMClientClientCreatorMock(t) - mockZkEVMClient := mocks.NewZkEVMClientMock(t) - - mockZkEVMClientCreator.On("NewClient", mock.Anything).Return(mockZkEVMClient).Once() - mockZkEVMClient.On("BatchByNumber", mock.Anything, big.NewInt(int64(signedTx.Tx.NewVerifiedBatch))). - Return(nil, nil).Once() - - // Set the ZkEVMClientCreator to return the mock ZkEVMClient - executor.ZkEVMClientCreator = mockZkEVMClientCreator - - err := executor.Execute(context.Background(), signedTx) - require.NoError(t, err) - mockZkEVMClientCreator.AssertExpectations(t) - mockZkEVMClient.AssertExpectations(t) - }) } func TestExecutor_Settle(t *testing.T) { diff --git a/mocks/db.generated.go b/mocks/db.generated.go index 1946d157..9c23a1cf 100644 --- a/mocks/db.generated.go +++ b/mocks/db.generated.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.40.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package mocks diff --git a/mocks/eth_tx_manager.generated.go b/mocks/eth_tx_manager.generated.go index 3c0016f3..74fdc226 100644 --- a/mocks/eth_tx_manager.generated.go +++ b/mocks/eth_tx_manager.generated.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.40.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package mocks diff --git a/mocks/etherman.generated.go b/mocks/etherman.generated.go index a79052d8..cf7ed8da 100644 --- a/mocks/etherman.generated.go +++ b/mocks/etherman.generated.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.40.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package mocks diff --git a/mocks/etherman_client.generated.go b/mocks/etherman_client.generated.go index fda4481a..3b9211aa 100644 --- a/mocks/etherman_client.generated.go +++ b/mocks/etherman_client.generated.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.40.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package mocks diff --git a/mocks/zk_evm_client.generated.go b/mocks/zk_evm_client.generated.go index d0f363c5..4412a765 100644 --- a/mocks/zk_evm_client.generated.go +++ b/mocks/zk_evm_client.generated.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.40.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package mocks diff --git a/mocks/zk_evm_client_creator.generated.go b/mocks/zk_evm_client_creator.generated.go index 4a5d690a..d3e934ce 100644 --- a/mocks/zk_evm_client_creator.generated.go +++ b/mocks/zk_evm_client_creator.generated.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.40.1. DO NOT EDIT. +// Code generated by mockery v2.39.0. DO NOT EDIT. package mocks