github.com/turingchain2020/turingchain@v1.1.21/types/config_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/turingchain2020/turingchain/system/crypto/secp256k1"
    11  
    12  	"github.com/stretchr/testify/assert"
    13  )
    14  
    15  func TestChainConfig(t *testing.T) {
    16  	cfg := NewTuringchainConfig(GetDefaultCfgstring())
    17  	cfg.S("a", true)
    18  	_, err := cfg.G("b")
    19  	assert.Equal(t, err, ErrNotFound)
    20  	assert.True(t, cfg.IsEnable("TxHeight"))
    21  	adata, err := cfg.G("a")
    22  	assert.Equal(t, err, nil)
    23  	assert.Equal(t, adata.(bool), true)
    24  
    25  	// tx fee config
    26  	assert.Equal(t, cfg.GetMaxTxFee(), int64(1e9))
    27  	assert.Equal(t, cfg.GetMaxTxFeeRate(), int64(1e7))
    28  	assert.Equal(t, cfg.GetMinTxFeeRate(), int64(1e5))
    29  	height, ok := cfg.GetModuleConfig().Crypto.EnableHeight[secp256k1.Name]
    30  	assert.True(t, ok)
    31  	_, ok = cfg.GetSubConfig().Crypto[secp256k1.Name]
    32  	assert.True(t, ok)
    33  	assert.Equal(t, int64(0), height)
    34  }
    35  
    36  //测试实际的配置文件
    37  func TestSubConfig(t *testing.T) {
    38  	cfg, err := initSubModuleString(readFile("testdata/turingchain.toml"))
    39  	assert.Equal(t, 0, len(cfg.Consensus))
    40  	assert.Equal(t, 2, len(cfg.Store))
    41  	assert.Equal(t, 1, len(cfg.Exec))
    42  	assert.Equal(t, 1, len(cfg.Wallet))
    43  	assert.Nil(t, err)
    44  }
    45  
    46  func TestConfInit(t *testing.T) {
    47  	cfg := NewTuringchainConfig(ReadFile("testdata/turingchain.toml"))
    48  	assert.True(t, cfg.IsEnable("TxHeight"))
    49  }
    50  
    51  func TestConfigNoInit(t *testing.T) {
    52  	cfg := NewTuringchainConfigNoInit(ReadFile("testdata/turingchain.toml"))
    53  	assert.False(t, cfg.IsEnable("TxHeight"))
    54  	cfg.EnableCheckFork(false)
    55  	cfg.turingchainCfgInit(cfg.GetModuleConfig())
    56  	mcfg := cfg.GetModuleConfig()
    57  	assert.Equal(t, cfg.forks.forks["ForkV16Withdraw"], int64(480000))
    58  	assert.Equal(t, mcfg.Fork.Sub["token"]["Enable"], int64(100899))
    59  	confsystem := Conf(cfg, "config.fork.system")
    60  	assert.Equal(t, confsystem.GInt("ForkV16Withdraw"), int64(480000))
    61  	confsubtoken := Conf(cfg, "config.fork.sub.token")
    62  	assert.Equal(t, confsubtoken.GInt("Enable"), int64(100899))
    63  	// tx fee config
    64  	assert.Equal(t, int64(1e8), cfg.GetMaxTxFee())
    65  	assert.Equal(t, int64(1e6), cfg.GetMaxTxFeeRate())
    66  	assert.Equal(t, int64(1e4), cfg.GetMinTxFeeRate())
    67  	cfg.SetTxFeeConfig(1e9, 1e9, 1e9)
    68  	assert.True(t, int64(1e9) == cfg.GetMinTxFeeRate() && cfg.GetMaxTxFeeRate() == cfg.GetMaxTxFee())
    69  }
    70  
    71  func TestTuringchaincoinInit(t *testing.T) {
    72  	cfg, err := initCfgString(MergeCfg(ReadFile("testdata/turingchaincoin.toml"), ""))
    73  	assert.Nil(t, err)
    74  	assert.Equal(t, int64(200000), cfg.Fork.System["ForkWithdraw"])
    75  	assert.Equal(t, int64(0), cfg.Fork.Sub["token"]["Enable"])
    76  }
    77  
    78  func TestGetParaExecTitleName(t *testing.T) {
    79  	_, exist := GetParaExecTitleName("token")
    80  	assert.Equal(t, false, exist)
    81  
    82  	_, exist = GetParaExecTitleName("user.p.para")
    83  	assert.Equal(t, false, exist)
    84  
    85  	title, exist := GetParaExecTitleName("user.p.para.")
    86  	assert.Equal(t, true, exist)
    87  	assert.Equal(t, "user.p.para.", title)
    88  
    89  	title, exist = GetParaExecTitleName("user.p.guodux.token")
    90  	assert.Equal(t, true, exist)
    91  	assert.Equal(t, "user.p.guodux.", title)
    92  }