github.com/cheng762/platon-go@v1.8.17-0.20190529111256-7deff2d7be26/cmd/platon/genesis_test.go (about) 1 // Copyright 2016 The go-ethereum Authors 2 // This file is part of go-ethereum. 3 // 4 // go-ethereum is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // go-ethereum is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 var customGenesisTests = []struct { 20 genesis string 21 query string 22 result string 23 }{ 24 // Plain genesis file without anything extra 25 { 26 genesis: `{ 27 "alloc" : {}, 28 "coinbase" : "0x0000000000000000000000000000000000000000", 29 "difficulty" : "0x20000", 30 "extraData" : "", 31 "gasLimit" : "0x2fefd8", 32 "nonce" : "0x0000000000000042", 33 "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 34 "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 35 "timestamp" : "0x00" 36 }`, 37 query: "eth.getBlock(0).nonce", 38 result: "0x0000000000000042", 39 }, 40 // Genesis file with an empty chain configuration (ensure missing fields work) 41 { 42 genesis: `{ 43 "alloc" : {}, 44 "coinbase" : "0x0000000000000000000000000000000000000000", 45 "difficulty" : "0x20000", 46 "extraData" : "", 47 "gasLimit" : "0x2fefd8", 48 "nonce" : "0x0000000000000042", 49 "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 50 "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 51 "timestamp" : "0x00", 52 "config" : {} 53 }`, 54 query: "eth.getBlock(0).nonce", 55 result: "0x0000000000000042", 56 }, 57 // Genesis file with specific chain configurations 58 { 59 genesis: `{ 60 "alloc" : {}, 61 "coinbase" : "0x0000000000000000000000000000000000000000", 62 "difficulty" : "0x20000", 63 "extraData" : "", 64 "gasLimit" : "0x2fefd8", 65 "nonce" : "0x0000000000000042", 66 "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 67 "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 68 "timestamp" : "0x00", 69 "config" : { 70 "homesteadBlock" : 314, 71 "daoForkBlock" : 141, 72 "daoForkSupport" : true 73 } 74 }`, 75 query: "eth.getBlock(0).nonce", 76 result: "0x0000000000000042", 77 }, 78 } 79 80 // Tests that initializing Geth with a custom genesis block and chain definitions 81 // work properly. 82 /*func TestCustomGenesis(t *testing.T) { 83 for i, tt := range customGenesisTests { 84 // Create a temporary data directory to use and inspect later 85 datadir := tmpdir(t) 86 defer os.RemoveAll(datadir) 87 88 // Initialize the data directory with the custom genesis block 89 json := filepath.Join(datadir, "genesis.json") 90 if err := ioutil.WriteFile(json, []byte(tt.genesis), 0600); err != nil { 91 t.Fatalf("test %d: failed to write genesis file: %v", i, err) 92 } 93 runGeth(t, "--datadir", datadir, "init", json).WaitExit() 94 95 // Query the custom genesis block 96 geth := runGeth(t, 97 "--datadir", datadir, "--maxpeers", "0", "--port", "0", 98 "--nodiscover", "--nat", "none", "--ipcdisable", 99 "--exec", tt.query, "console") 100 geth.ExpectRegexp(tt.result) 101 geth.ExpectExit() 102 } 103 }*/