github.com/MetalBlockchain/subnet-evm@v0.6.3/tests/init.go (about)

     1  // (c) 2019-2020, Ava Labs, Inc.
     2  //
     3  // This file is a derived work, based on the go-ethereum library whose original
     4  // notices appear below.
     5  //
     6  // It is distributed under a license compatible with the licensing terms of the
     7  // original code from which it is derived.
     8  //
     9  // Much love to the original authors for their work.
    10  // **********
    11  // Copyright 2015 The go-ethereum Authors
    12  // This file is part of the go-ethereum library.
    13  //
    14  // The go-ethereum library is free software: you can redistribute it and/or modify
    15  // it under the terms of the GNU Lesser General Public License as published by
    16  // the Free Software Foundation, either version 3 of the License, or
    17  // (at your option) any later version.
    18  //
    19  // The go-ethereum library is distributed in the hope that it will be useful,
    20  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    21  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    22  // GNU Lesser General Public License for more details.
    23  //
    24  // You should have received a copy of the GNU Lesser General Public License
    25  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    26  
    27  package tests
    28  
    29  import (
    30  	"fmt"
    31  	"math/big"
    32  	"os"
    33  	"sort"
    34  	"strings"
    35  
    36  	"github.com/MetalBlockchain/subnet-evm/params"
    37  	"github.com/MetalBlockchain/subnet-evm/utils"
    38  )
    39  
    40  // Forks table defines supported forks and their chain config.
    41  var Forks = map[string]*params.ChainConfig{
    42  	"Frontier": {
    43  		ChainID: big.NewInt(1),
    44  	},
    45  	"Homestead": {
    46  		ChainID:        big.NewInt(1),
    47  		HomesteadBlock: big.NewInt(0),
    48  	},
    49  	"EIP150": {
    50  		ChainID:        big.NewInt(1),
    51  		HomesteadBlock: big.NewInt(0),
    52  		EIP150Block:    big.NewInt(0),
    53  	},
    54  	"EIP158": {
    55  		ChainID:        big.NewInt(1),
    56  		HomesteadBlock: big.NewInt(0),
    57  		EIP150Block:    big.NewInt(0),
    58  		EIP155Block:    big.NewInt(0),
    59  		EIP158Block:    big.NewInt(0),
    60  	},
    61  	"Byzantium": {
    62  		ChainID:        big.NewInt(1),
    63  		HomesteadBlock: big.NewInt(0),
    64  		EIP150Block:    big.NewInt(0),
    65  		EIP155Block:    big.NewInt(0),
    66  		EIP158Block:    big.NewInt(0),
    67  		ByzantiumBlock: big.NewInt(0),
    68  	},
    69  	"Constantinople": {
    70  		ChainID:             big.NewInt(1),
    71  		HomesteadBlock:      big.NewInt(0),
    72  		EIP150Block:         big.NewInt(0),
    73  		EIP155Block:         big.NewInt(0),
    74  		EIP158Block:         big.NewInt(0),
    75  		ByzantiumBlock:      big.NewInt(0),
    76  		ConstantinopleBlock: big.NewInt(0),
    77  		PetersburgBlock:     big.NewInt(10000000),
    78  	},
    79  	"ConstantinopleFix": {
    80  		ChainID:             big.NewInt(1),
    81  		HomesteadBlock:      big.NewInt(0),
    82  		EIP150Block:         big.NewInt(0),
    83  		EIP155Block:         big.NewInt(0),
    84  		EIP158Block:         big.NewInt(0),
    85  		ByzantiumBlock:      big.NewInt(0),
    86  		ConstantinopleBlock: big.NewInt(0),
    87  		PetersburgBlock:     big.NewInt(0),
    88  	},
    89  	"Istanbul": {
    90  		ChainID:             big.NewInt(1),
    91  		HomesteadBlock:      big.NewInt(0),
    92  		EIP150Block:         big.NewInt(0),
    93  		EIP155Block:         big.NewInt(0),
    94  		EIP158Block:         big.NewInt(0),
    95  		ByzantiumBlock:      big.NewInt(0),
    96  		ConstantinopleBlock: big.NewInt(0),
    97  		PetersburgBlock:     big.NewInt(0),
    98  		IstanbulBlock:       big.NewInt(0),
    99  	},
   100  	"MuirGlacier": {
   101  		ChainID:             big.NewInt(1),
   102  		HomesteadBlock:      big.NewInt(0),
   103  		EIP150Block:         big.NewInt(0),
   104  		EIP155Block:         big.NewInt(0),
   105  		EIP158Block:         big.NewInt(0),
   106  		ByzantiumBlock:      big.NewInt(0),
   107  		ConstantinopleBlock: big.NewInt(0),
   108  		PetersburgBlock:     big.NewInt(0),
   109  		IstanbulBlock:       big.NewInt(0),
   110  		MuirGlacierBlock:    big.NewInt(0),
   111  	},
   112  	"FrontierToHomesteadAt5": {
   113  		ChainID:        big.NewInt(1),
   114  		HomesteadBlock: big.NewInt(5),
   115  	},
   116  	"HomesteadToEIP150At5": {
   117  		ChainID:        big.NewInt(1),
   118  		HomesteadBlock: big.NewInt(0),
   119  		EIP150Block:    big.NewInt(5),
   120  	},
   121  	"EIP158ToByzantiumAt5": {
   122  		ChainID:        big.NewInt(1),
   123  		HomesteadBlock: big.NewInt(0),
   124  		EIP150Block:    big.NewInt(0),
   125  		EIP155Block:    big.NewInt(0),
   126  		EIP158Block:    big.NewInt(0),
   127  		ByzantiumBlock: big.NewInt(5),
   128  	},
   129  	"ByzantiumToConstantinopleAt5": {
   130  		ChainID:             big.NewInt(1),
   131  		HomesteadBlock:      big.NewInt(0),
   132  		EIP150Block:         big.NewInt(0),
   133  		EIP155Block:         big.NewInt(0),
   134  		EIP158Block:         big.NewInt(0),
   135  		ByzantiumBlock:      big.NewInt(0),
   136  		ConstantinopleBlock: big.NewInt(5),
   137  	},
   138  	"ByzantiumToConstantinopleFixAt5": {
   139  		ChainID:             big.NewInt(1),
   140  		HomesteadBlock:      big.NewInt(0),
   141  		EIP150Block:         big.NewInt(0),
   142  		EIP155Block:         big.NewInt(0),
   143  		EIP158Block:         big.NewInt(0),
   144  		ByzantiumBlock:      big.NewInt(0),
   145  		ConstantinopleBlock: big.NewInt(5),
   146  		PetersburgBlock:     big.NewInt(5),
   147  	},
   148  	"ConstantinopleFixToIstanbulAt5": {
   149  		ChainID:             big.NewInt(1),
   150  		HomesteadBlock:      big.NewInt(0),
   151  		EIP150Block:         big.NewInt(0),
   152  		EIP155Block:         big.NewInt(0),
   153  		EIP158Block:         big.NewInt(0),
   154  		ByzantiumBlock:      big.NewInt(0),
   155  		ConstantinopleBlock: big.NewInt(0),
   156  		PetersburgBlock:     big.NewInt(0),
   157  		IstanbulBlock:       big.NewInt(5),
   158  	},
   159  	"Pre-SubnetEVM": {
   160  		ChainID:             big.NewInt(1),
   161  		HomesteadBlock:      big.NewInt(0),
   162  		EIP150Block:         big.NewInt(0),
   163  		EIP155Block:         big.NewInt(0),
   164  		EIP158Block:         big.NewInt(0),
   165  		ByzantiumBlock:      big.NewInt(0),
   166  		ConstantinopleBlock: big.NewInt(0),
   167  		PetersburgBlock:     big.NewInt(0),
   168  		IstanbulBlock:       big.NewInt(0),
   169  		MuirGlacierBlock:    big.NewInt(0),
   170  	},
   171  	"SubnetEVM": {
   172  		ChainID:             big.NewInt(1),
   173  		HomesteadBlock:      big.NewInt(0),
   174  		EIP150Block:         big.NewInt(0),
   175  		EIP155Block:         big.NewInt(0),
   176  		EIP158Block:         big.NewInt(0),
   177  		ByzantiumBlock:      big.NewInt(0),
   178  		ConstantinopleBlock: big.NewInt(0),
   179  		PetersburgBlock:     big.NewInt(0),
   180  		IstanbulBlock:       big.NewInt(0),
   181  		NetworkUpgrades: params.NetworkUpgrades{
   182  			SubnetEVMTimestamp: utils.NewUint64(0),
   183  		},
   184  	},
   185  	"Durango": {
   186  		ChainID:             big.NewInt(1),
   187  		HomesteadBlock:      big.NewInt(0),
   188  		EIP150Block:         big.NewInt(0),
   189  		EIP155Block:         big.NewInt(0),
   190  		EIP158Block:         big.NewInt(0),
   191  		ByzantiumBlock:      big.NewInt(0),
   192  		ConstantinopleBlock: big.NewInt(0),
   193  		PetersburgBlock:     big.NewInt(0),
   194  		IstanbulBlock:       big.NewInt(0),
   195  		NetworkUpgrades: params.NetworkUpgrades{
   196  			SubnetEVMTimestamp: utils.NewUint64(0),
   197  			DurangoTimestamp:   utils.NewUint64(0),
   198  		},
   199  	},
   200  	"Cancun": {
   201  		ChainID:             big.NewInt(1),
   202  		HomesteadBlock:      big.NewInt(0),
   203  		EIP150Block:         big.NewInt(0),
   204  		EIP155Block:         big.NewInt(0),
   205  		EIP158Block:         big.NewInt(0),
   206  		ByzantiumBlock:      big.NewInt(0),
   207  		ConstantinopleBlock: big.NewInt(0),
   208  		PetersburgBlock:     big.NewInt(0),
   209  		IstanbulBlock:       big.NewInt(0),
   210  		CancunTime:          utils.NewUint64(0),
   211  		NetworkUpgrades: params.NetworkUpgrades{
   212  			SubnetEVMTimestamp: utils.NewUint64(0),
   213  			DurangoTimestamp:   utils.NewUint64(0),
   214  		},
   215  	},
   216  }
   217  
   218  // AvailableForks returns the set of defined fork names
   219  func AvailableForks() []string {
   220  	var availableForks []string
   221  	for k := range Forks {
   222  		availableForks = append(availableForks, k)
   223  	}
   224  	sort.Strings(availableForks)
   225  	return availableForks
   226  }
   227  
   228  // UnsupportedForkError is returned when a test requests a fork that isn't implemented.
   229  type UnsupportedForkError struct {
   230  	Name string
   231  }
   232  
   233  func (e UnsupportedForkError) Error() string {
   234  	return fmt.Sprintf("unsupported fork %q", e.Name)
   235  }
   236  
   237  func GetRepoRootPath(suffix string) string {
   238  	// - When executed via a test binary, the working directory will be wherever
   239  	// the binary is executed from, but scripts should require execution from
   240  	// the repo root.
   241  	//
   242  	// - When executed via ginkgo (nicer for development + supports
   243  	// parallel execution) the working directory will always be the
   244  	// target path (e.g. [repo root]./tests/warp) and getting the repo
   245  	// root will require stripping the target path suffix.
   246  	//
   247  	// TODO(marun) Avoid relying on the current working directory to find test
   248  	// dependencies by embedding data where possible (e.g. for genesis) and
   249  	// explicitly configuring paths for execution.
   250  	cwd, err := os.Getwd()
   251  	if err != nil {
   252  		panic(err)
   253  	}
   254  	return strings.TrimSuffix(cwd, suffix)
   255  }