From 2b702f8e846dd85c65cee825b8c128a5cceffabf Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 10 Feb 2023 14:21:05 +0300 Subject: [PATCH] fix/tests: fix `masternode payments` rpc, add tests (#5191) ## Issue being fixed or feature implemented it was picking the wrong DMN as a payee... ## What was done? see code and notes ## How Has This Been Tested? run tests ## Breaking Changes n/a ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation **For repository code-owners and collaborators only** - [x] I have assigned this pull request to a milestone --- src/rpc/masternode.cpp | 3 ++- test/functional/rpc_masternode.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index eff93f14cc..9a40da08b6 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -461,7 +461,8 @@ static UniValue masternode_payments(const JSONRPCRequest& request) payeesArr.push_back(obj); } - const auto dmnPayee = deterministicMNManager->GetListForBlock(pindex).GetMNPayee(); + // NOTE: we use _previous_ block to find a payee for the current one + const auto dmnPayee = deterministicMNManager->GetListForBlock(pindex->pprev).GetMNPayee(); protxObj.pushKV("proTxHash", dmnPayee == nullptr ? "" : dmnPayee->proTxHash.ToString()); protxObj.pushKV("amount", payedPerMasternode); protxObj.pushKV("payees", payeesArr); diff --git a/test/functional/rpc_masternode.py b/test/functional/rpc_masternode.py index 7ec1c34d47..55fe356271 100755 --- a/test/functional/rpc_masternode.py +++ b/test/functional/rpc_masternode.py @@ -66,6 +66,26 @@ class RPCMasternodeTest(DashTestFramework): assert_equal(gbt_masternode[i]["script"], payments_masternode["payees"][i]["script"]) assert_equal(gbt_masternode[i]["amount"], payments_masternode["payees"][i]["amount"]) + self.log.info("test that `masternode payments` results and `protx info` results match") + # we expect some masternodes to have 0 operator reward and some to have non-0 operator reward + checked_0_operator_reward = False + checked_non_0_operator_reward = False + while not checked_0_operator_reward or not checked_non_0_operator_reward: + payments_masternode = self.nodes[0].masternode("payments")[0]["masternodes"][0] + protx_info = self.nodes[0].protx("info", payments_masternode["proTxHash"]) + if len(payments_masternode["payees"]) == 1: + assert_equal(protx_info["state"]["payoutAddress"], payments_masternode["payees"][0]["address"]) + checked_0_operator_reward = True + else: + assert_equal(len(payments_masternode["payees"]), 2) + option1 = protx_info["state"]["payoutAddress"] == payments_masternode["payees"][0]["address"] and \ + protx_info["state"]["operatorPayoutAddress"] == payments_masternode["payees"][1]["address"] + option2 = protx_info["state"]["payoutAddress"] == payments_masternode["payees"][1]["address"] and \ + protx_info["state"]["operatorPayoutAddress"] == payments_masternode["payees"][0]["address"] + assert option1 or option2 + checked_non_0_operator_reward = True + self.nodes[0].generate(1) + self.log.info("test that `masternode outputs` show correct list") addr1 = self.nodes[0].getnewaddress() addr2 = self.nodes[0].getnewaddress()