Address AI review feedback, and fix AI screwups

- Pad base_uint::operator= with 0s.
- Add more base_uint tests for operator=, and simplify the "death" error
  match.
- Put back some } that AI suggestions removed, and I didn't notice when
  I took the suggestions..
This commit is contained in:
Ed Hennis
2026-07-07 19:28:44 -04:00
parent 2a30d519b9
commit 203d7d6bf8
3 changed files with 44 additions and 6 deletions

View File

@@ -323,6 +323,8 @@ public:
"xrpl::BaseUInt::operator=(Container auto) : input size match");
std::size_t const canCopy =
std::min(size(), c.size() * sizeof(typename Container::value_type));
if (canCopy < size())
*this = beast::kZero;
std::memcpy(data_.data(), c.data(), canCopy);
return *this;
}

View File

@@ -175,8 +175,8 @@ public:
auto const result = env.rpc("json", "sign", to_string(req))[jss::result];
BEAST_EXPECT(result[jss::error] == "invalidParams");
BEAST_EXPECT(
result[jss::error_message] == "Field 'tx_json.Asset' has invalid data.");
BEAST_EXPECT(result[jss::error_message] == "Field 'tx_json.Asset' has invalid data.");
}
void
testNoAccountIssuer()
@@ -248,8 +248,8 @@ public:
auto const result = env.rpc("json", "sign", to_string(req))[jss::result];
BEAST_EXPECT(result[jss::error] == "invalidParams");
BEAST_EXPECT(
result[jss::error_message] == "Field 'tx_json.Asset' has invalid data.");
BEAST_EXPECT(result[jss::error_message] == "Field 'tx_json.Asset' has invalid data.");
}
void
testXrpAccountIssuer()

View File

@@ -136,7 +136,7 @@ TEST_F(BaseUintDeathTest, fromRaw_size_mismatch)
auto const resultText = to_string(result);
EXPECT_EQ(resultText, "010203040506070800000000") << resultText;
}),
"xrpl::BaseUInt::fromRaw(Container auto) : input size match");
"input size match");
EXPECT_DEBUG_DEATH(
({
@@ -148,7 +148,43 @@ TEST_F(BaseUintDeathTest, fromRaw_size_mismatch)
auto const resultText = to_string(result);
EXPECT_EQ(resultText, "0102030405060708090A0B0C") << resultText;
}),
"xrpl::BaseUInt::fromRaw(Container auto) : input size match");
"input size match");
EXPECT_DEBUG_DEATH(
({
// Container smaller than the base_uint (8 bytes vs 12 bytes for
// test96). Only the first 8 bytes are copied; the remaining 4 bytes
// stay zero.
Blob const tooSmall{1, 2, 3, 4, 5, 6, 7, 8};
BaseUInt96 result{};
--result;
{
auto const originalText = to_string(result);
EXPECT_EQ(originalText, "FFFFFFFFFFFFFFFFFFFFFFFF") << originalText;
}
result = tooSmall;
auto const resultText = to_string(result);
EXPECT_EQ(resultText, "010203040506070800000000") << resultText;
}),
"input size match");
EXPECT_DEBUG_DEATH(
({
// Container larger than the base_uint (16 bytes vs 12 bytes for
// test96). Only the first 12 bytes are copied; the extra bytes are
// ignored.
Blob const tooBig{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
BaseUInt96 result{};
--result;
{
auto const originalText = to_string(result);
EXPECT_EQ(originalText, "FFFFFFFFFFFFFFFFFFFFFFFF") << originalText;
}
result = tooBig;
auto const resultText = to_string(result);
EXPECT_EQ(resultText, "0102030405060708090A0B0C") << resultText;
}),
"input size match");
}
TEST_F(BaseUintTest, base_uint)