Skip to content

Commit

Permalink
add log0 debug trace e2e tests (#3422)
Browse files Browse the repository at this point in the history
* add log0 debug trace e2e tests

* add log0 debug trace e2e tests
  • Loading branch information
tclemos authored Mar 8, 2024
1 parent 1365a55 commit 2261ccc
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/contracts/auto/Log0.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract Log0 {
// opcode 0xa0
function opLog0() public payable {
assembly {
log0(0, 32)
}
}

function opLog00() public payable {
assembly {
log0(0, 0)
}
}

function opLog01() public payable {
assembly {
log0(0, 28)
}
}
}
266 changes: 266 additions & 0 deletions test/contracts/bin/Log0/Log0.go

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

3 changes: 3 additions & 0 deletions test/e2e/debug_calltracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func TestDebugTraceTransactionCallTracer(t *testing.T) {
{name: "memory", prepare: prepareMemory, createSignedTx: createMemorySignedTx},
{name: "bridge", prepare: prepareBridge, createSignedTx: createBridgeSignedTx},
{name: "deploy create 0", createSignedTx: createDeployCreate0SignedTx},
{name: "log0 all zeros", prepare: prepareLog0, createSignedTx: createLog0AllZeros},
{name: "log0 empty", prepare: prepareLog0, createSignedTx: createLog0Empty},
{name: "log0 short", prepare: prepareLog0, createSignedTx: createLog0Short},

// failed transactions
{name: "sc deployment reverted", createSignedTx: createScDeployRevertedSignedTx},
Expand Down
70 changes: 70 additions & 0 deletions test/e2e/debug_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/Depth"
"github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/ERC20"
"github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/EmitLog"
"github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/Log0"
"github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/Memory"
"github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/OpCallAux"
"github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/Revert2"
Expand Down Expand Up @@ -883,3 +884,72 @@ func sendEthTransfersWithoutWaiting(t *testing.T, ctx context.Context, client *e
log.Debugf("sending eth transfer: %v", signedTx.Hash().String())
}
}

func prepareLog0(t *testing.T, ctx context.Context, auth *bind.TransactOpts, client *ethclient.Client) (map[string]interface{}, error) {
_, tx, sc, err := Log0.DeployLog0(auth, client)
require.NoError(t, err)

err = operations.WaitTxToBeMined(ctx, client, tx, operations.DefaultTimeoutTxToBeMined)
require.NoError(t, err)

return map[string]interface{}{
"sc": sc,
}, nil
}

func createLog0AllZeros(t *testing.T, ctx context.Context, auth *bind.TransactOpts, client *ethclient.Client, customData map[string]interface{}) (*ethTypes.Transaction, error) {
scInterface := customData["sc"]
sc := scInterface.(*Log0.Log0)

gasPrice, err := client.SuggestGasPrice(ctx)
require.NoError(t, err)

opts := *auth
opts.NoSend = true
opts.Value = big.NewInt(0).SetUint64(txValue)
opts.GasPrice = gasPrice
opts.GasLimit = fixedTxGasLimit

tx, err := sc.OpLog0(&opts)
require.NoError(t, err)

return tx, nil
}

func createLog0Empty(t *testing.T, ctx context.Context, auth *bind.TransactOpts, client *ethclient.Client, customData map[string]interface{}) (*ethTypes.Transaction, error) {
scInterface := customData["sc"]
sc := scInterface.(*Log0.Log0)

gasPrice, err := client.SuggestGasPrice(ctx)
require.NoError(t, err)

opts := *auth
opts.NoSend = true
opts.Value = big.NewInt(0).SetUint64(txValue)
opts.GasPrice = gasPrice
opts.GasLimit = fixedTxGasLimit

tx, err := sc.OpLog00(&opts)
require.NoError(t, err)

return tx, nil
}

func createLog0Short(t *testing.T, ctx context.Context, auth *bind.TransactOpts, client *ethclient.Client, customData map[string]interface{}) (*ethTypes.Transaction, error) {
scInterface := customData["sc"]
sc := scInterface.(*Log0.Log0)

gasPrice, err := client.SuggestGasPrice(ctx)
require.NoError(t, err)

opts := *auth
opts.NoSend = true
opts.Value = big.NewInt(0).SetUint64(txValue)
opts.GasPrice = gasPrice
opts.GasLimit = fixedTxGasLimit

tx, err := sc.OpLog01(&opts)
require.NoError(t, err)

return tx, nil
}
3 changes: 3 additions & 0 deletions test/e2e/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ func TestDebugTraceTransaction(t *testing.T) {
{name: "memory", prepare: prepareMemory, createSignedTx: createMemorySignedTx},
{name: "bridge", prepare: prepareBridge, createSignedTx: createBridgeSignedTx},
{name: "deploy create 0", createSignedTx: createDeployCreate0SignedTx},
{name: "log0 all zeros", prepare: prepareLog0, createSignedTx: createLog0AllZeros},
{name: "log0 empty", prepare: prepareLog0, createSignedTx: createLog0Empty},
{name: "log0 short", prepare: prepareLog0, createSignedTx: createLog0Short},

// failed transactions
{name: "sc deployment reverted", createSignedTx: createScDeployRevertedSignedTx},
Expand Down

0 comments on commit 2261ccc

Please sign in to comment.