From df09d98464feb5b5408852c750e40ab99ff113d3 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Wed, 25 May 2022 12:40:12 +0200 Subject: [PATCH] setcollateraltoken and set/updateloantoken work old way before FCC + 2 height (migration happens on end of FCC +1) --- src/masternodes/mn_checks.cpp | 11 +++--- test/functional/feature_token_split.py | 46 ++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/masternodes/mn_checks.cpp b/src/masternodes/mn_checks.cpp index a89d8acf59..0f6248e143 100644 --- a/src/masternodes/mn_checks.cpp +++ b/src/masternodes/mn_checks.cpp @@ -879,6 +879,9 @@ class CCustomTxVisitor : public boost::static_visitor tokenCurrency = std::move(trimmed); return Res::Ok(); } + bool IsTokensMigratedToGovVar() const { + return static_cast(height) > consensus.FortCanningCrunchHeight + 1; + } }; class CCustomTxApplyVisitor : public CCustomTxVisitor @@ -2308,7 +2311,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor if (!HasFoundationAuth()) return Res::Err("tx not from foundation member!"); - if (height >= static_cast(consensus.FortCanningCrunchHeight)) + if (IsTokensMigratedToGovVar()) { const auto& tokenId = obj.idToken.v; @@ -2410,7 +2413,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor if (!tokenId) return std::move(tokenId); - if (height >= static_cast(consensus.FortCanningCrunchHeight)) + if (IsTokensMigratedToGovVar()) { const auto& id = tokenId.val->v; @@ -2490,7 +2493,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor if (!pair) return Res::Err("Loan token (%s) does not exist!", obj.tokenTx.GetHex()); - auto loanToken = height >= static_cast(consensus.FortCanningCrunchHeight) ? + auto loanToken = IsTokensMigratedToGovVar() ? mnview.GetLoanTokenByID(pair->first) : mnview.GetLoanToken(obj.tokenTx); if (!loanToken) @@ -2515,7 +2518,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor if (!res) return res; - if (height >= static_cast(consensus.FortCanningCrunchHeight)) + if (IsTokensMigratedToGovVar()) { const auto& id = pair->first.v; diff --git a/test/functional/feature_token_split.py b/test/functional/feature_token_split.py index ae643679a3..0126d6bf5f 100755 --- a/test/functional/feature_token_split.py +++ b/test/functional/feature_token_split.py @@ -364,8 +364,41 @@ def check_pool_split(self, pool_id, pool_symbol, token_id, token_symbol, token_s def token_split(self): - # Move to GW - self.nodes[0].generate(151 - self.nodes[0].getblockcount()) + # Move to FCC + self.nodes[0].generate(149 - self.nodes[0].getblockcount()) + + # Mined in 150 height, still using old code + self.nodes[0].updateloantoken(self.idGOOGL, { + 'name': 'AAAA', + 'interest': 1 + }) + + self.nodes[0].generate(1) + + result = self.nodes[0].getgov('ATTRIBUTES')['ATTRIBUTES'] + assert_equal(result, {}) + + token = self.nodes[0].getloantoken(self.idGOOGL) + assert_equal(token['token']['1']['name'], 'AAAA') + assert_equal(token['interest'], Decimal(1)) + + # Mining height 151 - migration of token to gov var + self.nodes[0].generate(1) + + result = self.nodes[0].getgov('ATTRIBUTES')['ATTRIBUTES'] + assert_equal(result[f'v0/token/{self.idGOOGL}/loan_minting_enabled'], 'true') + assert_equal(result[f'v0/token/{self.idGOOGL}/loan_minting_interest'], '1') + assert_equal(result[f'v0/token/{self.idGOOGL}/fixed_interval_price_id'], f"{self.symbolGOOGL}/USD") + + token = self.nodes[0].getloantoken(self.idGOOGL) + assert_equal(token['token']['1']['name'], 'AAAA') + assert_equal(token['interest'], Decimal(1)) + + # Mined in 152 height, using new code + self.nodes[0].updateloantoken(self.idGOOGL, { + 'name': self.symbolGOOGL, + 'interest': 0 + }) # Set extra Gov vars for token self.nodes[0].setgov({"ATTRIBUTES":{f'v0/token/{self.idTSLA}/dfip2203':'true', @@ -377,6 +410,15 @@ def token_split(self): f'v0/token/{self.idTSLA}/loan_payback_fee_pct/{self.idDUSD}': '0.25'}}) self.nodes[0].generate(1) + result = self.nodes[0].getgov('ATTRIBUTES')['ATTRIBUTES'] + assert_equal(result[f'v0/token/{self.idGOOGL}/loan_minting_enabled'], 'true') + assert_equal(result[f'v0/token/{self.idGOOGL}/loan_minting_interest'], '0') + assert_equal(result[f'v0/token/{self.idGOOGL}/fixed_interval_price_id'], f"{self.symbolGOOGL}/USD") + + token = self.nodes[0].getloantoken(self.idGOOGL) + assert_equal(token['token']['1']['name'], self.symbolGOOGL) + assert_equal(token['interest'], Decimal(0)) + # Make sure we cannot make a token with '/' in its symbol assert_raises_rpc_error(-32600, "token symbol should not contain '/'", self.nodes[0].createtoken, { 'symbol': 'bad/v1',