Skip to content

Commit

Permalink
Add 'composite' path option in testpoolswap
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo committed Mar 2, 2022
1 parent 20f7ed2 commit 8c38863
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/masternodes/rpc_poolpair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ UniValue testpoolswap(const JSONRPCRequest& request) {
"One of auto/direct (default = direct)\n"
"auto - automatically use composite swap or direct swap as needed.\n"
"direct - uses direct path only or fails.\n"
"composite - uses composite path only or fails.\n"
"Note: The default will be switched to auto in the upcoming versions."
},
{
Expand Down Expand Up @@ -1051,7 +1052,7 @@ UniValue testpoolswap(const JSONRPCRequest& request) {
int targetHeight = ::ChainActive().Height() + 1;

auto poolPair = mnview_dummy.GetPoolPair(poolSwapMsg.idTokenFrom, poolSwapMsg.idTokenTo);
if (poolPair) path = "direct";
if (poolPair && path == "auto") path = "direct";

// If no direct swap found search for composite swap
if (path == "direct") {
Expand Down Expand Up @@ -1089,7 +1090,7 @@ UniValue testpoolswap(const JSONRPCRequest& request) {
auto compositeSwap = CPoolSwap(poolSwapMsg, targetHeight);

std::vector<DCT_ID> poolIds;
if (path == "auto") {
if (path == "auto" || path == "composite") {
poolIds = compositeSwap.CalculateSwaps(mnview_dummy, true);
} else {
path = "custom";
Expand Down
24 changes: 24 additions & 0 deletions test/functional/feature_poolswap_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,30 @@ def run_test(self):
assert_equal(estimateCompositePathsResAuto['path'], "direct")
assert_equal(estimateCompositePathsResDirect, estimateCompositePathsResAuto)

estimateCompositePathsResComposite = self.nodes[0].testpoolswap({
"from": source,
"tokenFrom": symbolLTC,
"amountFrom": 1,
"to": destination,
"tokenTo": symbolDFI,
}, "composite", True)

assert_equal(estimateCompositePathsResComposite['path'], "composite")

poolLTC_USDC = list(self.nodes[0].getpoolpair("LTC-USDC").keys())[0]
poolDOGE_USDC = list(self.nodes[0].getpoolpair("DOGE-USDC").keys())[0]
poolDOGE_DFI = list(self.nodes[0].getpoolpair("DOGE-DFI").keys())[0]
assert_equal(estimateCompositePathsResComposite['pools'], [poolLTC_USDC, poolDOGE_USDC, poolDOGE_DFI])

assert_raises_rpc_error(-32600, "Cannot find usable pool pair.", self.nodes[0].testpoolswap,
{
"from": source,
"tokenFrom": symbolDUSD,
"amountFrom": 100,
"to": destination,
"tokenTo": symbolDFI,
}, "composite")

assert_raises_rpc_error(-32600, "Custom pool path is invalid.", self.nodes[0].testpoolswap,
{
"from": source,
Expand Down

0 comments on commit 8c38863

Please sign in to comment.