-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2408 from 0xPolygonHermez/test/uniswap-benchmark-…
…script Add `uniswap-transfers` Benchmark Script to `zkevm-node`
- Loading branch information
Showing
17 changed files
with
615 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
test/benchmarks/sequencer/e2e/uniswap-transfers/tx_sender.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package uniswap_transfers | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"math/big" | ||
"strings" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/core/types" | ||
|
||
"github.com/0xPolygonHermez/zkevm-node/log" | ||
"github.com/0xPolygonHermez/zkevm-node/state" | ||
"github.com/0xPolygonHermez/zkevm-node/test/contracts/bin/ERC20" | ||
uniswap "github.com/0xPolygonHermez/zkevm-node/test/scripts/uniswap/pkg" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
) | ||
|
||
var ( | ||
gasLimit = 21000 | ||
sleepTime = 5 * time.Second | ||
countTxs = 0 | ||
txTimeout = 60 * time.Second | ||
) | ||
|
||
// TxSender sends eth transfer to the sequencer | ||
func TxSender(l2Client *ethclient.Client, gasPrice *big.Int, nonce uint64, auth *bind.TransactOpts, erc20SC *ERC20.ERC20, uniswapDeployments *uniswap.Deployments) ([]*types.Transaction, error) { | ||
msg := fmt.Sprintf("# swap cycle number: %d #", countTxs) | ||
delimiter := strings.Repeat("#", len(msg)) | ||
log.Infof("%s\n%s\n%s", delimiter, msg, delimiter) | ||
var err error | ||
|
||
transactions := uniswap.SwapTokens(l2Client, auth, *uniswapDeployments) | ||
if errors.Is(err, state.ErrStateNotSynchronized) || errors.Is(err, state.ErrInsufficientFunds) { | ||
for errors.Is(err, state.ErrStateNotSynchronized) || errors.Is(err, state.ErrInsufficientFunds) { | ||
time.Sleep(sleepTime) | ||
transactions = uniswap.SwapTokens(l2Client, auth, *uniswapDeployments) | ||
} | ||
} | ||
|
||
if err == nil { | ||
countTxs += 1 | ||
} | ||
|
||
return transactions, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.