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

Or 1906 update e2e test for deposit withdrawal flows #294

Merged
merged 8 commits into from
Oct 30, 2024

Conversation

nguyenzung
Copy link
Member

Remove comments and update some tests

Thank you!

@0x6e616d
Copy link
Member

Can you check this test?

// func TestMintOnRevertedDeposit(t *testing.T) {
// e2e.InitParallel(t)
// cfg := e2e.DefaultSystemConfig(t)
// sys, err := cfg.Start(t)
// require.Nil(t, err, "Error starting up system")
// defer sys.Close()
// l1Client := sys.Clients["l1"]
// l2Verif := sys.Clients["verifier"]
// // create signer
// aliceKey := cfg.Secrets.Alice
// opts, err := bind.NewKeyedTransactorWithChainID(aliceKey, cfg.L1ChainIDBig())
// require.Nil(t, err)
// fromAddr := opts.From
// ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
// startBalance, err := l2Verif.BalanceAt(ctx, fromAddr, nil)
// cancel()
// require.Nil(t, err)
// ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
// startNonce, err := l2Verif.NonceAt(ctx, fromAddr, nil)
// require.NoError(t, err)
// cancel()
// nativeTokenContract, err := bindings.NewL2NativeToken(cfg.L1Deployments.L2NativeToken, l1Client)
// require.NoError(t, err)
// toAddr := common.Address{0xff, 0xff}
// mintAmount := big.NewInt(9_000_000)
// // opts.Value = mintAmount
// // faucet NativeToken
// tx, err := nativeTokenContract.Faucet(opts, mintAmount)
// require.NoError(t, err)
// _, err = wait.ForReceiptOK(context.Background(), l1Client, tx.Hash())
// require.NoError(t, err)
// // Approve NativeToken with the OP
// tx, err = nativeTokenContract.Approve(opts, cfg.L1Deployments.OptimismPortalProxy, new(big.Int).SetUint64(math.MaxUint64))
// require.NoError(t, err)
// _, err = wait.ForReceiptOK(context.Background(), l1Client, tx.Hash())
// require.NoError(t, err)
// 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
// l2Opts.Value = new(big.Int).Mul(common.Big2, startBalance)
// l2Opts.IsCreation = false
// l2Opts.ExpectedStatus = types.ReceiptStatusFailed
// })
// // Confirm balance
// ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
// endBalance, err := l2Verif.BalanceAt(ctx, fromAddr, nil)
// cancel()
// require.Nil(t, err)
// ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
// toAddrBalance, err := l2Verif.BalanceAt(ctx, toAddr, nil)
// require.NoError(t, err)
// cancel()
// diff := new(big.Int)
// diff = diff.Sub(endBalance, startBalance)
// require.Equal(t, mintAmount, diff, "Did not get expected balance change")
// require.Equal(t, common.Big0.Int64(), toAddrBalance.Int64(), "The recipient account balance should be zero")
// ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
// endNonce, err := l2Verif.NonceAt(ctx, fromAddr, nil)
// require.NoError(t, err)
// cancel()
// require.Equal(t, startNonce+1, endNonce, "Nonce of deposit sender should increment on L2, even if the deposit fails")
// }

@nguyenzung nguyenzung force-pushed the OR-1906-update-e2e-test-for-deposit-withdrawal-flows branch from 8487038 to f0e098a Compare October 29, 2024 06:26
@nguyenzung
Copy link
Member Author

Can you check this test?

// func TestMintOnRevertedDeposit(t *testing.T) {
// e2e.InitParallel(t)
// cfg := e2e.DefaultSystemConfig(t)
// sys, err := cfg.Start(t)
// require.Nil(t, err, "Error starting up system")
// defer sys.Close()
// l1Client := sys.Clients["l1"]
// l2Verif := sys.Clients["verifier"]
// // create signer
// aliceKey := cfg.Secrets.Alice
// opts, err := bind.NewKeyedTransactorWithChainID(aliceKey, cfg.L1ChainIDBig())
// require.Nil(t, err)
// fromAddr := opts.From
// ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
// startBalance, err := l2Verif.BalanceAt(ctx, fromAddr, nil)
// cancel()
// require.Nil(t, err)
// ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
// startNonce, err := l2Verif.NonceAt(ctx, fromAddr, nil)
// require.NoError(t, err)
// cancel()
// nativeTokenContract, err := bindings.NewL2NativeToken(cfg.L1Deployments.L2NativeToken, l1Client)
// require.NoError(t, err)
// toAddr := common.Address{0xff, 0xff}
// mintAmount := big.NewInt(9_000_000)
// // opts.Value = mintAmount
// // faucet NativeToken
// tx, err := nativeTokenContract.Faucet(opts, mintAmount)
// require.NoError(t, err)
// _, err = wait.ForReceiptOK(context.Background(), l1Client, tx.Hash())
// require.NoError(t, err)
// // Approve NativeToken with the OP
// tx, err = nativeTokenContract.Approve(opts, cfg.L1Deployments.OptimismPortalProxy, new(big.Int).SetUint64(math.MaxUint64))
// require.NoError(t, err)
// _, err = wait.ForReceiptOK(context.Background(), l1Client, tx.Hash())
// require.NoError(t, err)
// 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
// l2Opts.Value = new(big.Int).Mul(common.Big2, startBalance)
// l2Opts.IsCreation = false
// l2Opts.ExpectedStatus = types.ReceiptStatusFailed
// })
// // Confirm balance
// ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
// endBalance, err := l2Verif.BalanceAt(ctx, fromAddr, nil)
// cancel()
// require.Nil(t, err)
// ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
// toAddrBalance, err := l2Verif.BalanceAt(ctx, toAddr, nil)
// require.NoError(t, err)
// cancel()
// diff := new(big.Int)
// diff = diff.Sub(endBalance, startBalance)
// require.Equal(t, mintAmount, diff, "Did not get expected balance change")
// require.Equal(t, common.Big0.Int64(), toAddrBalance.Int64(), "The recipient account balance should be zero")
// ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
// endNonce, err := l2Verif.NonceAt(ctx, fromAddr, nil)
// require.NoError(t, err)
// cancel()
// require.Equal(t, startNonce+1, endNonce, "Nonce of deposit sender should increment on L2, even if the deposit fails")
// }

Thank you!
It is done!

Copy link
Member

@0x6e616d 0x6e616d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your changes worked well, thank you

@nguyenzung nguyenzung merged commit d442f84 into main Oct 30, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants