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

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vcastellm committed Jan 4, 2024
1 parent 73d9a75 commit 472b3f3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
6 changes: 3 additions & 3 deletions interop/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (e *Executor) Execute(signedTx tx.SignedTx) error {
return nil
}

func (e *Executor) Settle(signedTx tx.SignedTx, dbTx pgx.Tx) (common.Hash, error) {
func (e *Executor) Settle(ctx context.Context, signedTx tx.SignedTx, dbTx pgx.Tx) (common.Hash, error) {
// // Send L1 tx
// Verify ZKP using eth_call
l1TxData, err := e.etherman.BuildTrustedVerifyBatchesTxData(
Expand All @@ -154,12 +154,12 @@ func (e *Executor) Settle(signedTx tx.SignedTx, dbTx pgx.Tx) (common.Hash, error
}

if err := e.ethTxMan.Add(
context.Background(),
ctx,
ethTxManOwner,
signedTx.Tx.Hash().Hex(),
e.interopAdminAddr,
&signedTx.Tx.L1Contract,
nil,
big.NewInt(0),
l1TxData,
0,
dbTx,
Expand Down
41 changes: 41 additions & 0 deletions interop/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,44 @@ func TestExecutor_Execute(t *testing.T) {
mockZkEVMClientCreator.AssertExpectations(t)
mockZkEVMClient.AssertExpectations(t)
}

func TestExecutor_Settle(t *testing.T) {
cfg := &config.Config{
// Set your desired config values here
}
interopAdminAddr := common.HexToAddress("0x1234567890abcdef")
etherman := &mocks.EthermanMock{}
ethTxManager := &mocks.EthTxManagerMock{}
dbTx := &mocks.TxMock{}

executor := New(nil, cfg, interopAdminAddr, etherman, ethTxManager)

signedTx := tx.SignedTx{
Tx: tx.Tx{
LastVerifiedBatch: 0,
NewVerifiedBatch: 1,
ZKP: tx.ZKP{
Proof: []byte("sampleProof"),
},
L1Contract: common.HexToAddress("0x1234567890abcdef"),
},
}

l1TxData := []byte("sampleL1TxData")
etherman.On("BuildTrustedVerifyBatchesTxData",
uint64(signedTx.Tx.LastVerifiedBatch), uint64(signedTx.Tx.NewVerifiedBatch), signedTx.Tx.ZKP).
Return(l1TxData, nil).Once()

ctx := context.Background()
txHash := signedTx.Tx.Hash().Hex()
ethTxManager.On("Add",
ctx, ethTxManOwner, txHash, interopAdminAddr, &signedTx.Tx.L1Contract, big.NewInt(0), l1TxData, uint64(0), dbTx).
Return(nil).Once()

hash, err := executor.Settle(ctx, signedTx, dbTx)
require.NoError(t, err)
assert.Equal(t, signedTx.Tx.Hash(), hash)

etherman.AssertExpectations(t)
ethTxManager.AssertExpectations(t)
}
2 changes: 1 addition & 1 deletion mocks/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type EthTxManagerMock struct {

func (e *EthTxManagerMock) Add(ctx context.Context, owner, id string,
from common.Address, to *common.Address, value *big.Int, data []byte, gasOffset uint64, dbTx pgx.Tx) error {
args := e.Called(ctx, owner, id, from, to, value, data, dbTx)
args := e.Called(ctx, owner, id, from, to, value, data, gasOffset, dbTx)

return args.Error(0)
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (i *InteropEndpoints) SendTx(signedTx tx.SignedTx) (interface{}, rpctypes.E
return "0x0", rpctypes.NewRPCError(rpctypes.DefaultErrorCode, fmt.Sprintf("failed to begin dbTx, error: %s", err))
}

_, err = i.executor.Settle(signedTx, dbTx)
_, err = i.executor.Settle(i.ctx, signedTx, dbTx)
if err != nil {
if errRollback := dbTx.Rollback(i.ctx); errRollback != nil {
log.Error("rollback err: ", errRollback)
Expand Down

0 comments on commit 472b3f3

Please sign in to comment.