Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve E2E test time #1860

Merged
merged 3 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions test/benchmarks/sequencer/common/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,4 @@ func BootstrapSequencer(b *testing.B, opsman *operations.Manager) {
err := operations.StartComponent("seq")
require.NoError(b, err)
log.Debug("Sequencer Started!")
log.Debug("Setup sequencer ....")
require.NoError(b, opsman.SetUpSequencer())
log.Debug("Sequencer Setup ready!")
}
5 changes: 0 additions & 5 deletions test/e2e/jsonrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ func Test_Transactions(t *testing.T) {
require.NoError(t, err)

// Test Case: TX with invalid nonce

tx = ethTypes.NewTransaction(nonce-1, // Nonce will be lower than the current getNonceAt()
toAddress, big.NewInt(100), gasLimit, gasPrice, nil)
signedTx, err := auth.Signer(auth.From, tx)
Expand All @@ -544,11 +543,9 @@ func Test_Transactions(t *testing.T) {
log.Infof("Sending Tx %v Nonce (invalid) %v", signedTx.Hash(), signedTx.Nonce())
err = client.SendTransaction(context.Background(), signedTx)
require.ErrorContains(t, err, "nonce too low")

// End Test Case

// Test Case: TX with no signature (which would fail the EIP-155)

invalidTx := ethTypes.NewTx(&ethTypes.LegacyTx{
Nonce: nonce,
Value: big.NewInt(10000),
Expand All @@ -561,7 +558,6 @@ func Test_Transactions(t *testing.T) {
// End Test Case

// Test Case: TX with amount being higher than balance

balance, err := client.BalanceAt(context.Background(), auth.From, nil)
require.NoError(t, err)

Expand All @@ -579,7 +575,6 @@ func Test_Transactions(t *testing.T) {
require.ErrorContains(t, err, pool.ErrInsufficientFunds.Error())

// no contract code at given address test

// deploy contract with not enough gas for storage, just execution
address := common.HexToAddress("0xDEADBEEF596a836C9063a7EE35dA94DDA3b57B62")
instance, err := Double.NewDouble(address, client)
Expand Down
1 change: 0 additions & 1 deletion test/e2e/uniswap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func TestUniswap(t *testing.T) {
require.NoError(t, err)

require.NoError(t, opsman.StartNetwork())
require.NoError(t, opsman.SetUpSequencer())
require.NoError(t, opsman.StartNode())
require.NoError(t, opsman.InitNetwork())

Expand Down
131 changes: 2 additions & 129 deletions test/operations/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/0xPolygonHermez/zkevm-node/db"
"github.com/0xPolygonHermez/zkevm-node/encoding"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/merkletree"
"github.com/0xPolygonHermez/zkevm-node/state"
Expand All @@ -20,18 +19,13 @@ import (
"github.com/0xPolygonHermez/zkevm-node/test/dbutils"
"github.com/0xPolygonHermez/zkevm-node/test/testutils"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
)

const (
poeAddress = "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853"
maticTokenAddress = "0x5FbDB2315678afecb367f032d93F642f64180aa3" //nolint:gosec
l1AccHexAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
l1AccHexPrivateKey = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
cmdFolder = "test"
cmdFolder = "test"
)

// Public shared
Expand Down Expand Up @@ -294,17 +288,12 @@ func (m *Manager) Setup() error {
return err
}

err = m.SetUpSequencer()
if err != nil {
return err
}

// Run node container
err = m.StartNode()
if err != nil {
return err
}

// Run node container
return nil
}

Expand Down Expand Up @@ -343,122 +332,6 @@ func initState(maxCumulativeGasUsed uint64) (*state.State, error) {
return st, nil
}

// func (m *Manager) checkRoot(root []byte, expectedRoot string) error {
// actualRoot := hex.EncodeToHex(root)

// if expectedRoot != actualRoot {
// return fmt.Errorf("Invalid root, want %q, got %q", expectedRoot, actualRoot)
// }
// return nil
// }

// SetUpSequencer provide ETH, Matic to and register the sequencer
func (m *Manager) SetUpSequencer() error {
ctx := context.Background()
// Eth client
client, err := ethclient.Dial(DefaultL1NetworkURL)
if err != nil {
return err
}

// Get network chain id
chainID, err := client.NetworkID(context.Background())
if err != nil {
return err
}

auth, err := GetAuth(l1AccHexPrivateKey, chainID.Uint64())
if err != nil {
return err
}

// Getting l1 info
gasPrice, err := client.SuggestGasPrice(context.Background())
if err != nil {
return err
}

// Send some Ether from l1Acc to sequencer acc
fromAddress := common.HexToAddress(l1AccHexAddress)
nonce, err := client.PendingNonceAt(context.Background(), fromAddress)
if err != nil {
return err
}

const (
gasLimit = 21000
OneEther = 1000000000000000000
)
toAddress := common.HexToAddress(m.cfg.Sequencer.Address)
tx := types.NewTransaction(nonce, toAddress, big.NewInt(OneEther), uint64(gasLimit), gasPrice, nil)
signedTx, err := auth.Signer(auth.From, tx)
if err != nil {
return err
}

err = client.SendTransaction(context.Background(), signedTx)
if err != nil {
return err
}

// Wait eth transfer to be mined
err = WaitTxToBeMined(ctx, client, signedTx, DefaultTxMinedDeadline)
if err != nil {
return err
}

// Create matic maticTokenSC sc instance
maticTokenSC, err := NewToken(common.HexToAddress(maticTokenAddress), client)
if err != nil {
return err
}

// Send matic to sequencer
maticAmount, ok := big.NewInt(0).SetString("100000000000000000000000", encoding.Base10)
if !ok {
return fmt.Errorf("Error setting matic amount")
}

tx, err = maticTokenSC.Transfer(auth, toAddress, maticAmount)
if err != nil {
return err
}

// wait matic transfer to be mined
err = WaitTxToBeMined(ctx, client, tx, DefaultTxMinedDeadline)
if err != nil {
return err
}

// Check matic balance
b, err := maticTokenSC.BalanceOf(&bind.CallOpts{}, toAddress)
if err != nil {
return err
}

if b.Cmp(maticAmount) < 0 {
return fmt.Errorf("Minimum amount is: %v but found: %v", maticAmount.Text(encoding.Base10), b.Text(encoding.Base10))
}

// Create sequencer auth
auth, err = GetAuth(m.cfg.Sequencer.PrivateKey, chainID.Uint64())
if err != nil {
return err
}

// approve tokens to be used by PoE SC on behalf of the sequencer
tx, err = maticTokenSC.Approve(auth, common.HexToAddress(poeAddress), maticAmount)
if err != nil {
return err
}

err = WaitTxToBeMined(ctx, client, tx, DefaultTxMinedDeadline)
if err != nil {
return err
}
return nil
}

// StartNetwork starts the L1 network container
func (m *Manager) StartNetwork() error {
return StartComponent("network", networkUpCondition)
Expand Down