github.com/iotexproject/iotex-core@v1.14.1-rc1/blockchain/config_test.go (about)

     1  // Copyright (c) 2022 IoTeX Foundation
     2  // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
     3  // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
     4  // This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
     5  
     6  package blockchain
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/iotexproject/go-pkgs/crypto"
    12  
    13  	"github.com/stretchr/testify/require"
    14  )
    15  
    16  func TestProducer(t *testing.T) {
    17  	r := require.New(t)
    18  	cfg := DefaultConfig
    19  	r.NotNil(cfg.ProducerAddress())
    20  	r.NotNil(cfg.ProducerPrivateKey())
    21  }
    22  
    23  func TestWhitelist(t *testing.T) {
    24  	r := require.New(t)
    25  	cfg := Config{}
    26  	sk, err := crypto.HexStringToPrivateKey("308193020100301306072a8648ce3d020106082a811ccf5501822d0479307702010104202d57ec7da578b98dad465997748ed02af0c69092ad809598073e5a2356c20492a00a06082a811ccf5501822da14403420004223356f0c6f40822ade24d47b0cd10e9285402cbc8a5028a8eec9efba44b8dfe1a7e8bc44953e557b32ec17039fb8018a58d48c8ffa54933fac8030c9a169bf6")
    27  	r.NoError(err)
    28  	r.False(cfg.whitelistSignatureScheme(sk))
    29  	cfg.ProducerPrivKey = sk.HexString()
    30  	r.Panics(func() { cfg.ProducerPrivateKey() })
    31  
    32  	cfg.SignatureScheme = append(cfg.SignatureScheme, SigP256sm2)
    33  	r.Equal(sk, cfg.ProducerPrivateKey())
    34  	r.Equal(sk.PublicKey().Address().String(), cfg.ProducerAddress().String())
    35  }