MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestLocalKeyStore

Function TestLocalKeyStore

crypto/kms/localkeystore_test.go:30–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func TestLocalKeyStore(t *testing.T) {
31 Convey("set and get key", t, func() {
32 initLocalKeyStore()
33 So(localKey, ShouldNotBeNil)
34 gotPrivate, err := GetLocalPrivateKey()
35 So(gotPrivate, ShouldBeNil)
36 So(err, ShouldEqual, ErrNilField)
37 gotPublic, err := GetLocalPublicKey()
38 So(gotPublic, ShouldBeNil)
39 So(err, ShouldEqual, ErrNilField)
40
41 privKey1, pubKey1, _ := asymmetric.GenSecp256k1KeyPair()
42 privKey2, pubKey2, _ := asymmetric.GenSecp256k1KeyPair()
43 SetLocalKeyPair(privKey1, pubKey1)
44 SetLocalKeyPair(privKey2, pubKey2) // no effect
45 gotPrivate, err = GetLocalPrivateKey()
46 So(err, ShouldBeNil)
47 gotPublic, err = GetLocalPublicKey()
48 So(err, ShouldBeNil)
49 So(bytes.Compare(gotPrivate.Serialize(), privKey1.Serialize()), ShouldBeZeroValue)
50 So(gotPublic.IsEqual(pubKey1), ShouldBeTrue)
51 So(gotPrivate.PubKey().IsEqual(pubKey1), ShouldBeTrue)
52 ResetLocalKeyStore()
53 })
54 Convey("set and get key", t, func() {
55 initLocalKeyStore()
56 So(localKey, ShouldNotBeNil)
57 gotID, err := GetLocalNodeIDBytes()
58 So(gotID, ShouldBeNil)
59 So(err, ShouldEqual, ErrNilField)
60 gotNonce, err := GetLocalNonce()
61 So(gotNonce, ShouldBeNil)
62 So(err, ShouldEqual, ErrNilField)
63 SetLocalNodeIDNonce([]byte("aaa"), nil)
64 SetLocalNodeIDNonce([]byte("aaa"), &mine.Uint256{A: 1, B: 1, C: 1, D: 1})
65 gotID, err = GetLocalNodeIDBytes()
66 So(bytes.Compare(gotID, []byte("aaa")), ShouldBeZeroValue)
67 So(err, ShouldBeNil)
68 gotNonce, err = GetLocalNonce()
69 So(*gotNonce == mine.Uint256{A: 1, B: 1, C: 1, D: 1}, ShouldBeTrue)
70 So(err, ShouldBeNil)
71 rawNodeID := &proto.RawNodeID{}
72 nodeIDBefore := rawNodeID.ToNodeID()
73 SetLocalNodeIDNonce(nodeIDBefore.ToRawNodeID().CloneBytes(), nil)
74 nodeID, err := GetLocalNodeID()
75 So(nodeID, ShouldResemble, nodeIDBefore)
76 })
77}

Callers

nothing calls this directly

Calls 15

ToNodeIDMethod · 0.95
GenSecp256k1KeyPairFunction · 0.92
initLocalKeyStoreFunction · 0.85
GetLocalPrivateKeyFunction · 0.85
GetLocalPublicKeyFunction · 0.85
SetLocalKeyPairFunction · 0.85
ResetLocalKeyStoreFunction · 0.85
GetLocalNodeIDBytesFunction · 0.85
GetLocalNonceFunction · 0.85
SetLocalNodeIDNonceFunction · 0.85
GetLocalNodeIDFunction · 0.85
PubKeyMethod · 0.80

Tested by

no test coverage detected