github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/crypto/keys/armor/armor_unsafe_test.go (about)

     1  package armor
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/gnolang/gno/tm2/pkg/crypto/secp256k1"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  // TestArmorUnarmor_PrivKey_Unencrypted verifies that an unencrypted private key
    11  // can be correctly armored and unarmored
    12  func TestArmorUnarmor_PrivKey_Unencrypted(t *testing.T) {
    13  	t.Parallel()
    14  
    15  	// Generate a random private key
    16  	randomPrivateKey := secp256k1.GenPrivKey()
    17  
    18  	// Armor it, then unarmor it
    19  	unarmoredPrivateKey, err := UnarmorPrivateKey(ArmorPrivateKey(randomPrivateKey))
    20  	if err != nil {
    21  		t.Fatalf("unable to unarmor private key, %v", err)
    22  	}
    23  
    24  	// Make sure the keys match
    25  	assert.True(t, randomPrivateKey.Equals(unarmoredPrivateKey))
    26  }