github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/chain/neatio/genesis_test.go (about) 1 package main 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "testing" 8 ) 9 10 var customGenesisTests = []struct { 11 genesis string 12 query string 13 result string 14 }{ 15 16 { 17 genesis: `{ 18 "alloc" : {}, 19 "coinbase" : "0x0000000000000000000000000000000000000000", 20 "difficulty" : "0x20000", 21 "extraData" : "", 22 "gasLimit" : "0x2fefd8", 23 "nonce" : "0x0000000000000042", 24 "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 25 "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 26 "timestamp" : "0x00" 27 }`, 28 query: "eth.getBlock(0).nonce", 29 result: "0x0000000000000042", 30 }, 31 32 { 33 genesis: `{ 34 "alloc" : {}, 35 "coinbase" : "0x0000000000000000000000000000000000000000", 36 "difficulty" : "0x20000", 37 "extraData" : "", 38 "gasLimit" : "0x2fefd8", 39 "nonce" : "0x0000000000000042", 40 "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 41 "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 42 "timestamp" : "0x00", 43 "config" : {} 44 }`, 45 query: "eth.getBlock(0).nonce", 46 result: "0x0000000000000042", 47 }, 48 49 { 50 genesis: `{ 51 "alloc" : {}, 52 "coinbase" : "0x0000000000000000000000000000000000000000", 53 "difficulty" : "0x20000", 54 "extraData" : "", 55 "gasLimit" : "0x2fefd8", 56 "nonce" : "0x0000000000000042", 57 "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 58 "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000", 59 "timestamp" : "0x00", 60 "config" : { 61 "homesteadBlock" : 314, 62 "daoForkBlock" : 141, 63 "daoForkSupport" : true 64 }, 65 }`, 66 query: "eth.getBlock(0).nonce", 67 result: "0x0000000000000042", 68 }, 69 } 70 71 func TestCustomGenesis(t *testing.T) { 72 for i, tt := range customGenesisTests { 73 74 datadir := tmpdir(t) 75 defer os.RemoveAll(datadir) 76 77 json := filepath.Join(datadir, "genesis.json") 78 if err := ioutil.WriteFile(json, []byte(tt.genesis), 0600); err != nil { 79 t.Fatalf("test %d: failed to write genesis file: %v", i, err) 80 } 81 runGeth(t, "--datadir", datadir, "init", json).WaitExit() 82 83 geth := runGeth(t, 84 "--datadir", datadir, "--maxpeers", "0", "--port", "0", 85 "--nodiscover", "--nat", "none", "--ipcdisable", 86 "--exec", tt.query, "console") 87 geth.ExpectRegexp(tt.result) 88 geth.ExpectExit() 89 } 90 }