diff --git a/src/masternodes/rpc_customtx.cpp b/src/masternodes/rpc_customtx.cpp index 6452907ca9..ffad1f2892 100644 --- a/src/masternodes/rpc_customtx.cpp +++ b/src/masternodes/rpc_customtx.cpp @@ -514,17 +514,21 @@ class CCustomTxRpcVisitor { rpcInfo.pushKV("context", obj.context); rpcInfo.pushKV("amount", ValueFromAmount(obj.nAmount)); rpcInfo.pushKV("cycles", int(obj.nCycles)); - auto proposalEndHeight = height; + int64_t proposalEndHeight{}; if (auto prop = mnview.GetProposal(propId)) { proposalEndHeight = prop->proposalEndHeight; } else { - auto votingPeriod = prop->votingPeriod; + // TX still in mempool. For the most accurate guesstimate use + // votingPeriod as it would be set when TX is added to the chain. + const auto votingPeriod = obj.options & CProposalOption::Emergency ? + mnview.GetEmergencyPeriodFromAttributes(type) : + mnview.GetVotingPeriodFromAttributes(); proposalEndHeight = height + (votingPeriod - height % votingPeriod); for (uint8_t i = 1; i <= obj.nCycles; ++i) { proposalEndHeight += votingPeriod; } } - rpcInfo.pushKV("proposalEndHeight", int64_t(proposalEndHeight)); + rpcInfo.pushKV("proposalEndHeight", proposalEndHeight); rpcInfo.pushKV("payoutAddress", ScriptToString(obj.address)); if (obj.options) { UniValue opt = UniValue(UniValue::VARR); diff --git a/test/functional/feature_on_chain_government.py b/test/functional/feature_on_chain_government.py index 678e01fcea..0441daa253 100755 --- a/test/functional/feature_on_chain_government.py +++ b/test/functional/feature_on_chain_government.py @@ -270,11 +270,39 @@ def run_test(self): context = "Test context" tx = self.nodes[0].creategovvoc({"title": title, "context": context}) raw_tx = self.nodes[0].getrawtransaction(tx) + + # Check VoC in mempool + result = self.nodes[0].getcustomtx(tx) + assert_equal(result['type'], 'CreateVoc') + assert_equal(result['valid'], True) + assert_equal(result['results']['proposalId'], tx) + assert_equal(result['results']['type'], 'VoteOfConfidence') + assert_equal(result['results']['title'], title) + assert_equal(result['results']['context'], context) + assert_equal(result['results']['amount'], Decimal('0E-8')) + assert_equal(result['results']['cycles'], 1) + assert_equal(result['results']['proposalEndHeight'], 420) + assert_equal(result['results']['payoutAddress'], '') + + # Send transaction through a different node self.nodes[3].sendrawtransaction(raw_tx) self.nodes[3].generate(1) self.sync_blocks() creationHeight = self.nodes[0].getblockcount() + # Check VoC on-chain + result = self.nodes[0].getcustomtx(tx) + assert_equal(result['type'], 'CreateVoc') + assert_equal(result['valid'], True) + assert_equal(result['results']['proposalId'], tx) + assert_equal(result['results']['type'], 'VoteOfConfidence') + assert_equal(result['results']['title'], title) + assert_equal(result['results']['context'], context) + assert_equal(result['results']['amount'], Decimal('0E-8')) + assert_equal(result['results']['cycles'], 1) + assert_equal(result['results']['proposalEndHeight'], 420) + assert_equal(result['results']['payoutAddress'], '') + # Check burn fee increment assert_equal(self.nodes[0].getburninfo()['feeburn'], Decimal('7.50000000'))