From 9ca4c7afd351b4ab675dded60b797dc38076ebd6 Mon Sep 17 00:00:00 2001 From: nkramer44 Date: Tue, 21 Jan 2025 07:17:54 -0500 Subject: [PATCH] fix: Remove InvalidHotWallet Error from gateway_balances RPC handler (#1830) Fixes #1825 by removing the check in the gateway_balances RPC handler that returns the RpcInvalidHotWallet error code if one of the addresses supplied in the request's `hotwallet` array does not have a trustline with the `account` from the request. As stated in the original ticket, this change fixes a discrepancy in behavior between Clio and rippled, as rippled does not check for trustline existence when handling gateway_balances RPCs Co-authored-by: Sergey Kuznetsov --- src/rpc/Errors.cpp | 1 - src/rpc/Errors.hpp | 1 - src/rpc/handlers/GatewayBalances.cpp | 4 -- src/web/impl/ErrorHandling.hpp | 1 - .../rpc/handlers/GatewayBalancesTests.cpp | 48 ------------------- 5 files changed, 55 deletions(-) diff --git a/src/rpc/Errors.cpp b/src/rpc/Errors.cpp index b63d77b43..a083fc999 100644 --- a/src/rpc/Errors.cpp +++ b/src/rpc/Errors.cpp @@ -79,7 +79,6 @@ getErrorInfo(ClioError code) {ClioError::rpcMALFORMED_REQUEST, "malformedRequest", "Malformed request."}, {ClioError::rpcMALFORMED_OWNER, "malformedOwner", "Malformed owner."}, {ClioError::rpcMALFORMED_ADDRESS, "malformedAddress", "Malformed address."}, - {ClioError::rpcINVALID_HOT_WALLET, "invalidHotWallet", "Invalid hot wallet."}, {ClioError::rpcUNKNOWN_OPTION, "unknownOption", "Unknown option."}, {ClioError::rpcFIELD_NOT_FOUND_TRANSACTION, "fieldNotFoundTransaction", "Missing field."}, {ClioError::rpcMALFORMED_ORACLE_DOCUMENT_ID, "malformedDocumentID", "Malformed oracle_document_id."}, diff --git a/src/rpc/Errors.hpp b/src/rpc/Errors.hpp index e177b6304..c7da10fc9 100644 --- a/src/rpc/Errors.hpp +++ b/src/rpc/Errors.hpp @@ -39,7 +39,6 @@ enum class ClioError { rpcMALFORMED_REQUEST = 5001, rpcMALFORMED_OWNER = 5002, rpcMALFORMED_ADDRESS = 5003, - rpcINVALID_HOT_WALLET = 5004, rpcUNKNOWN_OPTION = 5005, rpcFIELD_NOT_FOUND_TRANSACTION = 5006, rpcMALFORMED_ORACLE_DOCUMENT_ID = 5007, diff --git a/src/rpc/handlers/GatewayBalances.cpp b/src/rpc/handlers/GatewayBalances.cpp index 91155cece..6c9aaf5eb 100644 --- a/src/rpc/handlers/GatewayBalances.cpp +++ b/src/rpc/handlers/GatewayBalances.cpp @@ -142,10 +142,6 @@ GatewayBalancesHandler::process(GatewayBalancesHandler::Input input, Context con if (auto status = std::get_if(&ret)) return Error{*status}; - auto inHotbalances = [&](auto const& hw) { return output.hotBalances.contains(hw); }; - if (not std::all_of(input.hotWallets.begin(), input.hotWallets.end(), inHotbalances)) - return Error{Status{ClioError::rpcINVALID_HOT_WALLET}}; - output.accountID = input.account; output.ledgerHash = ripple::strHex(lgrInfo.hash); output.ledgerIndex = lgrInfo.seq; diff --git a/src/web/impl/ErrorHandling.hpp b/src/web/impl/ErrorHandling.hpp index b78876335..32c5796a1 100644 --- a/src/web/impl/ErrorHandling.hpp +++ b/src/web/impl/ErrorHandling.hpp @@ -87,7 +87,6 @@ public: case rpc::ClioError::rpcMALFORMED_REQUEST: case rpc::ClioError::rpcMALFORMED_OWNER: case rpc::ClioError::rpcMALFORMED_ADDRESS: - case rpc::ClioError::rpcINVALID_HOT_WALLET: case rpc::ClioError::rpcFIELD_NOT_FOUND_TRANSACTION: case rpc::ClioError::rpcMALFORMED_ORACLE_DOCUMENT_ID: case rpc::ClioError::rpcMALFORMED_AUTHORIZED_CREDENTIALS: diff --git a/tests/unit/rpc/handlers/GatewayBalancesTests.cpp b/tests/unit/rpc/handlers/GatewayBalancesTests.cpp index 5a018390d..8646fb1a6 100644 --- a/tests/unit/rpc/handlers/GatewayBalancesTests.cpp +++ b/tests/unit/rpc/handlers/GatewayBalancesTests.cpp @@ -322,54 +322,6 @@ TEST_F(RPCGatewayBalancesHandlerTest, AccountNotFound) }); } -TEST_F(RPCGatewayBalancesHandlerTest, InvalidHotWallet) -{ - auto const seq = 300; - - backend->setRange(10, seq); - EXPECT_CALL(*backend, fetchLedgerBySequence).Times(1); - // return valid ledgerHeader - auto const ledgerHeader = CreateLedgerHeader(LEDGERHASH, seq); - ON_CALL(*backend, fetchLedgerBySequence(seq, _)).WillByDefault(Return(ledgerHeader)); - - // return valid account - auto const accountKk = ripple::keylet::account(GetAccountIDWithString(ACCOUNT)).key; - ON_CALL(*backend, doFetchLedgerObject(accountKk, seq, _)).WillByDefault(Return(Blob{'f', 'a', 'k', 'e'})); - - // return valid owner dir - auto const ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX2}}, INDEX1); - auto const ownerDirKk = ripple::keylet::ownerDir(GetAccountIDWithString(ACCOUNT)).key; - ON_CALL(*backend, doFetchLedgerObject(ownerDirKk, seq, _)) - .WillByDefault(Return(ownerDir.getSerializer().peekData())); - EXPECT_CALL(*backend, doFetchLedgerObject).Times(2); - - // create a valid line, balance is 0 - auto const line1 = CreateRippleStateLedgerObject("USD", ISSUER, 0, ACCOUNT, 10, ACCOUNT2, 20, TXNID, 123); - std::vector bbs; - bbs.push_back(line1.getSerializer().peekData()); - ON_CALL(*backend, doFetchLedgerObjects).WillByDefault(Return(bbs)); - EXPECT_CALL(*backend, doFetchLedgerObjects).Times(1); - - auto const handler = AnyHandler{GatewayBalancesHandler{backend}}; - runSpawn([&](auto yield) { - auto const output = handler.process( - json::parse(fmt::format( - R"({{ - "account": "{}", - "hotwallet": "{}" - }})", - ACCOUNT, - ACCOUNT2 - )), - Context{yield} - ); - ASSERT_FALSE(output); - auto const err = rpc::makeError(output.result.error()); - EXPECT_EQ(err.at("error").as_string(), "invalidHotWallet"); - EXPECT_EQ(err.at("error_message").as_string(), "Invalid hot wallet."); - }); -} - struct NormalTestBundle { std::string testName; ripple::STObject mockedDir;