Skip to content

Self destruct test #3062

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

Merged
merged 14 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
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
2 changes: 1 addition & 1 deletion contracts
2 changes: 1 addition & 1 deletion go-ethereum
68 changes: 68 additions & 0 deletions system_tests/self_destruct_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package arbtest

import (
"context"
"math/big"
"testing"

"github.com/ethereum/go-ethereum/params"

"github.com/offchainlabs/nitro/solgen/go/mocksgen"
)

func TestSelfDestruct(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
cleanup := builder.Build(t)
defer cleanup()

builder.L2Info.GenerateAccount("destination")
destination := builder.L2Info.GetAddress("destination")
builder.L2Info.GenerateAccount("self_destruct")
auth := builder.L2Info.GetDefaultTransactOpts("self_destruct", ctx)
auth.GasLimit = 32000000
balance := big.NewInt(params.Ether)
balance.Mul(balance, big.NewInt(100))
builder.L2.TransferBalance(t, "Faucet", "self_destruct", balance, builder.L2Info)

// Test self-destruct with recipient same as the contract (contract is created and destroyed in the same transaction)
auth.Value = big.NewInt(params.Ether)
_, tx, _, err := mocksgen.DeploySelfDestructInConstructorWithoutDestination(&auth, builder.L2.Client)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)

// Test self-destruct with recipient different from the contract (contract is created and destroyed in the same transaction)
auth.Value = big.NewInt(params.Ether)
_, tx, _, err = mocksgen.DeploySelfDestructInConstructorWithDestination(&auth, builder.L2.Client, destination)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)

// Test self-destruct with recipient same as the contract (contract is created and destroyed in different transaction)
auth.Value = big.NewInt(params.Ether)
_, tx, selfDestructOutsideConstructor, err := mocksgen.DeploySelfDestructOutsideConstructor(&auth, builder.L2.Client)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)
auth.Value = nil
tx, err = selfDestructOutsideConstructor.SelfDestructWithoutDestination(&auth)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)

// Test self-destruct with recipient same as the contract (contract is created and destroyed in the different transaction)
auth.Value = big.NewInt(params.Ether)
_, tx, selfDestructOutsideConstructor, err = mocksgen.DeploySelfDestructOutsideConstructor(&auth, builder.L2.Client)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)
auth.Value = nil
tx, err = selfDestructOutsideConstructor.SelfDestructWithDestination(&auth, destination)
Require(t, err)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)
}
Loading