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

Function TestCaller_CallNode

rpc/mux/wrapper_test.go:46–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

44)
45
46func TestCaller_CallNode(t *testing.T) {
47 log.SetLevel(log.FatalLevel)
48 utils.RemoveAll(PubKeyStorePath + "*")
49 defer utils.RemoveAll(PubKeyStorePath + "*")
50 utils.RemoveAll(publicKeyStore + "*")
51 defer utils.RemoveAll(publicKeyStore + "*")
52
53 _, testFile, _, _ := runtime.Caller(0)
54 confFile := filepath.Join(filepath.Dir(testFile), "../../test/node_standalone/config.yaml")
55 privateKeyPath := filepath.Join(filepath.Dir(testFile), "../../test/node_standalone/private.key")
56
57 conf.GConf, _ = conf.LoadConfig(confFile)
58 log.Debugf("GConf: %#v", conf.GConf)
59 // reset the once
60 route.Once.Reset()
61 _ = GetSessionPoolInstance().Close()
62 route.InitKMS(publicKeyStore)
63
64 addr := conf.GConf.ListenAddr // see ../test/node_standalone/config.yaml
65 masterKey := []byte("")
66 dht, err := route.NewDHTService(PubKeyStorePath, new(consistent.KMSStorage), true)
67
68 server, err := NewServerWithService(ServiceMap{route.DHTRPCName: dht})
69 if err != nil {
70 t.Fatal(err)
71 }
72
73 _ = server.InitRPCServer(addr, privateKeyPath, masterKey)
74 go server.Serve()
75
76 //publicKey, err := kms.GetLocalPublicKey()
77 //nonce := asymmetric.GetPubKeyNonce(publicKey, 10, 100*time.Millisecond, nil)
78 //serverNodeID := proto.NodeID(nonce.Hash.String())
79 //kms.SetPublicKey(serverNodeID, nonce.Nonce, publicKey)
80 //
81 //kms.SetLocalNodeIDNonce(nonce.Hash.CloneBytes(), &nonce.Nonce)
82 //route.SetNodeAddrCache(&proto.RawNodeID{Hash: nonce.Hash}, server.Listener.Addr().String())
83
84 client := NewCaller()
85 node1 := proto.NewNode()
86 _ = node1.InitNodeCryptoInfo(100 * time.Millisecond)
87 node1.Addr = "1.1.1.1:1"
88
89 reqA := &proto.PingReq{
90 Node: *node1,
91 }
92
93 respA := new(proto.PingResp)
94 err = client.CallNode(conf.GConf.BP.NodeID, route.DHTPing.String(), reqA, respA)
95 if err != nil {
96 t.Fatal(err)
97 }
98 log.Debugf("respA: %v", respA)
99
100 node1addr, err := GetNodeAddr(node1.ID.ToRawNodeID())
101 Convey("test GetNodeAddr", t, func() {
102 So(err, ShouldBeNil)
103 So(node1addr, ShouldEqual, node1.Addr)

Callers

nothing calls this directly

Calls 15

InitNodeCryptoInfoMethod · 0.95
CallNodeMethod · 0.95
CallNodeWithContextMethod · 0.95
SetLevelFunction · 0.92
RemoveAllFunction · 0.92
LoadConfigFunction · 0.92
DebugfFunction · 0.92
InitKMSFunction · 0.92
NewDHTServiceFunction · 0.92
NewNodeFunction · 0.92
DelNodeFunction · 0.92
NodeIDTypeAlias · 0.92

Tested by

no test coverage detected