-
Notifications
You must be signed in to change notification settings - Fork 20.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18172 from holiman/puppeth_converter
cmd/puppeth: implement chainspec converters
- Loading branch information
Showing
17 changed files
with
892 additions
and
190 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright 2018 The go-ethereum Authors | ||
// This file is part of go-ethereum. | ||
// | ||
// go-ethereum is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// go-ethereum is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/davecgh/go-spew/spew" | ||
"github.com/ethereum/go-ethereum/core" | ||
) | ||
|
||
// Tests the go-ethereum to Aleth chainspec conversion for the Stureby testnet. | ||
func TestAlethSturebyConverter(t *testing.T) { | ||
blob, err := ioutil.ReadFile("testdata/stureby_geth.json") | ||
if err != nil { | ||
t.Fatalf("could not read file: %v", err) | ||
} | ||
var genesis core.Genesis | ||
if err := json.Unmarshal(blob, &genesis); err != nil { | ||
t.Fatalf("failed parsing genesis: %v", err) | ||
} | ||
spec, err := newAlethGenesisSpec("stureby", &genesis) | ||
if err != nil { | ||
t.Fatalf("failed creating chainspec: %v", err) | ||
} | ||
|
||
expBlob, err := ioutil.ReadFile("testdata/stureby_aleth.json") | ||
if err != nil { | ||
t.Fatalf("could not read file: %v", err) | ||
} | ||
expspec := &alethGenesisSpec{} | ||
if err := json.Unmarshal(expBlob, expspec); err != nil { | ||
t.Fatalf("failed parsing genesis: %v", err) | ||
} | ||
if !reflect.DeepEqual(expspec, spec) { | ||
t.Errorf("chainspec mismatch") | ||
c := spew.ConfigState{ | ||
DisablePointerAddresses: true, | ||
SortKeys: true, | ||
} | ||
exp := strings.Split(c.Sdump(expspec), "\n") | ||
got := strings.Split(c.Sdump(spec), "\n") | ||
for i := 0; i < len(exp) && i < len(got); i++ { | ||
if exp[i] != got[i] { | ||
fmt.Printf("got: %v\nexp: %v\n", exp[i], got[i]) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Tests the go-ethereum to Parity chainspec conversion for the Stureby testnet. | ||
func TestParitySturebyConverter(t *testing.T) { | ||
blob, err := ioutil.ReadFile("testdata/stureby_geth.json") | ||
if err != nil { | ||
t.Fatalf("could not read file: %v", err) | ||
} | ||
var genesis core.Genesis | ||
if err := json.Unmarshal(blob, &genesis); err != nil { | ||
t.Fatalf("failed parsing genesis: %v", err) | ||
} | ||
spec, err := newParityChainSpec("Stureby", &genesis, []string{}) | ||
if err != nil { | ||
t.Fatalf("failed creating chainspec: %v", err) | ||
} | ||
|
||
expBlob, err := ioutil.ReadFile("testdata/stureby_parity.json") | ||
if err != nil { | ||
t.Fatalf("could not read file: %v", err) | ||
} | ||
expspec := &parityChainSpec{} | ||
if err := json.Unmarshal(expBlob, expspec); err != nil { | ||
t.Fatalf("failed parsing genesis: %v", err) | ||
} | ||
expspec.Nodes = []string{} | ||
|
||
if !reflect.DeepEqual(expspec, spec) { | ||
t.Errorf("chainspec mismatch") | ||
c := spew.ConfigState{ | ||
DisablePointerAddresses: true, | ||
SortKeys: true, | ||
} | ||
exp := strings.Split(c.Sdump(expspec), "\n") | ||
got := strings.Split(c.Sdump(spec), "\n") | ||
for i := 0; i < len(exp) && i < len(got); i++ { | ||
if exp[i] != got[i] { | ||
fmt.Printf("got: %v\nexp: %v\n", exp[i], got[i]) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
{ | ||
"sealEngine":"Ethash", | ||
"params":{ | ||
"accountStartNonce":"0x00", | ||
"maximumExtraDataSize":"0x20", | ||
"homesteadForkBlock":"0x2710", | ||
"daoHardforkBlock":"0x00", | ||
"EIP150ForkBlock":"0x3a98", | ||
"EIP158ForkBlock":"0x59d8", | ||
"byzantiumForkBlock":"0x7530", | ||
"constantinopleForkBlock":"0x9c40", | ||
"minGasLimit":"0x1388", | ||
"maxGasLimit":"0x7fffffffffffffff", | ||
"tieBreakingGas":false, | ||
"gasLimitBoundDivisor":"0x0400", | ||
"minimumDifficulty":"0x20000", | ||
"difficultyBoundDivisor":"0x0800", | ||
"durationLimit":"0x0d", | ||
"blockReward":"0x4563918244F40000", | ||
"networkID":"0x4cb2e", | ||
"chainID":"0x4cb2e", | ||
"allowFutureBlocks":false | ||
}, | ||
"genesis":{ | ||
"nonce":"0x0000000000000000", | ||
"difficulty":"0x20000", | ||
"mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"author":"0x0000000000000000000000000000000000000000", | ||
"timestamp":"0x59a4e76d", | ||
"parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"extraData":"0x0000000000000000000000000000000000000000000000000000000b4dc0ffee", | ||
"gasLimit":"0x47b760" | ||
}, | ||
"accounts":{ | ||
"0000000000000000000000000000000000000001":{ | ||
"balance":"1", | ||
"precompiled":{ | ||
"name":"ecrecover", | ||
"linear":{ | ||
"base":3000, | ||
"word":0 | ||
} | ||
} | ||
}, | ||
"0000000000000000000000000000000000000002":{ | ||
"balance":"1", | ||
"precompiled":{ | ||
"name":"sha256", | ||
"linear":{ | ||
"base":60, | ||
"word":12 | ||
} | ||
} | ||
}, | ||
"0000000000000000000000000000000000000003":{ | ||
"balance":"1", | ||
"precompiled":{ | ||
"name":"ripemd160", | ||
"linear":{ | ||
"base":600, | ||
"word":120 | ||
} | ||
} | ||
}, | ||
"0000000000000000000000000000000000000004":{ | ||
"balance":"1", | ||
"precompiled":{ | ||
"name":"identity", | ||
"linear":{ | ||
"base":15, | ||
"word":3 | ||
} | ||
} | ||
}, | ||
"0000000000000000000000000000000000000005":{ | ||
"balance":"1", | ||
"precompiled":{ | ||
"name":"modexp", | ||
"startingBlock":"0x7530" | ||
} | ||
}, | ||
"0000000000000000000000000000000000000006":{ | ||
"balance":"1", | ||
"precompiled":{ | ||
"name":"alt_bn128_G1_add", | ||
"startingBlock":"0x7530", | ||
"linear":{ | ||
"base":500, | ||
"word":0 | ||
} | ||
} | ||
}, | ||
"0000000000000000000000000000000000000007":{ | ||
"balance":"1", | ||
"precompiled":{ | ||
"name":"alt_bn128_G1_mul", | ||
"startingBlock":"0x7530", | ||
"linear":{ | ||
"base":40000, | ||
"word":0 | ||
} | ||
} | ||
}, | ||
"0000000000000000000000000000000000000008":{ | ||
"balance":"1", | ||
"precompiled":{ | ||
"name":"alt_bn128_pairing_product", | ||
"startingBlock":"0x7530" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"config": { | ||
"ethash":{}, | ||
"chainId": 314158, | ||
"homesteadBlock": 10000, | ||
"eip150Block": 15000, | ||
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"eip155Block": 23000, | ||
"eip158Block": 23000, | ||
"byzantiumBlock": 30000, | ||
"constantinopleBlock": 40000 | ||
}, | ||
"nonce": "0x0", | ||
"timestamp": "0x59a4e76d", | ||
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"extraData": "0x0000000000000000000000000000000000000000000000000000000b4dc0ffee", | ||
"gasLimit": "0x47b760", | ||
"difficulty": "0x20000", | ||
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
"coinbase": "0x0000000000000000000000000000000000000000", | ||
"alloc": { | ||
"0000000000000000000000000000000000000001": { | ||
"balance": "0x01" | ||
}, | ||
"0000000000000000000000000000000000000002": { | ||
"balance": "0x01" | ||
}, | ||
"0000000000000000000000000000000000000003": { | ||
"balance": "0x01" | ||
}, | ||
"0000000000000000000000000000000000000004": { | ||
"balance": "0x01" | ||
}, | ||
"0000000000000000000000000000000000000005": { | ||
"balance": "0x01" | ||
}, | ||
"0000000000000000000000000000000000000006": { | ||
"balance": "0x01" | ||
}, | ||
"0000000000000000000000000000000000000007": { | ||
"balance": "0x01" | ||
}, | ||
"0000000000000000000000000000000000000008": { | ||
"balance": "0x01" | ||
} | ||
} | ||
} |
Oops, something went wrong.