Skip to content

Commit

Permalink
Functional test linting
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Mar 20, 2019
1 parent 242515f commit 0148024
Show file tree
Hide file tree
Showing 33 changed files with 69 additions and 72 deletions.
7 changes: 2 additions & 5 deletions test/functional/feature_assetsdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
# Test listissuances returns a list of all issuances or specific issuances based on asset hex or asset label.
#

from decimal import Decimal
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, assert_greater_than
from test_framework.util import *

class AssetdirTests(BitcoinTestFramework):
"""
Expand Down Expand Up @@ -45,13 +42,13 @@ def run_test(self):
#Check that listissuances return all issuances
issuances = self.nodes[0].listissuances()
assert_equal(len(issuances), 2)

#Check all asset labels have been set: 'asset1', 'asset2'
#We can not be sure they will always be returned in the same order so will loop each one
label = ""
for issue in issuances:
label += issue["assetlabel"]

assert_greater_than(label.find("asset1"), -1)
assert_greater_than(label.find("asset2"), -1)

Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_blocksign.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import random

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (assert_raises_rpc_error, assert_equal, connect_nodes_bi, BITCOIN_ASSET)
from test_framework.util import (assert_raises_rpc_error, assert_equal, connect_nodes_bi)
from test_framework import (
address,
key,
Expand Down
14 changes: 7 additions & 7 deletions test/functional/feature_confidential_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def run_test(self):
tx = self.nodes[0].createrawtransaction([{"txid": unspent[0]["txid"],
"vout": unspent[0]["vout"],
"nValue": unspent[0]["amount"]}],
{unconfidential_address: unspent[0]["amount"] - fee, "fee":fee});
{unconfidential_address: unspent[0]["amount"] - fee, "fee":fee})

# Test that blindrawtransaction adds an OP_RETURN output to balance blinders
temptx = self.nodes[0].blindrawtransaction(tx)
Expand All @@ -164,7 +164,7 @@ def run_test(self):
"vout": unspent[0]["vout"],
"nValue": unspent[0]["amount"]}],
{unconfidential_address: value4,
change_address: unspent[0]["amount"] - value4 - fee, "fee":fee});
change_address: unspent[0]["amount"] - value4 - fee, "fee":fee})
tx = self.nodes[0].blindrawtransaction(tx)
tx_signed = self.nodes[0].signrawtransactionwithwallet(tx)
txid = self.nodes[0].sendrawtransaction(tx_signed['hex'])
Expand Down Expand Up @@ -222,7 +222,7 @@ def run_test(self):
# therefore result will be same even though we change blinding keys
assert_equal(len(self.nodes[0].listunspent(0, 0, [new_validated["unconfidential"]])), 1)

#### Confidential Assets Tests ####
# Confidential Assets Tests

print("Assets tests...")

Expand Down Expand Up @@ -295,8 +295,8 @@ def run_test(self):
self.nodes[2].generate(1)
self.sync_all()

redata1 = self.nodes[1].reissueasset(issuancedata["asset"], Decimal('0.05'))
redata2 = self.nodes[2].reissueasset(issuancedata["asset"], Decimal('0.025'))
self.nodes[1].reissueasset(issuancedata["asset"], Decimal('0.05'))
self.nodes[2].reissueasset(issuancedata["asset"], Decimal('0.025'))
self.nodes[1].generate(1)
self.sync_all()

Expand Down Expand Up @@ -349,8 +349,8 @@ def run_test(self):
# Basic checks of rawblindrawtransaction functionality
blinded_addr = self.nodes[0].getnewaddress()
addr = self.nodes[0].validateaddress(blinded_addr)["unconfidential"]
txid1 = self.nodes[0].sendtoaddress(blinded_addr, 1)
txid2 = self.nodes[0].sendtoaddress(blinded_addr, 3)
self.nodes[0].sendtoaddress(blinded_addr, 1)
self.nodes[0].sendtoaddress(blinded_addr, 3)
unspent = self.nodes[0].listunspent(0, 0)
assert_equal(len(unspent), 4)
rawtx = self.nodes[0].createrawtransaction([{"txid":unspent[0]["txid"], "vout":unspent[0]["vout"]}, {"txid":unspent[1]["txid"], "vout":unspent[1]["vout"]}], {addr:unspent[0]["amount"]+unspent[1]["amount"]-Decimal("0.2"), "fee":Decimal("0.2")})
Expand Down
4 changes: 1 addition & 3 deletions test/functional/feature_default_asset_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
# Test chain initialisation when specifying default asset name.
#

from decimal import Decimal
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, connect_nodes_bi

class NamedDefaultAssetTest(BitcoinTestFramework):
Expand Down Expand Up @@ -42,7 +40,7 @@ def run_test(self):
assert_equal(walletinfo1["balance"]["testasset"], 21000000)

#Send some of the default asset to the second node
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1, "", "", False)
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1, "", "", False)
self.nodes[0].generate(101)
self.sync_all()

Expand Down
3 changes: 0 additions & 3 deletions test/functional/feature_initial_reissuance_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
# Test chain initialisation when specifying number of reissuance tokens to issue.
#

from decimal import Decimal
from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import connect_nodes_bi, assert_equal
from test_framework.util import *

class InitialReissuanceTokenTest(BitcoinTestFramework):
"""
Expand Down
7 changes: 3 additions & 4 deletions test/functional/feature_issuance.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def process_raw_issuance(node, issuance_list):
if "asset" in output and output["asset"] == issuance_details[issuance_type]:
if issuance_type+"_address" not in issuance_req:
raise Exception("Found asset type not requested")
if "value" in output and \
output["value"] == issuance_req[issuance_type+"_amount"]:
if "value" in output and output["value"] == issuance_req[issuance_type+"_amount"]:
asset_found = True

# Find the asset type if it was created
Expand All @@ -105,7 +104,7 @@ def setup_network(self, split=False):
def run_test(self):
self.nodes[0].generate(105)
# Make sure test starts with no initial issuance.
assert_equal(len(self.nodes[0].listissuances()), 0);
assert_equal(len(self.nodes[0].listissuances()), 0)

# Unblinded issuance of asset
issued = self.nodes[0].issueasset(1, 1, False)
Expand Down Expand Up @@ -211,7 +210,7 @@ def run_test(self):
addr2 = txdet2[len(txdet2)-1]["address"]
addr3 = txdet3[len(txdet3)-1]["address"]

assert_equal(len(self.nodes[0].listissuances()), 5);
assert_equal(len(self.nodes[0].listissuances()), 5)
self.nodes[0].importaddress(addr1)
self.nodes[0].importaddress(addr2)
self.nodes[0].importaddress(addr3)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_pak.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Distributed under the MIT/X11 software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes_bi, sync_blocks, Decimal, BITCOIN_ASSET
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes_bi, sync_blocks, Decimal
import copy
import time

Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_rbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut, CTxOutValue
from test_framework.script import CScript, OP_DROP
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, hex_str_to_bytes, satoshi_round, BITCOIN_ASSET
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, hex_str_to_bytes, satoshi_round

from io import BytesIO

Expand Down
2 changes: 1 addition & 1 deletion test/functional/feature_segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut, FromHex, sha256, ToHex
from test_framework.script import CScript, OP_HASH160, OP_CHECKSIG, OP_0, hash160, OP_EQUAL, OP_DUP, OP_EQUALVERIFY, OP_1, OP_2, OP_CHECKMULTISIG, OP_TRUE, OP_DROP, OP_RETURN
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes, hex_str_to_bytes, sync_blocks, try_rpc, BITCOIN_ASSET
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes, hex_str_to_bytes, sync_blocks, try_rpc

from io import BytesIO

Expand Down
1 change: 0 additions & 1 deletion test/functional/interface_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
assert_greater_than,
assert_greater_than_or_equal,
hex_str_to_bytes,
BITCOIN_ASSET,
)

class ReqType(Enum):
Expand Down
2 changes: 1 addition & 1 deletion test/functional/mempool_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import time

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, wait_until, BITCOIN_ASSET
from test_framework.util import assert_equal, assert_raises_rpc_error, wait_until

class MempoolPersistTest(BitcoinTestFramework):
def set_test_params(self):
Expand Down
2 changes: 1 addition & 1 deletion test/functional/p2p_compactblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from test_framework.mininode import mininode_lock, P2PInterface
from test_framework.script import CScript, OP_TRUE, OP_DROP
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, get_bip9_status, satoshi_round, sync_blocks, wait_until, BITCOIN_ASSET
from test_framework.util import assert_equal, get_bip9_status, satoshi_round, sync_blocks, wait_until
from test_framework import util

# TestP2PConn: A peer we use to send messages to bitcoind, and store responses.
Expand Down
12 changes: 8 additions & 4 deletions test/functional/p2p_segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ def test_v0_outputs_arent_spendable(self):
tx.vin = [CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b'')]
tx.vout = [CTxOut(value, script_pubkey), CTxOut(value, p2sh_script_pubkey)]
tx.vout.append(CTxOut(value, CScript([OP_TRUE])))
if self.utxo[0].nValue % 3 > 0: tx.vout.append(CTxOut(self.utxo[0].nValue - 3*value))
if self.utxo[0].nValue % 3 > 0:
tx.vout.append(CTxOut(self.utxo[0].nValue - 3*value))
tx.rehash()
txid = tx.sha256

Expand Down Expand Up @@ -1742,7 +1743,8 @@ def test_signature_version_1(self):
split_value = total_value // num_outputs
for i in range(num_outputs):
tx.vout.append(CTxOut(split_value, script_pubkey))
if total_value % num_outputs > 0: tx.vout.append(CTxOut(total_value - num_outputs*split_value)) # fee
if total_value % num_outputs > 0:
tx.vout.append(CTxOut(total_value - num_outputs*split_value)) # fee
for i in range(num_inputs):
# Now try to sign each input, using a random hashtype.
anyonecanpay = 0
Expand Down Expand Up @@ -1815,7 +1817,8 @@ def test_signature_version_1(self):
# Just spend to our usual anyone-can-spend output
tx.vout = [CTxOut(output_value, CScript([OP_TRUE]))] * 2
total_in = sum(i.nValue for i in temp_utxos)
if total_in - 2*output_value > 0: tx.vout.append(CTxOut(total_in - 2*output_value)) # fee
if total_in - 2*output_value > 0:
tx.vout.append(CTxOut(total_in - 2*output_value)) # fee
for i in temp_utxos:
# Use SIGHASH_ALL|SIGHASH_ANYONECANPAY so we can build up
# the signatures as we go.
Expand Down Expand Up @@ -2054,7 +2057,8 @@ def test_witness_sigops(self):
tx.vout.append(CTxOut(split_value, script_pubkey))
tx.vout[-2].scriptPubKey = script_pubkey_toomany
tx.vout[-1].scriptPubKey = script_pubkey_justright
if self.utxo[0].nValue % outputs > 0: tx.vout.append(CTxOut(self.utxo[0].nValue - outputs*split_value)) # fee
if self.utxo[0].nValue % outputs > 0:
tx.vout.append(CTxOut(self.utxo[0].nValue - outputs*split_value)) # fee
tx.rehash()

block_1 = self.build_next_block()
Expand Down
1 change: 0 additions & 1 deletion test/functional/rpc_createmultisig.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""Test transaction signing using the signrawtransaction* RPCs."""

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import BITCOIN_ASSET
import decimal

class RpcCreateMultiSigTest(BitcoinTestFramework):
Expand Down
1 change: 0 additions & 1 deletion test/functional/rpc_fundrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
connect_nodes_bi,
count_bytes,
find_vout_for_address,
BITCOIN_ASSET,
)


Expand Down
2 changes: 1 addition & 1 deletion test/functional/rpc_rawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from io import BytesIO
from test_framework.messages import CTransaction, ToHex
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes_bi, hex_str_to_bytes, BITCOIN_ASSET
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes_bi, hex_str_to_bytes

class multidict(dict):
"""Dictionary that allows duplicate keys.
Expand Down
4 changes: 2 additions & 2 deletions test/functional/rpc_tweakfedpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def run_test(self):
assert_equal(tweak, nontweak)

# Elements 0.14 Daemon example
assert_equal(self.nodes[1].tweakfedpegscript("0014008b1fdbaec5a82a9322af1640e871727245bce1")["script"], \
assert_equal(self.nodes[1].tweakfedpegscript("0014008b1fdbaec5a82a9322af1640e871727245bce1")["script"],
"522102f5bc6bc407187d06854005c366b84b411534757f4503587cf335645a620f896a2102fd90164e4e7d53417e4eacfa3f86fd39fe40594791758739e8af31eeea4e79c552ae")

# Test Liquid-style fedpegscript with CSV emergency keys(which don't get tweaked!)
Expand All @@ -72,7 +72,7 @@ def run_test(self):


# Liquid Deamon example:
assert_equal(self.nodes[2].tweakfedpegscript("0014008b1fdbaec5a82a9322af1640e871727245bce1")["script"], \
assert_equal(self.nodes[2].tweakfedpegscript("0014008b1fdbaec5a82a9322af1640e871727245bce1")["script"],
"745c87635b2103258857ed88024e5296436f851337451d3d68522fbb21dc5a047b965cd2f790932103ab43d77e8706a799cee3c14678574bccaca98c101217369cee987073cd2546492102ee5c8dfdf742bcc2b08386a6a3ec4b6087d39a6fd7e6f0fdeb82ecc30b11d0342102b104b6a469d8b3ccf0a671198e5f7d7010dbf2eb5587733b168f6e0d3be75760210207fc37d4877529fb0d63b1de352689627400a43f18717fa182fe0eea283bdd7921025d8724d82c61708458bc1a08ec9a7fcaf0ab6747ccf0a7d378faea07a261ab3e2102af6859d48d0a4518a4811f12adb974bbd051931e3f96f0b6ae16142c43ae6fd12102458215967f7977effc21b964bd92d870ae7eca98f343801031639150139e63ed2102cdef66bf4b5d26d0be22cabd5761970cfa84be905dc0137ad08ab634f104cb9e210297fb764f808c126f46ce0444124213bdc6a18f2904e75c9144f53bed4c19376e2103c631e77d14a5eb2fc61496ee3e9ea19d1e56e7e65a07aaa786f25ffc2921efde210270addb9011a4b41987b0848a8dc52e5442964fe5188c6a4c9320fbb9016390772103bf9aa75444d0013c46dcf10d70831b75b46a25d901fb7c6360beb2f6cac9c503210278f303dbaad1410a26d99e4dca8925fae4c90532a156c29e8ab1abf5ccaa663d210394cc0983add2dc60aa988c9faedebdc5463106184d72dd430ef24d215daf8b935f6702c00fb275522103aab896d53a8e7d6433137bbba940f9c521e085dd07e60994579b64a6d992cf79210291b7d0b1b692f8f524516ed950872e5da10fb1b808b5a526dedc6fed1cf29807210386aa9372fbab374593466bc5451dc59954e90787f08060964d95c87ef34ca5bb5368ae")


Expand Down
2 changes: 1 addition & 1 deletion test/functional/rpc_txoutproof.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from test_framework.messages import CMerkleBlock, FromHex, ToHex
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes, BITCOIN_ASSET
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes

class MerkleBlockTest(BitcoinTestFramework):
def set_test_params(self):
Expand Down
2 changes: 0 additions & 2 deletions test/functional/test_framework/blocktools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
CTxIn,
CTxInWitness,
CTxOut,
CTxOutAsset,
CTxOutValue,
FromHex,
ToHex,
Expand All @@ -30,7 +29,6 @@
sha256,
uint256_from_str,
CProof,
BITCOIN_ASSET_OUT,
)
from .script import (
CScript,
Expand Down
48 changes: 32 additions & 16 deletions test/functional/test_framework/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,16 @@ def setNull(self):

def deserialize(self, f):
version = ord(f.read(1))
if version == 0: self.vchCommitment = b'\x00'
elif version == 1: self.vchCommitment = b'\x01' + f.read(32)
elif version == 0xff: self.vchCommitment = b'\xff' + f.read(32)
elif version == 10 or version == 11: self.vchCommitment = bytes([version]) + f.read(32)
else: raise 'invalid CTxOutAsset in deserialize'
if version == 0:
self.vchCommitment = b'\x00'
elif version == 1:
self.vchCommitment = b'\x01' + f.read(32)
elif version == 0xff:
self.vchCommitment = b'\xff' + f.read(32)
elif version == 10 or version == 11:
self.vchCommitment = bytes([version]) + f.read(32)
else:
raise 'invalid CTxOutAsset in deserialize'

def serialize(self):
r = b""
Expand All @@ -353,15 +358,21 @@ def setNull(self):

def deserialize(self, f):
version = ord(f.read(1))
if version == 0: self.vchCommitment = b'\x00'
elif version == 1: self.vchCommitment = b'\x01' + f.read(8)
elif version == 0xff: self.vchCommitment = b'\xff' + f.read(8)
elif version == 8 or version == 9: self.vchCommitment = bytes([version]) + f.read(32)
else: raise Exception('invalid CTxOutValue in deserialize. version %d' % version)
if version == 0:
self.vchCommitment = b'\x00'
elif version == 1:
self.vchCommitment = b'\x01' + f.read(8)
elif version == 0xff:
self.vchCommitment = b'\xff' + f.read(8)
elif version == 8 or version == 9:
self.vchCommitment = bytes([version]) + f.read(32)
else:
raise Exception('invalid CTxOutValue in deserialize. version %d' % version)

def serialize(self):
r = b""
if len(self.vchCommitment) < 1: raise ValueError('invalid commitment')
if len(self.vchCommitment) < 1:
raise ValueError('invalid commitment')
r += self.vchCommitment
return r

Expand Down Expand Up @@ -392,11 +403,16 @@ def setNull(self):

def deserialize(self, f):
version = ord(f.read(1))
if version == 0: self.vchCommitment = b'\x00'
elif version == 1: self.vchCommitment = b'\x01' + f.read(32)
elif version == 0xff: self.vchCommitment = b'\xff' + f.read(32)
elif version == 2 or version == 3: self.vchCommitment = bytes([version]) + f.read(32)
else: raise ValueError('invalid CTxOutNonce in deserialize')
if version == 0:
self.vchCommitment = b'\x00'
elif version == 1:
self.vchCommitment = b'\x01' + f.read(32)
elif version == 0xff:
self.vchCommitment = b'\xff' + f.read(32)
elif version == 2 or version == 3:
self.vchCommitment = bytes([version]) + f.read(32)
else:
raise ValueError('invalid CTxOutNonce in deserialize')

def serialize(self):
r = b""
Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_abandonconflict.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from decimal import Decimal

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes, disconnect_nodes, sync_blocks, sync_mempools, BITCOIN_ASSET
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes, disconnect_nodes, sync_blocks, sync_mempools

class AbandonConflictTest(BitcoinTestFramework):
def set_test_params(self):
Expand Down
1 change: 0 additions & 1 deletion test/functional/wallet_address_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
connect_nodes_bi,
sync_blocks,
sync_mempools,
BITCOIN_ASSET,
)


Expand Down
Loading

0 comments on commit 0148024

Please sign in to comment.