Skip to content

Commit

Permalink
MERGE-FIX: General fixes for functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed May 14, 2019
1 parent 3a83980 commit 1a2a93a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 26 deletions.
2 changes: 1 addition & 1 deletion test/functional/combine_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def main():
parser = argparse.ArgumentParser(usage='%(prog)s [options] <test temporary directory>', description=__doc__)
parser.add_argument('-c', '--color', dest='color', action='store_true', help='outputs the combined log with events colored by source (requires posix terminal colors. Use less -r for viewing)')
parser.add_argument('--html', dest='html', action='store_true', help='outputs the combined log as html. Requires jinja2. pip install jinja2')
parser.add_argument('--chain', dest='chain', help='selected chain in the tests (default: regtest2)', default='regtest2')
parser.add_argument('--chain', dest='chain', help='selected chain in the tests (default: elementsregtest)', default='elementsregtest')
args, unknown_args = parser.parse_known_args()

if args.html and args.color:
Expand Down
32 changes: 22 additions & 10 deletions test/functional/test_framework/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ def __repr__(self):
OUTPOINT_INDEX_MASK = 0x3fffffff

class CAssetIssuance():
__slots__ = ("assetBlindingNonce", "assetEntropy", "nAmount", "nInflationKeys")

def __init__(self):
self.assetBlindingNonce = 0
self.assetEntropy = 0
Expand Down Expand Up @@ -329,7 +331,7 @@ def __repr__(self):
return "CAssetIssuance(assetBlindingNonce=%064x assetEntropy=%064x nAmount=%s nInflationKeys=%s)" % (self.assetBlindingNonce, self.assetEntropy, self.nAmount.vchCommitment, self.nInflationKeys.vchCommitment)

class CTxIn:
__slots__ = ("nSequence", "prevout", "scriptSig")
__slots__ = ("nSequence", "prevout", "scriptSig", "m_is_pegin", "assetIssuance")

def __init__(self, outpoint=None, scriptSig=b"", nSequence=0):
if outpoint is None:
Expand Down Expand Up @@ -385,7 +387,9 @@ def __repr__(self):
% (repr(self.prevout), bytes_to_hex_str(self.scriptSig),
self.nSequence, self.m_is_pegin, self.assetIssuance)

class CTxOutAsset(object):
class CTxOutAsset:
__slots__ = ("vchCommitment")

def __init__(self, vchCommitment=b"\x00"):
self.vchCommitment = vchCommitment

Expand Down Expand Up @@ -418,7 +422,8 @@ def setToAsset(self, val):
def __repr__(self):
return "CTxOutAsset(vchCommitment=%s)" % self.vchCommitment

class CTxOutValue(object):
class CTxOutValue:
__slots__ = ("vchCommitment")

def __init__(self, value=None):
self.setNull()
Expand Down Expand Up @@ -469,7 +474,9 @@ def getAmount(self):
def __repr__(self):
return "CTxOutValue(vchCommitment=%s)" % self.vchCommitment

class CTxOutNonce(object):
class CTxOutNonce:
__slots__ = ("vchCommitment")

def __init__(self, vchCommitment=b"\x00"):
self.vchCommitment = vchCommitment

Expand Down Expand Up @@ -499,7 +506,7 @@ def __repr__(self):


class CTxOut():
__slots__ = ("nValue", "scriptPubKey")
__slots__ = ("nValue", "scriptPubKey", "nAsset", "nNonce")

def __init__(self, nValue=CTxOutValue(), scriptPubKey=b'', nAsset=CTxOutAsset(BITCOIN_ASSET_OUT), nNonce=CTxOutNonce()):
self.nAsset = nAsset
Expand Down Expand Up @@ -559,7 +566,8 @@ def is_null(self):


class CTxInWitness:
__slots__ = ("scriptWitness",)
__slots__ = ("scriptWitness", "vchIssuanceAmountRangeproof",
"vchInflationKeysRangeproof", "peginWitness")

def __init__(self):
self.vchIssuanceAmountRangeproof = b''
Expand Down Expand Up @@ -601,7 +609,9 @@ def is_null(self):
and self.scriptWitness.is_null()


class CTxOutWitness(object):
class CTxOutWitness:
__slots__ = ("vchSurjectionproof", "vchRangeproof")

def __init__(self):
self.vchSurjectionproof = b''
self.vchRangeproof = b''
Expand Down Expand Up @@ -632,7 +642,7 @@ def is_null(self):


class CTxWitness:
__slots__ = ("vtxinwit",)
__slots__ = ("vtxinwit", "vtxoutwit")

def __init__(self):
self.vtxinwit = []
Expand Down Expand Up @@ -793,7 +803,9 @@ def __repr__(self):
% (self.nVersion, repr(self.vin), repr(self.vout), repr(self.wit), self.nLockTime)


class CProof(object):
class CProof:
__slots__ = ("challenge", "solution")

# Default allows OP_TRUE blocks
def __init__(self, challenge=bytearray.fromhex('51'), solution=b""):
self.challenge = challenge
Expand Down Expand Up @@ -824,7 +836,7 @@ def __repr__(self):

class CBlockHeader:
__slots__ = ("hash", "hashMerkleRoot", "hashPrevBlock", "nBits", "nNonce",
"nTime", "nVersion", "sha256")
"nTime", "nVersion", "sha256", "block_height", "proof")

def __init__(self, header=None):
if header is None:
Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):

def __init__(self):
"""Sets test framework defaults. Do not override this method. Instead, override the set_test_params() method"""
self.chain = 'regtest2'
self.chain = 'elementsregtest'
self.setup_clean_chain = False
self.nodes = []
self.network_thread = None
Expand Down
35 changes: 25 additions & 10 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,36 @@ def __init__(self, i, datadir, chain, *, rpchost, timewait, bitcoind, bitcoin_cl

self.p2ps = []

# ELEMENTS:
self.deterministic_priv_key = None

def set_deterministic_priv_key(self, address, privkey):
AddressKeyPair = collections.namedtuple('AddressKeyPair', ['address', 'key'])
self.deterministic_priv_key = AddressKeyPair(address, privkey)

def get_deterministic_priv_key(self):
"""Return a deterministic priv key in base58, that only depends on the node's index"""

AddressKeyPair = collections.namedtuple('AddressKeyPair', ['address', 'key'])
PRIV_KEYS = [
# address , privkey
AddressKeyPair('mjTkW3DjgyZck4KbiRusZsqTgaYTxdSz6z', 'cVpF924EspNh8KjYsfhgY96mmxvT6DgdWiTYMtMjuM74hJaU5psW'),
AddressKeyPair('msX6jQXvxiNhx3Q62PKeLPrhrqZQdSimTg', 'cUxsWyKyZ9MAQTaAhUQWJmBbSvHMwSmuv59KgxQV7oZQU3PXN3KE'),
AddressKeyPair('mnonCMyH9TmAsSj3M59DsbH8H63U3RKoFP', 'cTrh7dkEAeJd6b3MRX9bZK8eRmNqVCMH3LSUkE3dSFDyzjU38QxK'),
AddressKeyPair('mqJupas8Dt2uestQDvV2NH3RU8uZh2dqQR', 'cVuKKa7gbehEQvVq717hYcbE9Dqmq7KEBKqWgWrYBa2CKKrhtRim'),
AddressKeyPair('msYac7Rvd5ywm6pEmkjyxhbCDKqWsVeYws', 'cQDCBuKcjanpXDpCqacNSjYfxeQj8G6CAtH1Dsk3cXyqLNC4RPuh'),
AddressKeyPair('n2rnuUnwLgXqf9kk2kjvVm8R5BZK1yxQBi', 'cQakmfPSLSqKHyMFGwAqKHgWUiofJCagVGhiB4KCainaeCSxeyYq'),
AddressKeyPair('myzuPxRwsf3vvGzEuzPfK9Nf2RfwauwYe6', 'cQMpDLJwA8DBe9NcQbdoSb1BhmFxVjWD5gRyrLZCtpuF9Zi3a9RK'),
AddressKeyPair('mumwTaMtbxEPUswmLBBN3vM9oGRtGBrys8', 'cSXmRKXVcoouhNNVpcNKFfxsTsToY5pvB9DVsFksF1ENunTzRKsy'),
AddressKeyPair('mpV7aGShMkJCZgbW7F6iZgrvuPHjZjH9qg', 'cSoXt6tm3pqy43UMabY6eUTmR3eSUYFtB2iNQDGgb3VUnRsQys2k'),
AddressKeyPair('XLk5KrNPcrDQgX2VLZoWcarPhAdWiaT2kj', 'cUefCfa8BubvB647rZkJZx693KxHV6SYCnixB63GnDbAfeayrTZn'),
AddressKeyPair('XNE8xf6DVprZ7uKeTF5D6fU2UV3JXgidky', 'cSV5h5frESA7GP1E7qUFFLr5GuJTqWH6sfvWhqhUk6viimDjGfhA'),
AddressKeyPair('XX8fKzSef3pfhYn57UMUHVqF3i2ADEduKP', 'cPWfJTmzWJUD9evKEzTF8x7rjXRxnZcaPAjBYBck8yxiLgthUEFm'),
AddressKeyPair('XM98ggwbX6JZv4baocdAg17Srvep8aUw5J', 'cUPkzzKWSTqTAtYanCJXC8e6LkLaxaqagcxAvbdJj7bN6rhfyJCS'),
AddressKeyPair('XKbMRzP9735q3aQBne8KUSoXeopjVDsA4Q', 'cQVhmMSGoMSYTLPkQkqSpskosHwx8N7EZeFKJcJgfruPjiw8Q7tV'),
AddressKeyPair('XD8eGQh8ihNzpTLrqErCJMFdm5W3yjrqyw', 'cQn4GB4xHcAwzAEsFfDUqvGGa6t4hpqxtrjAzj3T7UfYWdhzyEjg'),
AddressKeyPair('XZzJC9V6tgP4G4dciz4McK9CHFYGA98hJ3', 'cUyxqmWmFGTFkd1H9AR4CJ9QpRKDC7nVEirSe79xMJ8MTv8rJAiT'),
AddressKeyPair('XFPZFwRmVVW8LmmQoqUu81ynS3WHEbN11t', 'cMjyVk6QF2ffE7FrWM19jSNCs7VLdmdYQEDZ2BVfwXs8QCHmJ44c'),
AddressKeyPair('XZY7RA4gkBErWUey3egGois93D11mA6zWj', 'cVXrhqnTc519sK8A1jsR1Zm7oBqDRbwkx7GMT3KZ78Dbv6e9vZef'),
]

# ELEMENTS: this allows overriding the default for parent nodes in fedpeg test
if self.deterministic_priv_key is not None:
self.log.debug("Custom deterministic_priv_key: {}".format(self.deterministic_priv_key))
return self.deterministic_priv_key
assert(self.chain == "elementsregtest")

return PRIV_KEYS[self.index]

def get_mem_rss(self):
Expand Down Expand Up @@ -278,7 +293,7 @@ def wait_until_stopped(self, timeout=BITCOIND_PROC_WAIT_TIMEOUT):

@contextlib.contextmanager
def assert_debug_log(self, expected_msgs):
debug_log = os.path.join(self.datadir, 'regtest2', 'debug.log')
debug_log = os.path.join(self.datadir, self.chain, 'debug.log')
with open(debug_log, encoding='utf-8') as dl:
dl.seek(0, 2)
prev_size = dl.tell()
Expand Down
8 changes: 4 additions & 4 deletions test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

logger = logging.getLogger("TestFramework.utils")

BITCOIN_ASSET = "e08fa5a62d79b9e3f5f476743a5535512f0f44444533275a2adc5fe8476a2eac"
BITCOIN_ASSET = "b2e15d0d7a0c94e4e2ce0fe6e8691b9e451377f6e46e8045a86f7c4b5d4f0f23"
BITCOIN_ASSET_BYTES = bytearray.fromhex(BITCOIN_ASSET)
BITCOIN_ASSET_BYTES.reverse()
BITCOIN_ASSET_OUT = b"\x01"+BITCOIN_ASSET_BYTES
Expand Down Expand Up @@ -330,9 +330,9 @@ def initialize_datadir(dirname, n, chain):
f.write("con_bip66height=1251\n")
f.write("con_csv_deploy_start=0\n") # Enhance tests if removing this line
f.write("blindedaddresses=0\n") # Set to minimize broken tests in favor of custom
f.write("pubkeyprefix=111\n")
f.write("scriptprefix=196\n")
f.write("bech32_hrp=bcrt\n")
#f.write("pubkeyprefix=111\n")
#f.write("scriptprefix=196\n")
#f.write("bech32_hrp=bcrt\n")
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
return datadir
Expand Down

0 comments on commit 1a2a93a

Please sign in to comment.