-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package itest | ||
|
||
import ( | ||
"encoding/hex" | ||
"encoding/json" | ||
"log" | ||
|
||
"github.com/breez/lntest" | ||
"github.com/breez/lspd/lsps0" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func testLsps2GetVersions(p *testParams) { | ||
p.BreezClient().Node().ConnectPeer(p.Lsp().LightningNode()) | ||
|
||
rawMsg := `{ | ||
"method": "lsps2.get_versions", | ||
"jsonrpc": "2.0", | ||
"id": "example#3cad6a54d302edba4c9ade2f7ffac098", | ||
"params": {} | ||
}` | ||
p.BreezClient().Node().SendCustomMessage(&lntest.CustomMsgRequest{ | ||
PeerId: hex.EncodeToString(p.Lsp().NodeId()), | ||
Type: lsps0.Lsps0MessageType, | ||
Data: []byte(rawMsg), | ||
}) | ||
|
||
resp := p.BreezClient().ReceiveCustomMessage() | ||
assert.Equal(p.t, uint32(37913), resp.Type) | ||
|
||
content := make(map[string]json.RawMessage) | ||
err := json.Unmarshal(resp.Data[:], &content) | ||
lntest.CheckError(p.t, err) | ||
|
||
log.Print(string(resp.Data)) | ||
result := make(map[string][]int) | ||
err = json.Unmarshal(content["result"], &result) | ||
lntest.CheckError(p.t, err) | ||
assert.Equal(p.t, []int{1}, result["versions"]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package lsps2 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/breez/lspd/lsps0" | ||
) | ||
|
||
type GetVersionsRequest struct { | ||
} | ||
|
||
type GetVersionsResponse struct { | ||
Versions []int32 `json:"versions"` | ||
} | ||
|
||
type Lsps2Server interface { | ||
GetVersions(ctx context.Context, request *GetVersionsRequest) (*GetVersionsResponse, error) | ||
} | ||
type server struct{} | ||
|
||
func NewLsps2Server() Lsps2Server { | ||
return &server{} | ||
} | ||
|
||
func (s *server) GetVersions( | ||
ctx context.Context, | ||
request *GetVersionsRequest, | ||
) (*GetVersionsResponse, error) { | ||
return &GetVersionsResponse{ | ||
Versions: []int32{1}, | ||
}, nil | ||
} | ||
|
||
func RegisterLsps2Server(s lsps0.ServiceRegistrar, l Lsps2Server) { | ||
s.RegisterService( | ||
&lsps0.ServiceDesc{ | ||
ServiceName: "lsps2", | ||
HandlerType: (*Lsps2Server)(nil), | ||
Methods: []lsps0.MethodDesc{ | ||
{ | ||
MethodName: "lsps2.get_versions", | ||
Handler: func(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { | ||
in := new(GetVersionsRequest) | ||
if err := dec(in); err != nil { | ||
return nil, err | ||
} | ||
return srv.(Lsps2Server).GetVersions(ctx, in) | ||
}, | ||
}, | ||
}, | ||
}, | ||
l, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters