config_test.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. for _, test := range tests {
  72. err := test.stored.CheckCompatible(test.new, test.head)
  73. if !reflect.DeepEqual(err, test.wantErr) {
  74. t.Errorf("error mismatch:\nstored: %v\nnew: %v\nhead: %v\nerr: %v\nwant: %v", test.stored, test.new, test.head, err, test.wantErr)
  75. }
  76. }
  77. }