Commit 7f61f6ef authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

op-chain-ops: Allow configurable dev accounts (#3381)

* op-chain-ops: Allow configurable dev accounts

* Set difficulty to zero

* Add tests
parent f927bc58
...@@ -72,6 +72,8 @@ type DeployConfig struct { ...@@ -72,6 +72,8 @@ type DeployConfig struct {
EIP1559Elasticity uint64 `json:"eip1559Elasticity"` EIP1559Elasticity uint64 `json:"eip1559Elasticity"`
EIP1559Denominator uint64 `json:"eip1559Denominator"` EIP1559Denominator uint64 `json:"eip1559Denominator"`
FundDevAccounts bool `json:"fundDevAccounts"`
} }
// NewDeployConfig reads a config file given a path on the filesystem. // NewDeployConfig reads a config file given a path on the filesystem.
......
...@@ -74,7 +74,7 @@ func NewL2Genesis(config *DeployConfig, block *types.Block) (*core.Genesis, erro ...@@ -74,7 +74,7 @@ func NewL2Genesis(config *DeployConfig, block *types.Block) (*core.Genesis, erro
} }
difficulty := config.L2GenesisBlockDifficulty difficulty := config.L2GenesisBlockDifficulty
if difficulty == nil { if difficulty == nil {
difficulty = newHexBig(1) difficulty = newHexBig(0)
} }
return &core.Genesis{ return &core.Genesis{
......
...@@ -24,7 +24,9 @@ func BuildL2DeveloperGenesis(config *DeployConfig, l1StartBlock *types.Block, l2 ...@@ -24,7 +24,9 @@ func BuildL2DeveloperGenesis(config *DeployConfig, l1StartBlock *types.Block, l2
db := state.NewMemoryStateDB(genspec) db := state.NewMemoryStateDB(genspec)
if config.FundDevAccounts {
FundDevAccounts(db) FundDevAccounts(db)
}
SetPrecompileBalances(db) SetPrecompileBalances(db)
return BuildL2Genesis(db, config, l1StartBlock, l2Addrs) return BuildL2Genesis(db, config, l1StartBlock, l2Addrs)
......
...@@ -77,9 +77,30 @@ func TestBuildL2DeveloperGenesis(t *testing.T) { ...@@ -77,9 +77,30 @@ func TestBuildL2DeveloperGenesis(t *testing.T) {
require.Equal(t, adminSlot, proxyAdmin.Address.Hash()) require.Equal(t, adminSlot, proxyAdmin.Address.Hash())
require.Equal(t, account.Code, depB) require.Equal(t, account.Code, depB)
} }
require.Equal(t, 2337, len(gen.Alloc))
if writeFile { if writeFile {
file, _ := json.MarshalIndent(gen, "", " ") file, _ := json.MarshalIndent(gen, "", " ")
_ = os.WriteFile("genesis.json", file, 0644) _ = os.WriteFile("genesis.json", file, 0644)
} }
} }
func TestBuildL2DeveloperGenesisDevAccountsFunding(t *testing.T) {
config, err := genesis.NewDeployConfig("./testdata/test-deploy-config-devnet-l1.json")
require.Nil(t, err)
config.FundDevAccounts = false
backend := backends.NewSimulatedBackend(
core.GenesisAlloc{
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(10000000000000000)},
},
15000000,
)
block, err := backend.BlockByNumber(context.Background(), common.Big0)
require.NoError(t, err)
gen, err := genesis.BuildL2DeveloperGenesis(config, block, &genesis.L2Addresses{
ProxyAdmin: common.Address{},
})
require.NoError(t, err)
require.Equal(t, 2316, len(gen.Alloc))
}
...@@ -23,5 +23,6 @@ ...@@ -23,5 +23,6 @@
"optimismBaseFeeRecipient": "0xBcd4042DE499D14e55001CcbB24a551F3b954096", "optimismBaseFeeRecipient": "0xBcd4042DE499D14e55001CcbB24a551F3b954096",
"optimismL1FeeRecipient": "0x71bE63f3384f5fb98995898A86B02Fb2426c5788", "optimismL1FeeRecipient": "0x71bE63f3384f5fb98995898A86B02Fb2426c5788",
"deploymentWaitConfirmations": 1 "deploymentWaitConfirmations": 1,
"fundDevAccounts": true
} }
...@@ -47,5 +47,6 @@ ...@@ -47,5 +47,6 @@
"gasPriceOracleDecimals": 6, "gasPriceOracleDecimals": 6,
"deploymentWaitConfirmations": 1, "deploymentWaitConfirmations": 1,
"eip1559Denominator": 8, "eip1559Denominator": 8,
"eip1559Elasticity": 2 "eip1559Elasticity": 2,
"fundDevAccounts": true
} }
\ No newline at end of file
...@@ -23,5 +23,6 @@ ...@@ -23,5 +23,6 @@
"optimismBaseFeeRecipient": "0xBcd4042DE499D14e55001CcbB24a551F3b954096", "optimismBaseFeeRecipient": "0xBcd4042DE499D14e55001CcbB24a551F3b954096",
"optimismL1FeeRecipient": "0x71bE63f3384f5fb98995898A86B02Fb2426c5788", "optimismL1FeeRecipient": "0x71bE63f3384f5fb98995898A86B02Fb2426c5788",
"deploymentWaitConfirmations": 1 "deploymentWaitConfirmations": 1,
"fundDevAccounts": true
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment