github.com/turingchain2020/turingchain@v1.1.21/types/config_mver_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 TestConfigFlat(t *testing.T) {
    14  	conf := map[string]interface{}{
    15  		"key1": "value1",
    16  		"key2": map[string]interface{}{
    17  			"key21": "value21",
    18  		},
    19  	}
    20  	flat := FlatConfig(conf)
    21  	assert.Equal(t, "value1", flat["key1"])
    22  	assert.Equal(t, "value21", flat["key2.key21"])
    23  }
    24  
    25  func TestConfigMverInit(t *testing.T) {
    26  	RegFork("store-kvmvccmavl", func(cfg *TuringchainConfig) {
    27  		cfg.RegisterDappFork("store-kvmvccmavl", "ForkKvmvccmavl", MaxHeight)
    28  	})
    29  	cfg := NewTuringchainConfigNoInit(ReadFile("testdata/local.mvertest.toml"))
    30  	cfg.EnableCheckFork(false)
    31  	cfg.turingchainCfgInit(cfg.GetModuleConfig())
    32  	assert.Equal(t, cfg.MGStr("mver.consensus.name2", 0), "ticket-turingchaincoin")
    33  	assert.Equal(t, cfg.MGStr("mver.consensus.name2", 10), "ticket-turingchaincoinv5")
    34  	assert.Equal(t, cfg.MGStr("mver.consensus.name2", 25), "ticket-turingchaincoinv2")
    35  	assert.Equal(t, cfg.MGStr("mver.hello", 0), "world")
    36  	assert.Equal(t, cfg.MGStr("mver.hello", 11), "forkworld")
    37  	assert.Equal(t, cfg.MGStr("mver.nofork", 0), "nofork")
    38  	assert.Equal(t, cfg.MGStr("mver.nofork", 9), "nofork")
    39  	assert.Equal(t, cfg.MGStr("mver.nofork", 11), "nofork")
    40  
    41  	assert.Equal(t, cfg.MGStr("mver.exec.sub.coins.name2", -1), "ticket-turingchaincoin")
    42  	assert.Equal(t, cfg.MGStr("mver.exec.sub.coins.name2", 0), "ticket-turingchaincoinv5-enable")
    43  	assert.Equal(t, cfg.MGStr("mver.exec.sub.coins.name2", 9), "ticket-turingchaincoinv5-enable")
    44  	assert.Equal(t, cfg.MGStr("mver.exec.sub.coins.name2", 10), "ticket-turingchaincoinv5")
    45  	assert.Equal(t, cfg.MGStr("mver.exec.sub.coins.name2", 11), "ticket-turingchaincoinv5")
    46  	assert.Equal(t, int64(1), cfg.GetDappFork("store-kvmvccmavl", "ForkKvmvccmavl"))
    47  
    48  	assert.Equal(t, cfg.MGInt("mver.consensus.ticket.ticketPrice", 1), int64(10000))
    49  	assert.Equal(t, cfg.MGInt("mver.consensus.ticket.ticketPrice", 11), int64(20000))
    50  	assert.Equal(t, cfg.MGInt("mver.consensus.ticket.ticketPrice", 21), int64(30000))
    51  
    52  	assert.Equal(t, cfg.MGInt("mver.consensus.ticket.ticketFrozenTime", -2), int64(5))
    53  	assert.Equal(t, cfg.MGInt("mver.consensus.ticket.ticketFrozenTime", 1), int64(5))
    54  	assert.Equal(t, cfg.MGInt("mver.consensus.ticket.ticketFrozenTime", 10), int64(5))
    55  	assert.Equal(t, cfg.MGInt("mver.consensus.ticket.ticketFrozenTime", 20), int64(5))
    56  }
    57  
    58  var chainBaseParam *ChainParam
    59  var chainV3Param *ChainParam
    60  
    61  func initChainBase() {
    62  	chainBaseParam = &ChainParam{}
    63  	chainBaseParam.PowLimitBits = uint32(0x1f00ffff)
    64  	chainBaseParam.MaxTxNumber = 1600 //160
    65  
    66  }
    67  
    68  func getP(cfg *TuringchainConfig, height int64) *ChainParam {
    69  	initChainBase()
    70  	initChainTuringchaincoinV3()
    71  	if cfg.IsFork(height, "ForkChainParamV1") {
    72  		return chainV3Param
    73  	}
    74  	return chainBaseParam
    75  }
    76  
    77  func initChainTuringchaincoinV3() {
    78  	chainV3Param = &ChainParam{}
    79  	tmp := *chainBaseParam
    80  	//copy base param
    81  	chainV3Param = &tmp
    82  	//修改的值
    83  
    84  	chainV3Param.MaxTxNumber = 1500
    85  
    86  }
    87  
    88  func TestInitChainParam(t *testing.T) {
    89  	cfg := NewTuringchainConfig(ReadFile("../cmd/turingchain/turingchain.toml"))
    90  	forkid := cfg.GetFork("ForkChainParamV1")
    91  	assert.Equal(t, cfg.GetP(0), getP(cfg, 0))
    92  	assert.Equal(t, cfg.GetP(forkid-1), getP(cfg, forkid-1))
    93  	assert.Equal(t, cfg.GetP(forkid), getP(cfg, forkid))
    94  	assert.Equal(t, cfg.GetP(forkid+1), getP(cfg, forkid+1))
    95  	assert.Equal(t, cfg.GetFundAddr(), "1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5")
    96  
    97  	conf := ConfSub(cfg, "manage")
    98  	assert.Equal(t, cfg.GetFundAddr(), "1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5")
    99  	assert.Equal(t, conf.GStrList("superManager"), []string{
   100  		"1Bsg9j6gW83sShoee1fZAt9TkUjcrCgA9S",
   101  		"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv",
   102  		"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK",
   103  	})
   104  }