config_test.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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. "github.com/ethereum/go-ethereum/common"
  22. )
  23. // Quorum - test code size and transaction size limit in chain config
  24. func TestMaxCodeSizeAndTransactionSizeLimit(t *testing.T) {
  25. type testData struct {
  26. size uint64
  27. valid bool
  28. err string
  29. }
  30. type testDataType struct {
  31. isCodeSize bool
  32. data []testData
  33. }
  34. const codeSizeErr = "Genesis max code size must be between 24 and 128"
  35. const txSizeErr = "Genesis transaction size limit must be between 32 and 128"
  36. var codeSizeData = []testData{
  37. {23, false, codeSizeErr},
  38. {24, true, ""},
  39. {50, true, ""},
  40. {128, true, ""},
  41. {129, false, codeSizeErr},
  42. }
  43. var txSizeData = []testData{
  44. {31, false, txSizeErr},
  45. {32, true, ""},
  46. {50, true, ""},
  47. {128, true, ""},
  48. {129, false, txSizeErr},
  49. }
  50. var testDataArr = []testDataType{
  51. {true, codeSizeData},
  52. {false, txSizeData},
  53. }
  54. for _, td := range testDataArr {
  55. var ccfg *ChainConfig
  56. for _, d := range td.data {
  57. var msgPrefix string
  58. if td.isCodeSize {
  59. ccfg = &ChainConfig{MaxCodeSize: d.size, TransactionSizeLimit: 50}
  60. msgPrefix = "max code size"
  61. } else {
  62. ccfg = &ChainConfig{MaxCodeSize: 50, TransactionSizeLimit: d.size}
  63. msgPrefix = "transaction size limit"
  64. }
  65. err := ccfg.IsValid()
  66. if d.valid {
  67. if err != nil {
  68. t.Errorf(msgPrefix+" %d, expected no error but got %v", d.size, err)
  69. }
  70. } else {
  71. if err == nil {
  72. t.Errorf(msgPrefix+" %d, expected error but got none", d.size)
  73. } else {
  74. if err.Error() != d.err {
  75. t.Errorf(msgPrefix+" %d, expected error but got %v", d.size, err.Error())
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. func TestCheckCompatible(t *testing.T) {
  83. type test struct {
  84. stored, new *ChainConfig
  85. head uint64
  86. wantErr *ConfigCompatError
  87. }
  88. var storedMaxCodeConfig0, storedMaxCodeConfig1, storedMaxCodeConfig2 []MaxCodeConfigStruct
  89. defaultRec := MaxCodeConfigStruct{big.NewInt(0), 24}
  90. rec1 := MaxCodeConfigStruct{big.NewInt(5), 32}
  91. rec2 := MaxCodeConfigStruct{big.NewInt(10), 40}
  92. rec3 := MaxCodeConfigStruct{big.NewInt(8), 40}
  93. storedMaxCodeConfig0 = append(storedMaxCodeConfig0, defaultRec)
  94. storedMaxCodeConfig1 = append(storedMaxCodeConfig1, defaultRec)
  95. storedMaxCodeConfig1 = append(storedMaxCodeConfig1, rec1)
  96. storedMaxCodeConfig1 = append(storedMaxCodeConfig1, rec2)
  97. storedMaxCodeConfig2 = append(storedMaxCodeConfig2, rec1)
  98. storedMaxCodeConfig2 = append(storedMaxCodeConfig2, rec2)
  99. var passedValidMaxConfig0 []MaxCodeConfigStruct
  100. passedValidMaxConfig0 = append(passedValidMaxConfig0, defaultRec)
  101. passedValidMaxConfig0 = append(passedValidMaxConfig0, rec1)
  102. var passedValidMaxConfig1 []MaxCodeConfigStruct
  103. passedValidMaxConfig1 = append(passedValidMaxConfig1, defaultRec)
  104. passedValidMaxConfig1 = append(passedValidMaxConfig1, rec1)
  105. passedValidMaxConfig1 = append(passedValidMaxConfig1, rec3)
  106. tests := []test{
  107. {stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, head: 0, wantErr: nil},
  108. {stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, head: 100, wantErr: nil},
  109. {
  110. stored: &ChainConfig{EIP150Block: big.NewInt(10)},
  111. new: &ChainConfig{EIP150Block: big.NewInt(20)},
  112. head: 9,
  113. wantErr: nil,
  114. },
  115. {
  116. stored: AllEthashProtocolChanges,
  117. new: &ChainConfig{HomesteadBlock: nil},
  118. head: 3,
  119. wantErr: &ConfigCompatError{
  120. What: "Homestead fork block",
  121. StoredConfig: big.NewInt(0),
  122. NewConfig: nil,
  123. RewindTo: 0,
  124. },
  125. },
  126. {
  127. stored: AllEthashProtocolChanges,
  128. new: &ChainConfig{HomesteadBlock: big.NewInt(1)},
  129. head: 3,
  130. wantErr: &ConfigCompatError{
  131. What: "Homestead fork block",
  132. StoredConfig: big.NewInt(0),
  133. NewConfig: big.NewInt(1),
  134. RewindTo: 0,
  135. },
  136. },
  137. {
  138. stored: &ChainConfig{HomesteadBlock: big.NewInt(30), EIP150Block: big.NewInt(10)},
  139. new: &ChainConfig{HomesteadBlock: big.NewInt(25), EIP150Block: big.NewInt(20)},
  140. head: 25,
  141. wantErr: &ConfigCompatError{
  142. What: "EIP150 fork block",
  143. StoredConfig: big.NewInt(10),
  144. NewConfig: big.NewInt(20),
  145. RewindTo: 9,
  146. },
  147. },
  148. {
  149. stored: &ChainConfig{ConstantinopleBlock: big.NewInt(30)},
  150. new: &ChainConfig{ConstantinopleBlock: big.NewInt(30), PetersburgBlock: big.NewInt(30)},
  151. head: 40,
  152. wantErr: nil,
  153. },
  154. {
  155. stored: &ChainConfig{ConstantinopleBlock: big.NewInt(30)},
  156. new: &ChainConfig{ConstantinopleBlock: big.NewInt(30), PetersburgBlock: big.NewInt(31)},
  157. head: 40,
  158. wantErr: &ConfigCompatError{
  159. What: "Petersburg fork block",
  160. StoredConfig: nil,
  161. NewConfig: big.NewInt(31),
  162. RewindTo: 30,
  163. },
  164. },
  165. {
  166. stored: &ChainConfig{Istanbul: &IstanbulConfig{Ceil2Nby3Block: big.NewInt(10)}},
  167. new: &ChainConfig{Istanbul: &IstanbulConfig{Ceil2Nby3Block: big.NewInt(20)}},
  168. head: 4,
  169. wantErr: nil,
  170. },
  171. {
  172. stored: &ChainConfig{Istanbul: &IstanbulConfig{Ceil2Nby3Block: big.NewInt(10)}},
  173. new: &ChainConfig{Istanbul: &IstanbulConfig{Ceil2Nby3Block: big.NewInt(20)}},
  174. head: 30,
  175. wantErr: &ConfigCompatError{
  176. What: "Ceil 2N/3 fork block",
  177. StoredConfig: big.NewInt(10),
  178. NewConfig: big.NewInt(20),
  179. RewindTo: 9,
  180. },
  181. },
  182. {
  183. stored: &ChainConfig{Istanbul: &IstanbulConfig{TestQBFTBlock: big.NewInt(50)}},
  184. new: &ChainConfig{Istanbul: &IstanbulConfig{TestQBFTBlock: big.NewInt(60)}},
  185. head: 40,
  186. wantErr: nil,
  187. },
  188. {
  189. stored: &ChainConfig{Istanbul: &IstanbulConfig{TestQBFTBlock: big.NewInt(20)}},
  190. new: &ChainConfig{Istanbul: &IstanbulConfig{TestQBFTBlock: big.NewInt(30)}},
  191. head: 20,
  192. wantErr: &ConfigCompatError{
  193. What: "Test QBFT fork block",
  194. StoredConfig: big.NewInt(20),
  195. NewConfig: big.NewInt(30),
  196. RewindTo: 19,
  197. },
  198. },
  199. {
  200. stored: &ChainConfig{MaxCodeSizeChangeBlock: big.NewInt(10)},
  201. new: &ChainConfig{MaxCodeSizeChangeBlock: big.NewInt(20)},
  202. head: 30,
  203. wantErr: &ConfigCompatError{
  204. What: "max code size change fork block",
  205. StoredConfig: big.NewInt(10),
  206. NewConfig: big.NewInt(20),
  207. RewindTo: 9,
  208. },
  209. },
  210. {
  211. stored: &ChainConfig{MaxCodeSizeChangeBlock: big.NewInt(10)},
  212. new: &ChainConfig{MaxCodeSizeChangeBlock: big.NewInt(20)},
  213. head: 4,
  214. wantErr: nil,
  215. },
  216. {
  217. stored: &ChainConfig{QIP714Block: big.NewInt(10)},
  218. new: &ChainConfig{QIP714Block: big.NewInt(20)},
  219. head: 30,
  220. wantErr: &ConfigCompatError{
  221. What: "permissions fork block",
  222. StoredConfig: big.NewInt(10),
  223. NewConfig: big.NewInt(20),
  224. RewindTo: 9,
  225. },
  226. },
  227. {
  228. stored: &ChainConfig{QIP714Block: big.NewInt(10)},
  229. new: &ChainConfig{QIP714Block: big.NewInt(20)},
  230. head: 4,
  231. wantErr: nil,
  232. },
  233. {
  234. stored: &ChainConfig{MaxCodeSizeConfig: storedMaxCodeConfig0},
  235. new: &ChainConfig{MaxCodeSizeConfig: nil},
  236. head: 4,
  237. wantErr: &ConfigCompatError{
  238. What: "genesis file missing max code size information",
  239. StoredConfig: big.NewInt(4),
  240. NewConfig: big.NewInt(4),
  241. RewindTo: 3,
  242. },
  243. },
  244. {
  245. stored: &ChainConfig{MaxCodeSizeConfig: storedMaxCodeConfig0},
  246. new: &ChainConfig{MaxCodeSizeConfig: storedMaxCodeConfig0},
  247. head: 4,
  248. wantErr: nil,
  249. },
  250. {
  251. stored: &ChainConfig{MaxCodeSizeConfig: storedMaxCodeConfig0},
  252. new: &ChainConfig{MaxCodeSizeConfig: passedValidMaxConfig0},
  253. head: 10,
  254. wantErr: &ConfigCompatError{
  255. What: "maxCodeSizeConfig data incompatible. updating maxCodeSize for past",
  256. StoredConfig: big.NewInt(10),
  257. NewConfig: big.NewInt(10),
  258. RewindTo: 9,
  259. },
  260. },
  261. {
  262. stored: &ChainConfig{MaxCodeSizeConfig: storedMaxCodeConfig0},
  263. new: &ChainConfig{MaxCodeSizeConfig: passedValidMaxConfig0},
  264. head: 4,
  265. wantErr: nil,
  266. },
  267. {
  268. stored: &ChainConfig{MaxCodeSizeConfig: storedMaxCodeConfig1},
  269. new: &ChainConfig{MaxCodeSizeConfig: storedMaxCodeConfig1},
  270. head: 12,
  271. wantErr: nil,
  272. },
  273. {
  274. stored: &ChainConfig{MaxCodeSizeConfig: storedMaxCodeConfig1},
  275. new: &ChainConfig{MaxCodeSizeConfig: passedValidMaxConfig1},
  276. head: 12,
  277. wantErr: &ConfigCompatError{
  278. What: "maxCodeSizeConfig data incompatible. maxCodeSize historical data does not match",
  279. StoredConfig: big.NewInt(12),
  280. NewConfig: big.NewInt(12),
  281. RewindTo: 11,
  282. },
  283. },
  284. {
  285. stored: &ChainConfig{MaxCodeSize: 32},
  286. new: &ChainConfig{MaxCodeSizeConfig: storedMaxCodeConfig2},
  287. head: 8,
  288. wantErr: nil,
  289. },
  290. {
  291. stored: &ChainConfig{MaxCodeSize: 32},
  292. new: &ChainConfig{MaxCodeSizeConfig: storedMaxCodeConfig2},
  293. head: 15,
  294. wantErr: nil,
  295. },
  296. {
  297. stored: &ChainConfig{MaxCodeSize: 32, MaxCodeSizeChangeBlock: big.NewInt(10)},
  298. new: &ChainConfig{MaxCodeSizeConfig: storedMaxCodeConfig1},
  299. head: 15,
  300. wantErr: nil,
  301. },
  302. }
  303. for _, test := range tests {
  304. err := test.stored.CheckCompatible(test.new, test.head, false)
  305. if !reflect.DeepEqual(err, test.wantErr) {
  306. t.Errorf("error mismatch:\nstored: %v\nnew: %v\nhead: %v\nerr: %v\nwant: %v", test.stored, test.new, test.head, err, test.wantErr)
  307. }
  308. }
  309. }
  310. func TestCheckTransitionsData(t *testing.T) {
  311. type test struct {
  312. stored *ChainConfig
  313. wantErr error
  314. }
  315. var ibftTransitionsConfig, qbftTransitionsConfig, invalidTransition, invalidBlockOrder []Transition
  316. var emptyBlockPeriodSeconds uint64 = 10
  317. tranI0 := Transition{big.NewInt(0), IBFT, 30000, 5, nil, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil}
  318. tranQ5 := Transition{big.NewInt(5), QBFT, 30000, 5, &emptyBlockPeriodSeconds, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil}
  319. tranI10 := Transition{big.NewInt(10), IBFT, 30000, 5, nil, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil}
  320. tranQ8 := Transition{big.NewInt(8), QBFT, 30000, 5, &emptyBlockPeriodSeconds, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil}
  321. ibftTransitionsConfig = append(ibftTransitionsConfig, tranI0, tranI10)
  322. qbftTransitionsConfig = append(qbftTransitionsConfig, tranQ5, tranQ8)
  323. invalidTransition = append(invalidTransition, tranI0, tranQ5, tranI10)
  324. invalidBlockOrder = append(invalidBlockOrder, tranQ8, tranQ5)
  325. tests := []test{
  326. {stored: MainnetChainConfig, wantErr: nil},
  327. {stored: RopstenChainConfig, wantErr: nil},
  328. {stored: RinkebyChainConfig, wantErr: nil},
  329. {stored: GoerliChainConfig, wantErr: nil},
  330. {stored: YoloV3ChainConfig, wantErr: nil},
  331. {stored: AllEthashProtocolChanges, wantErr: nil},
  332. {stored: AllCliqueProtocolChanges, wantErr: nil},
  333. {stored: TestChainConfig, wantErr: nil},
  334. {stored: QuorumTestChainConfig, wantErr: nil},
  335. {stored: QuorumMPSTestChainConfig, wantErr: nil},
  336. {
  337. stored: &ChainConfig{IBFT: &IBFTConfig{}},
  338. wantErr: nil,
  339. },
  340. {
  341. stored: &ChainConfig{IBFT: &IBFTConfig{}, Transitions: ibftTransitionsConfig},
  342. wantErr: nil,
  343. },
  344. {
  345. stored: &ChainConfig{QBFT: &QBFTConfig{}},
  346. wantErr: nil,
  347. },
  348. {
  349. stored: &ChainConfig{QBFT: &QBFTConfig{}, Transitions: qbftTransitionsConfig},
  350. wantErr: nil,
  351. },
  352. {
  353. stored: &ChainConfig{IBFT: &IBFTConfig{}, Transitions: qbftTransitionsConfig},
  354. wantErr: nil,
  355. },
  356. {
  357. stored: &ChainConfig{Transitions: ibftTransitionsConfig},
  358. wantErr: nil,
  359. },
  360. {
  361. stored: &ChainConfig{Transitions: qbftTransitionsConfig},
  362. wantErr: nil,
  363. },
  364. {
  365. stored: &ChainConfig{IBFT: &IBFTConfig{}, Transitions: invalidTransition},
  366. wantErr: ErrTransition,
  367. },
  368. {
  369. stored: &ChainConfig{QBFT: &QBFTConfig{}, Transitions: ibftTransitionsConfig},
  370. wantErr: ErrTransition,
  371. },
  372. {
  373. stored: &ChainConfig{Transitions: invalidBlockOrder},
  374. wantErr: ErrBlockOrder,
  375. },
  376. {
  377. stored: &ChainConfig{Transitions: []Transition{{nil, IBFT, 30000, 5, &emptyBlockPeriodSeconds, 10, 50, common.Address{}, nil, "", nil, nil, nil, nil, 0, nil, 0, nil, nil, nil}}},
  378. wantErr: ErrBlockNumberMissing,
  379. },
  380. {
  381. stored: &ChainConfig{Transitions: []Transition{{Block: big.NewInt(0), Algorithm: "AA"}}},
  382. wantErr: ErrTransitionAlgorithm,
  383. },
  384. {
  385. stored: &ChainConfig{Transitions: []Transition{{Block: big.NewInt(0), Algorithm: ""}}},
  386. wantErr: nil,
  387. },
  388. {
  389. stored: &ChainConfig{MaxCodeSizeConfig: []MaxCodeConfigStruct{{big.NewInt(10), 24}}, Transitions: []Transition{{Block: big.NewInt(0), ContractSizeLimit: 50}}},
  390. wantErr: ErrMaxCodeSizeConfigAndTransitions,
  391. },
  392. {
  393. stored: &ChainConfig{Transitions: []Transition{{Block: big.NewInt(0), ContractSizeLimit: 23}}},
  394. wantErr: ErrContractSizeLimit,
  395. },
  396. {
  397. stored: &ChainConfig{Transitions: []Transition{{Block: big.NewInt(0), ContractSizeLimit: 129}}},
  398. wantErr: ErrContractSizeLimit,
  399. },
  400. {
  401. stored: &ChainConfig{Transitions: []Transition{{Block: big.NewInt(0), ContractSizeLimit: 50}}},
  402. wantErr: nil,
  403. },
  404. {
  405. stored: &ChainConfig{Transitions: []Transition{{Block: big.NewInt(0)}}},
  406. wantErr: nil,
  407. },
  408. }
  409. for _, test := range tests {
  410. err := test.stored.CheckTransitionsData()
  411. if !reflect.DeepEqual(err, test.wantErr) {
  412. t.Errorf("error mismatch:\nstored: %v\nerr: %v\nwant: %v", test.stored, err, test.wantErr)
  413. }
  414. }
  415. }
  416. func TestGetMaxCodeSize(t *testing.T) {
  417. type test struct {
  418. config *ChainConfig
  419. blockNumber int64
  420. maxCode int
  421. }
  422. config1, config2, config3 := *TestChainConfig, *TestChainConfig, *TestChainConfig
  423. config1.MaxCodeSizeConfig = []MaxCodeConfigStruct{
  424. {big.NewInt(2), 28},
  425. {big.NewInt(4), 32},
  426. }
  427. config1.MaxCodeSize = 34
  428. config2.MaxCodeSize = 36
  429. config2.MaxCodeSizeChangeBlock = big.NewInt(2)
  430. config3.MaxCodeSize = 0
  431. config3.Transitions = []Transition{
  432. {Block: big.NewInt(2), ContractSizeLimit: 50},
  433. {Block: big.NewInt(4), ContractSizeLimit: 54},
  434. }
  435. maxCodeDefault := 32 * 1024
  436. tests := []test{
  437. {MainnetChainConfig, 0, MaxCodeSize},
  438. {RopstenChainConfig, 0, MaxCodeSize},
  439. {RinkebyChainConfig, 0, MaxCodeSize},
  440. {GoerliChainConfig, 0, MaxCodeSize},
  441. {YoloV3ChainConfig, 0, MaxCodeSize},
  442. {AllEthashProtocolChanges, 0, 35 * 1024},
  443. {AllCliqueProtocolChanges, 0, maxCodeDefault},
  444. {TestChainConfig, 0, maxCodeDefault},
  445. {QuorumTestChainConfig, 0, maxCodeDefault},
  446. {QuorumMPSTestChainConfig, 0, maxCodeDefault},
  447. {&config1, 0, MaxCodeSize},
  448. {&config1, 1, MaxCodeSize},
  449. {&config1, 2, 28 * 1024},
  450. {&config1, 3, 28 * 1024},
  451. {&config1, 4, 32 * 1024},
  452. {&config2, 0, MaxCodeSize},
  453. {&config2, 1, MaxCodeSize},
  454. {&config2, 2, 36 * 1024},
  455. {&config2, 3, 36 * 1024},
  456. {&config3, 0, MaxCodeSize},
  457. {&config3, 1, MaxCodeSize},
  458. {&config3, 2, 50 * 1024},
  459. {&config3, 3, 50 * 1024},
  460. {&config3, 4, 54 * 1024},
  461. {&config3, 8, 54 * 1024},
  462. }
  463. for _, test := range tests {
  464. maxCodeSize := test.config.GetMaxCodeSize(big.NewInt(test.blockNumber))
  465. if !reflect.DeepEqual(maxCodeSize, test.maxCode) {
  466. t.Errorf("error mismatch:\nexpected: %v\nreceived: %v\n", test.maxCode, maxCodeSize)
  467. }
  468. }
  469. }
  470. func TestIsQIP714(t *testing.T) {
  471. type test struct {
  472. config *ChainConfig
  473. blockNumber int64
  474. IsQIP714 bool
  475. }
  476. config1, config2 := *TestChainConfig, *TestChainConfig
  477. config1.QIP714Block = big.NewInt(11)
  478. config2.QIP714Block = nil
  479. config2.Transitions = []Transition{
  480. {Block: big.NewInt(21), EnhancedPermissioningEnabled: newPBool(true)},
  481. }
  482. tests := []test{
  483. {MainnetChainConfig, 0, false},
  484. {&config1, 10, false},
  485. {&config1, 11, true},
  486. {&config2, 20, false},
  487. {&config2, 21, true},
  488. {&config2, 22, true},
  489. }
  490. for _, test := range tests {
  491. isQIP714 := test.config.IsQIP714(big.NewInt(test.blockNumber))
  492. if !reflect.DeepEqual(isQIP714, test.IsQIP714) {
  493. t.Errorf("error mismatch on %v:\nexpected: %v\nreceived: %v\n", test.blockNumber, test.IsQIP714, isQIP714)
  494. }
  495. }
  496. }
  497. func TestIsPrivacyEnhancementsEnabled(t *testing.T) {
  498. type test struct {
  499. config *ChainConfig
  500. blockNumber int64
  501. PrivacyEnhancementsEnabled bool
  502. }
  503. config1, config2 := *TestChainConfig, *TestChainConfig
  504. config1.PrivacyEnhancementsBlock = big.NewInt(11)
  505. config2.PrivacyEnhancementsBlock = nil
  506. config2.Transitions = []Transition{
  507. {Block: big.NewInt(21), PrivacyEnhancementsEnabled: newPBool(true)},
  508. }
  509. tests := []test{
  510. {MainnetChainConfig, 0, false},
  511. {&config1, 10, false},
  512. {&config1, 11, true},
  513. {&config2, 20, false},
  514. {&config2, 21, true},
  515. {&config2, 22, true},
  516. }
  517. for _, test := range tests {
  518. isPrivacyEnhancementsEnabled := test.config.IsPrivacyEnhancementsEnabled(big.NewInt(test.blockNumber))
  519. if !reflect.DeepEqual(isPrivacyEnhancementsEnabled, test.PrivacyEnhancementsEnabled) {
  520. t.Errorf("error mismatch on %v:\nexpected: %v\nreceived: %v\n", test.blockNumber, test.PrivacyEnhancementsEnabled, isPrivacyEnhancementsEnabled)
  521. }
  522. }
  523. }
  524. func TestIsPrivacyPrecompileEnabled(t *testing.T) {
  525. type test struct {
  526. config *ChainConfig
  527. blockNumber int64
  528. PrivacyPrecompileEnabled bool
  529. }
  530. config1, config2 := *TestChainConfig, *TestChainConfig
  531. config1.PrivacyPrecompileBlock = big.NewInt(11)
  532. config2.PrivacyPrecompileBlock = nil
  533. config2.Transitions = []Transition{
  534. {Block: big.NewInt(21), PrivacyPrecompileEnabled: newPBool(true)},
  535. }
  536. tests := []test{
  537. {MainnetChainConfig, 0, false},
  538. {&config1, 10, false},
  539. {&config1, 11, true},
  540. {&config2, 20, false},
  541. {&config2, 21, true},
  542. {&config2, 22, true},
  543. }
  544. for _, test := range tests {
  545. isPrivacyPrecompileEnabled := test.config.IsPrivacyPrecompileEnabled(big.NewInt(test.blockNumber))
  546. if !reflect.DeepEqual(isPrivacyPrecompileEnabled, test.PrivacyPrecompileEnabled) {
  547. t.Errorf("error mismatch on %v:\nexpected: %v\nreceived: %v\n", test.blockNumber, test.PrivacyPrecompileEnabled, isPrivacyPrecompileEnabled)
  548. }
  549. }
  550. }
  551. func TestIsGasPriceEnabled(t *testing.T) {
  552. type test struct {
  553. config *ChainConfig
  554. blockNumber int64
  555. GasPriceEnabled bool
  556. }
  557. config1, config2 := *TestChainConfig, *TestChainConfig
  558. config1.EnableGasPriceBlock = big.NewInt(11)
  559. config2.EnableGasPriceBlock = nil
  560. config2.Transitions = []Transition{
  561. {Block: big.NewInt(21), GasPriceEnabled: newPBool(true)},
  562. }
  563. tests := []test{
  564. {MainnetChainConfig, 0, false},
  565. {&config1, 10, false},
  566. {&config1, 11, true},
  567. {&config2, 20, false},
  568. {&config2, 21, true},
  569. {&config2, 22, true},
  570. }
  571. for _, test := range tests {
  572. isGasPriceEnabled := test.config.IsGasPriceEnabled(big.NewInt(test.blockNumber))
  573. if !reflect.DeepEqual(isGasPriceEnabled, test.GasPriceEnabled) {
  574. t.Errorf("error mismatch on %v:\nexpected: %v\nreceived: %v\n", test.blockNumber, test.GasPriceEnabled, isGasPriceEnabled)
  575. }
  576. }
  577. }
  578. func newPBool(b bool) *bool {
  579. return &b
  580. }