github.com/mit-dci/lit@v0.0.0-20221102210550-8c3d3b49f2ce/test/itest_push.py (about)

     1  import testlib
     2  
     3  fee = 20
     4  initialsend = 200000
     5  capacity = 1000000
     6  
     7  def run_test(env):
     8      bc = env.bitcoind
     9      lit1 = env.lits[0]
    10      lit2 = env.lits[1]
    11  
    12      # Connect the nodes.
    13      lit1.connect_to_peer(lit2)
    14  
    15      # First figure out where we should send the money.
    16      addr1 = lit1.make_new_addr()
    17      print('Got lit1 address:', addr1)
    18  
    19      # Send a bitcoin.
    20      bc.rpc.sendtoaddress(addr1, 1)
    21      env.generate_block()
    22  
    23      # Log it to make sure we got it.
    24      bal1 = lit1.get_balance_info()['TxoTotal']
    25      print('initial lit1 balance:', bal1)
    26  
    27      # Set the fee so we know what's going on.
    28      lit1.rpc.SetFee(Fee=fee, CoinType=testlib.REGTEST_COINTYPE)
    29      lit2.rpc.SetFee(Fee=fee, CoinType=testlib.REGTEST_COINTYPE)
    30      print('fees set to', fee, '(per byte)')
    31  
    32      # Now actually do the funding.
    33      cid = lit1.open_channel(lit2, capacity, initialsend)
    34      print('Created channel:', cid)
    35  
    36      # Now we confirm the block.
    37      env.generate_block()
    38  
    39      # Figure out if it's actually open now.
    40      res = lit1.rpc.ChannelList(ChanIdx=cid)
    41      cinfo = res['Channels'][0]
    42      assert cinfo['Height'] == env.get_height(), "Channel height doesn't match new block."
    43  
    44      # Now update the balances back and forth a bit to make sure it all works.
    45      ct0 = lit1.get_balance_info()['ChanTotal']
    46      lit1.rpc.Push(ChanIdx=cid, Amt=1000, Data=None)
    47      ct1 = lit1.get_balance_info()['ChanTotal']
    48      assert ct1 == ct0 - 1000, "channel update didn't work properly"
    49      lit1.rpc.Push(ChanIdx=cid, Amt=10000, Data=None)
    50      ct2 = lit1.get_balance_info()['ChanTotal']
    51      assert ct2 == ct1 - 10000, "channel update didn't work properly"
    52      lit2.rpc.Push(ChanIdx=cid, Amt=5000, Data=None)
    53      ct3 = lit1.get_balance_info()['ChanTotal']
    54      assert ct3 == ct2 + 5000, "channel update didn't work properly"
    55      lit1.rpc.Push(ChanIdx=cid, Amt=250, Data=None)
    56      ct4 = lit1.get_balance_info()['ChanTotal']
    57      assert ct4 == ct3 - 250, "channel update didn't work properly"