Skip to content

Commit

Permalink
Throw error on pairSymbol larger than expected (#1069)
Browse files Browse the repository at this point in the history
* Throw error on pairSymbol larger than expected

* Remove if else

* Move pairSymbol length check to RPC level

* Fix typos (#1212)

* Update test case to use blockHeight from tip instead of deprecatedHeight (#1204)

Co-authored-by: Anthony Fieroni <[email protected]>
Co-authored-by: Shoham Chakraborty <[email protected]>
Co-authored-by: Prasanna Loganathar <[email protected]>
  • Loading branch information
4 people authored May 7, 2022
1 parent ff55056 commit be009c8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/masternodes/icxorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Res CICXOrderView::ICXCreateOrder(CICXOrderImpl const & order)
if (order.amountFrom == 0)
return Res::Err("order amountFrom must be greater than 0!");
if (order.amountToFill != order.amountFrom)
return Res::Err("order amountToFill does not equal to amountFrom!");
return Res::Err("order amountToFill is not equal to amountFrom!");
if (order.orderPrice == 0)
return Res::Err("order price must be greater than 0!");
if (order.expiry < CICXOrder::DEFAULT_EXPIRY)
Expand Down
5 changes: 5 additions & 0 deletions src/masternodes/rpc_poolpair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,11 @@ UniValue createpoolpair(const JSONRPCRequest& request) {
targetHeight = view.GetLastHeight() + 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));
}

CCreatePoolPairMessage poolPairMsg{};
poolPairMsg.idTokenA = idtokenA;
poolPairMsg.idTokenB = idtokenB;
Expand Down
10 changes: 5 additions & 5 deletions src/masternodes/rpc_vault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ UniValue closevault(const JSONRPCRequest& request) {
// decode vaultId
auto vault = view.GetVault(msg.vaultId);
if (!vault)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Vault <%s> does not found", msg.vaultId.GetHex()));
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Vault <%s> not found", msg.vaultId.GetHex()));

if (vault->isUnderLiquidation)
throw JSONRPCError(RPC_TRANSACTION_REJECTED, "Vault is under liquidation.");
Expand Down Expand Up @@ -609,7 +609,7 @@ UniValue updatevault(const JSONRPCRequest& request) {
// decode vaultId
auto storedVault = view.GetVault(vaultId);
if (!storedVault)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Vault <%s> does not found", vaultId.GetHex()));
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Vault <%s> not found", vaultId.GetHex()));

if(storedVault->isUnderLiquidation)
throw JSONRPCError(RPC_TRANSACTION_REJECTED, "Vault is under liquidation.");
Expand Down Expand Up @@ -834,7 +834,7 @@ UniValue withdrawfromvault(const JSONRPCRequest& request) {
// decode vaultId
auto vault = view.GetVault(vaultId);
if (!vault)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Vault <%s> does not found", vaultId.GetHex()));
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Vault <%s> not found", vaultId.GetHex()));

ownerAddress = vault->ownerAddress;
targetHeight = view.GetLastHeight() + 1;
Expand Down Expand Up @@ -1285,8 +1285,8 @@ UniValue listvaulthistory(const JSONRPCRequest& request) {
"[{},{}...] (array) Objects with vault history information\n"
},
RPCExamples{
HelpExampleCli("listburnhistory", "84b22eee1964768304e624c416f29a91d78a01dc5e8e12db26bdac0670c67bb2 '{\"maxBlockHeight\":160,\"depth\":10}'")
+ HelpExampleRpc("listburnhistory", "84b22eee1964768304e624c416f29a91d78a01dc5e8e12db26bdac0670c67bb2, '{\"maxBlockHeight\":160,\"depth\":10}'")
HelpExampleCli("listvaulthistory", "84b22eee1964768304e624c416f29a91d78a01dc5e8e12db26bdac0670c67bb2 '{\"maxBlockHeight\":160,\"depth\":10}'")
+ HelpExampleRpc("listvaulthistory", "84b22eee1964768304e624c416f29a91d78a01dc5e8e12db26bdac0670c67bb2, '{\"maxBlockHeight\":160,\"depth\":10}'")
},
}.Check(request);

Expand Down
4 changes: 3 additions & 1 deletion src/test/blockencodings_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static CBlock BuildBlockTestCase() {
uint256 masternodeID = testMasternodeKeys.begin()->first;
uint32_t mintedBlocks(0);
int64_t creationHeight;
int64_t blockHeight;
CKey minterKey;
std::map<uint256, TestMasternodeKeys>::const_iterator pos = testMasternodeKeys.find(masternodeID);
if (pos == testMasternodeKeys.end())
Expand All @@ -59,6 +60,7 @@ static CBlock BuildBlockTestCase() {
creationHeight = int64_t(nodePtr->creationHeight);
}

blockHeight = tip->nHeight + 1;
block.deprecatedHeight = tip->nHeight + 1;
block.mintedBlocks = mintedBlocks + 1;
block.stakeModifier = pos::ComputeStakeModifier(tip->stakeModifier, minterKey.GetPubKey().GetID());
Expand All @@ -80,7 +82,7 @@ static CBlock BuildBlockTestCase() {
block.nTime = 0;
CheckContextState ctxState;

while (!pos::CheckKernelHash(block.stakeModifier, block.nBits, creationHeight, (int64_t) block.nTime, block.deprecatedHeight, masternodeID, Params().GetConsensus(), {0, 0, 0, 0}, 0, ctxState)) block.nTime++;
while (!pos::CheckKernelHash(block.stakeModifier, block.nBits, creationHeight, (int64_t) block.nTime, blockHeight, masternodeID, Params().GetConsensus(), {0, 0, 0, 0}, 0, ctxState)) block.nTime++;

std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>(std::move(block));
auto err = pos::SignPosBlock(pblock, minterKey);
Expand Down
13 changes: 13 additions & 0 deletions test/functional/feature_poolpair.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit be009c8

Please sign in to comment.