github.com/klaytn/klaytn@v1.12.1/params/config_test.go (about) 1 // Copyright 2022 The klaytn Authors 2 // This file is part of the klaytn library. 3 // 4 // The klaytn 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 klaytn 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 klaytn library. If not, see <http://www.gnu.org/licenses/>. 16 17 package params 18 19 import ( 20 "math/big" 21 "testing" 22 23 "github.com/stretchr/testify/assert" 24 ) 25 26 func TestChainConfig_CheckConfigForkOrder(t *testing.T) { 27 assert.Nil(t, BaobabChainConfig.CheckConfigForkOrder()) 28 assert.Nil(t, CypressChainConfig.CheckConfigForkOrder()) 29 } 30 31 func TestChainConfig_Copy(t *testing.T) { 32 // Temporarily modify CypressChainConfig to simulate copying `nil` field. 33 savedBlock := CypressChainConfig.LondonCompatibleBlock 34 CypressChainConfig.LondonCompatibleBlock = nil 35 defer func() { CypressChainConfig.LondonCompatibleBlock = savedBlock }() 36 37 a := CypressChainConfig 38 b := a.Copy() 39 40 // simple field 41 assert.Equal(t, a.UnitPrice, b.UnitPrice) 42 b.UnitPrice = 0x1111 43 assert.NotEqual(t, a.UnitPrice, b.UnitPrice) 44 45 // nested field 46 assert.Equal(t, a.Istanbul.Epoch, b.Istanbul.Epoch) 47 b.Istanbul.Epoch = 0x2222 48 assert.NotEqual(t, a.Istanbul.Epoch, b.Istanbul.Epoch) 49 50 // non-nil pointer field with omitempty 51 assert.NotNil(t, a.IstanbulCompatibleBlock) 52 assert.Equal(t, a.IstanbulCompatibleBlock, b.IstanbulCompatibleBlock) 53 b.IstanbulCompatibleBlock = big.NewInt(111111) 54 assert.NotEqual(t, a.IstanbulCompatibleBlock, b.IstanbulCompatibleBlock) 55 56 // nil pointer field with omitempty 57 assert.Nil(t, a.LondonCompatibleBlock) 58 assert.Equal(t, a.LondonCompatibleBlock, b.LondonCompatibleBlock) 59 b.LondonCompatibleBlock = big.NewInt(222222) 60 assert.NotEqual(t, a.LondonCompatibleBlock, b.LondonCompatibleBlock) 61 62 // non-nil pointer field without omitempty 63 assert.Equal(t, a.Governance.Reward.MintingAmount, b.Governance.Reward.MintingAmount) 64 b.Governance.Reward.MintingAmount = big.NewInt(3333333) 65 assert.NotEqual(t, a.Governance.Reward.MintingAmount, b.Governance.Reward.MintingAmount) 66 67 // nested field of *struct type 68 assert.Equal(t, a.Governance.Reward.Ratio, b.Governance.Reward.Ratio) 69 b.Governance.Reward = &RewardConfig{Ratio: "11/22/33"} 70 assert.NotEqual(t, a.Governance.Reward.Ratio, b.Governance.Reward.Ratio) 71 } 72 73 func BenchmarkChainConfig_Copy(b *testing.B) { 74 a := CypressChainConfig 75 for i := 0; i < b.N; i++ { 76 a.Copy() 77 } 78 }