Skip to content

Commit

Permalink
revert again and rename proto package to
Browse files Browse the repository at this point in the history
daywalker90 committed Jun 16, 2024
1 parent 88170b8 commit 7eecf7c
Showing 5 changed files with 34 additions and 37 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,8 @@

### Changed

- Renamed `primitives.proto` to `hold_primitives.proto` as to not be confused with CLN's `primitives.proto`
- Merged `primitives.proto` into `hold.proto`. It was already very small and conflicting with CLN's `primitives.proto`
- Renamed proto package name from `cln` to `hold` so this plugin can stand alone and work together with cln-grpc


## [2.0.0] - 2024-05-06
14 changes: 12 additions & 2 deletions proto/hold.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
syntax = "proto3";
package cln;
package hold;

import "hold_primitives.proto";

service Hold {
rpc HoldInvoice(HoldInvoiceRequest) returns (HoldInvoiceResponse) {}
@@ -11,6 +10,17 @@ service Hold {

}

message Amount {
uint64 msat = 1;
}

enum Holdstate {
OPEN = 0;
SETTLED = 1;
CANCELED = 2;
ACCEPTED = 3;
}

message HoldInvoiceRequest {
Amount amount_msat = 10;
string description = 2;
13 changes: 0 additions & 13 deletions proto/hold_primitives.proto

This file was deleted.

2 changes: 1 addition & 1 deletion src/pb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tonic::include_proto!("cln");
tonic::include_proto!("hold");

use cln_rpc::primitives::Amount as JAmount;

39 changes: 19 additions & 20 deletions tests/test_holdinvoice_grpc.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
import grpc
import hold_pb2 as holdrpc
import hold_pb2_grpc as holdstub
import hold_primitives_pb2 as hold_primitives__pb2
import pytest
from grpc._channel import _InactiveRpcError
from pyln.testing.fixtures import * # noqa: F403
@@ -73,7 +72,7 @@ def test_inputs(node_factory, bitcoind, get_plugin): # noqa: F811

request = holdrpc.HoldInvoiceRequest(
description="Valid invoice description",
amount_msat=hold_primitives__pb2.Amount(msat=1000000),
amount_msat=holdrpc.Amount(msat=1000000),
label=generate_random_label(),
cltv=144,
)
@@ -84,7 +83,7 @@ def test_inputs(node_factory, bitcoind, get_plugin): # noqa: F811

request = holdrpc.HoldInvoiceRequest(
description="",
amount_msat=hold_primitives__pb2.Amount(msat=1000000),
amount_msat=holdrpc.Amount(msat=1000000),
label=generate_random_label(),
cltv=144,
)
@@ -95,7 +94,7 @@ def test_inputs(node_factory, bitcoind, get_plugin): # noqa: F811

random_hex = secrets.token_hex(32)
request = holdrpc.HoldInvoiceRequest(
amount_msat=hold_primitives__pb2.Amount(msat=2000000),
amount_msat=holdrpc.Amount(msat=2000000),
description="Invoice with optional fields",
label=generate_random_label(),
expiry=3600,
@@ -115,7 +114,7 @@ def test_inputs(node_factory, bitcoind, get_plugin): # noqa: F811
# 0 amount_msat
request = holdrpc.HoldInvoiceRequest(
description="Invalid amount",
amount_msat=hold_primitives__pb2.Amount(msat=0),
amount_msat=holdrpc.Amount(msat=0),
label=generate_random_label(),
cltv=144,
)
@@ -128,7 +127,7 @@ def test_inputs(node_factory, bitcoind, get_plugin): # noqa: F811
# Fallbacks not as a list of strings
request = holdrpc.HoldInvoiceRequest(
description="Invalid fallbacks",
amount_msat=hold_primitives__pb2.Amount(msat=800000),
amount_msat=holdrpc.Amount(msat=800000),
label=generate_random_label(),
fallbacks="invalid_fallback",
cltv=144,
@@ -139,7 +138,7 @@ def test_inputs(node_factory, bitcoind, get_plugin): # noqa: F811
# missing cltv
request = holdrpc.HoldInvoiceRequest(
description="Missing cltv",
amount_msat=hold_primitives__pb2.Amount(msat=800000),
amount_msat=holdrpc.Amount(msat=800000),
label=generate_random_label(),
)
with pytest.raises(
@@ -149,7 +148,7 @@ def test_inputs(node_factory, bitcoind, get_plugin): # noqa: F811

request = holdrpc.HoldInvoiceRequest(
description="Expose private channel",
amount_msat=hold_primitives__pb2.Amount(msat=1000000),
amount_msat=holdrpc.Amount(msat=1000000),
label=generate_random_label(),
cltv=144,
exposeprivatechannels=[cl2],
@@ -217,7 +216,7 @@ def test_valid_hold_then_settle(node_factory, bitcoind, get_plugin): # noqa: F8

request = holdrpc.HoldInvoiceRequest(
description="Valid invoice description",
amount_msat=hold_primitives__pb2.Amount(msat=1_000_100_000),
amount_msat=holdrpc.Amount(msat=1_000_100_000),
label=generate_random_label(),
cltv=144,
)
@@ -234,7 +233,7 @@ def test_valid_hold_then_settle(node_factory, bitcoind, get_plugin): # noqa: F8
assert isinstance(result_lookup, holdrpc.HoldInvoiceLookupResponse) is True
assert result_lookup.state is not None
LOGGER.info(f"{result_lookup}")
assert result_lookup.state == hold_primitives__pb2.Holdstate.OPEN
assert result_lookup.state == holdrpc.Holdstate.OPEN
assert result_lookup.htlc_expiry == 0

# test that it won't settle if it's still open
@@ -262,12 +261,12 @@ def test_valid_hold_then_settle(node_factory, bitcoind, get_plugin): # noqa: F8
isinstance(result_lookup, holdrpc.HoldInvoiceLookupResponse) is True
)

if result_lookup.state == hold_primitives__pb2.Holdstate.ACCEPTED:
if result_lookup.state == holdrpc.Holdstate.ACCEPTED:
break
else:
time.sleep(1)

assert result_lookup.state == hold_primitives__pb2.Holdstate.ACCEPTED
assert result_lookup.state == holdrpc.Holdstate.ACCEPTED
assert result_lookup.htlc_expiry > 0

# test that it's actually holding the htlcs
@@ -283,15 +282,15 @@ def test_valid_hold_then_settle(node_factory, bitcoind, get_plugin): # noqa: F8
result_settle = hold_stub.HoldInvoiceSettle(request_settle)
assert result_settle is not None
assert isinstance(result_settle, holdrpc.HoldInvoiceSettleResponse) is True
assert result_settle.state == hold_primitives__pb2.Holdstate.SETTLED
assert result_settle.state == holdrpc.Holdstate.SETTLED

request_lookup = holdrpc.HoldInvoiceLookupRequest(
payment_hash=result.payment_hash
)
result_lookup = hold_stub.HoldInvoiceLookup(request_lookup)
assert result_lookup is not None
assert isinstance(result_lookup, holdrpc.HoldInvoiceLookupResponse) is True
assert result_lookup.state == hold_primitives__pb2.Holdstate.SETTLED
assert result_lookup.state == holdrpc.Holdstate.SETTLED
assert result_lookup.htlc_expiry == 0

# ask cln if the invoice is actually paid
@@ -363,7 +362,7 @@ def test_valid_hold_then_cancel(node_factory, bitcoind, get_plugin): # noqa: F8

request = holdrpc.HoldInvoiceRequest(
description="Valid invoice description",
amount_msat=hold_primitives__pb2.Amount(msat=1_000_100_000),
amount_msat=holdrpc.Amount(msat=1_000_100_000),
label=generate_random_label(),
cltv=144,
)
@@ -380,7 +379,7 @@ def test_valid_hold_then_cancel(node_factory, bitcoind, get_plugin): # noqa: F8
assert isinstance(result_lookup, holdrpc.HoldInvoiceLookupResponse) is True
assert result_lookup.state is not None
LOGGER.info(f"{result_lookup}")
assert result_lookup.state == hold_primitives__pb2.Holdstate.OPEN
assert result_lookup.state == holdrpc.Holdstate.OPEN
assert result_lookup.htlc_expiry == 0

# test that it won't settle if it's still open
@@ -408,12 +407,12 @@ def test_valid_hold_then_cancel(node_factory, bitcoind, get_plugin): # noqa: F8
isinstance(result_lookup, holdrpc.HoldInvoiceLookupResponse) is True
)

if result_lookup.state == hold_primitives__pb2.Holdstate.ACCEPTED:
if result_lookup.state == holdrpc.Holdstate.ACCEPTED:
break
else:
time.sleep(1)

assert result_lookup.state == hold_primitives__pb2.Holdstate.ACCEPTED
assert result_lookup.state == holdrpc.Holdstate.ACCEPTED
assert result_lookup.htlc_expiry > 0

# test that it's actually holding the htlcs
@@ -429,15 +428,15 @@ def test_valid_hold_then_cancel(node_factory, bitcoind, get_plugin): # noqa: F8
result_cancel = hold_stub.HoldInvoiceCancel(request_cancel)
assert result_cancel is not None
assert isinstance(result_cancel, holdrpc.HoldInvoiceCancelResponse) is True
assert result_cancel.state == hold_primitives__pb2.Holdstate.CANCELED
assert result_cancel.state == holdrpc.Holdstate.CANCELED

request_lookup = holdrpc.HoldInvoiceLookupRequest(
payment_hash=result.payment_hash
)
result_lookup = hold_stub.HoldInvoiceLookup(request_lookup)
assert result_lookup is not None
assert isinstance(result_lookup, holdrpc.HoldInvoiceLookupResponse) is True
assert result_lookup.state == hold_primitives__pb2.Holdstate.CANCELED
assert result_lookup.state == holdrpc.Holdstate.CANCELED
assert result_lookup.htlc_expiry == 0

# ask cln if the invoice is actually unpaid

0 comments on commit 7eecf7c

Please sign in to comment.