diff --git a/src/masternodes/mn_checks.cpp b/src/masternodes/mn_checks.cpp index 5b5458c56eb..0e4c41b7f22 100644 --- a/src/masternodes/mn_checks.cpp +++ b/src/masternodes/mn_checks.cpp @@ -4436,7 +4436,11 @@ Res CPoolSwap::ExecuteSwap(CCustomCSView& view, std::vector poolIDs, boo intermediateView.Flush(); auto& addView = lastSwap ? view : intermediateView; - res = addView.AddBalance(lastSwap ? obj.to : obj.from, swapAmountResult); + if (height >= static_cast(Params().GetConsensus().GrandCentralHeight)) { + res = addView.AddBalance(lastSwap ? (obj.to.empty() ? obj.from : obj.to) : obj.from, swapAmountResult); + } else { + res = addView.AddBalance(lastSwap ? obj.to : obj.from, swapAmountResult); + } if (!res) { return res; } diff --git a/test/functional/feature_poolswap.py b/test/functional/feature_poolswap.py old mode 100755 new mode 100644 index 30f1d6283b2..19ef7080dad --- a/test/functional/feature_poolswap.py +++ b/test/functional/feature_poolswap.py @@ -26,9 +26,9 @@ def set_test_params(self): # node0: main (Foundation) self.setup_clean_chain = True self.extra_args = [ - ['-txnotokens=0', '-amkheight=50', '-bayfrontheight=50', '-bayfrontgardensheight=0', '-dakotaheight=160', '-fortcanningheight=163', '-fortcanninghillheight=170', '-fortcanningroadheight=177', '-acindex=1', '-dexstats'], - ['-txnotokens=0', '-amkheight=50', '-bayfrontheight=50', '-bayfrontgardensheight=0', '-dakotaheight=160', '-fortcanningheight=163', '-fortcanninghillheight=170', '-fortcanningroadheight=177', '-acindex=1', '-dexstats'], - ['-txnotokens=0', '-amkheight=50', '-bayfrontheight=50', '-bayfrontgardensheight=0', '-dakotaheight=160', '-fortcanningheight=163', '-fortcanninghillheight=170', '-fortcanningroadheight=177', '-dexstats']] + ['-txnotokens=0', '-amkheight=50', '-bayfrontheight=50', '-bayfrontgardensheight=0', '-dakotaheight=160', '-fortcanningheight=163', '-fortcanninghillheight=170', '-fortcanningroadheight=177', '-grandcentralheight=200', '-acindex=1', '-dexstats'], + ['-txnotokens=0', '-amkheight=50', '-bayfrontheight=50', '-bayfrontgardensheight=0', '-dakotaheight=160', '-fortcanningheight=163', '-fortcanninghillheight=170', '-fortcanningroadheight=177', '-grandcentralheight=200', '-acindex=1', '-dexstats'], + ['-txnotokens=0', '-amkheight=50', '-bayfrontheight=50', '-bayfrontgardensheight=0', '-dakotaheight=160', '-fortcanningheight=163', '-fortcanninghillheight=170', '-fortcanningroadheight=177', '-grandcentralheight=200', '-dexstats']] def setup(self): assert_equal(len(self.nodes[0].listtokens()), 1) # only one token == DFI @@ -311,20 +311,24 @@ def test_fort_canning_max_price_one_satoshi_below(self): assert("Price is higher than indicated" in errorString) def setup_new_pool_BTC_LTC(self): + + self.symbolBTC = "BTC" + self.symbolLTC = "LTC" + self.nodes[0].createtoken({ - "symbol": "BTC", - "name": "Bitcoin", - "collateralAddress": self.accountGN0 + "symbol": self.symbolBTC, + "name": self.symbolBTC, + "collateralAddress": self.accountGN0, + "isDAT" : True }) self.nodes[0].createtoken({ - "symbol": "LTC", - "name": "Litecoin", - "collateralAddress": self.accountGN0 + "symbol": self.symbolLTC, + "name": self.symbolLTC, + "collateralAddress": self.accountGN0, + "isDAT" : True }) self.nodes[0].generate(1) - self.symbolBTC = "BTC#" + self.get_id_token("BTC") - self.symbolLTC = "LTC#" + self.get_id_token("LTC") self.idBTC = list(self.nodes[0].gettoken(self.symbolBTC).keys())[0] self.idLTC = list(self.nodes[0].gettoken(self.symbolLTC).keys())[0] @@ -528,6 +532,28 @@ def update_comission_and_fee_to_1pct_pool2(self): assert_equal(attributes['v0/live/economy/dex/%s/fee_burn_b'%(self.idBL)], round(dexinfee, 8)) assert_equal(attributes['v0/live/economy/dex/%s/fee_burn_a'%(self.idBL)], Decimal(str(round(dexoutfee, 8)))) + def test_swap_to_self(self): + + # Move to fork + self.nodes[0].generate(200 - self.nodes[0].getblockcount()) + + # Get and fund new address + address = self.nodes[0].getnewaddress() + self.nodes[0].accounttoaccount(self.accountGN0, {address: f"1@{self.symbolLTC}"}) + self.nodes[0].generate(1) + + # Swap to self + self.nodes[0].poolswap({ + "from": address, + "tokenFrom": self.symbolLTC, + "amountFrom": 1, + "tokenTo": self.symbolBTC + }) + self.nodes[0].generate(1) + + # Check that LTC has gone and only BTC is present + assert_equal(self.nodes[0].getaccount(address), [f'0.00759157@{self.symbolBTC}']) + def test_testpoolswap_errors(self): assert_raises_rpc_error(-8, "tokenFrom is empty", self.nodes[0].testpoolswap, { "amountFrom": 0.1, "tokenFrom": "", "tokenTo": self.symbolBTC, "from": self.accountGN0, "to": self.accountSN1, "maxPrice": 0.1}) @@ -564,6 +590,7 @@ def run_test(self): self.update_comission_and_fee_to_1pct_pool1() self.update_comission_and_fee_to_1pct_pool2() self.test_testpoolswap_errors() + self.test_swap_to_self() self.revert_to_initial_state() if __name__ == '__main__':