mirror of
https://github.com/XRPLF/rippled.git
synced 2026-09-27 15:28:03 +00:00
Start writing tests for LoanBrokerCover*
This commit is contained in:
@@ -185,6 +185,16 @@ class LoanBroker_test : public beast::unit_test::suite
|
||||
BEAST_EXPECT(pseudo->at(sfLoanBrokerID) == keylet.key);
|
||||
}
|
||||
|
||||
// Test Cover funding before allowing alterations
|
||||
env(coverDeposit(alice, uint256(0), vault.asset(10)),
|
||||
ter(temINVALID));
|
||||
env(coverDeposit(alice, uint256(0), vault.asset(-10)),
|
||||
ter(temBAD_AMOUNT));
|
||||
env(coverDeposit(evan, keylet.key, vault.asset(10)),
|
||||
ter(tecNO_PERMISSION));
|
||||
env(coverDeposit(alice, vault.vaultID, vault.asset(10)),
|
||||
ter(tecNO_ENTRY));
|
||||
|
||||
// no-op
|
||||
env(set(alice, vault.vaultID), loanBrokerID(keylet.key));
|
||||
|
||||
@@ -255,16 +265,19 @@ class LoanBroker_test : public beast::unit_test::suite
|
||||
// Evan will attempt to be naughty
|
||||
Account evan{"evan"};
|
||||
Vault vault{env};
|
||||
env.fund(XRP(100000), issuer, noripple(alice, evan));
|
||||
|
||||
// Fund the accounts and trust lines with the same amount so that tests
|
||||
// can use the same values regardless of the asset.
|
||||
env.fund(XRP(100'000), issuer, noripple(alice, evan));
|
||||
env.close();
|
||||
|
||||
// Create assets
|
||||
PrettyAsset const xrpAsset{xrpIssue(), 1'000'000};
|
||||
PrettyAsset const iouAsset = issuer["IOU"];
|
||||
env(trust(alice, iouAsset(1000)));
|
||||
env(trust(evan, iouAsset(1000)));
|
||||
env(pay(issuer, evan, iouAsset(1000)));
|
||||
env(pay(issuer, alice, iouAsset(1000)));
|
||||
env(trust(alice, iouAsset(1'000'000)));
|
||||
env(trust(evan, iouAsset(1'000'000)));
|
||||
env(pay(issuer, evan, iouAsset(100'000)));
|
||||
env(pay(issuer, alice, iouAsset(100'000)));
|
||||
env.close();
|
||||
|
||||
MPTTester mptt{env, issuer, mptInitNoFund};
|
||||
@@ -273,8 +286,8 @@ class LoanBroker_test : public beast::unit_test::suite
|
||||
PrettyAsset const mptAsset = mptt.issuanceID();
|
||||
mptt.authorize({.account = alice});
|
||||
mptt.authorize({.account = evan});
|
||||
env(pay(issuer, alice, mptAsset(1000)));
|
||||
env(pay(issuer, evan, mptAsset(1000)));
|
||||
env(pay(issuer, alice, mptAsset(100'000)));
|
||||
env(pay(issuer, evan, mptAsset(100'000)));
|
||||
env.close();
|
||||
|
||||
std::array const assets{xrpAsset, iouAsset, mptAsset};
|
||||
|
||||
@@ -609,6 +609,20 @@ set(AccountID const& account, uint256 const& vaultId, uint32_t flags = 0);
|
||||
Json::Value
|
||||
del(AccountID const& account, uint256 const& loanBrokerID, uint32_t flags = 0);
|
||||
|
||||
Json::Value
|
||||
coverDeposit(
|
||||
AccountID const& account,
|
||||
uint256 const& loanBrokerID,
|
||||
STAmount const& amount,
|
||||
uint32_t flags = 0);
|
||||
|
||||
Json::Value
|
||||
coverWithdraw(
|
||||
AccountID const& account,
|
||||
uint256 const& loanBrokerID,
|
||||
STAmount const& amount,
|
||||
uint32_t flags = 0);
|
||||
|
||||
auto const loanBrokerID = JTxFieldWrapper<uint256Field>(sfLoanBrokerID);
|
||||
|
||||
auto const data = JTxFieldWrapper<blobField>(sfData);
|
||||
|
||||
@@ -398,10 +398,10 @@ Json::Value
|
||||
set(AccountID const& account, uint256 const& vaultId, uint32_t flags)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[sfTransactionType.jsonName] = jss::LoanBrokerSet;
|
||||
jv[sfAccount.jsonName] = to_string(account);
|
||||
jv[sfVaultID.jsonName] = to_string(vaultId);
|
||||
jv[sfFlags.jsonName] = flags;
|
||||
jv[sfTransactionType] = jss::LoanBrokerSet;
|
||||
jv[sfAccount] = to_string(account);
|
||||
jv[sfVaultID] = to_string(vaultId);
|
||||
jv[sfFlags] = flags;
|
||||
return jv;
|
||||
}
|
||||
|
||||
@@ -409,10 +409,42 @@ Json::Value
|
||||
del(AccountID const& account, uint256 const& loanBrokerID, uint32_t flags)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[sfTransactionType.jsonName] = jss::LoanBrokerDelete;
|
||||
jv[sfAccount.jsonName] = to_string(account);
|
||||
jv[sfLoanBrokerID.jsonName] = to_string(loanBrokerID);
|
||||
jv[sfFlags.jsonName] = flags;
|
||||
jv[sfTransactionType] = jss::LoanBrokerDelete;
|
||||
jv[sfAccount] = to_string(account);
|
||||
jv[sfLoanBrokerID] = to_string(loanBrokerID);
|
||||
jv[sfFlags] = flags;
|
||||
return jv;
|
||||
}
|
||||
|
||||
Json::Value
|
||||
coverDeposit(
|
||||
AccountID const& account,
|
||||
uint256 const& loanBrokerID,
|
||||
STAmount const& amount,
|
||||
uint32_t flags)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[sfTransactionType] = jss::LoanBrokerCoverDeposit;
|
||||
jv[sfAccount] = to_string(account);
|
||||
jv[sfLoanBrokerID] = to_string(loanBrokerID);
|
||||
jv[sfAmount] = amount.getJson(JsonOptions::none);
|
||||
jv[sfFlags] = flags;
|
||||
return jv;
|
||||
}
|
||||
|
||||
Json::Value
|
||||
coverWithdraw(
|
||||
AccountID const& account,
|
||||
uint256 const& loanBrokerID,
|
||||
STAmount const& amount,
|
||||
uint32_t flags)
|
||||
{
|
||||
Json::Value jv;
|
||||
jv[sfTransactionType] = jss::LoanBrokerCoverWithdraw;
|
||||
jv[sfAccount] = to_string(account);
|
||||
jv[sfLoanBrokerID] = to_string(loanBrokerID);
|
||||
jv[sfAmount] = amount.getJson(JsonOptions::none);
|
||||
jv[sfFlags] = flags;
|
||||
return jv;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user