github.com/mit-dci/lit@v0.0.0-20221102210550-8c3d3b49f2ce/test/itest_fund.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 print('Mined new block to confirm channel') 39 40 # Figure out if it's actually open now. 41 res = lit1.rpc.ChannelList(ChanIdx=cid) 42 cinfo = res['Channels'][0] 43 assert cinfo['Height'] == env.get_height(), "Channel height doesn't match new block." 44 45 # Make sure balances make sense 46 bals2 = lit1.get_balance_info() 47 print('new lit1 balance:', bals2['TxoTotal'], 'in txos,', bals2['ChanTotal'], 'in chans') 48 bal2sum = bals2['TxoTotal'] + bals2['ChanTotal'] 49 print(' = sum ', bal2sum) 50 print(' -> diff', bal1 - bal2sum) 51 print(' -> fee ', bal1 - bal2sum - initialsend) 52 53 assert bals2['ChanTotal'] > 0, "channel balance isn't nonzero!"