From e03f4e8e2497ce66dcd40c74ba5a344c20907ebd Mon Sep 17 00:00:00 2001 From: Shoham Chakraborty Date: Fri, 11 Nov 2022 15:32:17 +0800 Subject: [PATCH] Backport of `Throw error on pairSymbol larger than expected` (#1069) (#1546) * Throw error on pairSymbol larger than expected Co-authored-by: Diego del Corral Co-authored-by: Prasanna Loganathar --- src/masternodes/rpc_poolpair.cpp | 5 +++++ test/functional/feature_poolpair.py | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/masternodes/rpc_poolpair.cpp b/src/masternodes/rpc_poolpair.cpp index 9015df7a92..bdefb49878 100644 --- a/src/masternodes/rpc_poolpair.cpp +++ b/src/masternodes/rpc_poolpair.cpp @@ -601,6 +601,11 @@ UniValue createpoolpair(const JSONRPCRequest& request) { targetHeight = ::ChainActive().Height() + 1; } + const auto symbolLength = targetHeight >= Params().GetConsensus().FortCanningHeight ? CToken::MAX_TOKEN_POOLPAIR_LENGTH : CToken::MAX_TOKEN_SYMBOL_LENGTH; + if(pairSymbol.length() > symbolLength){ + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("pairSymbol is larger than %d", symbolLength)); + } + CPoolPairMessage poolPairMsg; poolPairMsg.idTokenA = idtokenA; poolPairMsg.idTokenB = idtokenB; diff --git a/test/functional/feature_poolpair.py b/test/functional/feature_poolpair.py index aa33bdb45d..347c03ae9a 100755 --- a/test/functional/feature_poolpair.py +++ b/test/functional/feature_poolpair.py @@ -104,6 +104,19 @@ def run_test(self): errorString = e.error['message'] assert("Error, there is already a poolpair with same tokens, but different poolId" in errorString) + try: + self.nodes[0].createpoolpair({ + "tokenA": "PT", + "tokenB": "GOLD#128", + "comission": 0.001, + "status": True, + "ownerAddress": collateral0, + "pairSymbol": "000000000" + }, []) + except JSONRPCException as e: + errorString = e.error['message'] + assert("pairSymbol is larger than" in errorString) + # Creating another one trPP = self.nodes[0].createpoolpair({ "tokenA": "DFI",