Skip to content

Commit

Permalink
ledger_entry test
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnxie999 committed Oct 15, 2024
1 parent af29f41 commit cbb8d67
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/test/rpc/LedgerRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2361,6 +2361,77 @@ class LedgerRPC_test : public beast::unit_test::suite
}
}

void
testLedgerEntryMPT()
{
testcase("ledger_entry Request MPT");
using namespace test::jtx;
using namespace std::literals::chrono_literals;
Env env{*this};
Account const alice{"alice"};
Account const bob("bob");

MPTTester mptAlice(env, alice, {.holders = {&bob}});
mptAlice.create(
{.transferFee = 10,
.metadata = "123",
.ownerCount = 1,
.flags = tfMPTCanLock | tfMPTRequireAuth | tfMPTCanEscrow |
tfMPTCanTrade | tfMPTCanTransfer | tfMPTCanClawback});
mptAlice.authorize({.account = &bob, .holderCount = 1});

std::string const ledgerHash{to_string(env.closed()->info().hash)};

std::string const badMptID =
"00000193B9DDCAF401B5B3B26875986043F82CD0D13B4315";
{
// Request the MPTIssuance using its MPTIssuanceID.
Json::Value jvParams;
jvParams[jss::mpt_issuance] = strHex(mptAlice.issuanceID());
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
BEAST_EXPECT(
jrr[jss::node][sfMPTokenMetadata.jsonName] ==
strHex(std::string{"123"}));
}
{
// Request an index that is not a MPTIssuance.
Json::Value jvParams;
jvParams[jss::mpt_issuance] = badMptID;
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "entryNotFound", "");
}
{
// Request the MPToken using its owner + mptIssuanceID.
Json::Value jvParams;
jvParams[jss::mptoken] = Json::objectValue;
jvParams[jss::mptoken][jss::account] = bob.human();
jvParams[jss::mptoken][jss::mpt_issuance_id] =
strHex(mptAlice.issuanceID());
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
BEAST_EXPECT(
jrr[jss::node][sfMPTokenIssuanceID.jsonName] ==
strHex(mptAlice.issuanceID()));
}
{
// Request the MPToken using a bad mptIssuanceID.
Json::Value jvParams;
jvParams[jss::mptoken] = Json::objectValue;
jvParams[jss::mptoken][jss::account] = bob.human();
jvParams[jss::mptoken][jss::mpt_issuance_id] = badMptID;
strHex(mptAlice.issuanceID());
jvParams[jss::ledger_hash] = ledgerHash;
Json::Value const jrr = env.rpc(
"json", "ledger_entry", to_string(jvParams))[jss::result];
checkErrorValue(jrr, "entryNotFound", "");
}
}

public:
void
run() override
Expand Down Expand Up @@ -2388,6 +2459,7 @@ class LedgerRPC_test : public beast::unit_test::suite
testLedgerEntryDID();
testInvalidOracleLedgerEntry();
testOracleLedgerEntry();
testLedgerEntryMPT();

forAllApiVersions(std::bind_front(
&LedgerRPC_test::testLedgerEntryInvalidParams, this));
Expand Down

0 comments on commit cbb8d67

Please sign in to comment.