Skip to content

Commit

Permalink
merge primitives.proto into hold.proto
Browse files Browse the repository at this point in the history
  • Loading branch information
daywalker90 committed Jun 16, 2024
1 parent e057b3c commit cd5d713
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 39 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

### Changed

- Merged `primitives.proto` into `hold.proto`. It was already very small and conflicting with CLN's `primitives.proto`


## [2.0.0] - 2024-05-06

### Added
Expand Down
16 changes: 10 additions & 6 deletions proto/hold.proto
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
syntax = "proto3";
package cln;

// This file was automatically derived from the JSON-RPC schemas in
// `doc/schemas`. Do not edit this file manually as it would get
// overwritten.

import "primitives.proto";

service Hold {
rpc HoldInvoice(HoldInvoiceRequest) returns (HoldInvoiceResponse) {}
rpc HoldInvoiceSettle(HoldInvoiceSettleRequest) returns (HoldInvoiceSettleResponse) {}
Expand All @@ -15,6 +9,16 @@ service Hold {

}

message Amount {
uint64 msat = 1;
}

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

message HoldInvoiceRequest {
Amount amount_msat = 10;
Expand Down
13 changes: 0 additions & 13 deletions proto/primitives.proto

This file was deleted.

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

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

request = holdrpc.HoldInvoiceRequest(
description="",
amount_msat=primitives__pb2.Amount(msat=1000000),
amount_msat=holdrpc.Amount(msat=1000000),
label=generate_random_label(),
cltv=144,
)
Expand All @@ -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=primitives__pb2.Amount(msat=2000000),
amount_msat=holdrpc.Amount(msat=2000000),
description="Invoice with optional fields",
label=generate_random_label(),
expiry=3600,
Expand All @@ -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=primitives__pb2.Amount(msat=0),
amount_msat=holdrpc.Amount(msat=0),
label=generate_random_label(),
cltv=144,
)
Expand All @@ -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=primitives__pb2.Amount(msat=800000),
amount_msat=holdrpc.Amount(msat=800000),
label=generate_random_label(),
fallbacks="invalid_fallback",
cltv=144,
Expand All @@ -139,7 +138,7 @@ def test_inputs(node_factory, bitcoind, get_plugin): # noqa: F811
# missing cltv
request = holdrpc.HoldInvoiceRequest(
description="Missing cltv",
amount_msat=primitives__pb2.Amount(msat=800000),
amount_msat=holdrpc.Amount(msat=800000),
label=generate_random_label(),
)
with pytest.raises(
Expand All @@ -149,7 +148,7 @@ def test_inputs(node_factory, bitcoind, get_plugin): # noqa: F811

request = holdrpc.HoldInvoiceRequest(
description="Expose private channel",
amount_msat=primitives__pb2.Amount(msat=1000000),
amount_msat=holdrpc.Amount(msat=1000000),
label=generate_random_label(),
cltv=144,
exposeprivatechannels=[cl2],
Expand Down Expand Up @@ -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=primitives__pb2.Amount(msat=1_000_100_000),
amount_msat=holdrpc.Amount(msat=1_000_100_000),
label=generate_random_label(),
cltv=144,
)
Expand All @@ -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 == 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
Expand Down Expand Up @@ -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 == primitives__pb2.Holdstate.ACCEPTED:
if result_lookup.state == holdrpc.Holdstate.ACCEPTED:
break
else:
time.sleep(1)

assert result_lookup.state == 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
Expand All @@ -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 == 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 == 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
Expand Down Expand Up @@ -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=primitives__pb2.Amount(msat=1_000_100_000),
amount_msat=holdrpc.Amount(msat=1_000_100_000),
label=generate_random_label(),
cltv=144,
)
Expand All @@ -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 == 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
Expand Down Expand Up @@ -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 == primitives__pb2.Holdstate.ACCEPTED:
if result_lookup.state == holdrpc.Holdstate.ACCEPTED:
break
else:
time.sleep(1)

assert result_lookup.state == 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
Expand All @@ -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 == 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 == 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
Expand Down

0 comments on commit cd5d713

Please sign in to comment.