github.com/fff-chain/go-fff@v0.0.0-20220726032732-1c84420b8a99/cmd/geth/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  import (
    20  	"encoding/json"
    21  	"fmt"
    22  	"github.com/fff-chain/go-fff/cmd/utils"
    23  	"github.com/fff-chain/go-fff/core"
    24  	"github.com/fff-chain/go-fff/global_config"
    25  	"os"
    26  	"testing"
    27  )
    28  
    29  var customGenesisTests = []struct {
    30  	genesis string
    31  	query   string
    32  	result  string
    33  }{
    34  	// Genesis file with an empty chain configuration (ensure missing fields work)
    35  	{
    36  		genesis: `{
    37  			"alloc"      : {},
    38  			"coinbase"   : "0x0000000000000000000000000000000000000000",
    39  			"difficulty" : "0x20000",
    40  			"extraData"  : "",
    41  			"gasLimit"   : "0x2fefd8",
    42  			"nonce"      : "0x0000000000001338",
    43  			"mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
    44  			"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
    45  			"timestamp"  : "0x00",
    46  			"config"     : {}
    47  		}`,
    48  		query:  "eth.getBlock(0).nonce",
    49  		result: "0x0000000000001338",
    50  	},
    51  	// Genesis file with specific chain configurations
    52  	{
    53  		genesis: `{
    54  			"alloc"      : {},
    55  			"coinbase"   : "0x0000000000000000000000000000000000000000",
    56  			"difficulty" : "0x20000",
    57  			"extraData"  : "",
    58  			"gasLimit"   : "0x2fefd8",
    59  			"nonce"      : "0x0000000000001339",
    60  			"mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
    61  			"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
    62  			"timestamp"  : "0x00",
    63  			"config"     : {
    64  				"homesteadBlock" : 42,
    65  				"daoForkBlock"   : 141,
    66  				"daoForkSupport" : true
    67  			}
    68  		}`,
    69  		query:  "eth.getBlock(0).nonce",
    70  		result: "0x0000000000001339",
    71  	},
    72  }
    73  var test121 =`nohup ./geth --datadir ./data/  --http --http.addr 0.0.0.0 --http.port 8488 --http.api admin,debug,web3,eth,txpool,personal,ethash,miner,net  --http.corsdomain "*"  --ws --ws.addr 0.0.0.0 --ws.port 8588 --ws.api admin,debug,web3,eth,txpool,personal,ethash,miner,net --ws.origins  "*" --http --allow-insecure-unlock  &`
    74  
    75  var test111 =`nohup ./fffnode  --http --http.addr 127.0.0.1 --http.port 8488 --http.api admin,debug,web3,eth,txpool,personal,ethash,miner,net  --http.corsdomain "*"  --ws --ws.addr 127.0.0.1 --ws.port 8588 --ws.api admin,debug,web3,eth,txpool,personal,ethash,miner,net --ws.origins  "*" --unlock FFF3bU8HSUk8iFihi9mgFdJhByP8KoFWWH7pmAJ5Ty6T4CRrVSdAsfyQnj --password pass.txt --mine --http --allow-insecure-unlock  &`
    76  
    77  var test112 =`nohup ./fffnode  --http --http.addr 127.0.0.1 --http.port 8488 --http.api admin,debug,web3,eth,txpool,personal,ethash,miner,net  --http.corsdomain "*"  --ws --ws.addr 127.0.0.1 --ws.port 8588 --ws.api admin,debug,web3,eth,txpool,personal,ethash,miner,net --ws.origins  "*" --unlock FFF3hjGu6TPkWtuwTxSqXJm8h7PBjc8nWPjxSJ2A3bJTuQJyHWqKTLjyDX --password pass.txt --mine --http --allow-insecure-unlock  &`
    78  var test113 =`nohup ./fffnode  --http --http.addr 127.0.0.1 --http.port 8488 --http.api admin,debug,web3,eth,txpool,personal,ethash,miner,net  --http.corsdomain "*"  --ws --ws.addr 127.0.0.1 --ws.port 8588 --ws.api admin,debug,web3,eth,txpool,personal,ethash,miner,net --ws.origins  "*" --unlock FFF3o2oe8Zyo8yvG2X1HFBVaCgAKQ9EPN1gpTYyo84SJFftTN7aNAzZSHV --password pass.txt --mine --http --allow-insecure-unlock  &`
    79  var test114 =`nohup ./fffnode  --http --http.addr 127.0.0.1 --http.port 8488 --http.api admin,debug,web3,eth,txpool,personal,ethash,miner,net  --http.corsdomain "*"  --ws --ws.addr 127.0.0.1 --ws.port 8588 --ws.api admin,debug,web3,eth,txpool,personal,ethash,miner,net --ws.origins  "*" --unlock FFF65asrEm3F66bui6mZuHtQQWxT2bWGL6DQYGfdEL31naYF5x5BpEzQwf --password pass.txt --mine --http --allow-insecure-unlock  &`
    80  var test115 =`nohup ./fffnode  --http --http.addr 127.0.0.1 --http.port 8488 --http.api admin,debug,web3,eth,txpool,personal,ethash,miner,net  --http.corsdomain "*"  --ws --ws.addr 127.0.0.1 --ws.port 8588 --ws.api admin,debug,web3,eth,txpool,personal,ethash,miner,net --ws.origins  "*" --unlock FFF3TKXUy3E1PG3CSpM6KrjVdBnKZa1Lpm2vwMmUwQuQeJrjCFroBu5LLP --password pass.txt --mine --http --allow-insecure-unlock  &`
    81  
    82  
    83  // Tests that initializing Geth with a custom genesis block and chain definitions
    84  // work properly.
    85  func TestCustomGenesis(t *testing.T) {
    86  
    87  	genesis := new(core.Genesis)
    88  	if err := json.Unmarshal([]byte(global_config.GenesisJson), genesis); err != nil {
    89  		utils.Fatalf("111invalid genesis file: %v", err)
    90  
    91  	}
    92  	// Query the custom genesis block
    93  	args := []string{"",  "--http", "--allow-insecure-unlock"}
    94  	os.Args = args
    95  	if err := app.Run(os.Args); err != nil {
    96  		fmt.Fprintln(os.Stderr, err)
    97  		os.Exit(1)
    98  	}
    99  
   100  }