Skip to content

Commit

Permalink
Merge branch 'master' into create-erc20-rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
gvladika committed Oct 30, 2023
2 parents be17fea + ab694f2 commit 382599c
Show file tree
Hide file tree
Showing 39 changed files with 1,023 additions and 1,074 deletions.
26 changes: 13 additions & 13 deletions system_tests/aliasing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ func TestAliasing(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

l2info, node, l2client, l1info, _, l1client, l1stack := createTestNodeOnL1(t, ctx, true)
defer requireClose(t, l1stack)
defer node.StopAndWait()
builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
cleanup := builder.Build(t)
defer cleanup()

auth := l2info.GetDefaultTransactOpts("Owner", ctx)
user := l1info.GetDefaultTransactOpts("User", ctx)
TransferBalanceTo(t, "Owner", util.RemapL1Address(user.From), big.NewInt(1e18), l2info, l2client, ctx)
auth := builder.L2Info.GetDefaultTransactOpts("Owner", ctx)
user := builder.L1Info.GetDefaultTransactOpts("User", ctx)
builder.L2.TransferBalanceTo(t, "Owner", util.RemapL1Address(user.From), big.NewInt(1e18), builder.L2Info)

simpleAddr, simple := deploySimple(t, ctx, auth, l2client)
simpleAddr, simple := builder.L2.DeploySimple(t, auth)
simpleContract, err := abi.JSON(strings.NewReader(mocksgen.SimpleABI))
Require(t, err)

// Test direct calls
arbsys, err := precompilesgen.NewArbSys(types.ArbSysAddress, l2client)
arbsys, err := precompilesgen.NewArbSys(types.ArbSysAddress, builder.L2.Client)
Require(t, err)
top, err := arbsys.IsTopLevelCall(nil)
Require(t, err)
Expand All @@ -56,14 +56,14 @@ func TestAliasing(t *testing.T) {
// check via L2
tx, err := simple.CheckCalls(&auth, top, direct, static, delegate, callcode, call)
Require(t, err)
_, err = EnsureTxSucceeded(ctx, l2client, tx)
_, err = builder.L2.EnsureTxSucceeded(tx)
Require(t, err)

// check signed txes via L1
data, err := simpleContract.Pack("checkCalls", top, direct, static, delegate, callcode, call)
Require(t, err)
tx = l2info.PrepareTxTo("Owner", &simpleAddr, 500000, big.NewInt(0), data)
SendSignedTxViaL1(t, ctx, l1info, l1client, l2client, tx)
tx = builder.L2Info.PrepareTxTo("Owner", &simpleAddr, 500000, big.NewInt(0), data)
builder.L1.SendSignedTx(t, builder.L2.Client, tx, builder.L1Info)
}

testUnsigned := func(top, direct, static, delegate, callcode, call bool) {
Expand All @@ -72,8 +72,8 @@ func TestAliasing(t *testing.T) {
// check unsigned txes via L1
data, err := simpleContract.Pack("checkCalls", top, direct, static, delegate, callcode, call)
Require(t, err)
tx := l2info.PrepareTxTo("Owner", &simpleAddr, 500000, big.NewInt(0), data)
SendUnsignedTxViaL1(t, ctx, l1info, l1client, l2client, tx)
tx := builder.L2Info.PrepareTxTo("Owner", &simpleAddr, 500000, big.NewInt(0), data)
builder.L1.SendUnsignedTx(t, builder.L2.Client, tx, builder.L1Info)
}

testL2Signed(true, true, false, false, false, false)
Expand Down
33 changes: 15 additions & 18 deletions system_tests/arbtrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
"github.com/offchainlabs/nitro/execution/gethexec"
"github.com/offchainlabs/nitro/util/testhelpers"
)

type callTxArgs struct {
Expand Down Expand Up @@ -140,18 +138,17 @@ func TestArbTraceForwarding(t *testing.T) {
Public: false,
})
listener, srv, err := rpc.StartIPCEndpoint(ipcPath, apis)
testhelpers.RequireImpl(t, err)
Require(t, err)
defer srv.Stop()
defer listener.Close()

execConfig := gethexec.ConfigDefaultTest()
execConfig.RPC.ClassicRedirect = ipcPath
execConfig.RPC.ClassicRedirectTimeout = time.Second
_, _, _, l2stack, _, _, _, l1stack := createTestNodeOnL1WithConfigImpl(t, ctx, true, nil, execConfig, nil, nil, nil)
defer requireClose(t, l1stack)
defer requireClose(t, l2stack)
builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
builder.execConfig.RPC.ClassicRedirect = ipcPath
builder.execConfig.RPC.ClassicRedirectTimeout = time.Second
cleanup := builder.Build(t)
defer cleanup()

l2rpc, _ := l2stack.Attach()
l2rpc, _ := builder.L2.Stack.Attach()
txArgs := callTxArgs{}
traceTypes := []string{"trace"}
blockNum := rpc.BlockNumberOrHash{}
Expand All @@ -162,22 +159,22 @@ func TestArbTraceForwarding(t *testing.T) {
filter := filterRequest{}
var result traceResult
err = l2rpc.CallContext(ctx, &result, "arbtrace_call", txArgs, traceTypes, blockNum)
testhelpers.RequireImpl(t, err)
Require(t, err)
var results []*traceResult
err = l2rpc.CallContext(ctx, &results, "arbtrace_callMany", traceRequests, blockNum)
testhelpers.RequireImpl(t, err)
Require(t, err)
err = l2rpc.CallContext(ctx, &results, "arbtrace_replayBlockTransactions", blockNum, traceTypes)
testhelpers.RequireImpl(t, err)
Require(t, err)
err = l2rpc.CallContext(ctx, &result, "arbtrace_replayTransaction", txHash, traceTypes)
testhelpers.RequireImpl(t, err)
Require(t, err)
var frames []traceFrame
err = l2rpc.CallContext(ctx, &frames, "arbtrace_transaction", txHash)
testhelpers.RequireImpl(t, err)
Require(t, err)
var frame traceFrame
err = l2rpc.CallContext(ctx, &frame, "arbtrace_get", txHash, path)
testhelpers.RequireImpl(t, err)
Require(t, err)
err = l2rpc.CallContext(ctx, &frames, "arbtrace_block", blockNum)
testhelpers.RequireImpl(t, err)
Require(t, err)
err = l2rpc.CallContext(ctx, &frames, "arbtrace_filter", filter)
testhelpers.RequireImpl(t, err)
Require(t, err)
}
54 changes: 26 additions & 28 deletions system_tests/batch_poster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ func testBatchPosterParallel(t *testing.T, useRedis bool) {
builder.nodeConfig.BatchPoster.RedisUrl = redisUrl
cleanup := builder.Build(t)
defer cleanup()
l1A, l2A := builder.L1, builder.L2

l2B, cleanup2nd := builder.Build2ndNode(t, &SecondNodeParams{})
defer cleanup2nd()
testClientB, cleanupB := builder.Build2ndNode(t, &SecondNodeParams{})
defer cleanupB()

builder.L2Info.GenerateAccount("User2")

Expand All @@ -63,12 +62,12 @@ func testBatchPosterParallel(t *testing.T, useRedis bool) {
tx := builder.L2Info.PrepareTx("Owner", "User2", builder.L2Info.TransferGas, common.Big1, nil)
txs = append(txs, tx)

err := l2A.Client.SendTransaction(ctx, tx)
err := builder.L2.Client.SendTransaction(ctx, tx)
Require(t, err)
}

for _, tx := range txs {
_, err := EnsureTxSucceeded(ctx, l2A.Client, tx)
_, err := builder.L2.EnsureTxSucceeded(tx)
Require(t, err)
}

Expand All @@ -77,20 +76,20 @@ func testBatchPosterParallel(t *testing.T, useRedis bool) {
seqTxOpts := builder.L1Info.GetDefaultTransactOpts("Sequencer", ctx)
builder.nodeConfig.BatchPoster.Enable = true
builder.nodeConfig.BatchPoster.MaxSize = len(firstTxData) * 2
startL1Block, err := l1A.Client.BlockNumber(ctx)
startL1Block, err := builder.L1.Client.BlockNumber(ctx)
Require(t, err)
for i := 0; i < parallelBatchPosters; i++ {
// Make a copy of the batch poster config so NewBatchPoster calling Validate() on it doesn't race
batchPosterConfig := builder.nodeConfig.BatchPoster
batchPoster, err := arbnode.NewBatchPoster(ctx,
&arbnode.BatchPosterOpts{
DataPosterDB: nil,
L1Reader: l2A.ConsensusNode.L1Reader,
Inbox: l2A.ConsensusNode.InboxTracker,
Streamer: l2A.ConsensusNode.TxStreamer,
SyncMonitor: l2A.ConsensusNode.SyncMonitor,
L1Reader: builder.L2.ConsensusNode.L1Reader,
Inbox: builder.L2.ConsensusNode.InboxTracker,
Streamer: builder.L2.ConsensusNode.TxStreamer,
SyncMonitor: builder.L2.ConsensusNode.SyncMonitor,
Config: func() *arbnode.BatchPosterConfig { return &batchPosterConfig },
DeployInfo: l2A.ConsensusNode.DeployInfo,
DeployInfo: builder.L2.ConsensusNode.DeployInfo,
TransactOpts: &seqTxOpts,
DAWriter: nil,
},
Expand All @@ -102,11 +101,11 @@ func testBatchPosterParallel(t *testing.T, useRedis bool) {

lastTxHash := txs[len(txs)-1].Hash()
for i := 90; i > 0; i-- {
SendWaitTestTransactions(t, ctx, l1A.Client, []*types.Transaction{
builder.L1.SendWaitTestTransactions(t, []*types.Transaction{
builder.L1Info.PrepareTx("Faucet", "User", 30000, big.NewInt(1e12), nil),
})
time.Sleep(500 * time.Millisecond)
_, err := l2B.Client.TransactionReceipt(ctx, lastTxHash)
_, err := testClientB.Client.TransactionReceipt(ctx, lastTxHash)
if err == nil {
break
}
Expand All @@ -121,9 +120,9 @@ func testBatchPosterParallel(t *testing.T, useRedis bool) {
// However, setting the clique period to 1 slows everything else (including the L1 deployment for this test) down to a crawl.
if false {
// Make sure the batch poster is able to post multiple batches in one block
endL1Block, err := l1A.Client.BlockNumber(ctx)
endL1Block, err := builder.L1.Client.BlockNumber(ctx)
Require(t, err)
seqInbox, err := arbnode.NewSequencerInbox(l1A.Client, l2A.ConsensusNode.DeployInfo.SequencerInbox, 0)
seqInbox, err := arbnode.NewSequencerInbox(builder.L1.Client, builder.L2.ConsensusNode.DeployInfo.SequencerInbox, 0)
Require(t, err)
batches, err := seqInbox.LookupBatchesInRange(ctx, new(big.Int).SetUint64(startL1Block), new(big.Int).SetUint64(endL1Block))
Require(t, err)
Expand All @@ -143,7 +142,7 @@ func testBatchPosterParallel(t *testing.T, useRedis bool) {
}
}

l2balance, err := l2B.Client.BalanceAt(ctx, builder.L2Info.GetAddress("User2"), nil)
l2balance, err := testClientB.Client.BalanceAt(ctx, builder.L2Info.GetAddress("User2"), nil)
Require(t, err)

if l2balance.Sign() == 0 {
Expand All @@ -160,22 +159,21 @@ func TestBatchPosterLargeTx(t *testing.T) {
builder.execConfig.Sequencer.MaxTxDataSize = 110000
cleanup := builder.Build(t)
defer cleanup()
l2A := builder.L2

l2B, cleanup2nd := builder.Build2ndNode(t, &SecondNodeParams{})
defer cleanup2nd()
testClientB, cleanupB := builder.Build2ndNode(t, &SecondNodeParams{})
defer cleanupB()

data := make([]byte, 100000)
_, err := rand.Read(data)
Require(t, err)
faucetAddr := builder.L2Info.GetAddress("Faucet")
gas := builder.L2Info.TransferGas + 20000*uint64(len(data))
tx := builder.L2Info.PrepareTxTo("Faucet", &faucetAddr, gas, common.Big0, data)
err = l2A.Client.SendTransaction(ctx, tx)
err = builder.L2.Client.SendTransaction(ctx, tx)
Require(t, err)
receiptA, err := EnsureTxSucceeded(ctx, l2A.Client, tx)
receiptA, err := builder.L2.EnsureTxSucceeded(tx)
Require(t, err)
receiptB, err := EnsureTxSucceededWithTimeout(ctx, l2B.Client, tx, time.Second*30)
receiptB, err := testClientB.EnsureTxSucceededWithTimeout(tx, time.Second*30)
Require(t, err)
if receiptA.BlockHash != receiptB.BlockHash {
Fatal(t, "receipt A block hash", receiptA.BlockHash, "does not equal receipt B block hash", receiptB.BlockHash)
Expand All @@ -193,7 +191,7 @@ func TestBatchPosterKeepsUp(t *testing.T) {
builder.execConfig.RPC.RPCTxFeeCap = 1000.
cleanup := builder.Build(t)
defer cleanup()
l2A := builder.L2

builder.L2Info.GasPrice = big.NewInt(100e9)

go func() {
Expand All @@ -203,21 +201,21 @@ func TestBatchPosterKeepsUp(t *testing.T) {
for {
gas := builder.L2Info.TransferGas + 20000*uint64(len(data))
tx := builder.L2Info.PrepareTx("Faucet", "Faucet", gas, common.Big0, data)
err = l2A.Client.SendTransaction(ctx, tx)
err = builder.L2.Client.SendTransaction(ctx, tx)
Require(t, err)
_, err := EnsureTxSucceeded(ctx, l2A.Client, tx)
_, err := builder.L2.EnsureTxSucceeded(tx)
Require(t, err)
}
}()

start := time.Now()
for {
time.Sleep(time.Second)
batches, err := l2A.ConsensusNode.InboxTracker.GetBatchCount()
batches, err := builder.L2.ConsensusNode.InboxTracker.GetBatchCount()
Require(t, err)
postedMessages, err := l2A.ConsensusNode.InboxTracker.GetBatchMessageCount(batches - 1)
postedMessages, err := builder.L2.ConsensusNode.InboxTracker.GetBatchMessageCount(batches - 1)
Require(t, err)
haveMessages, err := l2A.ConsensusNode.TxStreamer.GetMessageCount()
haveMessages, err := builder.L2.ConsensusNode.TxStreamer.GetMessageCount()
Require(t, err)
duration := time.Since(start)
fmt.Printf("batches posted: %v over %v (%.2f batches/second)\n", batches, duration, float64(batches)/(float64(duration)/float64(time.Second)))
Expand Down
10 changes: 5 additions & 5 deletions system_tests/block_hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ func TestBlockHash(t *testing.T) {
defer cancel()

// Even though we don't use the L1, we need to create this node on L1 to get accurate L1 block numbers
l2info, l2node, l2client, _, _, _, l1stack := createTestNodeOnL1(t, ctx, true)
defer requireClose(t, l1stack)
defer l2node.StopAndWait()
builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
cleanup := builder.Build(t)
defer cleanup()

auth := l2info.GetDefaultTransactOpts("Faucet", ctx)
auth := builder.L2Info.GetDefaultTransactOpts("Faucet", ctx)

_, _, simple, err := mocksgen.DeploySimple(&auth, l2client)
_, _, simple, err := mocksgen.DeploySimple(&auth, builder.L2.Client)
Require(t, err)

_, err = simple.CheckBlockHashes(&bind.CallOpts{Context: ctx})
Expand Down
Loading

0 comments on commit 382599c

Please sign in to comment.