Skip to content

Commit

Permalink
[Tests] Fix TierTwo functional tests with BLS operator key
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Sep 19, 2021
1 parent d734a92 commit b20679a
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 79 deletions.
14 changes: 7 additions & 7 deletions test/functional/test_framework/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1438,26 +1438,26 @@ def serialize(self):

# PIVX Classes
class Masternode(object):
def __init__(self, idx, owner_addr, operator_addr, voting_addr, ipport, payout_addr, operator_key):
def __init__(self, idx, owner_addr, operator_pk, voting_addr, ipport, payout_addr, operator_sk):
self.idx = idx
self.owner = owner_addr
self.operator = operator_addr
self.operator_pk = operator_pk
self.voting = voting_addr
self.ipport = ipport
self.payee = payout_addr
self.operator_key = operator_key
self.operator_sk = operator_sk
self.proTx = None
self.collateral = None

def revoked(self):
self.ipport = "[::]:0"
self.operator = ""
self.operator_key = None
self.operator_pk = "0" * 96
self.operator_sk = None

def __repr__(self):
return "Masternode(idx=%d, owner=%s, operator=%s, voting=%s, ip=%s, payee=%s, opkey=%s, protx=%s, collateral=%s)" % (
self.idx, str(self.owner), str(self.operator), str(self.voting), str(self.ipport),
str(self.payee), str(self.operator_key), str(self.proTx), str(self.collateral)
self.idx, str(self.owner), str(self.operator_pk), str(self.voting), str(self.ipport),
str(self.payee), str(self.operator_sk), str(self.proTx), str(self.collateral)
)

def __str__(self):
Expand Down
29 changes: 14 additions & 15 deletions test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,8 +1072,7 @@ def setupDMN(self,
collateralAdd = mnOwner.getnewaddress("dmn")
ipport = "127.0.0.1:" + str(p2p_port(mnRemotePos))
ownerAdd = mnOwner.getnewaddress("dmn_owner")
operatorAdd = mnOwner.getnewaddress("dmn_operator")
operatorKey = mnOwner.dumpprivkey(operatorAdd)
bls_keypair = mnOwner.generateblskeypair()
votingAdd = mnOwner.getnewaddress("dmn_voting")
if strType == "fund":
# send to the owner the collateral tx cost + some dust for the ProReg and fee
Expand All @@ -1083,7 +1082,7 @@ def setupDMN(self,
assert_greater_than(mnOwner.getrawtransaction(fundingTxId, 1)["confirmations"], 0)
# create and send the ProRegTx funding the collateral
proTxId = mnOwner.protx_register_fund(collateralAdd, ipport, ownerAdd,
operatorAdd, votingAdd, collateralAdd)
bls_keypair["public"], votingAdd, collateralAdd)
elif strType == "internal":
mnOwner.getnewaddress("dust")
# send to the owner the collateral tx cost + some dust for the ProReg and fee
Expand All @@ -1100,13 +1099,13 @@ def setupDMN(self,
assert_greater_than(collateralTxId_n, -1)
assert_greater_than(json_tx["confirmations"], 0)
proTxId = mnOwner.protx_register(collateralTxId, collateralTxId_n, ipport, ownerAdd,
operatorAdd, votingAdd, collateralAdd)
bls_keypair["public"], votingAdd, collateralAdd)
elif strType == "external":
self.log.info("Setting up ProRegTx with collateral externally-signed...")
# send the tx from the miner
payoutAdd = mnOwner.getnewaddress("payout")
register_res = miner.protx_register_prepare(outpoint.hash, outpoint.n, ipport, ownerAdd,
operatorAdd, votingAdd, payoutAdd)
bls_keypair["public"], votingAdd, payoutAdd)
self.log.info("ProTx prepared")
message_to_sign = register_res["signMessage"]
collateralAdd = register_res["collateralAddress"]
Expand All @@ -1121,7 +1120,7 @@ def setupDMN(self,
self.stake_and_sync(self.nodes.index(miner), 1)
assert_greater_than(self.nodes[mnRemotePos].getrawtransaction(proTxId, 1)["confirmations"], 0)
assert proTxId in self.nodes[mnRemotePos].protx_list(False)
return proTxId, operatorKey
return proTxId, bls_keypair["secret"]

def setupMasternode(self,
mnOwner,
Expand Down Expand Up @@ -1188,10 +1187,10 @@ def protx_register_fund(self, miner, controller, dmn, collateral_addr, op_rew=No
# create and send the ProRegTx funding the collateral
if op_rew is None:
dmn.proTx = controller.protx_register_fund(collateral_addr, dmn.ipport, dmn.owner,
dmn.operator, dmn.voting, dmn.payee)
dmn.operator_pk, dmn.voting, dmn.payee)
else:
dmn.proTx = controller.protx_register_fund(collateral_addr, dmn.ipport, dmn.owner,
dmn.operator, dmn.voting, dmn.payee,
dmn.operator_pk, dmn.voting, dmn.payee,
op_rew["reward"], op_rew["address"])
dmn.collateral = COutPoint(int(dmn.proTx, 16),
get_collateral_vout(controller.getrawtransaction(dmn.proTx, True)))
Expand All @@ -1213,7 +1212,7 @@ def protx_register(self, miner, controller, dmn, collateral_addr):
# create and send the ProRegTx
dmn.collateral = COutPoint(int(funding_txid, 16), get_collateral_vout(json_tx))
dmn.proTx = controller.protx_register(funding_txid, dmn.collateral.n, dmn.ipport, dmn.owner,
dmn.operator, dmn.voting, dmn.payee)
dmn.operator_pk, dmn.voting, dmn.payee)

"""
Create a ProReg tx, referencing a collateral signed externally (eg. HW wallets).
Expand All @@ -1232,7 +1231,7 @@ def protx_register_ext(self, miner, controller, dmn, outpoint, fSubmit):
dmn.collateral = outpoint
# Prepare the message to be signed externally by the owner of the collateral (the controller)
reg_tx = miner.protx_register_prepare("%064x" % outpoint.hash, outpoint.n, dmn.ipport, dmn.owner,
dmn.operator, dmn.voting, dmn.payee)
dmn.operator_pk, dmn.voting, dmn.payee)
sig = controller.signmessage(reg_tx["collateralAddress"], reg_tx["signMessage"])
if fSubmit:
dmn.proTx = miner.protx_register_submit(reg_tx["tx"], sig)
Expand All @@ -1248,12 +1247,12 @@ def protx_register_ext(self, miner, controller, dmn, outpoint, fSubmit):
outpoint: (COutPoint) collateral outpoint to be used with "external".
It must be owned by the controller (proTx is sent from the miner).
If not provided, a new utxo is created, sending it from the miner.
op_addr_and_key: (list of strings) List with two entries, operator address (0) and private key (1).
op_blskeys: (list of strings) List with two entries, operator public (0) and private (1) key.
If not provided, a new address-key pair is generated.
:return: dmn: (Masternode) the deterministic masternode object
"""
def register_new_dmn(self, idx, miner_idx, controller_idx, strType,
payout_addr=None, outpoint=None, op_addr_and_key=None):
payout_addr=None, outpoint=None, op_blskeys=None):
# Prepare remote node
assert idx != miner_idx
assert idx != controller_idx
Expand All @@ -1265,7 +1264,7 @@ def register_new_dmn(self, idx, miner_idx, controller_idx, strType,
collateral_addr = controller_node.getnewaddress("mncollateral-%d" % idx)
if payout_addr is None:
payout_addr = collateral_addr
dmn = create_new_dmn(idx, controller_node, payout_addr, op_addr_and_key)
dmn = create_new_dmn(idx, controller_node, payout_addr, op_blskeys)

# Create ProRegTx
self.log.info("Creating%s proRegTx for deterministic masternode idx=%d..." % (
Expand Down Expand Up @@ -1315,7 +1314,7 @@ def check_mn_list_on_node(self, idx, mns):
mn2 = protxs[mn.proTx]
collateral = mn.collateral.to_json()
assert_equal(mn.owner, mn2["dmnstate"]["ownerAddress"])
assert_equal(mn.operator, mn2["dmnstate"]["operatorAddress"])
assert_equal(mn.operator_pk, mn2["dmnstate"]["operatorPubKey"])
assert_equal(mn.voting, mn2["dmnstate"]["votingAddress"])
assert_equal(mn.ipport, mn2["dmnstate"]["service"])
assert_equal(mn.payee, mn2["dmnstate"]["payoutAddress"])
Expand All @@ -1334,7 +1333,7 @@ def check_proreg_payload(self, dmn, json_tx):
assert_equal(pl["service"], dmn.ipport)
assert_equal(pl["ownerAddress"], dmn.owner)
assert_equal(pl["votingAddress"], dmn.voting)
assert_equal(pl["operatorAddress"], dmn.operator)
assert_equal(pl["operatorPubKey"], dmn.operator_pk)
assert_equal(pl["payoutAddress"], dmn.payee)


Expand Down
17 changes: 9 additions & 8 deletions test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,19 +602,20 @@ def get_collateral_vout(json_tx):
return funding_txidn

# owner and voting keys are created from controller node.
# operator key and address are created, if operator_addr_and_key is None.
def create_new_dmn(idx, controller, payout_addr, operator_addr_and_key):
# operator keys are created, if operator_keys is None.
def create_new_dmn(idx, controller, payout_addr, operator_keys):
port = p2p_port(idx) if idx <= MAX_NODES else p2p_port(MAX_NODES) + (idx - MAX_NODES)
ipport = "127.0.0.1:" + str(port)
owner_addr = controller.getnewaddress("mnowner-%d" % idx)
voting_addr = controller.getnewaddress("mnvoting-%d" % idx)
if operator_addr_and_key is None:
operator_addr = controller.getnewaddress("mnoperator-%d" % idx)
operator_key = controller.dumpprivkey(operator_addr)
if operator_keys is None:
bls_keypair = controller.generateblskeypair()
operator_pk = bls_keypair["public"]
operator_sk = bls_keypair["secret"]
else:
operator_addr = operator_addr_and_key[0]
operator_key = operator_addr_and_key[1]
return messages.Masternode(idx, owner_addr, operator_addr, voting_addr, ipport, payout_addr, operator_key)
operator_pk = operator_keys[0]
operator_sk = operator_keys[1]
return messages.Masternode(idx, owner_addr, operator_pk, voting_addr, ipport, payout_addr, operator_sk)

def spend_mn_collateral(spender, dmn):
inputs = [dmn.collateral.to_json()]
Expand Down
Loading

0 comments on commit b20679a

Please sign in to comment.