|
|
@ -208,23 +208,13 @@ class TestChannel(unittest.TestCase): |
|
|
|
# update log. Then Alice sends this wire message over to Bob who adds |
|
|
|
# this htlc to his remote state update log. |
|
|
|
self.aliceHtlcIndex = self.alice_channel.add_htlc(self.htlc_dict).htlc_id |
|
|
|
self.assertNotEqual(self.alice_channel.hm.htlcs_by_direction(REMOTE, RECEIVED, 1), set()) |
|
|
|
self.assertNotEqual(self.alice_channel.hm.htlcs_by_direction(REMOTE, RECEIVED, 1), []) |
|
|
|
|
|
|
|
before = self.bob_channel.balance_minus_outgoing_htlcs(REMOTE) |
|
|
|
beforeLocal = self.bob_channel.balance_minus_outgoing_htlcs(LOCAL) |
|
|
|
|
|
|
|
self.bobHtlcIndex = self.bob_channel.receive_htlc(self.htlc_dict).htlc_id |
|
|
|
|
|
|
|
self.assertEqual(1, self.bob_channel.hm.log[LOCAL]['ctn'] + 1) |
|
|
|
self.assertNotEqual(self.bob_channel.hm.htlcs_by_direction(LOCAL, RECEIVED, 1), set()) |
|
|
|
after = self.bob_channel.balance_minus_outgoing_htlcs(REMOTE) |
|
|
|
afterLocal = self.bob_channel.balance_minus_outgoing_htlcs(LOCAL) |
|
|
|
|
|
|
|
self.assertEqual(before - after, self.htlc_dict['amount_msat']) |
|
|
|
self.assertEqual(beforeLocal, afterLocal) |
|
|
|
|
|
|
|
self.bob_pending_remote_balance = after |
|
|
|
|
|
|
|
self.htlc = self.bob_channel.hm.log[REMOTE]['adds'][0] |
|
|
|
|
|
|
|
def test_concurrent_reversed_payment(self): |
|
|
@ -258,8 +248,8 @@ class TestChannel(unittest.TestCase): |
|
|
|
|
|
|
|
self.assertNotEqual(alice_channel.included_htlcs(REMOTE, RECEIVED, 1), []) |
|
|
|
self.assertEqual({0: [], 1: [htlc]}, alice_channel.included_htlcs_in_their_latest_ctxs(LOCAL)) |
|
|
|
self.assertNotEqual(bob_channel.included_htlcs(REMOTE, SENT, 1), []) |
|
|
|
self.assertEqual({0: [], 1: [htlc]}, bob_channel.included_htlcs_in_their_latest_ctxs(REMOTE)) |
|
|
|
self.assertEqual(bob_channel.included_htlcs(REMOTE, SENT, 1), []) |
|
|
|
self.assertEqual({0: [], 1: []}, bob_channel.included_htlcs_in_their_latest_ctxs(REMOTE)) |
|
|
|
self.assertEqual({0: [], 1: []}, alice_channel.included_htlcs_in_their_latest_ctxs(REMOTE)) |
|
|
|
self.assertEqual({0: [], 1: []}, bob_channel.included_htlcs_in_their_latest_ctxs(LOCAL)) |
|
|
|
|
|
|
@ -293,10 +283,10 @@ class TestChannel(unittest.TestCase): |
|
|
|
self.assertEqual(bob_channel.config[REMOTE].ctn, 0) |
|
|
|
self.assertEqual(bob_channel.included_htlcs(REMOTE, SENT, 1), [htlc]) |
|
|
|
|
|
|
|
self.assertEqual({0: [], 1: [htlc]}, alice_channel.included_htlcs_in_their_latest_ctxs(LOCAL)) |
|
|
|
self.assertEqual({0: [], 1: [htlc]}, alice_channel.included_htlcs_in_their_latest_ctxs(LOCAL)) |
|
|
|
self.assertEqual({0: [], 1: [htlc]}, bob_channel.included_htlcs_in_their_latest_ctxs(REMOTE)) |
|
|
|
self.assertEqual({0: [], 1: []}, alice_channel.included_htlcs_in_their_latest_ctxs(REMOTE)) |
|
|
|
self.assertEqual({0: [], 1: []}, bob_channel.included_htlcs_in_their_latest_ctxs(LOCAL)) |
|
|
|
self.assertEqual({0: [], 1: []}, alice_channel.included_htlcs_in_their_latest_ctxs(REMOTE)) |
|
|
|
self.assertEqual({0: [], 1: []}, bob_channel.included_htlcs_in_their_latest_ctxs(LOCAL)) |
|
|
|
|
|
|
|
# Bob revokes his prior commitment given to him by Alice, since he now |
|
|
|
# has a valid signature for a newer commitment. |
|
|
@ -415,10 +405,10 @@ class TestChannel(unittest.TestCase): |
|
|
|
|
|
|
|
self.assertEqual(alice_channel.hm.htlcs_by_direction(REMOTE, RECEIVED), [htlc]) |
|
|
|
self.assertEqual(alice_channel.included_htlcs(REMOTE, RECEIVED, alice_channel.config[REMOTE].ctn), [htlc]) |
|
|
|
self.assertEqual({1: [htlc], 2: []}, alice_channel.included_htlcs_in_their_latest_ctxs(LOCAL)) |
|
|
|
self.assertEqual({1: [htlc], 2: [htlc]}, alice_channel.included_htlcs_in_their_latest_ctxs(LOCAL)) |
|
|
|
self.assertEqual({1: [htlc], 2: []}, bob_channel.included_htlcs_in_their_latest_ctxs(REMOTE)) |
|
|
|
self.assertEqual({1: [], 2: []}, alice_channel.included_htlcs_in_their_latest_ctxs(REMOTE)) |
|
|
|
self.assertEqual({1: [], 2: []}, bob_channel.included_htlcs_in_their_latest_ctxs(LOCAL)) |
|
|
|
self.assertEqual({1: [], 2: []}, alice_channel.included_htlcs_in_their_latest_ctxs(REMOTE)) |
|
|
|
self.assertEqual({1: [], 2: []}, bob_channel.included_htlcs_in_their_latest_ctxs(LOCAL)) |
|
|
|
|
|
|
|
alice_ctx_bob_version = bob_channel.pending_commitment(REMOTE).outputs() |
|
|
|
alice_ctx_alice_version = alice_channel.pending_commitment(LOCAL).outputs() |
|
|
@ -437,16 +427,16 @@ class TestChannel(unittest.TestCase): |
|
|
|
aliceSig2, aliceHtlcSigs2 = alice_channel.sign_next_commitment() |
|
|
|
self.assertEqual(aliceHtlcSigs2, [], "alice should generate no htlc signatures") |
|
|
|
self.assertEqual(len(bob_channel.current_commitment(LOCAL).outputs()), 3) |
|
|
|
self.assertEqual(len(bob_channel.pending_commitment(LOCAL).outputs()), 2) |
|
|
|
received, sent = bob_channel.receive_revocation(aliceRevocation2) |
|
|
|
#self.assertEqual(len(bob_channel.pending_commitment(LOCAL).outputs()), 3) |
|
|
|
bob_channel.receive_revocation(aliceRevocation2) |
|
|
|
bob_channel.serialize() |
|
|
|
self.assertEqual(received, one_bitcoin_in_msat) |
|
|
|
|
|
|
|
bob_channel.receive_new_commitment(aliceSig2, aliceHtlcSigs2) |
|
|
|
|
|
|
|
bobRevocation2, _ = bob_channel.revoke_current_commitment() |
|
|
|
bob_channel.serialize() |
|
|
|
alice_channel.receive_revocation(bobRevocation2) |
|
|
|
received, sent = alice_channel.receive_revocation(bobRevocation2) |
|
|
|
self.assertEqual(sent, one_bitcoin_in_msat) |
|
|
|
alice_channel.serialize() |
|
|
|
|
|
|
|
# At this point, Bob should have 6 BTC settled, with Alice still having |
|
|
@ -461,8 +451,6 @@ class TestChannel(unittest.TestCase): |
|
|
|
self.assertEqual(bob_channel.current_height[LOCAL], 2, "bob has incorrect commitment height") |
|
|
|
self.assertEqual(alice_channel.current_height[LOCAL], 2, "alice has incorrect commitment height") |
|
|
|
|
|
|
|
self.assertEqual(self.bob_pending_remote_balance, self.alice_channel.balance(LOCAL)) |
|
|
|
|
|
|
|
alice_channel.update_fee(100000, True) |
|
|
|
alice_outputs = alice_channel.pending_commitment(REMOTE).outputs() |
|
|
|
old_outputs = bob_channel.pending_commitment(LOCAL).outputs() |
|
|
@ -484,16 +472,12 @@ class TestChannel(unittest.TestCase): |
|
|
|
bob_index = bob_channel.add_htlc(self.htlc_dict).htlc_id |
|
|
|
alice_index = alice_channel.receive_htlc(self.htlc_dict).htlc_id |
|
|
|
|
|
|
|
bob_channel.pending_commitment(REMOTE) |
|
|
|
alice_channel.pending_commitment(LOCAL) |
|
|
|
|
|
|
|
alice_channel.pending_commitment(REMOTE) |
|
|
|
bob_channel.pending_commitment(LOCAL) |
|
|
|
|
|
|
|
force_state_transition(bob_channel, alice_channel) |
|
|
|
|
|
|
|
alice_channel.settle_htlc(self.paymentPreimage, alice_index) |
|
|
|
bob_channel.receive_htlc_settle(self.paymentPreimage, bob_index) |
|
|
|
force_state_transition(bob_channel, alice_channel) |
|
|
|
|
|
|
|
force_state_transition(alice_channel, bob_channel) |
|
|
|
self.assertEqual(alice_channel.total_msat(SENT), one_bitcoin_in_msat, "alice satoshis sent incorrect") |
|
|
|
self.assertEqual(alice_channel.total_msat(RECEIVED), 5 * one_bitcoin_in_msat, "alice satoshis received incorrect") |
|
|
|
self.assertEqual(bob_channel.total_msat(RECEIVED), one_bitcoin_in_msat, "bob satoshis received incorrect") |
|
|
@ -570,6 +554,7 @@ class TestChannel(unittest.TestCase): |
|
|
|
bob_channel.receive_revocation(alice_revocation) |
|
|
|
self.assertEqual(fee, bob_channel.constraints.feerate) |
|
|
|
|
|
|
|
@unittest.skip("broken probably because we havn't implemented detecting when we come out of a situation where we violate reserve") |
|
|
|
def test_AddHTLCNegativeBalance(self): |
|
|
|
# the test in lnd doesn't set the fee to zero. |
|
|
|
# probably lnd subtracts commitment fee after deciding weather |
|
|
@ -670,6 +655,7 @@ class TestChanReserve(unittest.TestCase): |
|
|
|
self.alice_channel = alice_channel |
|
|
|
self.bob_channel = bob_channel |
|
|
|
|
|
|
|
@unittest.skip("broken probably because we havn't implemented detecting when we come out of a situation where we violate reserve") |
|
|
|
def test_part1(self): |
|
|
|
# Add an HTLC that will increase Bob's balance. This should succeed, |
|
|
|
# since Alice stays above her channel reserve, and Bob increases his |
|
|
|