Skip to content

Commit

Permalink
Review fixes 6
Browse files Browse the repository at this point in the history
  • Loading branch information
oleks-rip committed Dec 10, 2024
1 parent 77c9e45 commit 2050f0e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
46 changes: 27 additions & 19 deletions src/test/jtx/impl/permissioned_domains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ setTx(
std::optional<uint256> domain)
{
Json::Value jv;
jv[sfTransactionType.jsonName] = jss::PermissionedDomainSet;
jv[sfAccount.jsonName] = to_string(account);
jv[sfTransactionType] = jss::PermissionedDomainSet;
jv[sfAccount] = to_string(account);
if (domain)
jv[sfDomainID.jsonName] = to_string(*domain);
Json::Value a(Json::arrayValue);
jv[sfDomainID] = to_string(*domain);
Json::Value credentials2(Json::arrayValue);
for (auto const& credential : credentials)
{
Json::Value obj(Json::objectValue);
obj[sfCredential.jsonName] = credential.toJson();
a.append(std::move(obj));
Json::Value object(Json::objectValue);
object[sfCredential] = credential.toJson();
credentials2.append(std::move(object));
}
jv[sfAcceptedCredentials.jsonName] = a;
jv[sfAcceptedCredentials] = credentials2;
return jv;
}

Expand All @@ -54,9 +54,9 @@ Json::Value
deleteTx(AccountID const& account, uint256 const& domain)
{
Json::Value jv{Json::objectValue};
jv[sfTransactionType.jsonName] = jss::PermissionedDomainDelete;
jv[sfAccount.jsonName] = to_string(account);
jv[sfDomainID.jsonName] = to_string(domain);
jv[sfTransactionType] = jss::PermissionedDomainDelete;
jv[sfAccount] = to_string(account);
jv[sfDomainID] = to_string(domain);
return jv;
}

Expand All @@ -70,12 +70,20 @@ getObjects(Account const& account, Env& env, bool withType)
if (withType)
params[jss::type] = jss::permissioned_domain;
auto const& resp = env.rpc("json", "account_objects", to_string(params));
Json::Value a(Json::arrayValue);
a = resp[jss::result][jss::account_objects];
for (auto const& object : a)
Json::Value objects(Json::arrayValue);
objects = resp[jss::result][jss::account_objects];
for (auto const& object : objects)
{
if (object["LedgerEntryType"] != "PermissionedDomain")
{
if (withType)
{ // impossible to get there
Throw<std::runtime_error>(
"Invalid object type: " +
object["LedgerEntryType"].asString()); // LCOV_EXCL_LINE
}
continue;
}
uint256 index;
std::ignore = index.parseHex(object[jss::index].asString());
ret[index] = object;
Expand Down Expand Up @@ -106,9 +114,9 @@ credentialsFromJson(
std::unordered_map<std::string, Account> const& pubKey2Acc)
{
Credentials ret;
Json::Value a(Json::arrayValue);
a = object["AcceptedCredentials"];
for (auto const& credential : a)
Json::Value credentials(Json::arrayValue);
credentials = object["AcceptedCredentials"];
for (auto const& credential : credentials)
{
Json::Value obj(Json::objectValue);
obj = credential[jss::Credential];
Expand All @@ -128,8 +136,8 @@ Credentials
sortCredentials(Credentials const& input)
{
std::set<Credential> credentialsSet;
for (auto const& c : input)
credentialsSet.insert(c);
for (auto const& credential : input)
credentialsSet.insert(credential);
return {credentialsSet.begin(), credentialsSet.end()};
}

Expand Down
20 changes: 12 additions & 8 deletions src/test/ledger/Invariants_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ class Invariants_test : public beast::unit_test::suite
testPermissionedDomainInvariants()
{
using namespace test::jtx;

testcase << "PermissionedDomain";
doInvariantCheck(
{{"permissioned domain with no rules."}},
Expand All @@ -819,16 +820,19 @@ class Invariants_test : public beast::unit_test::suite
{tecINVARIANT_FAILED, tecINVARIANT_FAILED});

testcase << "PermissionedDomain 2";

auto constexpr tooBig = maxPermissionedDomainCredentialsArraySize + 1;
doInvariantCheck(
{{"permissioned domain bad credentials size 11"}},
[](Account const& A1, Account const& A2, ApplyContext& ac) {
{{std::format(
"permissioned domain bad credentials size {}", tooBig)}},
[tooBig](Account const& A1, Account const& A2, ApplyContext& ac) {
Keylet const pdKeylet = keylet::permissionedDomain(A1.id(), 10);
auto slePd = std::make_shared<SLE>(pdKeylet);
slePd->setAccountID(sfOwner, A1);
slePd->setFieldU32(sfSequence, 10);

STArray credentials(sfAcceptedCredentials, 11);
for (std::size_t n = 0; n < 11; ++n)
STArray credentials(sfAcceptedCredentials, tooBig);
for (std::size_t n = 0; n < tooBig; ++n)
{
auto cred = STObject::makeInnerObject(sfCredential);
cred.setAccountID(sfIssuer, A2);
Expand All @@ -844,7 +848,7 @@ class Invariants_test : public beast::unit_test::suite
return true;
},
XRPAmount{},
STTx{ttPERMISSIONED_DOMAIN_SET, [](STObject& tx) {}},
STTx{ttPERMISSIONED_DOMAIN_SET, [](STObject&) {}},
{tecINVARIANT_FAILED, tecINVARIANT_FAILED});

testcase << "PermissionedDomain 3";
Expand All @@ -856,7 +860,7 @@ class Invariants_test : public beast::unit_test::suite
slePd->setAccountID(sfOwner, A1);
slePd->setFieldU32(sfSequence, 10);

STArray credentials(sfAcceptedCredentials, 11);
STArray credentials(sfAcceptedCredentials, 2);
for (std::size_t n = 0; n < 2; ++n)
{
auto cred = STObject::makeInnerObject(sfCredential);
Expand All @@ -873,7 +877,7 @@ class Invariants_test : public beast::unit_test::suite
return true;
},
XRPAmount{},
STTx{ttPERMISSIONED_DOMAIN_SET, [](STObject& tx) {}},
STTx{ttPERMISSIONED_DOMAIN_SET, [](STObject&) {}},
{tecINVARIANT_FAILED, tecINVARIANT_FAILED});

testcase << "PermissionedDomain 4";
Expand All @@ -885,7 +889,7 @@ class Invariants_test : public beast::unit_test::suite
slePd->setAccountID(sfOwner, A1);
slePd->setFieldU32(sfSequence, 10);

STArray credentials(sfAcceptedCredentials, 11);
STArray credentials(sfAcceptedCredentials, 2);
for (std::size_t n = 0; n < 2; ++n)
{
auto cred = STObject::makeInnerObject(sfCredential);
Expand Down

0 comments on commit 2050f0e

Please sign in to comment.