Commit 2eb8cee5 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #6436 from ethereum-optimism/op-chain-ops/deploy-config-copy

op-chain-ops: deploy config copy
parents c4edcd2e d5480423
......@@ -169,6 +169,22 @@ type DeployConfig struct {
FundDevAccounts bool `json:"fundDevAccounts"`
}
// Copy will deeply copy the DeployConfig. This does a JSON roundtrip to copy
// which makes it easier to maintain, we do not need efficiency in this case.
func (d *DeployConfig) Copy() *DeployConfig {
raw, err := json.Marshal(d)
if err != nil {
panic(err)
}
cpy := DeployConfig{}
if err = json.Unmarshal(raw, &cpy); err != nil {
panic(err)
}
return &cpy
}
// Check will ensure that the config is sane and return an error when it is not
func (d *DeployConfig) Check() error {
if d.L1StartingBlockTag == nil {
......
......@@ -48,3 +48,19 @@ func TestRegolithTimeAsOffset(t *testing.T) {
config := &DeployConfig{L2GenesisRegolithTimeOffset: &regolithOffset}
require.Equal(t, uint64(1500+5000), *config.RegolithTime(5000))
}
// TestCopy will copy a DeployConfig and ensure that the copy is equal to the original.
func TestCopy(t *testing.T) {
b, err := os.ReadFile("testdata/test-deploy-config-full.json")
require.NoError(t, err)
decoded := new(DeployConfig)
require.NoError(t, json.NewDecoder(bytes.NewReader(b)).Decode(decoded))
cpy := decoded.Copy()
require.EqualValues(t, decoded, cpy)
offset := hexutil.Uint64(100)
cpy.L2GenesisRegolithTimeOffset = &offset
require.NotEqual(t, decoded, cpy)
}
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