Skip to content

Commit

Permalink
setcollateraltoken and set/updateloantoken work old way before FCC + …
Browse files Browse the repository at this point in the history
…2 height (migration happens on end of FCC +1)
  • Loading branch information
Mixa84 committed May 25, 2022
1 parent d229e92 commit df09d98
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
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 (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 (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 = 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 (IsTokensMigratedToGovVar())
{
const auto& id = pair->first.v;

Expand Down
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

0 comments on commit df09d98

Please sign in to comment.