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

Function TestDB

crypto/kms/pubkeystore_test.go:38–136  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

36const dbFile = ".test.keystore"
37
38func TestDB(t *testing.T) {
39 privKey1, pubKey1, _ := asymmetric.GenSecp256k1KeyPair()
40 privKey2, pubKey2, _ := asymmetric.GenSecp256k1KeyPair()
41 node1 := &proto.Node{
42 ID: proto.NodeID("1111"),
43 Addr: "",
44 PublicKey: pubKey1,
45 Nonce: cpuminer.Uint256{},
46 }
47 node2 := &proto.Node{
48 ID: proto.NodeID("2222"),
49 Addr: "",
50 PublicKey: pubKey2,
51 Nonce: cpuminer.Uint256{},
52 }
53 BPNode := &proto.Node{
54 ID: BP.NodeID,
55 Addr: "",
56 PublicKey: BP.PublicKey,
57 Nonce: BP.Nonce,
58 }
59
60 Convey("Init db", t, func() {
61 ClosePublicKeyStore()
62 utils.RemoveAll(dbFile + "*")
63 defer utils.RemoveAll(dbFile + "*")
64 InitPublicKeyStore(dbFile, []proto.Node{*BPNode})
65
66 nodeInfo, err := GetNodeInfo(BP.NodeID)
67 log.Debugf("nodeInfo %v", nodeInfo)
68 pubk, err := GetPublicKey(BP.NodeID)
69 So(pubk, ShouldNotBeNil)
70 So(err, ShouldBeNil)
71 So(pubk.IsEqual(BP.PublicKey), ShouldBeTrue)
72
73 pubk, err = GetPublicKey(proto.NodeID("99999999"))
74 So(pubk, ShouldBeNil)
75 So(errors.Cause(err), ShouldEqual, ErrKeyNotFound)
76
77 err = SetNode(nil)
78 So(err, ShouldEqual, ErrNilNode)
79
80 err = setNode(node1)
81 So(err, ShouldBeNil)
82
83 err = setNode(node2)
84 So(err, ShouldBeNil)
85
86 err = SetPublicKey(BP.NodeID, BP.Nonce, BP.PublicKey)
87 So(err, ShouldBeNil)
88
89 err = SetPublicKey(BP.NodeID, cpuminer.Uint256{}, BP.PublicKey)
90 So(err, ShouldEqual, ErrNodeIDKeyNonceNotMatch)
91
92 err = SetPublicKey(proto.NodeID("00"+BP.NodeID), BP.Nonce, BP.PublicKey)
93 So(err, ShouldEqual, ErrNodeIDKeyNonceNotMatch)
94
95 pubk, err = GetPublicKey(proto.NodeID("1111"))

Callers

nothing calls this directly

Calls 15

GenSecp256k1KeyPairFunction · 0.92
NodeIDTypeAlias · 0.92
RemoveAllFunction · 0.92
DebugfFunction · 0.92
ClosePublicKeyStoreFunction · 0.85
InitPublicKeyStoreFunction · 0.85
GetPublicKeyFunction · 0.85
SetNodeFunction · 0.85
setNodeFunction · 0.85
SetPublicKeyFunction · 0.85
GetAllNodeIDFunction · 0.85
DelNodeFunction · 0.85

Tested by

no test coverage detected