From 7eecf7c0fbe3cd520d2295cd86031dd776fe834c Mon Sep 17 00:00:00 2001 From: daywalker90 <8257956+daywalker90@users.noreply.github.com> Date: Sun, 16 Jun 2024 16:44:59 +0200 Subject: [PATCH] revert again and rename proto package to --- CHANGELOG.md | 3 ++- proto/hold.proto | 14 ++++++++++-- proto/hold_primitives.proto | 13 ------------ src/pb.rs | 2 +- tests/test_holdinvoice_grpc.py | 39 +++++++++++++++++----------------- 5 files changed, 34 insertions(+), 37 deletions(-) delete mode 100644 proto/hold_primitives.proto diff --git a/CHANGELOG.md b/CHANGELOG.md index 569c4e9..3440a58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/proto/hold.proto b/proto/hold.proto index 678eb2c..6166405 100644 --- a/proto/hold.proto +++ b/proto/hold.proto @@ -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; diff --git a/proto/hold_primitives.proto b/proto/hold_primitives.proto deleted file mode 100644 index 1bbcba0..0000000 --- a/proto/hold_primitives.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; -package cln; - -message Amount { - uint64 msat = 1; -} - -enum Holdstate { - OPEN = 0; - SETTLED = 1; - CANCELED = 2; - ACCEPTED = 3; -} \ No newline at end of file diff --git a/src/pb.rs b/src/pb.rs index 6d72730..cdb6160 100644 --- a/src/pb.rs +++ b/src/pb.rs @@ -1,4 +1,4 @@ -tonic::include_proto!("cln"); +tonic::include_proto!("hold"); use cln_rpc::primitives::Amount as JAmount; diff --git a/tests/test_holdinvoice_grpc.py b/tests/test_holdinvoice_grpc.py index 856c248..571e02e 100644 --- a/tests/test_holdinvoice_grpc.py +++ b/tests/test_holdinvoice_grpc.py @@ -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,7 +282,7 @@ 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 @@ -291,7 +290,7 @@ def test_valid_hold_then_settle(node_factory, bitcoind, get_plugin): # noqa: F8 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,7 +428,7 @@ 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 @@ -437,7 +436,7 @@ def test_valid_hold_then_cancel(node_factory, bitcoind, get_plugin): # noqa: F8 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