@ -16,27 +16,6 @@ def txFromHex(hexstring):
tx . deserialize ( f )
tx . deserialize ( f )
return tx
return tx
def check_array_result ( object_array , to_match , expected ) :
"""
Pass in array of JSON objects , a dictionary with key / value pairs
to match against , and another dictionary with expected key / value
pairs .
"""
num_matched = 0
for item in object_array :
all_match = True
for key , value in to_match . items ( ) :
if item [ key ] != value :
all_match = False
if not all_match :
continue
for key , value in expected . items ( ) :
if item [ key ] != value :
raise AssertionError ( " %s : expected %s = %s " % ( str ( item ) , str ( key ) , str ( value ) ) )
num_matched = num_matched + 1
if num_matched == 0 :
raise AssertionError ( " No objects matched %s " % ( str ( to_match ) ) )
class ListTransactionsTest ( BitcoinTestFramework ) :
class ListTransactionsTest ( BitcoinTestFramework ) :
def setup_nodes ( self ) :
def setup_nodes ( self ) :
@ -48,28 +27,28 @@ class ListTransactionsTest(BitcoinTestFramework):
# Simple send, 0 to 1:
# Simple send, 0 to 1:
txid = self . nodes [ 0 ] . sendtoaddress ( self . nodes [ 1 ] . getnewaddress ( ) , 0.1 )
txid = self . nodes [ 0 ] . sendtoaddress ( self . nodes [ 1 ] . getnewaddress ( ) , 0.1 )
self . sync_all ( )
self . sync_all ( )
check _array_result( self . nodes [ 0 ] . listtransactions ( ) ,
assert _array_result( self . nodes [ 0 ] . listtransactions ( ) ,
{ " txid " : txid } ,
{ " txid " : txid } ,
{ " category " : " send " , " account " : " " , " amount " : Decimal ( " -0.1 " ) , " confirmations " : 0 } )
{ " category " : " send " , " account " : " " , " amount " : Decimal ( " -0.1 " ) , " confirmations " : 0 } )
check _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
assert _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
{ " txid " : txid } ,
{ " txid " : txid } ,
{ " category " : " receive " , " account " : " " , " amount " : Decimal ( " 0.1 " ) , " confirmations " : 0 } )
{ " category " : " receive " , " account " : " " , " amount " : Decimal ( " 0.1 " ) , " confirmations " : 0 } )
# mine a block, confirmations should change:
# mine a block, confirmations should change:
self . nodes [ 0 ] . generate ( 1 )
self . nodes [ 0 ] . generate ( 1 )
self . sync_all ( )
self . sync_all ( )
check _array_result( self . nodes [ 0 ] . listtransactions ( ) ,
assert _array_result( self . nodes [ 0 ] . listtransactions ( ) ,
{ " txid " : txid } ,
{ " txid " : txid } ,
{ " category " : " send " , " account " : " " , " amount " : Decimal ( " -0.1 " ) , " confirmations " : 1 } )
{ " category " : " send " , " account " : " " , " amount " : Decimal ( " -0.1 " ) , " confirmations " : 1 } )
check _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
assert _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
{ " txid " : txid } ,
{ " txid " : txid } ,
{ " category " : " receive " , " account " : " " , " amount " : Decimal ( " 0.1 " ) , " confirmations " : 1 } )
{ " category " : " receive " , " account " : " " , " amount " : Decimal ( " 0.1 " ) , " confirmations " : 1 } )
# send-to-self:
# send-to-self:
txid = self . nodes [ 0 ] . sendtoaddress ( self . nodes [ 0 ] . getnewaddress ( ) , 0.2 )
txid = self . nodes [ 0 ] . sendtoaddress ( self . nodes [ 0 ] . getnewaddress ( ) , 0.2 )
check _array_result( self . nodes [ 0 ] . listtransactions ( ) ,
assert _array_result( self . nodes [ 0 ] . listtransactions ( ) ,
{ " txid " : txid , " category " : " send " } ,
{ " txid " : txid , " category " : " send " } ,
{ " amount " : Decimal ( " -0.2 " ) } )
{ " amount " : Decimal ( " -0.2 " ) } )
check _array_result( self . nodes [ 0 ] . listtransactions ( ) ,
assert _array_result( self . nodes [ 0 ] . listtransactions ( ) ,
{ " txid " : txid , " category " : " receive " } ,
{ " txid " : txid , " category " : " receive " } ,
{ " amount " : Decimal ( " 0.2 " ) } )
{ " amount " : Decimal ( " 0.2 " ) } )
@ -80,28 +59,28 @@ class ListTransactionsTest(BitcoinTestFramework):
self . nodes [ 1 ] . getaccountaddress ( " toself " ) : 0.44 }
self . nodes [ 1 ] . getaccountaddress ( " toself " ) : 0.44 }
txid = self . nodes [ 1 ] . sendmany ( " " , send_to )
txid = self . nodes [ 1 ] . sendmany ( " " , send_to )
self . sync_all ( )
self . sync_all ( )
check _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
assert _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
{ " category " : " send " , " amount " : Decimal ( " -0.11 " ) } ,
{ " category " : " send " , " amount " : Decimal ( " -0.11 " ) } ,
{ " txid " : txid } )
{ " txid " : txid } )
check _array_result( self . nodes [ 0 ] . listtransactions ( ) ,
assert _array_result( self . nodes [ 0 ] . listtransactions ( ) ,
{ " category " : " receive " , " amount " : Decimal ( " 0.11 " ) } ,
{ " category " : " receive " , " amount " : Decimal ( " 0.11 " ) } ,
{ " txid " : txid } )
{ " txid " : txid } )
check _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
assert _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
{ " category " : " send " , " amount " : Decimal ( " -0.22 " ) } ,
{ " category " : " send " , " amount " : Decimal ( " -0.22 " ) } ,
{ " txid " : txid } )
{ " txid " : txid } )
check _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
assert _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
{ " category " : " receive " , " amount " : Decimal ( " 0.22 " ) } ,
{ " category " : " receive " , " amount " : Decimal ( " 0.22 " ) } ,
{ " txid " : txid } )
{ " txid " : txid } )
check _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
assert _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
{ " category " : " send " , " amount " : Decimal ( " -0.33 " ) } ,
{ " category " : " send " , " amount " : Decimal ( " -0.33 " ) } ,
{ " txid " : txid } )
{ " txid " : txid } )
check _array_result( self . nodes [ 0 ] . listtransactions ( ) ,
assert _array_result( self . nodes [ 0 ] . listtransactions ( ) ,
{ " category " : " receive " , " amount " : Decimal ( " 0.33 " ) } ,
{ " category " : " receive " , " amount " : Decimal ( " 0.33 " ) } ,
{ " txid " : txid , " account " : " from1 " } )
{ " txid " : txid , " account " : " from1 " } )
check _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
assert _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
{ " category " : " send " , " amount " : Decimal ( " -0.44 " ) } ,
{ " category " : " send " , " amount " : Decimal ( " -0.44 " ) } ,
{ " txid " : txid , " account " : " " } )
{ " txid " : txid , " account " : " " } )
check _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
assert _array_result( self . nodes [ 1 ] . listtransactions ( ) ,
{ " category " : " receive " , " amount " : Decimal ( " 0.44 " ) } ,
{ " category " : " receive " , " amount " : Decimal ( " 0.44 " ) } ,
{ " txid " : txid , " account " : " toself " } )
{ " txid " : txid , " account " : " toself " } )
@ -111,7 +90,7 @@ class ListTransactionsTest(BitcoinTestFramework):
self . nodes [ 1 ] . generate ( 1 )
self . nodes [ 1 ] . generate ( 1 )
self . sync_all ( )
self . sync_all ( )
assert ( len ( self . nodes [ 0 ] . listtransactions ( " watchonly " , 100 , 0 , False ) ) == 0 )
assert ( len ( self . nodes [ 0 ] . listtransactions ( " watchonly " , 100 , 0 , False ) ) == 0 )
check _array_result( self . nodes [ 0 ] . listtransactions ( " watchonly " , 100 , 0 , True ) ,
assert _array_result( self . nodes [ 0 ] . listtransactions ( " watchonly " , 100 , 0 , True ) ,
{ " category " : " receive " , " amount " : Decimal ( " 0.1 " ) } ,
{ " category " : " receive " , " amount " : Decimal ( " 0.1 " ) } ,
{ " txid " : txid , " account " : " watchonly " } )
{ " txid " : txid , " account " : " watchonly " } )
@ -139,9 +118,9 @@ class ListTransactionsTest(BitcoinTestFramework):
# 1. Chain a few transactions that don't opt-in.
# 1. Chain a few transactions that don't opt-in.
txid_1 = self . nodes [ 0 ] . sendtoaddress ( self . nodes [ 1 ] . getnewaddress ( ) , 1 )
txid_1 = self . nodes [ 0 ] . sendtoaddress ( self . nodes [ 1 ] . getnewaddress ( ) , 1 )
assert ( not is_opt_in ( self . nodes [ 0 ] , txid_1 ) )
assert ( not is_opt_in ( self . nodes [ 0 ] , txid_1 ) )
check _array_result( self . nodes [ 0 ] . listtransactions ( ) , { " txid " : txid_1 } , { " bip125-replaceable " : " no " } )
assert _array_result( self . nodes [ 0 ] . listtransactions ( ) , { " txid " : txid_1 } , { " bip125-replaceable " : " no " } )
sync_mempools ( self . nodes )
sync_mempools ( self . nodes )
check _array_result( self . nodes [ 1 ] . listtransactions ( ) , { " txid " : txid_1 } , { " bip125-replaceable " : " no " } )
assert _array_result( self . nodes [ 1 ] . listtransactions ( ) , { " txid " : txid_1 } , { " bip125-replaceable " : " no " } )
# Tx2 will build off txid_1, still not opting in to RBF.
# Tx2 will build off txid_1, still not opting in to RBF.
utxo_to_use = get_unconfirmed_utxo_entry ( self . nodes [ 1 ] , txid_1 )
utxo_to_use = get_unconfirmed_utxo_entry ( self . nodes [ 1 ] , txid_1 )
@ -155,9 +134,9 @@ class ListTransactionsTest(BitcoinTestFramework):
# ...and check the result
# ...and check the result
assert ( not is_opt_in ( self . nodes [ 1 ] , txid_2 ) )
assert ( not is_opt_in ( self . nodes [ 1 ] , txid_2 ) )
check _array_result( self . nodes [ 1 ] . listtransactions ( ) , { " txid " : txid_2 } , { " bip125-replaceable " : " no " } )
assert _array_result( self . nodes [ 1 ] . listtransactions ( ) , { " txid " : txid_2 } , { " bip125-replaceable " : " no " } )
sync_mempools ( self . nodes )
sync_mempools ( self . nodes )
check _array_result( self . nodes [ 0 ] . listtransactions ( ) , { " txid " : txid_2 } , { " bip125-replaceable " : " no " } )
assert _array_result( self . nodes [ 0 ] . listtransactions ( ) , { " txid " : txid_2 } , { " bip125-replaceable " : " no " } )
# Tx3 will opt-in to RBF
# Tx3 will opt-in to RBF
utxo_to_use = get_unconfirmed_utxo_entry ( self . nodes [ 0 ] , txid_2 )
utxo_to_use = get_unconfirmed_utxo_entry ( self . nodes [ 0 ] , txid_2 )
@ -171,9 +150,9 @@ class ListTransactionsTest(BitcoinTestFramework):
txid_3 = self . nodes [ 0 ] . sendrawtransaction ( tx3_signed )
txid_3 = self . nodes [ 0 ] . sendrawtransaction ( tx3_signed )
assert ( is_opt_in ( self . nodes [ 0 ] , txid_3 ) )
assert ( is_opt_in ( self . nodes [ 0 ] , txid_3 ) )
check _array_result( self . nodes [ 0 ] . listtransactions ( ) , { " txid " : txid_3 } , { " bip125-replaceable " : " yes " } )
assert _array_result( self . nodes [ 0 ] . listtransactions ( ) , { " txid " : txid_3 } , { " bip125-replaceable " : " yes " } )
sync_mempools ( self . nodes )
sync_mempools ( self . nodes )
check _array_result( self . nodes [ 1 ] . listtransactions ( ) , { " txid " : txid_3 } , { " bip125-replaceable " : " yes " } )
assert _array_result( self . nodes [ 1 ] . listtransactions ( ) , { " txid " : txid_3 } , { " bip125-replaceable " : " yes " } )
# Tx4 will chain off tx3. Doesn't signal itself, but depends on one
# Tx4 will chain off tx3. Doesn't signal itself, but depends on one
# that does.
# that does.
@ -185,9 +164,9 @@ class ListTransactionsTest(BitcoinTestFramework):
txid_4 = self . nodes [ 1 ] . sendrawtransaction ( tx4_signed )
txid_4 = self . nodes [ 1 ] . sendrawtransaction ( tx4_signed )
assert ( not is_opt_in ( self . nodes [ 1 ] , txid_4 ) )
assert ( not is_opt_in ( self . nodes [ 1 ] , txid_4 ) )
check _array_result( self . nodes [ 1 ] . listtransactions ( ) , { " txid " : txid_4 } , { " bip125-replaceable " : " yes " } )
assert _array_result( self . nodes [ 1 ] . listtransactions ( ) , { " txid " : txid_4 } , { " bip125-replaceable " : " yes " } )
sync_mempools ( self . nodes )
sync_mempools ( self . nodes )
check _array_result( self . nodes [ 0 ] . listtransactions ( ) , { " txid " : txid_4 } , { " bip125-replaceable " : " yes " } )
assert _array_result( self . nodes [ 0 ] . listtransactions ( ) , { " txid " : txid_4 } , { " bip125-replaceable " : " yes " } )
# Replace tx3, and check that tx4 becomes unknown
# Replace tx3, and check that tx4 becomes unknown
tx3_b = tx3_modified
tx3_b = tx3_modified
@ -197,9 +176,9 @@ class ListTransactionsTest(BitcoinTestFramework):
txid_3b = self . nodes [ 0 ] . sendrawtransaction ( tx3_b_signed , True )
txid_3b = self . nodes [ 0 ] . sendrawtransaction ( tx3_b_signed , True )
assert ( is_opt_in ( self . nodes [ 0 ] , txid_3b ) )
assert ( is_opt_in ( self . nodes [ 0 ] , txid_3b ) )
check _array_result( self . nodes [ 0 ] . listtransactions ( ) , { " txid " : txid_4 } , { " bip125-replaceable " : " unknown " } )
assert _array_result( self . nodes [ 0 ] . listtransactions ( ) , { " txid " : txid_4 } , { " bip125-replaceable " : " unknown " } )
sync_mempools ( self . nodes )
sync_mempools ( self . nodes )
check _array_result( self . nodes [ 1 ] . listtransactions ( ) , { " txid " : txid_4 } , { " bip125-replaceable " : " unknown " } )
assert _array_result( self . nodes [ 1 ] . listtransactions ( ) , { " txid " : txid_4 } , { " bip125-replaceable " : " unknown " } )
# Check gettransaction as well:
# Check gettransaction as well:
for n in self . nodes [ 0 : 2 ] :
for n in self . nodes [ 0 : 2 ] :