Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make setcollateraltoken and set/updateloantoken work old way before token migration to gov var #1289

Merged
merged 4 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,9 @@ class CCustomTxVisitor : public boost::static_visitor<Res>
tokenCurrency = std::move(trimmed);
return Res::Ok();
}
bool IsTokensMigratedToGovVar() const {
return static_cast<int>(height) > consensus.FortCanningCrunchHeight + 1;
}
};

class CCustomTxApplyVisitor : public CCustomTxVisitor
Expand Down Expand Up @@ -2308,7 +2311,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
if (!HasFoundationAuth())
return Res::Err("tx not from foundation member!");

if (height >= static_cast<uint32_t>(consensus.FortCanningCrunchHeight))
if (height >= static_cast<uint32_t>(consensus.FortCanningCrunchHeight) && IsTokensMigratedToGovVar())
{
const auto& tokenId = obj.idToken.v;

Expand Down Expand Up @@ -2410,7 +2413,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
if (!tokenId)
return std::move(tokenId);

if (height >= static_cast<uint32_t>(consensus.FortCanningCrunchHeight))
if (height >= static_cast<uint32_t>(consensus.FortCanningCrunchHeight) && IsTokensMigratedToGovVar())
{
const auto& id = tokenId.val->v;

Expand Down Expand Up @@ -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<uint32_t>(consensus.FortCanningCrunchHeight) ?
auto loanToken = (height >= static_cast<uint32_t>(consensus.FortCanningCrunchHeight) && IsTokensMigratedToGovVar()) ?
mnview.GetLoanTokenByID(pair->first) : mnview.GetLoanToken(obj.tokenTx);

if (!loanToken)
Expand All @@ -2515,7 +2518,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
if (!res)
return res;

if (height >= static_cast<uint32_t>(consensus.FortCanningCrunchHeight))
if (height >= static_cast<uint32_t>(consensus.FortCanningCrunchHeight) && IsTokensMigratedToGovVar())
{
const auto& id = pair->first.v;

Expand Down
8 changes: 8 additions & 0 deletions test/functional/feature_loan_setcollateraltoken.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ def run_test(self):
# Move to fork height
self.nodes[0].generate(150 - self.nodes[0].getblockcount())

# Check errors on FCC
assert_raises_rpc_error(-32600, "setCollateralToken factor must be lower or equal than 1.00000000", self.nodes[0].setcollateraltoken, {
'token': idDFI,
'factor': 1.01,
'fixedIntervalPriceId': "DFI/USD"})

self.nodes[0].generate(1)

# Check errors
assert_raises_rpc_error(-32600, "Percentage exceeds 100%", self.nodes[0].setcollateraltoken, {
'token': idDFI,
Expand Down
3 changes: 3 additions & 0 deletions test/functional/feature_loan_setloantoken.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ def run_test(self):
# Move to fork height
self.nodes[0].generate(110 - self.nodes[0].getblockcount())

# Move to FCC +1
self.nodes[0].generate(1)

assert_raises_rpc_error(-32600, 'token symbol should be non-empty and starts with a letter', self.nodes[0].setloantoken, {
'symbol': "",
'name': "Google",
Expand Down
Empty file modified test/functional/feature_token_lock.py
100644 → 100755
Empty file.
46 changes: 44 additions & 2 deletions test/functional/feature_token_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down