Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
cr fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rachit77 committed Mar 26, 2024
1 parent 9370cc0 commit 398777c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 85 deletions.
13 changes: 6 additions & 7 deletions interop/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
88 changes: 16 additions & 72 deletions interop/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand All @@ -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{}
Expand All @@ -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)
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion mocks/db.generated.go

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

2 changes: 1 addition & 1 deletion mocks/eth_tx_manager.generated.go

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

2 changes: 1 addition & 1 deletion mocks/etherman.generated.go

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

2 changes: 1 addition & 1 deletion mocks/etherman_client.generated.go

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

2 changes: 1 addition & 1 deletion mocks/zk_evm_client.generated.go

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

2 changes: 1 addition & 1 deletion mocks/zk_evm_client_creator.generated.go

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

0 comments on commit 398777c

Please sign in to comment.