config_test.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright 2017 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser 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. // The go-ethereum library 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 Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package params
  17. import (
  18. "math/big"
  19. "reflect"
  20. "testing"
  21. )
  22. func TestCheckCompatible(t *testing.T) {
  23. type test struct {
  24. stored, new *ChainConfig
  25. head uint64
  26. wantErr *ConfigCompatError
  27. }
  28. tests := []test{
  29. {stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, head: 0, wantErr: nil},
  30. {stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, head: 100, wantErr: nil},
  31. {
  32. stored: &ChainConfig{EIP150Block: big.NewInt(10)},
  33. new: &ChainConfig{EIP150Block: big.NewInt(20)},
  34. head: 9,
  35. wantErr: nil,
  36. },
  37. {
  38. stored: AllEthashProtocolChanges,
  39. new: &ChainConfig{HomesteadBlock: nil},
  40. head: 3,
  41. wantErr: &ConfigCompatError{
  42. What: "Homestead fork block",
  43. StoredConfig: big.NewInt(0),
  44. NewConfig: nil,
  45. RewindTo: 0,
  46. },
  47. },
  48. {
  49. stored: AllEthashProtocolChanges,
  50. new: &ChainConfig{HomesteadBlock: big.NewInt(1)},
  51. head: 3,
  52. wantErr: &ConfigCompatError{
  53. What: "Homestead fork block",
  54. StoredConfig: big.NewInt(0),
  55. NewConfig: big.NewInt(1),
  56. RewindTo: 0,
  57. },
  58. },
  59. {
  60. stored: &ChainConfig{HomesteadBlock: big.NewInt(30), EIP150Block: big.NewInt(10)},
  61. new: &ChainConfig{HomesteadBlock: big.NewInt(25), EIP150Block: big.NewInt(20)},
  62. head: 25,
  63. wantErr: &ConfigCompatError{
  64. What: "EIP150 fork block",
  65. StoredConfig: big.NewInt(10),
  66. NewConfig: big.NewInt(20),
  67. RewindTo: 9,
  68. },
  69. },
  70. {
  71. stored: &ChainConfig{ConstantinopleBlock: big.NewInt(30)},
  72. new: &ChainConfig{ConstantinopleBlock: big.NewInt(30), PetersburgBlock: big.NewInt(30)},
  73. head: 40,
  74. wantErr: nil,
  75. },
  76. {
  77. stored: &ChainConfig{ConstantinopleBlock: big.NewInt(30)},
  78. new: &ChainConfig{ConstantinopleBlock: big.NewInt(30), PetersburgBlock: big.NewInt(31)},
  79. head: 40,
  80. wantErr: &ConfigCompatError{
  81. What: "Petersburg fork block",
  82. StoredConfig: nil,
  83. NewConfig: big.NewInt(31),
  84. RewindTo: 30,
  85. },
  86. },
  87. }
  88. for _, test := range tests {
  89. err := test.stored.CheckCompatible(test.new, test.head)
  90. if !reflect.DeepEqual(err, test.wantErr) {
  91. t.Errorf("error mismatch:\nstored: %v\nnew: %v\nhead: %v\nerr: %v\nwant: %v", test.stored, test.new, test.head, err, test.wantErr)
  92. }
  93. }
  94. }