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

     1  import testlib
     2  
     3  def run_test(env):
     4      bc = env.bitcoind
     5      lit = env.lits[0]
     6  
     7      # First figure out where we should send the money.
     8      addr = lit.make_new_addr()
     9      print('Got lit address:', addr)
    10  
    11      # Get the starting balance.
    12      bal0 = bc.rpc.getbalance()
    13  
    14      # Send a bitcoin.
    15      tx1 = bc.rpc.sendtoaddress(addr, 1)
    16      env.generate_block(count=1)
    17      print('Sent and mined... (tx: %s)' % tx1)
    18  
    19      # Log it to make sure we got it.
    20      txo_total = lit.get_balance_info()['TxoTotal']
    21      print('lit balance:', txo_total)
    22  
    23      # Get an address for bitcoind.
    24      bcaddr = bc.rpc.getnewaddress("wallet.dat", "bech32")
    25      print('Got bitcoind address:', bcaddr)
    26  
    27      # Get the old balance.
    28      bal1 = bc.rpc.getbalance()
    29  
    30      # Send some bitcoin back, and mine it.
    31      res = lit.rpc.Send(DestAddrs=[ bcaddr ], Amts=[ 50000000 ])
    32      if "_error" in res:
    33          raise AssertionError("Problem sending bitcoin back to bitcoind.")
    34  
    35      env.generate_block(count=1)
    36      print('Sent and mined again... (tx: %s)' % res['Txids'][0])
    37  
    38      # Validate.
    39      bal2 = bc.rpc.getbalance()
    40      print('bitcoind balance:', bal0, '->', bal1, '->', bal2, '(', bal2 - bal1, ')')
    41      if bal2 != bal1 + 12.5 + 0.5: # the 12.5 is because we mined a block
    42          raise AssertionError("Balance in bitcoind doesn't match what we think it should be!")