Account_info add flags (#812)

Fixes #768
This commit is contained in:
cyan317
2023-08-04 16:22:39 +01:00
committed by GitHub
parent 4d42cb3cdb
commit d61d702ccd
10 changed files with 364 additions and 73 deletions

View File

@@ -0,0 +1,32 @@
//------------------------------------------------------------------------------
/*
This file is part of clio: https://github.com/XRPLF/clio
Copyright (c) 2023, the clio developers.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <rpc/Amendments.h>
#include <gtest/gtest.h>
using namespace RPC;
TEST(RPCAmendmentsTest, GenerateAmendmentId)
{
// https://xrpl.org/known-amendments.html#disallowincoming refer to the published id
EXPECT_EQ(
ripple::uint256("47C3002ABA31628447E8E9A8B315FAA935CE30183F9A9B86845E469CA2CDC3DF"),
Amendments::GetAmendmentId("DisallowIncoming"));
}

View File

@@ -22,6 +22,7 @@
#include <util/Fixtures.h>
#include <util/TestObject.h>
#include <ripple/protocol/digest.h>
#include <fmt/core.h>
using namespace RPC;
@@ -126,8 +127,8 @@ TEST_F(RPCAccountInfoHandlerTest, LedgerNonExistViaIntSequence)
auto const static input = boost::json::parse(fmt::format(
R"({{
"account":"{}",
"ledger_index":30
"account": "{}",
"ledger_index": 30
}})",
ACCOUNT));
auto const handler = AnyHandler{AccountInfoHandler{mockBackendPtr}};
@@ -151,8 +152,8 @@ TEST_F(RPCAccountInfoHandlerTest, LedgerNonExistViaStringSequence)
auto const static input = boost::json::parse(fmt::format(
R"({{
"account":"{}",
"ledger_index":"30"
"account": "{}",
"ledger_index": "30"
}})",
ACCOUNT));
auto const handler = AnyHandler{AccountInfoHandler{mockBackendPtr}};
@@ -177,8 +178,8 @@ TEST_F(RPCAccountInfoHandlerTest, LedgerNonExistViaHash)
auto const static input = boost::json::parse(fmt::format(
R"({{
"account":"{}",
"ledger_hash":"{}"
"account": "{}",
"ledger_hash": "{}"
}})",
ACCOUNT,
LEDGERHASH));
@@ -206,7 +207,7 @@ TEST_F(RPCAccountInfoHandlerTest, AccountNotExist)
auto const static input = boost::json::parse(fmt::format(
R"({{
"account":"{}"
"account": "{}"
}})",
ACCOUNT));
auto const handler = AnyHandler{AccountInfoHandler{mockBackendPtr}};
@@ -234,7 +235,7 @@ TEST_F(RPCAccountInfoHandlerTest, AccountInvalid)
auto const static input = boost::json::parse(fmt::format(
R"({{
"account":"{}"
"account": "{}"
}})",
ACCOUNT));
auto const handler = AnyHandler{AccountInfoHandler{mockBackendPtr}};
@@ -264,12 +265,14 @@ TEST_F(RPCAccountInfoHandlerTest, SignerListsInvalid)
auto signersKey = ripple::keylet::signers(account).key;
ON_CALL(*rawBackendPtr, doFetchLedgerObject(signersKey, 30, _))
.WillByDefault(Return(CreateFeeSettingBlob(1, 2, 3, 4, 0)));
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::amendments().key, 30, _))
.WillByDefault(Return(CreateAmendmentsObject({}).getSerializer().peekData()));
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(4);
auto const static input = boost::json::parse(fmt::format(
R"({{
"account":"{}",
"signer_lists":true
"account": "{}",
"signer_lists": true
}})",
ACCOUNT));
auto const handler = AnyHandler{AccountInfoHandler{mockBackendPtr}};
@@ -286,46 +289,46 @@ TEST_F(RPCAccountInfoHandlerTest, SignerListsTrue)
{
auto const expectedOutput = fmt::format(
R"({{
"account_data":{{
"Account":"{}",
"Balance":"200",
"Flags":0,
"LedgerEntryType":"AccountRoot",
"OwnerCount":2,
"PreviousTxnID":"{}",
"PreviousTxnLgrSeq":2,
"Sequence":2,
"TransferRate":0,
"index":"13F1A95D7AAB7108D5CE7EEAF504B2894B8C674E6D68499076441C4837282BF8"
"account_data": {{
"Account": "{}",
"Balance": "200",
"Flags": 0,
"LedgerEntryType": "AccountRoot",
"OwnerCount": 2,
"PreviousTxnID": "{}",
"PreviousTxnLgrSeq": 2,
"Sequence": 2,
"TransferRate": 0,
"index": "13F1A95D7AAB7108D5CE7EEAF504B2894B8C674E6D68499076441C4837282BF8"
}},
"signer_lists":
[
{{
"Flags":0,
"LedgerEntryType":"SignerList",
"OwnerNode":"0",
"PreviousTxnID":"0000000000000000000000000000000000000000000000000000000000000000",
"PreviousTxnLgrSeq":0,
"Flags": 0,
"LedgerEntryType": "SignerList",
"OwnerNode": "0",
"PreviousTxnID": "0000000000000000000000000000000000000000000000000000000000000000",
"PreviousTxnLgrSeq": 0,
"SignerEntries":
[
{{
"SignerEntry":
{{
"Account":"{}",
"SignerWeight":1
"Account": "{}",
"SignerWeight": 1
}}
}},
{{
"SignerEntry":
{{
"Account":"{}",
"SignerWeight":1
"Account": "{}",
"SignerWeight": 1
}}
}}
],
"SignerListID":0,
"SignerQuorum":2,
"index":"A9C28A28B85CD533217F5C0A0C7767666B093FA58A0F2D80026FCC4CD932DDC7"
"SignerListID": 0,
"SignerQuorum": 2,
"index": "A9C28A28B85CD533217F5C0A0C7767666B093FA58A0F2D80026FCC4CD932DDC7"
}}
],
"account_flags": {{
@@ -339,9 +342,9 @@ TEST_F(RPCAccountInfoHandlerTest, SignerListsTrue)
"requireAuthorization": false,
"requireDestinationTag": false
}},
"ledger_hash":"{}",
"ledger_index":30,
"validated":true
"ledger_hash": "{}",
"ledger_index": 30,
"validated": true
}})",
ACCOUNT,
INDEX1,
@@ -363,12 +366,14 @@ TEST_F(RPCAccountInfoHandlerTest, SignerListsTrue)
auto signersKey = ripple::keylet::signers(account).key;
ON_CALL(*rawBackendPtr, doFetchLedgerObject(signersKey, 30, _))
.WillByDefault(Return(CreateSignerLists({{ACCOUNT1, 1}, {ACCOUNT2, 1}}).getSerializer().peekData()));
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(2);
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::amendments().key, 30, _))
.WillByDefault(Return(CreateAmendmentsObject({}).getSerializer().peekData()));
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(4);
auto const static input = boost::json::parse(fmt::format(
R"({{
"account":"{}",
"signer_lists":true
"account": "{}",
"signer_lists": true
}})",
ACCOUNT));
auto const handler = AnyHandler{AccountInfoHandler{mockBackendPtr}};
@@ -383,17 +388,17 @@ TEST_F(RPCAccountInfoHandlerTest, Flags)
{
auto const expectedOutput = fmt::format(
R"({{
"account_data":{{
"Account":"{}",
"Balance":"200",
"Flags":33488896,
"LedgerEntryType":"AccountRoot",
"OwnerCount":2,
"PreviousTxnID":"{}",
"PreviousTxnLgrSeq":2,
"Sequence":2,
"TransferRate":0,
"index":"13F1A95D7AAB7108D5CE7EEAF504B2894B8C674E6D68499076441C4837282BF8"
"account_data": {{
"Account": "{}",
"Balance": "200",
"Flags": 33488896,
"LedgerEntryType": "AccountRoot",
"OwnerCount": 2,
"PreviousTxnID": "{}",
"PreviousTxnLgrSeq": 2,
"Sequence": 2,
"TransferRate": 0,
"index": "13F1A95D7AAB7108D5CE7EEAF504B2894B8C674E6D68499076441C4837282BF8"
}},
"account_flags": {{
"defaultRipple": true,
@@ -406,9 +411,9 @@ TEST_F(RPCAccountInfoHandlerTest, Flags)
"requireAuthorization": true,
"requireDestinationTag": true
}},
"ledger_hash":"{}",
"ledger_index":30,
"validated":true
"ledger_hash": "{}",
"ledger_index": 30,
"validated": true
}})",
ACCOUNT,
INDEX1,
@@ -434,11 +439,13 @@ TEST_F(RPCAccountInfoHandlerTest, Flags)
2);
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, 30, _))
.WillByDefault(Return(accountRoot.getSerializer().peekData()));
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(1);
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::amendments().key, 30, _))
.WillByDefault(Return(CreateAmendmentsObject({}).getSerializer().peekData()));
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(3);
auto const static input = boost::json::parse(fmt::format(
R"({{
"account":"{}"
"account": "{}"
}})",
ACCOUNT));
auto const handler = AnyHandler{AccountInfoHandler{mockBackendPtr}};
@@ -463,11 +470,13 @@ TEST_F(RPCAccountInfoHandlerTest, IdentAndSignerListsFalse)
auto const accountRoot = CreateAccountRootObject(ACCOUNT, 0, 2, 200, 2, INDEX1, 2);
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, 30, _))
.WillByDefault(Return(accountRoot.getSerializer().peekData()));
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(1);
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::amendments().key, 30, _))
.WillByDefault(Return(CreateAmendmentsObject({}).getSerializer().peekData()));
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(3);
auto const static input = boost::json::parse(fmt::format(
R"({{
"ident":"{}"
"ident": "{}"
}})",
ACCOUNT));
auto const handler = AnyHandler{AccountInfoHandler{mockBackendPtr}};
@@ -477,3 +486,153 @@ TEST_F(RPCAccountInfoHandlerTest, IdentAndSignerListsFalse)
EXPECT_FALSE(output->as_object().contains("signer_lists"));
});
}
TEST_F(RPCAccountInfoHandlerTest, DisallowIncoming)
{
auto const expectedOutput = fmt::format(
R"({{
"account_data": {{
"Account": "{}",
"Balance": "200",
"Flags": 1040121856,
"LedgerEntryType": "AccountRoot",
"OwnerCount": 2,
"PreviousTxnID": "{}",
"PreviousTxnLgrSeq": 2,
"Sequence": 2,
"TransferRate": 0,
"index": "13F1A95D7AAB7108D5CE7EEAF504B2894B8C674E6D68499076441C4837282BF8"
}},
"account_flags": {{
"defaultRipple": true,
"depositAuth": true,
"disableMasterKey": true,
"disallowIncomingXRP": true,
"globalFreeze": true,
"noFreeze": true,
"passwordSpent": true,
"requireAuthorization": true,
"requireDestinationTag": true,
"disallowIncomingCheck": true,
"disallowIncomingNFTokenOffer": true,
"disallowIncomingPayChan": true,
"disallowIncomingTrustline": true
}},
"ledger_hash": "{}",
"ledger_index": 30,
"validated": true
}})",
ACCOUNT,
INDEX1,
LEDGERHASH);
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
mockBackendPtr->updateRange(10); // min
mockBackendPtr->updateRange(30); // max
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
auto const account = GetAccountIDWithString(ACCOUNT);
auto const accountKk = ripple::keylet::account(account).key;
auto const accountRoot = CreateAccountRootObject(
ACCOUNT,
ripple::lsfDefaultRipple | ripple::lsfGlobalFreeze | ripple::lsfRequireDestTag | ripple::lsfRequireAuth |
ripple::lsfDepositAuth | ripple::lsfDisableMaster | ripple::lsfDisallowXRP | ripple::lsfNoFreeze |
ripple::lsfPasswordSpent | ripple::lsfDisallowIncomingNFTokenOffer | ripple::lsfDisallowIncomingCheck |
ripple::lsfDisallowIncomingPayChan | ripple::lsfDisallowIncomingTrustline,
2,
200,
2,
INDEX1,
2);
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, 30, _))
.WillByDefault(Return(accountRoot.getSerializer().peekData()));
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::amendments().key, 30, _))
.WillByDefault(Return(CreateAmendmentsObject({RPC::Amendments::DisallowIncoming}).getSerializer().peekData()));
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(3);
auto const static input = boost::json::parse(fmt::format(
R"({{
"account": "{}"
}})",
ACCOUNT));
auto const handler = AnyHandler{AccountInfoHandler{mockBackendPtr}};
runSpawn([&](auto yield) {
auto const output = handler.process(input, Context{yield});
ASSERT_TRUE(output);
EXPECT_EQ(*output, json::parse(expectedOutput));
});
}
TEST_F(RPCAccountInfoHandlerTest, Clawback)
{
auto const expectedOutput = fmt::format(
R"({{
"account_data": {{
"Account": "{}",
"Balance": "200",
"Flags": 2180972544,
"LedgerEntryType": "AccountRoot",
"OwnerCount": 2,
"PreviousTxnID": "{}",
"PreviousTxnLgrSeq": 2,
"Sequence": 2,
"TransferRate": 0,
"index": "13F1A95D7AAB7108D5CE7EEAF504B2894B8C674E6D68499076441C4837282BF8"
}},
"account_flags": {{
"defaultRipple": true,
"depositAuth": true,
"disableMasterKey": true,
"disallowIncomingXRP": true,
"globalFreeze": true,
"noFreeze": true,
"passwordSpent": true,
"requireAuthorization": true,
"requireDestinationTag": true,
"allowTrustLineClawback": true
}},
"ledger_hash": "{}",
"ledger_index": 30,
"validated": true
}})",
ACCOUNT,
INDEX1,
LEDGERHASH);
auto const rawBackendPtr = static_cast<MockBackend*>(mockBackendPtr.get());
mockBackendPtr->updateRange(10); // min
mockBackendPtr->updateRange(30); // max
auto const ledgerinfo = CreateLedgerInfo(LEDGERHASH, 30);
EXPECT_CALL(*rawBackendPtr, fetchLedgerBySequence).Times(1);
ON_CALL(*rawBackendPtr, fetchLedgerBySequence).WillByDefault(Return(ledgerinfo));
auto const account = GetAccountIDWithString(ACCOUNT);
auto const accountKk = ripple::keylet::account(account).key;
auto const accountRoot = CreateAccountRootObject(
ACCOUNT,
ripple::lsfDefaultRipple | ripple::lsfGlobalFreeze | ripple::lsfRequireDestTag | ripple::lsfRequireAuth |
ripple::lsfDepositAuth | ripple::lsfDisableMaster | ripple::lsfDisallowXRP | ripple::lsfNoFreeze |
ripple::lsfPasswordSpent | ripple::lsfAllowTrustLineClawback,
2,
200,
2,
INDEX1,
2);
ON_CALL(*rawBackendPtr, doFetchLedgerObject(accountKk, 30, _))
.WillByDefault(Return(accountRoot.getSerializer().peekData()));
ON_CALL(*rawBackendPtr, doFetchLedgerObject(ripple::keylet::amendments().key, 30, _))
.WillByDefault(Return(CreateAmendmentsObject({RPC::Amendments::Clawback}).getSerializer().peekData()));
EXPECT_CALL(*rawBackendPtr, doFetchLedgerObject).Times(3);
auto const static input = boost::json::parse(fmt::format(
R"({{
"account": "{}"
}})",
ACCOUNT));
auto const handler = AnyHandler{AccountInfoHandler{mockBackendPtr}};
runSpawn([&](auto yield) {
auto const output = handler.process(input, Context{yield});
ASSERT_TRUE(output);
EXPECT_EQ(*output, json::parse(expectedOutput));
});
}

View File

@@ -729,3 +729,14 @@ CreateCreateNFTOfferTxWithMetadata(
ret.metadata = metaObj.getSerializer().peekData();
return ret;
}
ripple::STObject
CreateAmendmentsObject(std::vector<ripple::uint256> const& enabledAmendments)
{
auto amendments = ripple::STObject(ripple::sfLedgerEntry);
amendments.setFieldU16(ripple::sfLedgerEntryType, ripple::ltAMENDMENTS);
amendments.setFieldU32(ripple::sfFlags, 0);
ripple::STVector256 list(enabledAmendments);
amendments.setFieldV256(ripple::sfAmendments, list);
return amendments;
}

View File

@@ -258,3 +258,6 @@ CreateCreateNFTOfferTxWithMetadata(
std::string_view nftId,
std::uint32_t offerPrice,
std::string_view offerId);
[[nodiscard]] ripple::STObject
CreateAmendmentsObject(std::vector<ripple::uint256> const& enabledAmendments);