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

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vcastellm committed Jan 4, 2024
1 parent a966245 commit 795d5ee
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions interop/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package interop

import (
"context"
"math/big"
"testing"

"github.com/0xPolygon/beethoven/config"
"github.com/0xPolygon/beethoven/test"
"github.com/0xPolygon/beethoven/tx"

rpctypes "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -143,3 +145,45 @@ func TestExecutor_VerifySignature(t *testing.T) {
require.NoError(t, err)
etherman.AssertExpectations(t)
}

func TestExecutor_Execute(t *testing.T) {
cfg := &config.Config{}
interopAdminAddr := common.HexToAddress("0x1234567890abcdef")
etherman := &test.EthermanMock{}
ethTxManager := &test.EthTxManagerMock{}

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")),
Proof: []byte("sampleProof"),
},
L1Contract: common.HexToAddress("0x1234567890abcdef"),
},
}

// Mock the ZkEVMClientCreator.NewClient method
mockZkEVMClientCreator := &test.ZkEVMClientCreatorMock{}
mockZkEVMClient := &test.ZkEVMClientMock{}

mockZkEVMClientCreator.On("NewClient", mock.Anything).Return(mockZkEVMClient).Once()
mockZkEVMClient.On("BatchByNumber", mock.Anything, big.NewInt(int64(signedTx.Tx.NewVerifiedBatch))).
Return(&rpctypes.Batch{
StateRoot: signedTx.Tx.ZKP.NewStateRoot,
LocalExitRoot: signedTx.Tx.ZKP.NewLocalExitRoot,
// Add other necessary fields here
}, nil).Once()

// Set the ZkEVMClientCreator to return the mock ZkEVMClient
executor.ZkEVMClientCreator = mockZkEVMClientCreator

err := executor.Execute(signedTx)
require.NoError(t, err)
mockZkEVMClientCreator.AssertExpectations(t)
mockZkEVMClient.AssertExpectations(t)
}

0 comments on commit 795d5ee

Please sign in to comment.