Allow registering MNs without actually starting them

This can be done by calling prepare_masternode() when inside run_test.
Also implement remove_masternode() which spends the collateral.
This commit is contained in:
Alexander Block 2019-04-04 08:08:44 +02:00
parent ef6b6a1e64
commit ade5760a92

View File

@ -277,37 +277,49 @@ class DashTestFramework(BitcoinTestFramework):
def prepare_masternodes(self): def prepare_masternodes(self):
for idx in range(0, self.mn_count): for idx in range(0, self.mn_count):
bls = self.nodes[0].bls('generate') self.prepare_masternode(idx)
address = self.nodes[0].getnewaddress()
txid = self.nodes[0].sendtoaddress(address, MASTERNODE_COLLATERAL)
txraw = self.nodes[0].getrawtransaction(txid, True) def prepare_masternode(self, idx):
collateral_vout = 0 bls = self.nodes[0].bls('generate')
for vout_idx in range(0, len(txraw["vout"])): address = self.nodes[0].getnewaddress()
vout = txraw["vout"][vout_idx] txid = self.nodes[0].sendtoaddress(address, MASTERNODE_COLLATERAL)
if vout["value"] == MASTERNODE_COLLATERAL:
collateral_vout = vout_idx
self.nodes[0].lockunspent(False, [{'txid': txid, 'vout': collateral_vout}])
# send to same address to reserve some funds for fees txraw = self.nodes[0].getrawtransaction(txid, True)
self.nodes[0].sendtoaddress(address, 0.001) collateral_vout = 0
for vout_idx in range(0, len(txraw["vout"])):
vout = txraw["vout"][vout_idx]
if vout["value"] == MASTERNODE_COLLATERAL:
collateral_vout = vout_idx
self.nodes[0].lockunspent(False, [{'txid': txid, 'vout': collateral_vout}])
ownerAddr = self.nodes[0].getnewaddress() # send to same address to reserve some funds for fees
votingAddr = self.nodes[0].getnewaddress() self.nodes[0].sendtoaddress(address, 0.001)
rewardsAddr = self.nodes[0].getnewaddress()
port = p2p_port(len(self.nodes) + idx) ownerAddr = self.nodes[0].getnewaddress()
if (idx % 2) == 0: votingAddr = self.nodes[0].getnewaddress()
self.nodes[0].lockunspent(True, [{'txid': txid, 'vout': collateral_vout}]) rewardsAddr = self.nodes[0].getnewaddress()
proTxHash = self.nodes[0].protx('register_fund', address, '127.0.0.1:%d' % port, ownerAddr, bls['public'], votingAddr, 0, rewardsAddr, address)
else: port = p2p_port(len(self.nodes) + idx)
self.nodes[0].generate(1) if (idx % 2) == 0:
proTxHash = self.nodes[0].protx('register', txid, collateral_vout, '127.0.0.1:%d' % port, ownerAddr, bls['public'], votingAddr, 0, rewardsAddr, address) self.nodes[0].lockunspent(True, [{'txid': txid, 'vout': collateral_vout}])
proTxHash = self.nodes[0].protx('register_fund', address, '127.0.0.1:%d' % port, ownerAddr, bls['public'], votingAddr, 0, rewardsAddr, address)
else:
self.nodes[0].generate(1) self.nodes[0].generate(1)
proTxHash = self.nodes[0].protx('register', txid, collateral_vout, '127.0.0.1:%d' % port, ownerAddr, bls['public'], votingAddr, 0, rewardsAddr, address)
self.nodes[0].generate(1)
self.mninfo.append(MasternodeInfo(proTxHash, ownerAddr, votingAddr, bls['public'], bls['secret'], address, txid, collateral_vout)) self.mninfo.append(MasternodeInfo(proTxHash, ownerAddr, votingAddr, bls['public'], bls['secret'], address, txid, collateral_vout))
self.sync_all() self.sync_all()
def remove_mastermode(self, idx):
mn = self.mninfo[idx]
rawtx = self.nodes[0].createrawtransaction([{"txid": mn.collateral_txid, "vout": mn.collateral_vout}], {self.nodes[0].getnewaddress(): 999.9999})
rawtx = self.nodes[0].signrawtransaction(rawtx)
self.nodes[0].sendrawtransaction(rawtx["hex"])
self.nodes[0].generate(1)
self.sync_all()
self.mninfo.remove(mn)
def prepare_datadirs(self): def prepare_datadirs(self):
# stop faucet node so that we can copy the datadir # stop faucet node so that we can copy the datadir
stop_node(self.nodes[0], 0) stop_node(self.nodes[0], 0)