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

Function TestPeers

proto/servers_test.go:28–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestPeers(t *testing.T) {
29 Convey("test peers", t, func() {
30 privKey, _, err := asymmetric.GenSecp256k1KeyPair()
31 So(err, ShouldBeNil)
32 p := &Peers{
33 PeersHeader: PeersHeader{
34 Term: 1,
35 Leader: NodeID("00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9"),
36 Servers: []NodeID{
37 NodeID("00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9"),
38 NodeID("00000381d46fd6cf7742d7fb94e2422033af989c0e348b5781b3219599a3af35"),
39 },
40 },
41 }
42 err = p.Sign(privKey)
43 So(err, ShouldBeNil)
44 err = p.Verify()
45 So(err, ShouldBeNil)
46
47 // after encode/decode
48 buf, err := utils.EncodeMsgPack(p)
49 var peers *Peers
50 err = utils.DecodeMsgPack(buf.Bytes(), &peers)
51 So(err, ShouldBeNil)
52 err = peers.Verify()
53 So(err, ShouldBeNil)
54
55 peers2 := peers.Clone()
56 err = peers2.Verify()
57 So(err, ShouldBeNil)
58
59 i, found := peers.Find(NodeID("00000381d46fd6cf7742d7fb94e2422033af989c0e348b5781b3219599a3af35"))
60 So(i, ShouldEqual, 1)
61 So(found, ShouldBeTrue)
62
63 i, found = peers.Find(NodeID("0000000000000000000000000000000000000000000000000000000000000001"))
64 So(found, ShouldBeFalse)
65
66 // verify hash failed
67 peers.Term = 2
68 err = peers.Verify()
69 So(err, ShouldNotBeNil)
70 err = peers.Sign(privKey)
71 So(err, ShouldBeNil)
72
73 // verify failed
74 p.Signature = peers.Signature
75 err = p.Verify()
76 So(err, ShouldNotBeNil)
77 })
78}

Callers

nothing calls this directly

Calls 10

SignMethod · 0.95
VerifyMethod · 0.95
CloneMethod · 0.95
FindMethod · 0.95
GenSecp256k1KeyPairFunction · 0.92
EncodeMsgPackFunction · 0.92
DecodeMsgPackFunction · 0.92
NodeIDTypeAlias · 0.85
VerifyMethod · 0.65
BytesMethod · 0.45

Tested by

no test coverage detected