-
Notifications
You must be signed in to change notification settings - Fork 129
Refactoring binding python test #805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ccf89d0
4b01075
215d5b2
fa2c431
b376446
58d16d5
d2ed4bc
232a795
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,6 +112,33 @@ def get_esplora_endpoint(): | |
| return str(os.environ['ESPLORA_ENDPOINT']) | ||
| return DEFAULT_ESPLORA_SERVER_URL | ||
|
|
||
| # handling expected event | ||
|
|
||
| def expect_event(node, expected_event_type): | ||
| event = node.wait_next_event() | ||
| assert isinstance(event, expected_event_type) | ||
| print("EVENT:", event) | ||
| node.event_handled() | ||
|
|
||
| # handling channel pending event | ||
|
|
||
| def expect_channel_pending_event(node): | ||
| event = node.wait_next_event() | ||
| assert isinstance(event, Event.CHANNEL_PENDING) | ||
| print("EVENT:", event) | ||
| node.event_handled() | ||
| return event | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused: if we now simply return the event, we can just reduce that to one
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. I should just return the event in the |
||
|
|
||
| # handling channel ready event | ||
|
|
||
| def expect_channel_ready_event(node): | ||
| event = node.wait_next_event() | ||
| assert isinstance(event, Event.CHANNEL_READY) | ||
| print("EVENT:", event) | ||
| node.event_handled() | ||
| return event | ||
|
|
||
|
|
||
| class TestLdkNode(unittest.TestCase): | ||
| def setUp(self): | ||
| bitcoin_cli("createwallet ldk_node_test") | ||
|
|
@@ -175,15 +202,10 @@ def test_channel_full_cycle(self): | |
|
|
||
| node_1.open_channel(node_id_2, listening_addresses_2[0], 50000, None, None) | ||
|
|
||
| channel_pending_event_1 = node_1.wait_next_event() | ||
| assert isinstance(channel_pending_event_1, Event.CHANNEL_PENDING) | ||
| print("EVENT:", channel_pending_event_1) | ||
| node_1.event_handled() | ||
| channel_pending_event_1 = expect_channel_pending_event(node_1) | ||
|
|
||
| channel_pending_event_2 = node_2.wait_next_event() | ||
| assert isinstance(channel_pending_event_2, Event.CHANNEL_PENDING) | ||
| print("EVENT:", channel_pending_event_2) | ||
| node_2.event_handled() | ||
| # expect channel pending event on node 2 but without return value since it doesn't contain the funding_txo | ||
| expect_event(node_2, Event.CHANNEL_PENDING) | ||
|
|
||
| funding_txid = channel_pending_event_1.funding_txo.txid | ||
| wait_for_tx(esplora_endpoint, funding_txid) | ||
|
|
@@ -192,42 +214,28 @@ def test_channel_full_cycle(self): | |
| node_1.sync_wallets() | ||
| node_2.sync_wallets() | ||
|
|
||
| channel_ready_event_1 = node_1.wait_next_event() | ||
| assert isinstance(channel_ready_event_1, Event.CHANNEL_READY) | ||
| print("EVENT:", channel_ready_event_1) | ||
| # expect generic channel ready event on node 1 | ||
| channel_ready_event_1 = expect_event(node_1, Event.CHANNEL_READY) | ||
| print("funding_txo:", funding_txid) | ||
| node_1.event_handled() | ||
|
|
||
| channel_ready_event_2 = node_2.wait_next_event() | ||
| assert isinstance(channel_ready_event_2, Event.CHANNEL_READY) | ||
| print("EVENT:", channel_ready_event_2) | ||
| node_2.event_handled() | ||
| channel_ready_event_2 = expect_channel_ready_event(node_2) | ||
|
|
||
| description = Bolt11InvoiceDescription.DIRECT("asdf") | ||
| invoice = node_2.bolt11_payment().receive(2500000, description, 9217) | ||
| node_1.bolt11_payment().send(invoice, None) | ||
|
|
||
| payment_successful_event_1 = node_1.wait_next_event() | ||
| assert isinstance(payment_successful_event_1, Event.PAYMENT_SUCCESSFUL) | ||
| print("EVENT:", payment_successful_event_1) | ||
| node_1.event_handled() | ||
| # expect payment successful event on node 1 and payment received event on node 2 | ||
| expect_event(node_1, Event.PAYMENT_SUCCESSFUL) | ||
|
|
||
| payment_received_event_2 = node_2.wait_next_event() | ||
| assert isinstance(payment_received_event_2, Event.PAYMENT_RECEIVED) | ||
| print("EVENT:", payment_received_event_2) | ||
| node_2.event_handled() | ||
| expect_event(node_2, Event.PAYMENT_RECEIVED) | ||
|
|
||
|
|
||
| node_2.close_channel(channel_ready_event_2.user_channel_id, node_id_1) | ||
|
|
||
| channel_closed_event_1 = node_1.wait_next_event() | ||
| assert isinstance(channel_closed_event_1, Event.CHANNEL_CLOSED) | ||
| print("EVENT:", channel_closed_event_1) | ||
| node_1.event_handled() | ||
| # expect channel closed event on both nodes | ||
| expect_event(node_1, Event.CHANNEL_CLOSED) | ||
|
|
||
| channel_closed_event_2 = node_2.wait_next_event() | ||
| assert isinstance(channel_closed_event_2, Event.CHANNEL_CLOSED) | ||
| print("EVENT:", channel_closed_event_2) | ||
| node_2.event_handled() | ||
| expect_event(node_2, Event.CHANNEL_CLOSED) | ||
|
|
||
| mine_and_wait(esplora_endpoint, 1) | ||
|
|
||
|
|
@@ -251,4 +259,3 @@ def test_channel_full_cycle(self): | |
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Please drop these comments, they are very redundant to the method names.