github.com/turingchain2020/turingchain@v1.1.21/types/config_merge_test.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package types 6 7 import ( 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestMergeConfig(t *testing.T) { 14 conf := map[string]interface{}{ 15 "key1": "value1", 16 } 17 def := map[string]interface{}{ 18 "key2": "value2", 19 } 20 errstr := MergeConfig(conf, def) 21 assert.Equal(t, errstr, "") 22 assert.Equal(t, conf["key1"], "value1") 23 assert.Equal(t, conf["key2"], "value2") 24 25 conf = map[string]interface{}{ 26 "key1": "value1", 27 } 28 def = map[string]interface{}{ 29 "key1": "value2", 30 } 31 errstr = MergeConfig(conf, def) 32 assert.Equal(t, errstr, "rewrite defalut key key1\n") 33 assert.Equal(t, conf["key1"], "value1") 34 35 //level2 36 conf1 := map[string]interface{}{ 37 "key1": "value1", 38 } 39 def1 := map[string]interface{}{ 40 "key2": "value2", 41 } 42 conf = map[string]interface{}{ 43 "key1": conf1, 44 } 45 def = map[string]interface{}{ 46 "key2": def1, 47 } 48 errstr = MergeConfig(conf, def) 49 assert.Equal(t, errstr, "") 50 assert.Equal(t, conf["key1"].(map[string]interface{})["key1"], "value1") 51 assert.Equal(t, conf["key2"].(map[string]interface{})["key2"], "value2") 52 } 53 54 func TestMergeLevel2Error(t *testing.T) { 55 //level2 56 conf1 := map[string]interface{}{ 57 "key1": "value1", 58 } 59 def1 := map[string]interface{}{ 60 "key1": "value2", 61 } 62 conf := map[string]interface{}{ 63 "key1": conf1, 64 } 65 def := map[string]interface{}{ 66 "key1": def1, 67 } 68 errstr := MergeConfig(conf, def) 69 assert.Equal(t, errstr, "rewrite defalut key key1.key1\n") 70 assert.Equal(t, conf["key1"].(map[string]interface{})["key1"], "value1") 71 } 72 73 func TestMergeToml(t *testing.T) { 74 newcfg := MergeCfg(ReadFile("../cmd/turingchain/turingchaincoin.toml"), turingchaincoincfg) 75 cfg1, err := initCfgString(newcfg) 76 assert.Nil(t, err) 77 cfg2, err := initCfgString(readFile("testdata/turingchaincoin.toml")) 78 assert.Nil(t, err) 79 assert.Equal(t, cfg1, cfg2) 80 } 81 82 var turingchaincoincfg = ` 83 TestNet=false 84 [blockchain] 85 defCacheSize=128 86 maxFetchBlockNum=128 87 timeoutSeconds=5 88 batchBlockNum=128 89 driver="leveldb" 90 isStrongConsistency=false 91 singleMode=false 92 93 [p2p] 94 enable=true 95 driver="leveldb" 96 97 [mempool] 98 poolCacheSize=102400 99 100 [consensus] 101 name="ticket" 102 minerstart=true 103 genesisBlockTime=1514533394 104 genesis="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt" 105 106 [mver.consensus] 107 fundKeyAddr = "1JmFaA6unrCFYEWPGRi7uuXY1KthTJxJEP" 108 coinReward = 18 109 coinDevFund = 12 110 ticketPrice = 10000 111 powLimitBits = "0x1f00ffff" 112 retargetAdjustmentFactor = 4 113 futureBlockTime = 15 114 ticketFrozenTime = 43200 115 ticketWithdrawTime = 172800 116 ticketMinerWaitTime = 7200 117 maxTxNumber = 1500 118 targetTimespan = 2160 119 targetTimePerBlock = 15 120 121 [consensus.sub.ticket] 122 genesisBlockTime=1526486816 123 [[consensus.sub.ticket.genesis]] 124 minerAddr="184wj4nsgVxKyz2NhM3Yb5RK5Ap6AFRFq2" 125 returnAddr="1FB8L3DykVF7Y78bRfUrRcMZwesKue7CyR" 126 count=3000 127 128 [[consensus.sub.ticket.genesis]] 129 minerAddr="1M4ns1eGHdHak3SNc2UTQB75vnXyJQd91s" 130 returnAddr="1Lw6QLShKVbKM6QvMaCQwTh5Uhmy4644CG" 131 count=3000 132 133 [[consensus.sub.ticket.genesis]] 134 minerAddr="19ozyoUGPAQ9spsFiz9CJfnUCFeszpaFuF" 135 returnAddr="1PSYYfCbtSeT1vJTvSKmQvhz8y6VhtddWi" 136 count=3000 137 138 [[consensus.sub.ticket.genesis]] 139 minerAddr="1MoEnCDhXZ6Qv5fNDGYoW6MVEBTBK62HP2" 140 returnAddr="1BG9ZoKtgU5bhKLpcsrncZ6xdzFCgjrZud" 141 count=3000 142 143 [[consensus.sub.ticket.genesis]] 144 minerAddr="1FjKcxY7vpmMH6iB5kxNYLvJkdkQXddfrp" 145 returnAddr="1G7s64AgX1ySDcUdSW5vDa8jTYQMnZktCd" 146 count=3000 147 148 [[consensus.sub.ticket.genesis]] 149 minerAddr="12T8QfKbCRBhQdRfnAfFbUwdnH7TDTm4vx" 150 returnAddr="1FiDC6XWHLe7fDMhof8wJ3dty24f6aKKjK" 151 count=3000 152 153 [[consensus.sub.ticket.genesis]] 154 minerAddr="1bgg6HwQretMiVcSWvayPRvVtwjyKfz1J" 155 returnAddr="1AMvuuQ7V7FPQ4hkvHQdgNWy8wVL4d4hmp" 156 count=3000 157 158 [[consensus.sub.ticket.genesis]] 159 minerAddr="1EwkKd9iU1pL2ZwmRAC5RrBoqFD1aMrQ2" 160 returnAddr="1ExRRLoJXa8LzXdNxnJvBkVNZpVw3QWMi4" 161 count=3000 162 163 [[consensus.sub.ticket.genesis]] 164 minerAddr="1HFUhgxarjC7JLru1FLEY6aJbQvCSL58CB" 165 returnAddr="1KNGHukhbBnbWWnMYxu1C7YMoCj45Z3amm" 166 count=3000 167 168 [[consensus.sub.ticket.genesis]] 169 minerAddr="1C9M1RCv2e9b4GThN9ddBgyxAphqMgh5zq" 170 returnAddr="1AH9HRd4WBJ824h9PP1jYpvRZ4BSA4oN6Y" 171 count=4733 172 173 [store] 174 name="mavl" 175 driver="leveldb" 176 177 [wallet] 178 minFee=100000 179 driver="leveldb" 180 signType="secp256k1" 181 182 [exec] 183 184 185 [exec.sub.token] 186 #配置一个空值,防止配置文件被覆盖 187 tokenApprs = [] 188 189 [exec.sub.relay] 190 genesis="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt" 191 192 [exec.sub.manage] 193 superManager=[ 194 "1JmFaA6unrCFYEWPGRi7uuXY1KthTJxJEP", 195 ] 196 197 #系统中所有的fork,默认用turingchain的测试网络的 198 #但是我们可以替换 199 [fork.system] 200 ForkChainParamV1= 0 201 ForkStateDBSet=-1 202 ForkCheckTxDup=0 203 ForkBlockHash= 1 204 ForkMinerTime= 0 205 ForkTransferExec= 100000 206 ForkExecKey= 200000 207 ForkTxGroup= 200000 208 ForkResetTx0= 200000 209 ForkWithdraw= 200000 210 ForkExecRollback= 450000 211 ForkCheckBlockTime=1200000 212 ForkMultiSignAddress=1298600 213 ForkTxHeight= -1 214 ForkTxGroupPara= -1 215 ForkChainParamV2= -1 216 ForkBlockCheck=1725000 217 ForkLocalDBAccess=1 218 ForkBase58AddressCheck=1800000 219 ForkTicketFundAddrV1=-1 220 ForkRootHash=1 221 [fork.sub.coins] 222 Enable=0 223 224 [fork.sub.manage] 225 Enable=0 226 ForkManageExec=100000 227 228 [fork.sub.store-kvmvccmavl] 229 ForkKvmvccmavl=1 230 `