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

Add option struct for creating L2 blockchain for tests #1933

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion system_tests/arbtrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ func TestArbTraceForwarding(t *testing.T) {
execConfig := gethexec.ConfigDefaultTest()
execConfig.RPC.ClassicRedirect = ipcPath
execConfig.RPC.ClassicRedirectTimeout = time.Second
_, _, _, l2stack, _, _, _, l1stack := createTestNodeOnL1WithConfigImpl(t, ctx, true, nil, execConfig, nil, nil, nil)
_, _, _, l2stack, _, _, _, l1stack := createTestNodeOnL1WithConfigImpl(t, ctx, &createTestNodeOnL1Options{
isSequencer: true,
execConfig: execConfig,
})
defer requireClose(t, l1stack)
defer requireClose(t, l2stack)

Expand Down
149 changes: 93 additions & 56 deletions system_tests/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,15 @@ func (b *NodeBuilder) Build(t *testing.T) func() {
if b.withL1 {
l1, l2 := NewTestClient(b.ctx), NewTestClient(b.ctx)
b.L2Info, l2.ConsensusNode, l2.Client, l2.Stack, b.L1Info, l1.L1Backend, l1.Client, l1.Stack =
createTestNodeOnL1WithConfigImpl(t, b.ctx, b.isSequencer, b.nodeConfig, b.execConfig, b.chainConfig, b.l2StackConfig, b.L2Info)
createTestNodeOnL1WithConfigImpl(t, b.ctx,
&createTestNodeOnL1Options{
isSequencer: b.isSequencer,
nodeConfig: b.nodeConfig,
execConfig: b.execConfig,
chainConfig: b.chainConfig,
stackConfig: b.l2StackConfig,
l2info_in: b.L2Info,
})
b.L1, b.L2 = l1, l2
b.L1.cleanup = func() { requireClose(t, b.L1.Stack) }
} else {
Expand Down Expand Up @@ -447,7 +455,7 @@ func (c *staticNodeConfigFetcher) Started() bool {
}

func createTestL1BlockChain(t *testing.T, l1info info) (info, *ethclient.Client, *eth.Ethereum, *node.Node) {
return createTestL1BlockChainWithConfig(t, l1info, nil)
return createTestL1BlockChainWithConfig(t, l1info)
}

func createStackConfigForTest(dataDir string) *node.Config {
Expand Down Expand Up @@ -533,13 +541,11 @@ func AddDefaultValNode(t *testing.T, ctx context.Context, nodeConfig *arbnode.Co
configByValidationNode(t, nodeConfig, valStack)
}

func createTestL1BlockChainWithConfig(t *testing.T, l1info info, stackConfig *node.Config) (info, *ethclient.Client, *eth.Ethereum, *node.Node) {
func createTestL1BlockChainWithConfig(t *testing.T, l1info info) (info, *ethclient.Client, *eth.Ethereum, *node.Node) {
if l1info == nil {
l1info = NewL1TestInfo(t)
}
if stackConfig == nil {
stackConfig = createStackConfigForTest(t.TempDir())
}
stackConfig := createStackConfigForTest(t.TempDir())
l1info.GenerateAccount("Faucet")

chainConfig := params.ArbitrumDevTestChainConfig()
Expand Down Expand Up @@ -644,50 +650,52 @@ func DeployOnTestL1(
return addresses, initMessage
}

func createL2BlockChain(
t *testing.T, l2info *BlockchainTestInfo, dataDir string, chainConfig *params.ChainConfig, cacheConfig *gethexec.CachingConfig,
) (*BlockchainTestInfo, *node.Node, ethdb.Database, ethdb.Database, *core.BlockChain) {
return createL2BlockChainWithStackConfig(t, l2info, dataDir, chainConfig, nil, nil, cacheConfig)
type createL2BlockChainOptions struct {
l2info *BlockchainTestInfo
dataDir string
chainConfig *params.ChainConfig
initMessage *arbostypes.ParsedInitMessage
stackConfig *node.Config
cacheConfig *gethexec.CachingConfig
}

func createL2BlockChainWithStackConfig(
t *testing.T, l2info *BlockchainTestInfo, dataDir string, chainConfig *params.ChainConfig, initMessage *arbostypes.ParsedInitMessage, stackConfig *node.Config, cacheConfig *gethexec.CachingConfig,
) (*BlockchainTestInfo, *node.Node, ethdb.Database, ethdb.Database, *core.BlockChain) {
if l2info == nil {
l2info = NewArbTestInfo(t, chainConfig.ChainID)
func createL2BlockChain(
t *testing.T, opts *createL2BlockChainOptions) (*BlockchainTestInfo, *node.Node, ethdb.Database, ethdb.Database, *core.BlockChain) {
if opts.l2info == nil {
opts.l2info = NewArbTestInfo(t, opts.chainConfig.ChainID)
}
var stack *node.Node
var err error
if stackConfig == nil {
stackConfig = createStackConfigForTest(dataDir)
if opts.stackConfig == nil {
opts.stackConfig = createStackConfigForTest(opts.dataDir)
}
stack, err = node.New(stackConfig)
stack, err = node.New(opts.stackConfig)
Require(t, err)

chainDb, err := stack.OpenDatabase("chaindb", 0, 0, "", false)
Require(t, err)
arbDb, err := stack.OpenDatabase("arbdb", 0, 0, "", false)
Require(t, err)

initReader := statetransfer.NewMemoryInitDataReader(&l2info.ArbInitData)
if initMessage == nil {
serializedChainConfig, err := json.Marshal(chainConfig)
initReader := statetransfer.NewMemoryInitDataReader(&opts.l2info.ArbInitData)
if opts.initMessage == nil {
serializedChainConfig, err := json.Marshal(opts.chainConfig)
Require(t, err)
initMessage = &arbostypes.ParsedInitMessage{
ChainId: chainConfig.ChainID,
opts.initMessage = &arbostypes.ParsedInitMessage{
ChainId: opts.chainConfig.ChainID,
InitialL1BaseFee: arbostypes.DefaultInitialL1BaseFee,
ChainConfig: chainConfig,
ChainConfig: opts.chainConfig,
SerializedChainConfig: serializedChainConfig,
}
}
var coreCacheConfig *core.CacheConfig
if cacheConfig != nil {
coreCacheConfig = gethexec.DefaultCacheConfigFor(stack, cacheConfig)
if opts.cacheConfig != nil {
coreCacheConfig = gethexec.DefaultCacheConfigFor(stack, opts.cacheConfig)
}
blockchain, err := gethexec.WriteOrTestBlockChain(chainDb, coreCacheConfig, initReader, chainConfig, initMessage, gethexec.ConfigDefaultTest().TxLookupLimit, 0)
blockchain, err := gethexec.WriteOrTestBlockChain(chainDb, coreCacheConfig, initReader, opts.chainConfig, opts.initMessage, gethexec.ConfigDefaultTest().TxLookupLimit, 0)
Require(t, err)

return l2info, stack, chainDb, arbDb, blockchain
return opts.l2info, stack, chainDb, arbDb, blockchain
}

func ClientForStack(t *testing.T, backend *node.Node) *ethclient.Client {
Expand Down Expand Up @@ -720,67 +728,88 @@ func createTestNodeOnL1WithConfig(
l2info info, currentNode *arbnode.Node, l2client *ethclient.Client, l1info info,
l1backend *eth.Ethereum, l1client *ethclient.Client, l1stack *node.Node,
) {
l2info, currentNode, l2client, _, l1info, l1backend, l1client, l1stack = createTestNodeOnL1WithConfigImpl(t, ctx, isSequencer, nodeConfig, execConfig, chainConfig, stackConfig, nil)
l2info, currentNode, l2client, _, l1info, l1backend, l1client, l1stack = createTestNodeOnL1WithConfigImpl(t, ctx,
&createTestNodeOnL1Options{
isSequencer: isSequencer,
nodeConfig: nodeConfig,
execConfig: execConfig,
chainConfig: chainConfig,
stackConfig: stackConfig,
l2info_in: nil,
})
return
}

type createTestNodeOnL1Options struct {
isSequencer bool
nodeConfig *arbnode.Config
execConfig *gethexec.Config
chainConfig *params.ChainConfig
stackConfig *node.Config
l2info_in info
}

func createTestNodeOnL1WithConfigImpl(
t *testing.T,
ctx context.Context,
isSequencer bool,
nodeConfig *arbnode.Config,
execConfig *gethexec.Config,
chainConfig *params.ChainConfig,
stackConfig *node.Config,
l2info_in info,
opts *createTestNodeOnL1Options,
) (
l2info info, currentNode *arbnode.Node, l2client *ethclient.Client, l2stack *node.Node,
l1info info, l1backend *eth.Ethereum, l1client *ethclient.Client, l1stack *node.Node,
) {
if nodeConfig == nil {
nodeConfig = arbnode.ConfigDefaultL1Test()
if opts.nodeConfig == nil {
opts.nodeConfig = arbnode.ConfigDefaultL1Test()
}
if execConfig == nil {
execConfig = gethexec.ConfigDefaultTest()
if opts.execConfig == nil {
opts.execConfig = gethexec.ConfigDefaultTest()
}
if chainConfig == nil {
chainConfig = params.ArbitrumDevTestChainConfig()
if opts.chainConfig == nil {
opts.chainConfig = params.ArbitrumDevTestChainConfig()
}
fatalErrChan := make(chan error, 10)
l1info, l1client, l1backend, l1stack = createTestL1BlockChain(t, nil)
var l2chainDb ethdb.Database
var l2arbDb ethdb.Database
var l2blockchain *core.BlockChain
l2info = l2info_in
l2info = opts.l2info_in
if l2info == nil {
l2info = NewArbTestInfo(t, chainConfig.ChainID)
l2info = NewArbTestInfo(t, opts.chainConfig.ChainID)
}
addresses, initMessage := DeployOnTestL1(t, ctx, l1info, l1client, chainConfig)
_, l2stack, l2chainDb, l2arbDb, l2blockchain = createL2BlockChainWithStackConfig(t, l2info, "", chainConfig, initMessage, stackConfig, &execConfig.Caching)
addresses, initMessage := DeployOnTestL1(t, ctx, l1info, l1client, opts.chainConfig)
_, l2stack, l2chainDb, l2arbDb, l2blockchain = createL2BlockChain(t,
&createL2BlockChainOptions{
l2info: l2info,
dataDir: "",
chainConfig: opts.chainConfig,
initMessage: initMessage,
stackConfig: opts.stackConfig,
cacheConfig: &opts.execConfig.Caching,
})
// l2info, "", chainConfig, initMessage, stackConfig, &execConfig.Caching)
var sequencerTxOptsPtr *bind.TransactOpts
var dataSigner signature.DataSignerFunc
if isSequencer {
if opts.isSequencer {
sequencerTxOpts := l1info.GetDefaultTransactOpts("Sequencer", ctx)
sequencerTxOptsPtr = &sequencerTxOpts
dataSigner = signature.DataSignerFromPrivateKey(l1info.GetInfoWithPrivKey("Sequencer").PrivateKey)
}

if !isSequencer {
nodeConfig.BatchPoster.Enable = false
nodeConfig.Sequencer = false
nodeConfig.DelayedSequencer.Enable = false
execConfig.Sequencer.Enable = false
if !opts.isSequencer {
opts.nodeConfig.BatchPoster.Enable = false
opts.nodeConfig.Sequencer = false
opts.nodeConfig.DelayedSequencer.Enable = false
opts.execConfig.Sequencer.Enable = false
}

AddDefaultValNode(t, ctx, nodeConfig, true)
AddDefaultValNode(t, ctx, opts.nodeConfig, true)

Require(t, execConfig.Validate())
execConfigFetcher := func() *gethexec.Config { return execConfig }
Require(t, opts.execConfig.Validate())
execConfigFetcher := func() *gethexec.Config { return opts.execConfig }
execNode, err := gethexec.CreateExecutionNode(ctx, l2stack, l2chainDb, l2blockchain, l1client, execConfigFetcher)
Require(t, err)

currentNode, err = arbnode.CreateNode(
ctx, l2stack, execNode, l2arbDb, NewFetcherFromConfig(nodeConfig), l2blockchain.Config(), l1client,
ctx, l2stack, execNode, l2arbDb, NewFetcherFromConfig(opts.nodeConfig), l2blockchain.Config(), l1client,
addresses, sequencerTxOptsPtr, sequencerTxOptsPtr, dataSigner, fatalErrChan,
)
Require(t, err)
Expand Down Expand Up @@ -814,7 +843,15 @@ func CreateTestL2WithConfig(

AddDefaultValNode(t, ctx, nodeConfig, true)

l2info, stack, chainDb, arbDb, blockchain := createL2BlockChain(t, l2Info, "", params.ArbitrumDevTestChainConfig(), &execConfig.Caching)
l2info, stack, chainDb, arbDb, blockchain := createL2BlockChain(t,
&createL2BlockChainOptions{
l2info: l2Info,
dataDir: "",
chainConfig: params.ArbitrumDevTestChainConfig(),
initMessage: nil,
stackConfig: nil,
cacheConfig: &execConfig.Caching,
})

Require(t, execConfig.Validate())
execConfigFetcher := func() *gethexec.Config { return execConfig }
Expand Down
21 changes: 19 additions & 2 deletions system_tests/das_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,15 @@ func TestDASRekey(t *testing.T) {
authorizeDASKeyset(t, ctx, pubkeyA, l1info, l1client)

// Setup L2 chain
_, l2stackA, l2chainDb, l2arbDb, l2blockchain := createL2BlockChainWithStackConfig(t, l2info, nodeDir, chainConfig, initMessage, nil, nil)
_, l2stackA, l2chainDb, l2arbDb, l2blockchain := createL2BlockChain(t,
&createL2BlockChainOptions{
l2info: l2info,
dataDir: nodeDir,
chainConfig: chainConfig,
initMessage: initMessage,
stackConfig: nil,
cacheConfig: nil,
})
l2info.GenerateAccount("User2")

// Setup DAS config
Expand Down Expand Up @@ -314,7 +322,16 @@ func TestDASComplexConfigAndRestMirror(t *testing.T) {
Require(t, err)

// Setup L2 chain
l2info, l2stackA, l2chainDb, l2arbDb, l2blockchain := createL2BlockChainWithStackConfig(t, nil, "", chainConfig, initMessage, nil, nil)
l2info, l2stackA, l2chainDb, l2arbDb, l2blockchain := createL2BlockChain(t,
&createL2BlockChainOptions{
l2info: nil,
dataDir: "",
chainConfig: chainConfig,
initMessage: initMessage,
stackConfig: nil,
cacheConfig: nil,
})
// nil, "", chainConfig, initMessage, nil, nil)
l2info.GenerateAccount("User2")

execA, err := gethexec.CreateExecutionNode(ctx, l2stackA, l2chainDb, l2blockchain, l1client, gethexec.ConfigDefaultTest)
Expand Down
2 changes: 1 addition & 1 deletion system_tests/debugapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestDebugAPI(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
_, _, _, l2stack, _, _, _, l1stack := createTestNodeOnL1WithConfigImpl(t, ctx, true, nil, nil, nil, nil, nil)
_, _, _, l2stack, _, _, _, l1stack := createTestNodeOnL1WithConfigImpl(t, ctx, &createTestNodeOnL1Options{isSequencer: true})
defer requireClose(t, l1stack)
defer requireClose(t, l2stack)

Expand Down
20 changes: 18 additions & 2 deletions system_tests/full_challenge_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,15 @@ func RunChallengeTest(t *testing.T, asserterIsCorrect bool, useStubs bool, chall
asserterBridgeAddr, asserterSeqInbox, asserterSeqInboxAddr := setupSequencerInboxStub(ctx, t, l1Info, l1Backend, chainConfig)
challengerBridgeAddr, challengerSeqInbox, challengerSeqInboxAddr := setupSequencerInboxStub(ctx, t, l1Info, l1Backend, chainConfig)

asserterL2Info, asserterL2Stack, asserterL2ChainDb, asserterL2ArbDb, asserterL2Blockchain := createL2BlockChainWithStackConfig(t, nil, "", chainConfig, initMessage, nil, nil)
asserterL2Info, asserterL2Stack, asserterL2ChainDb, asserterL2ArbDb, asserterL2Blockchain := createL2BlockChain(t,
&createL2BlockChainOptions{
l2info: nil,
dataDir: "",
chainConfig: chainConfig,
initMessage: initMessage,
stackConfig: nil,
cacheConfig: nil,
})
asserterRollupAddresses.Bridge = asserterBridgeAddr
asserterRollupAddresses.SequencerInbox = asserterSeqInboxAddr
asserterExec, err := gethexec.CreateExecutionNode(ctx, asserterL2Stack, asserterL2ChainDb, asserterL2Blockchain, l1Backend, gethexec.ConfigDefaultTest)
Expand All @@ -278,7 +286,15 @@ func RunChallengeTest(t *testing.T, asserterIsCorrect bool, useStubs bool, chall
err = asserterL2.Start(ctx)
Require(t, err)

challengerL2Info, challengerL2Stack, challengerL2ChainDb, challengerL2ArbDb, challengerL2Blockchain := createL2BlockChainWithStackConfig(t, nil, "", chainConfig, initMessage, nil, nil)
challengerL2Info, challengerL2Stack, challengerL2ChainDb, challengerL2ArbDb, challengerL2Blockchain := createL2BlockChain(t,
&createL2BlockChainOptions{
l2info: nil,
dataDir: "",
chainConfig: chainConfig,
initMessage: initMessage,
stackConfig: nil,
cacheConfig: nil,
})
challengerRollupAddresses := *asserterRollupAddresses
challengerRollupAddresses.Bridge = challengerBridgeAddr
challengerRollupAddresses.SequencerInbox = challengerSeqInboxAddr
Expand Down
20 changes: 18 additions & 2 deletions system_tests/recreatestate_rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,15 @@ func testSkippingSavingStateAndRecreatingAfterRestart(t *testing.T, cacheConfig
skipGas := execConfig.Caching.MaxAmountOfGasToSkipStateSaving

feedErrChan := make(chan error, 10)
l2info, stack, chainDb, arbDb, blockchain := createL2BlockChain(t, nil, t.TempDir(), params.ArbitrumDevTestChainConfig(), &execConfig.Caching)
l2info, stack, chainDb, arbDb, blockchain := createL2BlockChain(t,
&createL2BlockChainOptions{
l2info: nil,
dataDir: t.TempDir(),
chainConfig: params.ArbitrumDevTestChainConfig(),
initMessage: nil,
stackConfig: nil,
cacheConfig: &execConfig.Caching,
})

Require(t, execConfig.Validate())
execConfigFetcher := func() *gethexec.Config { return execConfig }
Expand Down Expand Up @@ -373,7 +381,15 @@ func testSkippingSavingStateAndRecreatingAfterRestart(t *testing.T, cacheConfig
cancel1()
t.Log("stopped first node")

l2info, stack, chainDb, arbDb, blockchain = createL2BlockChain(t, l2info, dataDir, params.ArbitrumDevTestChainConfig(), &execConfig.Caching)
l2info, stack, chainDb, arbDb, blockchain = createL2BlockChain(t,
&createL2BlockChainOptions{
l2info: l2info,
dataDir: dataDir,
chainConfig: params.ArbitrumDevTestChainConfig(),
initMessage: nil,
stackConfig: nil,
cacheConfig: &execConfig.Caching,
})

execNode, err = gethexec.CreateExecutionNode(ctx1, stack, chainDb, blockchain, nil, execConfigFetcher)
Require(t, err)
Expand Down
7 changes: 6 additions & 1 deletion system_tests/staker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ func stakerTestImpl(t *testing.T, faultyStaker bool, honestStakerInactive bool)
types.NewArbitrumSigner(types.NewLondonSigner(l2chainConfig.ChainID)), big.NewInt(l2pricing.InitialBaseFeeWei*2),
transferGas,
)
_, l2nodeA, l2clientA, _, l1info, _, l1client, l1stack := createTestNodeOnL1WithConfigImpl(t, ctx, true, nil, nil, l2chainConfig, nil, l2info)
_, l2nodeA, l2clientA, _, l1info, _, l1client, l1stack := createTestNodeOnL1WithConfigImpl(t, ctx,
&createTestNodeOnL1Options{
isSequencer: true,
chainConfig: l2chainConfig,
l2info_in: l2info,
})
defer requireClose(t, l1stack)
defer l2nodeA.StopAndWait()
execNodeA := getExecNode(t, l2nodeA)
Expand Down
Loading