github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/local/me_test.go (about)

     1  package local
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  
     8  	"github.com/onflow/flow-go/utils/unittest"
     9  )
    10  
    11  // should be able to initialize with a Identity whose PublicKey matches with
    12  // the given private key's public key
    13  func TestInitializeWithMatchingKey(t *testing.T) {
    14  	stakingPriv := unittest.StakingPrivKeyFixture()
    15  	nodeID := unittest.IdentityFixture()
    16  	nodeID.StakingPubKey = stakingPriv.PublicKey()
    17  
    18  	me, err := New(nodeID.IdentitySkeleton, stakingPriv)
    19  	require.NoError(t, err)
    20  	require.Equal(t, nodeID.NodeID, me.NodeID())
    21  }
    22  
    23  // should fail to initialize with a Identity whose PublicKey mismatch with
    24  // the given private key's public key
    25  func TestInitializeWithMisMatchingKey(t *testing.T) {
    26  	stakingPriv := unittest.StakingPrivKeyFixture()
    27  	badPriv := unittest.StakingPrivKeyFixture()
    28  
    29  	nodeID := unittest.IdentityFixture()
    30  	nodeID.StakingPubKey = badPriv.PublicKey()
    31  
    32  	_, err := New(nodeID.IdentitySkeleton, stakingPriv)
    33  	require.Error(t, err)
    34  }