Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions qa/rpc-tests/addressindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def run_test(self):
tx.rehash()

signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))
sent_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True, False, True)
sent_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True)

self.nodes[0].generate(1)
self.sync_all()
Expand All @@ -144,12 +144,13 @@ def run_test(self):

unspent = self.nodes[0].listunspent()
tx = CTransaction()
tx_fee_sat = 1000
tx.vin = [CTxIn(COutPoint(int(unspent[0]["txid"], 16), unspent[0]["vout"]))]
amount = int(unspent[0]["amount"] * 100000000)
amount = int(unspent[0]["amount"] * 100000000) - tx_fee_sat
tx.vout = [CTxOut(amount, scriptPubKey2)]
tx.rehash()
signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))
spending_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True, False, True)
spending_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True)
self.nodes[0].generate(1)
self.sync_all()
balance1 = self.nodes[1].getaddressbalance(address2)
Expand All @@ -163,7 +164,7 @@ def run_test(self):
tx.rehash()

signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))
sent_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True, False, True)
sent_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True)
self.nodes[0].generate(1)
self.sync_all()

Expand Down Expand Up @@ -241,17 +242,17 @@ def run_test(self):

tx = CTransaction()
tx.vin = [CTxIn(COutPoint(int(unspent[0]["txid"], 16), unspent[0]["vout"]))]
amount = int(unspent[0]["amount"] * 100000000)
amount = int(unspent[0]["amount"] * 100000000) - tx_fee_sat
tx.vout = [CTxOut(amount, scriptPubKey3)]
tx.rehash()
signed_tx = self.nodes[2].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))
memtxid1 = self.nodes[2].sendrawtransaction(signed_tx["hex"], True, False, True)
memtxid1 = self.nodes[2].sendrawtransaction(signed_tx["hex"], True)
set_mocktime(get_mocktime() + 2)
set_node_times(self.nodes, get_mocktime())

tx2 = CTransaction()
tx2.vin = [CTxIn(COutPoint(int(unspent[1]["txid"], 16), unspent[1]["vout"]))]
amount = int(unspent[1]["amount"] * 100000000)
amount = int(unspent[1]["amount"] * 100000000) - tx_fee_sat
tx2.vout = [
CTxOut(int(amount / 4), scriptPubKey3),
CTxOut(int(amount / 4), scriptPubKey3),
Expand All @@ -260,7 +261,7 @@ def run_test(self):
]
tx2.rehash()
signed_tx2 = self.nodes[2].signrawtransaction(binascii.hexlify(tx2.serialize()).decode("utf-8"))
memtxid2 = self.nodes[2].sendrawtransaction(signed_tx2["hex"], True, False, True)
memtxid2 = self.nodes[2].sendrawtransaction(signed_tx2["hex"], True)
set_mocktime(get_mocktime() + 2)
set_node_times(self.nodes, get_mocktime())

Expand Down Expand Up @@ -288,7 +289,7 @@ def run_test(self):
tx.rehash()
self.nodes[2].importprivkey(privKey3)
signed_tx3 = self.nodes[2].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))
memtxid3 = self.nodes[2].sendrawtransaction(signed_tx3["hex"], True, False, True)
memtxid3 = self.nodes[2].sendrawtransaction(signed_tx3["hex"], True)
set_mocktime(get_mocktime() + 2)
set_node_times(self.nodes, get_mocktime())

Expand Down Expand Up @@ -321,7 +322,7 @@ def run_test(self):
tx.rehash()
self.nodes[0].importprivkey(privkey1)
signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))
mem_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True, False, True)
mem_txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True)

self.sync_all()
mempool_deltas = self.nodes[2].getaddressmempool({"addresses": [address1]})
Expand Down
8 changes: 4 additions & 4 deletions qa/rpc-tests/mempool_spendcoinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def run_test(self):
# is too immature to spend.
b = [ self.nodes[0].getblockhash(n) for n in range(101, 103) ]
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
spends_raw = [ create_tx(self.nodes[0], txid, node0_address, 500) for txid in coinbase_txids ]
spends_raw = [ create_tx(self.nodes[0], txid, node0_address, 500 - Decimal('0.00001')) for txid in coinbase_txids ]

spend_101_id = self.nodes[0].sendrawtransaction(spends_raw[0], False, False, True)
spend_101_id = self.nodes[0].sendrawtransaction(spends_raw[0])

# coinbase at height 102 should be too immature to spend
assert_raises(JSONRPCException, self.nodes[0].sendrawtransaction, spends_raw[1], False, False, True)
assert_raises(JSONRPCException, self.nodes[0].sendrawtransaction, spends_raw[1])

# mempool should have just spend_101:
assert_equal(self.nodes[0].getrawmempool(), [ spend_101_id ])
Expand All @@ -55,7 +55,7 @@ def run_test(self):
assert_equal(set(self.nodes[0].getrawmempool()), set())

# ... and now height 102 can be spent:
spend_102_id = self.nodes[0].sendrawtransaction(spends_raw[1], False, False, True)
spend_102_id = self.nodes[0].sendrawtransaction(spends_raw[1])
assert_equal(self.nodes[0].getrawmempool(), [ spend_102_id ])

if __name__ == '__main__':
Expand Down
13 changes: 7 additions & 6 deletions qa/rpc-tests/merkle_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ def run_test(self):
assert_equal(self.nodes[1].getbalance(), 0)
assert_equal(self.nodes[2].getbalance(), 0)

tx_fee = Decimal('0.00001')
node0utxos = self.nodes[0].listunspent(1)
tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 500})
txid1 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx1)["hex"], False, False, True)
tx2 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 500})
txid2 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx2)["hex"], False, False, True)
tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 500 - tx_fee})
txid1 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx1)["hex"])
tx2 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 500 - tx_fee})
txid2 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx2)["hex"])
assert_raises(JSONRPCException, self.nodes[0].gettxoutproof, [txid1])

self.nodes[0].generate(1)
Expand All @@ -60,8 +61,8 @@ def run_test(self):
assert_equal(self.nodes[2].verifytxoutproof(self.nodes[2].gettxoutproof([txid1, txid2], blockhash)), txlist)

txin_spent = self.nodes[1].listunspent(1).pop()
tx3 = self.nodes[1].createrawtransaction([txin_spent], {self.nodes[0].getnewaddress(): 500})
self.nodes[0].sendrawtransaction(self.nodes[1].signrawtransaction(tx3)["hex"], False, False, True)
tx3 = self.nodes[1].createrawtransaction([txin_spent], {self.nodes[0].getnewaddress(): 500 - tx_fee*2})
self.nodes[0].sendrawtransaction(self.nodes[1].signrawtransaction(tx3)["hex"])
self.nodes[0].generate(1)
self.sync_all()

Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/prioritise_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def run_test(self):
mock_time = get_mocktime()
self.nodes[0].setmocktime(mock_time)
template = self.nodes[0].getblocktemplate()
self.nodes[0].prioritisetransaction(tx2_id, -int(self.relayfee*COIN))
self.nodes[0].prioritisetransaction(tx_id, -int(self.relayfee*COIN))
self.nodes[0].setmocktime(mock_time+10)
new_template = self.nodes[0].getblocktemplate()

Expand Down
14 changes: 8 additions & 6 deletions qa/rpc-tests/spentindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ def run_test(self):
scriptPubKey = CScript([OP_DUP, OP_HASH160, addressHash, OP_EQUALVERIFY, OP_CHECKSIG])
unspent = self.nodes[0].listunspent()
tx = CTransaction()
amount = int(unspent[0]["amount"] * COIN)
tx_fee = Decimal('0.00001')
tx_fee_sat = int(tx_fee * COIN)
amount = int(unspent[0]["amount"] * COIN) - tx_fee_sat
tx.vin = [CTxIn(COutPoint(int(unspent[0]["txid"], 16), unspent[0]["vout"]))]
tx.vout = [CTxOut(amount, scriptPubKey)]
tx.rehash()

signed_tx = self.nodes[0].signrawtransaction(binascii.hexlify(tx.serialize()).decode("utf-8"))
txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True, False, True)
txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True)
self.nodes[0].generate(1)
self.sync_all()

Expand All @@ -81,7 +83,7 @@ def run_test(self):
# Check that verbose raw transaction includes input values
txVerbose2 = self.nodes[3].getrawtransaction(txid, 1)
assert_equal(txVerbose2["vin"][0]["value"], Decimal(unspent[0]["amount"]))
assert_equal(txVerbose2["vin"][0]["valueSat"], amount)
assert_equal(txVerbose2["vin"][0]["valueSat"] - tx_fee_sat, amount)

# Check that verbose raw transaction includes address values and input values
privkey2 = "cU4zhap7nPJAWeMFu4j6jLrfPmqakDAzy8zn8Fhb3oEevdm4e5Lc"
Expand All @@ -94,13 +96,13 @@ def run_test(self):
tx2.rehash()
self.nodes[0].importprivkey(privkey)
signed_tx2 = self.nodes[0].signrawtransaction(binascii.hexlify(tx2.serialize()).decode("utf-8"))
txid2 = self.nodes[0].sendrawtransaction(signed_tx2["hex"], True, False, True)
txid2 = self.nodes[0].sendrawtransaction(signed_tx2["hex"], True)

# Check the mempool index
self.sync_all()
txVerbose3 = self.nodes[1].getrawtransaction(txid2, 1)
assert_equal(txVerbose3["vin"][0]["address"], address2)
assert_equal(txVerbose3["vin"][0]["value"], Decimal(unspent[0]["amount"]))
assert_equal(txVerbose3["vin"][0]["value"], Decimal(unspent[0]["amount"]) - tx_fee)
assert_equal(txVerbose3["vin"][0]["valueSat"], amount)

# Check the database index
Expand All @@ -109,7 +111,7 @@ def run_test(self):

txVerbose4 = self.nodes[3].getrawtransaction(txid2, 1)
assert_equal(txVerbose4["vin"][0]["address"], address2)
assert_equal(txVerbose4["vin"][0]["value"], Decimal(unspent[0]["amount"]))
assert_equal(txVerbose4["vin"][0]["value"], Decimal(unspent[0]["amount"]) - tx_fee)
assert_equal(txVerbose4["vin"][0]["valueSat"], amount)

self.log.info("Passed")
Expand Down
15 changes: 9 additions & 6 deletions qa/rpc-tests/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,30 @@ def run_test (self):
node0utxos = self.nodes[0].listunspent(1)
assert_equal(len(node0utxos), 2)

fee_per_input = Decimal('0.00001')
totalfee = 0
# create both transactions
txns_to_send = []
for utxo in node0utxos:
inputs = []
outputs = {}
inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]})
outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"]
outputs[self.nodes[2].getnewaddress("from1")] = utxo["amount"] - fee_per_input
raw_tx = self.nodes[0].createrawtransaction(inputs, outputs)
txns_to_send.append(self.nodes[0].signrawtransaction(raw_tx))
totalfee += fee_per_input

# Have node 1 (miner) send the transactions
self.nodes[1].sendrawtransaction(txns_to_send[0]["hex"], True, False, True)
self.nodes[1].sendrawtransaction(txns_to_send[1]["hex"], True, False, True)
self.nodes[1].sendrawtransaction(txns_to_send[0]["hex"])
self.nodes[1].sendrawtransaction(txns_to_send[1]["hex"])

# Have node1 mine a block to confirm transactions:
self.nodes[1].generate(1)
self.sync_all()

assert_equal(self.nodes[0].getbalance(), 0)
assert_equal(self.nodes[2].getbalance(), 1000)
assert_equal(self.nodes[2].getbalance("from1"), 1000-210)
assert_equal(self.nodes[2].getbalance(), 1000 - totalfee)
assert_equal(self.nodes[2].getbalance("from1"), 1000 - 210 - totalfee)

# Send 100 DASH normal
address = self.nodes[0].getnewaddress("test")
Expand All @@ -121,7 +124,7 @@ def run_test (self):
txid = self.nodes[2].sendtoaddress(address, 100, "", "", False)
self.nodes[2].generate(1)
self.sync_all()
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('900'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('900') - totalfee, fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid)))
assert_equal(self.nodes[0].getbalance(), Decimal('100'))

# Send 100 DASH with subtract fee from amount
Expand Down