Skip to content

Commit

Permalink
feat(ci): add deposit and withdrawal e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0x6e616d committed Jul 25, 2024
1 parent f9d4f24 commit 16405f1
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 46 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/deposit-withdraw-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Deposit and Withdrawal End To End Test'
on:
push:
branches:
- feat/OR-1749-deposit-withdraw-e2e-tests

jobs:
deposit-withdrawal-e2e-tests:
name: 'Deposit and Withdrawal E2E tests'
runs-on: ubuntu-latest
container:
image: tokamaknetwork/thanos-ci-builder:latest
steps:
- name: Check CPUs
run: lscpu && echo

- name: Checkout
uses: actions/[email protected]

- name: Add repository to git safe directories
run: git config --global --add safe.directory $GITHUB_WORKSPACE

- name: Git submodules
run: make submodules

- name: Setup
run: |
make cannon-prestate
DEPLOYMENT_CONTEXT=devnetL1 make devnet-allocs
- name: Run deposit withdrawal e2e tests
run: make test-deposit-withdrawal
working-directory: op-e2e
5 changes: 5 additions & 0 deletions op-e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,8 @@ clean:
rm -r ../.devnet
rm -r ../op-program/bin
.PHONY: clean


test-deposit-withdrawal:
$(go_test) $(go_test_flags) . ./e2e-dep-with/...
.PHONY: test-deposit-withdrawal
9 changes: 5 additions & 4 deletions op-e2e/USDC_test.go → op-e2e/e2e-dep-with/USDC_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package op_e2e
package e2e_dep_with

import (
"context"
e2e "github.com/tokamak-network/tokamak-thanos/op-e2e"
"math"
"math/big"
"testing"
Expand All @@ -19,9 +20,9 @@ import (
)

func TestUsdcDepositsAndWithdrawal(t *testing.T) {
InitParallel(t)
e2e.InitParallel(t)

cfg := DefaultSystemConfig(t)
cfg := e2e.DefaultSystemConfig(t)

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
Expand Down Expand Up @@ -173,7 +174,7 @@ func TestUsdcDepositsAndWithdrawal(t *testing.T) {
l2BalanceAfterWithdraw, err := FiatTokenContractL2.BalanceOf(&bind.CallOpts{}, opts.From)
require.NoError(t, err)

provedReceipt, finalizedReceipt, _, _ := ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
provedReceipt, finalizedReceipt, _, _ := e2e.ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
require.Equal(t, types.ReceiptStatusSuccessful, provedReceipt.Status)
require.Equal(t, types.ReceiptStatusSuccessful, finalizedReceipt.Status)

Expand Down
27 changes: 14 additions & 13 deletions op-e2e/bridge_test.go → op-e2e/e2e-dep-with/bridge_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package op_e2e
package e2e_dep_with

import (
"context"
e2e "github.com/tokamak-network/tokamak-thanos/op-e2e"
"math"
"math/big"
"testing"
Expand All @@ -24,9 +25,9 @@ import (
// TestERC20BridgeDeposits tests the the L1StandardBridge bridge ERC20
// functionality.
func TestERC20BridgeDeposits(t *testing.T) {
InitParallel(t)
e2e.InitParallel(t)

cfg := DefaultSystemConfig(t)
cfg := e2e.DefaultSystemConfig(t)

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
Expand Down Expand Up @@ -127,7 +128,7 @@ func TestERC20BridgeDeposits(t *testing.T) {
l1BalanceBeforeFinalizingWithdraw, err := wNativeToken.BalanceOf(&bind.CallOpts{}, opts.From)
require.NoError(t, err)

provedReceipt, finalizedReceipt, _, _ := ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
provedReceipt, finalizedReceipt, _, _ := e2e.ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
require.Equal(t, types.ReceiptStatusSuccessful, provedReceipt.Status)
require.Equal(t, types.ReceiptStatusSuccessful, finalizedReceipt.Status)

Expand All @@ -140,9 +141,9 @@ func TestERC20BridgeDeposits(t *testing.T) {
// TestETHBridgeDeposits tests the the L1StandardBridge bridge ETH
// functionality.
func TestETHBridgeDeposits(t *testing.T) {
InitParallel(t)
e2e.InitParallel(t)

cfg := DefaultSystemConfig(t)
cfg := e2e.DefaultSystemConfig(t)

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
Expand Down Expand Up @@ -223,7 +224,7 @@ func TestETHBridgeDeposits(t *testing.T) {
l1ETHBalanceAfterDeposit, err = l1Client.BalanceAt(context.Background(), opts.From, nil)
require.NoError(t, err)

provedReceipt, finalizedReceipt, _, _ := ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
provedReceipt, finalizedReceipt, _, _ := e2e.ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
require.Equal(t, types.ReceiptStatusSuccessful, provedReceipt.Status)
require.Equal(t, types.ReceiptStatusSuccessful, finalizedReceipt.Status)

Expand All @@ -246,9 +247,9 @@ func TestETHBridgeDeposits(t *testing.T) {
// TestNativeTokenBridgeDeposits tests the the L1StandardBridge bridgeNativeToken
// functionality.
func TestNativeTokenBridgeDeposits(t *testing.T) {
InitParallel(t)
e2e.InitParallel(t)

cfg := DefaultSystemConfig(t)
cfg := e2e.DefaultSystemConfig(t)

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
Expand Down Expand Up @@ -340,7 +341,7 @@ func TestNativeTokenBridgeDeposits(t *testing.T) {
withdrawalReceipt, err := wait.ForReceiptOK(context.Background(), l2Client, withdrawalTx.Hash())
require.NoError(t, err)

provedReceipt, finalizedReceipt, _, _ := ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
provedReceipt, finalizedReceipt, _, _ := e2e.ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
require.Equal(t, types.ReceiptStatusSuccessful, provedReceipt.Status)
require.Equal(t, types.ReceiptStatusSuccessful, finalizedReceipt.Status)

Expand All @@ -350,9 +351,9 @@ func TestNativeTokenBridgeDeposits(t *testing.T) {
}

func TestWithdrawNativeTokenTo(t *testing.T) {
InitParallel(t)
e2e.InitParallel(t)

cfg := DefaultSystemConfig(t)
cfg := e2e.DefaultSystemConfig(t)

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
Expand Down Expand Up @@ -448,7 +449,7 @@ func TestWithdrawNativeTokenTo(t *testing.T) {
withdrawalReceipt, err := wait.ForReceiptOK(context.Background(), l2Client, withdrawalTx.Hash())
require.NoError(t, err)

provedReceipt, finalizedReceipt, _, _ := ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
provedReceipt, finalizedReceipt, _, _ := e2e.ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
require.Equal(t, types.ReceiptStatusSuccessful, provedReceipt.Status)
require.Equal(t, types.ReceiptStatusSuccessful, finalizedReceipt.Status)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package op_e2e
package e2e_dep_with

import (
"context"
e2e "github.com/tokamak-network/tokamak-thanos/op-e2e"
"math"
"math/big"
"testing"
Expand All @@ -22,9 +23,9 @@ import (
// Success on L2
// Cannot get token on L1
func TestCannotWithdrawTokenWithEmptyMessage(t *testing.T) {
InitParallel(t)
e2e.InitParallel(t)

cfg := DefaultSystemConfig(t)
cfg := e2e.DefaultSystemConfig(t)

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
Expand Down Expand Up @@ -118,7 +119,7 @@ func TestCannotWithdrawTokenWithEmptyMessage(t *testing.T) {
require.NoError(t, err)
require.Equal(t, withdrawalReceipt.Status, types.ReceiptStatusSuccessful)

proveReceipt, finalizedReceipt, _, _ := ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
proveReceipt, finalizedReceipt, _, _ := e2e.ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
require.Equal(t, types.ReceiptStatusSuccessful, proveReceipt.Status)
require.Equal(t, types.ReceiptStatusSuccessful, finalizedReceipt.Status)

Expand All @@ -129,9 +130,9 @@ func TestCannotWithdrawTokenWithEmptyMessage(t *testing.T) {

// TestDepositWithdrawalSendMessageSuccess: test create a message for withdraw
func TestDepositWithdrawalSendMessageSuccess(t *testing.T) {
InitParallel(t)
e2e.InitParallel(t)

cfg := DefaultSystemConfig(t)
cfg := e2e.DefaultSystemConfig(t)

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
Expand Down Expand Up @@ -201,7 +202,7 @@ func TestDepositWithdrawalSendMessageSuccess(t *testing.T) {
balanceBeforeFinalization, err := nativeTokenContract.BalanceOf(&bind.CallOpts{}, opts.From)
require.NoError(t, err)

proveReceipt, finalizedReceipt, _, _ := ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
proveReceipt, finalizedReceipt, _, _ := e2e.ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
require.Equal(t, types.ReceiptStatusSuccessful, proveReceipt.Status)
require.Equal(t, types.ReceiptStatusSuccessful, finalizedReceipt.Status)

Expand All @@ -212,9 +213,9 @@ func TestDepositWithdrawalSendMessageSuccess(t *testing.T) {
}

func TestSendNativeTokenMessageWithOnApprove(t *testing.T) {
InitParallel(t)
e2e.InitParallel(t)

cfg := DefaultSystemConfig(t)
cfg := e2e.DefaultSystemConfig(t)

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
Expand All @@ -240,7 +241,7 @@ func TestSendNativeTokenMessageWithOnApprove(t *testing.T) {
_, err = wait.ForReceiptOK(context.Background(), l1Client, tx.Hash())
require.NoError(t, err)

calldata := EncodeCallData(opts.From, opts.From, amount, uint32(200000), []byte{})
calldata := e2e.EncodeCallData(opts.From, opts.From, amount, uint32(200000), []byte{})

l1BalanceBeforeDeposit, err := nativeTokenContract.BalanceOf(&bind.CallOpts{}, opts.From)
require.NoError(t, err)
Expand Down
15 changes: 8 additions & 7 deletions op-e2e/deposit_test.go → op-e2e/e2e-dep-with/deposit_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package op_e2e
package e2e_dep_with

import (
"context"
e2e "github.com/tokamak-network/tokamak-thanos/op-e2e"
"math"
"math/big"
"testing"
Expand All @@ -19,8 +20,8 @@ import (
// This test is impossible for the new version
// In the new version, we cannot send amount more than minted amount
func TestMintOnRevertedDeposit(t *testing.T) {
InitParallel(t)
cfg := DefaultSystemConfig(t)
e2e.InitParallel(t)
cfg := e2e.DefaultSystemConfig(t)

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
Expand Down Expand Up @@ -64,7 +65,7 @@ func TestMintOnRevertedDeposit(t *testing.T) {
_, err = wait.ForReceiptOK(context.Background(), l1Client, tx.Hash())
require.NoError(t, err)

SendDepositTx(t, cfg, l1Client, l2Verif, opts, func(l2Opts *DepositTxOpts) {
e2e.SendDepositTx(t, cfg, l1Client, l2Verif, opts, func(l2Opts *e2e.DepositTxOpts) {
l2Opts.ToAddr = toAddr
// trigger a revert by transferring more than we have available
l2Opts.Mint = mintAmount
Expand Down Expand Up @@ -96,8 +97,8 @@ func TestMintOnRevertedDeposit(t *testing.T) {
}

func TestDepositTxCreateContract(t *testing.T) {
InitParallel(t)
cfg := DefaultSystemConfig(t)
e2e.InitParallel(t)
cfg := e2e.DefaultSystemConfig(t)
delete(cfg.Nodes, "verifier")

sys, err := cfg.Start(t)
Expand Down Expand Up @@ -147,7 +148,7 @@ func TestDepositTxCreateContract(t *testing.T) {

deployData := append(deployPrefix, sstoreContract...)

l2Receipt := SendDepositTx(t, cfg, l1Client, l2Client, opts, func(l2Opts *DepositTxOpts) {
l2Receipt := e2e.SendDepositTx(t, cfg, l1Client, l2Client, opts, func(l2Opts *e2e.DepositTxOpts) {
l2Opts.Data = deployData
l2Opts.ToAddr = common.Address{}
l2Opts.IsCreation = true
Expand Down
25 changes: 13 additions & 12 deletions op-e2e/portals_test.go → op-e2e/e2e-dep-with/portal_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package op_e2e
package e2e_dep_with

import (
"context"
e2e "github.com/tokamak-network/tokamak-thanos/op-e2e"
"math"
"math/big"
"testing"
Expand All @@ -21,9 +22,9 @@ import (

// TestDepositAndWithdrawPortalsSuccessfully tests deposit via OptimismPortal and withdraw via L2ToL1MessagePasser successfully
func TestDepositAndWithdrawSuccessfully(t *testing.T) {
InitParallel(t)
e2e.InitParallel(t)

cfg := DefaultSystemConfig(t)
cfg := e2e.DefaultSystemConfig(t)

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
Expand Down Expand Up @@ -108,7 +109,7 @@ func TestDepositAndWithdrawSuccessfully(t *testing.T) {

l1BalanceBeforeFinalizeWithdraw, err := nativeTokenContract.BalanceOf(&bind.CallOpts{}, opts.From)
require.NoError(t, err)
ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)
e2e.ProveAndFinalizeWithdrawal(t, cfg, sys, "sequencer", cfg.Secrets.Alice, withdrawalReceipt)

tx, err = nativeTokenContract.TransferFrom(opts, cfg.L1Deployments.OptimismPortalProxy, opts.From, big.NewInt(depositedAmount))
require.NoError(t, err)
Expand All @@ -124,9 +125,9 @@ func TestDepositAndWithdrawSuccessfully(t *testing.T) {

// TestDepositAndCallContractL2ViaPortal tests successfully
func TestDepositAndCallL2Successfully(t *testing.T) {
InitParallel(t)
e2e.InitParallel(t)

cfg := DefaultSystemConfig(t)
cfg := e2e.DefaultSystemConfig(t)

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
Expand Down Expand Up @@ -197,9 +198,9 @@ func TestDepositAndCallL2Successfully(t *testing.T) {
}

func TestDeployContractFailedNonPayableConstructor(t *testing.T) {
InitParallel(t)
e2e.InitParallel(t)

cfg := DefaultSystemConfig(t)
cfg := e2e.DefaultSystemConfig(t)

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
Expand Down Expand Up @@ -259,9 +260,9 @@ func TestDeployContractFailedNonPayableConstructor(t *testing.T) {
}

func TestDeployContractFailedOutOfGas(t *testing.T) {
InitParallel(t)
e2e.InitParallel(t)

cfg := DefaultSystemConfig(t)
cfg := e2e.DefaultSystemConfig(t)

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
Expand Down Expand Up @@ -348,9 +349,9 @@ func TestDeployContractFailedOutOfGas(t *testing.T) {

// TestDeployContractSuccessfully tests successfully
func TestDeployContractSuccessfully(t *testing.T) {
InitParallel(t)
e2e.InitParallel(t)

cfg := DefaultSystemConfig(t)
cfg := e2e.DefaultSystemConfig(t)

sys, err := cfg.Start(t)
require.Nil(t, err, "Error starting up system")
Expand Down

0 comments on commit 16405f1

Please sign in to comment.