URI: 
       tlnbase: fix test - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 57b63cf4900113800d8dc9f84f5261cf3c99483b
   DIR parent 98f46dbaf5103a03e56b086144c5e0f529019ac0
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Fri, 13 Apr 2018 20:33:29 +0200
       
       lnbase: fix test
       
       Diffstat:
         M lib/lnbase.py                       |      11 ++++++-----
         M lib/tests/test_lnbase.py            |      26 ++++++--------------------
       
       2 files changed, 12 insertions(+), 25 deletions(-)
       ---
   DIR diff --git a/lib/lnbase.py b/lib/lnbase.py
       t@@ -255,12 +255,12 @@ def get_obscured_ctn(ctn, local, remote):
        def overall_weight(num_htlc):
            return 500 + 172 * num_htlc + 224
        
       -def make_commitment(local_funding_pubkey, remote_funding_pubkey, remotepubkey,
       +def make_commitment(ctn, local_funding_pubkey, remote_funding_pubkey, remotepubkey,
                            payment_pubkey, remote_payment_pubkey, revocation_pubkey, delayed_pubkey,
                            funding_txid, funding_pos, funding_satoshis,
                            to_local_msat, to_remote_msat, local_feerate, local_delay):
            pubkeys = sorted([bh2u(local_funding_pubkey), bh2u(remote_funding_pubkey)])
       -    obs = get_obscured_ctn(0, payment_pubkey, remote_payment_pubkey)
       +    obs = get_obscured_ctn(ctn, payment_pubkey, remote_payment_pubkey)
            locktime = (0x20 << 24) + (obs & 0xffffff)
            sequence = (0x80 << 24) + (obs >> 24)
            print_error('locktime', locktime, hex(locktime))
       t@@ -459,7 +459,7 @@ class Peer(PrintError):
                    accept_channel = await self.temporary_channel_id_to_incoming_accept_channel[temp_channel_id]
                finally:
                    del self.temporary_channel_id_to_incoming_accept_channel[temp_channel_id]
       -        remote_pubkey = accept_channel["funding_pubkey"]
       +        remote_funding_pubkey = accept_channel["funding_pubkey"]
                pubkeys = sorted([bh2u(funding_pubkey), bh2u(remote_pubkey)])
                redeem_script = transaction.multisig_script(pubkeys, 2)
                funding_address = bitcoin.redeem_script_to_address('p2wsh', redeem_script)
       t@@ -468,10 +468,11 @@ class Peer(PrintError):
                funding_index = funding_tx.outputs().index(funding_output)
                remote_payment_pubkey = accept_channel['payment_basepoint']
                c_tx = make_commitment(
       -            funding_pubkey, remote_pubkey,
       +            0,
       +            funding_pubkey, remote_funding_pubkey,
                    payment_pubkey, remote_payment_pubkey, revocation_pubkey, delayed_pubkey,
                    funding_tx.txid(), funding_index, funding_satoshis,
       -            funding_satoshis*1000, 0, 20000)
       +            funding_satoshis*1000, 0, 20000, 144)
                c_tx.sign({bh2u(funding_pubkey): (funding_privkey, True)})
                sig_index = pubkeys.index(bh2u(funding_pubkey))
                sig = bytes.fromhex(c_tx.inputs()[0]["signatures"][sig_index])
   DIR diff --git a/lib/tests/test_lnbase.py b/lib/tests/test_lnbase.py
       t@@ -38,37 +38,23 @@ class Test_LNBase(unittest.TestCase):
                remote_signature = "3045022100f51d2e566a70ba740fc5d8c0f07b9b93d2ed741c3c0860c613173de7d39e7968022041376d520e9c0e1ad52248ddf4b22e12be8763007df977253ef45a4ca3bdb7c0"
                # local_signature = 3044022051b75c73198c6deee1a875871c3961832909acd297c6b908d59e3319e5185a46022055c419379c5051a78d00dbbce11b5b664a0c22815fbcc6fcef6b1937c3836939
                #num_htlcs: 0
       -        our_commit_tx = make_commitment(
       +        our_commit_tx = make_commitment(commitment_number,
                    local_funding_pubkey, remote_funding_pubkey, remotepubkey,
                    local_payment_basepoint, remote_payment_basepoint,
                    local_revocation_pubkey, local_delayedpubkey,
                    funding_tx_id, funding_output_index, funding_amount_satoshi,
                    to_local_msat, to_remote_msat, local_feerate_per_kw, local_delay)
                our_commit_tx.sign({bh2u(local_funding_pubkey): (local_funding_privkey[:-1], True)})
       -        ref_commit_tx_str = '02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8002c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de84311054a56a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0400473044022051b75c73198c6deee1a875871c3961832909acd297c6b908d59e3319e5185a46022055c419379c5051a78d00dbbce11b5b664a0c22815fbcc6fcef6b1937c383693901483045022100f51d2e566a70ba740fc5d8c0f07b9b93d2ed741c3c0860c613173de7d39e7968022041376d520e9c0e1ad52248ddf4b22e12be8763007df977253ef45a4ca3bdb7c001475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220'
       -        ref_commit_tx = Transaction(ref_commit_tx_str)
       -
                pubkeys, _x_pubkeys = our_commit_tx.get_sorted_pubkeys(our_commit_tx.inputs()[0])
                index_of_pubkey = pubkeys.index(bh2u(remote_funding_pubkey))
                our_commit_tx._inputs[0]["signatures"][index_of_pubkey] = remote_signature + "01"
       +        our_commit_tx.raw=None
        
       -        #print("Reference inputs", json.dumps(ref_commit_tx.inputs(), indent=2))
       -        #print("Our inputs", json.dumps(our_commit_tx.inputs(), indent=2))
       -        print("Reference outputs", ref_commit_tx.outputs())
       -        print("Our outputs", our_commit_tx.outputs())
       -        #print("Reference tx", ref_commit_tx)
       -        #print("Our tx", our_commit_tx)
       -
       -
       -        for idx, inp in enumerate(our_commit_tx.inputs()):
       -            for field in inp.keys():
       -                 self.assertEqual(inp[field], ref_commit_tx.inputs()[idx][field], field)
       -
       -        self.assertEquals(ref_commit_tx.inputs()[0]["witness"], our_commit_tx.serialize_witness(txin=our_commit_tx.inputs()[0]))
       +        print(our_commit_tx)
       +        
       +        ref_commit_tx_str = '02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8002c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de84311054a56a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e0400473044022051b75c73198c6deee1a875871c3961832909acd297c6b908d59e3319e5185a46022055c419379c5051a78d00dbbce11b5b664a0c22815fbcc6fcef6b1937c383693901483045022100f51d2e566a70ba740fc5d8c0f07b9b93d2ed741c3c0860c613173de7d39e7968022041376d520e9c0e1ad52248ddf4b22e12be8763007df977253ef45a4ca3bdb7c001475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220'
       +        ref_commit_tx = Transaction(ref_commit_tx_str)
        
       -        output1adr = ref_commit_tx.outputs()[0][1]
       -        output2adr = ref_commit_tx.outputs()[1][1]
       -        self.assertTrue(bitcoin.redeem_script_to_address("p2wsh", "63210212a140cd0c6539d07cd08dfe09984dec3251ea808b892efeac3ede9402bf2b1967029000b2752103fd5960528dc152014952efdb702a88f71e3c1653b2314431701ec77e57fde83c68ac") in [output1adr, output2adr])
                # todo check order and other output
                self.assertEqual(str(our_commit_tx), ref_commit_tx_str)