fix: Use local variable for makeHost where applicable

This commit is contained in:
TimothyBanks
2026-08-18 13:00:21 -04:00
parent 80d8e827d7
commit dc0326a2a0
18 changed files with 85 additions and 73 deletions

View File

@@ -29,9 +29,10 @@ TEST_F(AmmKeyletImpl, InvalidParameters)
auto baseMpt = makeMptID(1, owner.id());
expectError(makeHost()->ammKeylet(xrpIssue(), xrpIssue()), HostFunctionError::InvalidParams);
expectError(makeHost()->ammKeylet(xrpIssue(), baseMpt), HostFunctionError::InvalidParams);
expectError(makeHost()->ammKeylet(baseMpt, xrpIssue()), HostFunctionError::InvalidParams);
auto h = makeHost();
expectError(h->ammKeylet(xrpIssue(), xrpIssue()), HostFunctionError::InvalidParams);
expectError(h->ammKeylet(xrpIssue(), baseMpt), HostFunctionError::InvalidParams);
expectError(h->ammKeylet(baseMpt, xrpIssue()), HostFunctionError::InvalidParams);
}
} // namespace xrpl::test

View File

@@ -60,11 +60,12 @@ TEST_F(CacheLedgerObjImpl, MatchesLedgerImplicitIndices)
TEST_F(CacheLedgerObjImpl, OutOfRange)
{
auto result = makeHost()->cacheLedgerObj(uint256{}, -1);
auto h = makeHost();
auto result = h->cacheLedgerObj(uint256{}, -1);
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error(), HostFunctionError::SlotOutRange);
result = makeHost()->cacheLedgerObj(uint256{}, 257);
result = h->cacheLedgerObj(uint256{}, 257);
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error(), HostFunctionError::SlotOutRange);
}

View File

@@ -48,13 +48,12 @@ TEST_F(CredentialKeyletImpl, InvalidAccount)
auto const credTypeStr = std::string{"test"};
auto const credType = Slice{credTypeStr.data(), credTypeStr.size()};
auto h = makeHost();
expectError(
makeHost()->credentialKeylet(AccountID{}, owner.id(), credType),
HostFunctionError::InvalidAccount);
h->credentialKeylet(AccountID{}, owner.id(), credType), HostFunctionError::InvalidAccount);
expectError(
makeHost()->credentialKeylet(owner.id(), AccountID{}, credType),
HostFunctionError::InvalidAccount);
h->credentialKeylet(owner.id(), AccountID{}, credType), HostFunctionError::InvalidAccount);
}
} // namespace xrpl::test

View File

@@ -34,11 +34,9 @@ TEST_F(DelegateKeyletImpl, InvalidAccount)
{
auto const owner = fund("owner");
expectError(
makeHost()->delegateKeylet(AccountID{}, owner.id()), HostFunctionError::InvalidAccount);
expectError(
makeHost()->delegateKeylet(owner.id(), AccountID{}), HostFunctionError::InvalidAccount);
auto h = makeHost();
expectError(h->delegateKeylet(AccountID{}, owner.id()), HostFunctionError::InvalidAccount);
expectError(h->delegateKeylet(owner.id(), AccountID{}), HostFunctionError::InvalidAccount);
}
} // namespace xrpl::test

View File

@@ -34,13 +34,11 @@ TEST_F(DepositPreauthKeyletImpl, InvalidAccount)
{
auto const owner = fund("owner");
auto h = makeHost();
expectError(
makeHost()->depositPreauthKeylet(AccountID{}, owner.id()),
HostFunctionError::InvalidAccount);
h->depositPreauthKeylet(AccountID{}, owner.id()), HostFunctionError::InvalidAccount);
expectError(
makeHost()->depositPreauthKeylet(owner.id(), AccountID{}),
HostFunctionError::InvalidAccount);
h->depositPreauthKeylet(owner.id(), AccountID{}), HostFunctionError::InvalidAccount);
}
} // namespace xrpl::test

View File

@@ -27,8 +27,9 @@ TEST_F(EscrowKeyletImpl, MatchesLedgerKeyletFunction)
TEST_F(EscrowKeyletImpl, DifferentAccountsGiveDifferentKeylets)
{
auto const a = makeHost()->escrowKeylet(Account{"alice"}.id(), 7);
auto const b = makeHost()->escrowKeylet(Account{"becky"}.id(), 7);
auto h = makeHost();
auto const a = h->escrowKeylet(Account{"alice"}.id(), 7);
auto const b = h->escrowKeylet(Account{"becky"}.id(), 7);
ASSERT_TRUE(a.has_value() && b.has_value());
EXPECT_NE(*a, *b);

View File

@@ -15,10 +15,10 @@ TEST_F(FloatCompareImpl, MalformedInputs)
{
// A wrong-size (here empty) buffer is malformed; the impl normalizes any well-formed
// 12-byte buffer, so size is the only rejection.
expectError(makeHost()->floatCompare(Slice{}, Slice{}), HostFunctionError::FloatInputMalformed);
auto h = makeHost();
expectError(h->floatCompare(Slice{}, Slice{}), HostFunctionError::FloatInputMalformed);
expectError(
makeHost()->floatCompare(slice(FloatTest::kOne), Slice{}),
HostFunctionError::FloatInputMalformed);
h->floatCompare(slice(FloatTest::kOne), Slice{}), HostFunctionError::FloatInputMalformed);
}
TEST_F(FloatCompareImpl, Less)

View File

@@ -36,10 +36,11 @@ TEST_F(FloatDivideImpl, DivideByZeroIsComputationError)
TEST_F(FloatDivideImpl, OverflowIsComputationError)
{
// A divisor just below 1, so max / it overflows.
auto const y = makeHost()->floatFromMantExp(STAmount::kMaxValue, -FloatTest::kNormalExp - 1, 0);
auto h = makeHost();
auto const y = h->floatFromMantExp(STAmount::kMaxValue, -FloatTest::kNormalExp - 1, 0);
ASSERT_TRUE(y.has_value());
expectError(
makeHost()->floatDivide(slice(FloatTest::kMax), slice(*y), 0),
h->floatDivide(slice(FloatTest::kMax), slice(*y), 0),
HostFunctionError::FloatComputationError);
}
@@ -60,10 +61,11 @@ TEST_F(FloatDivideImpl, MaxExpDividedByTenIsPreMaxExp)
// The rounding mode changes an inexact result: 1/3 rounded Downward differs from Upward.
TEST_F(FloatDivideImpl, RoundingModeAffectsInexactResult)
{
auto const three = makeHost()->floatFromInt(3, 0);
auto h = makeHost();
auto const three = h->floatFromInt(3, 0);
ASSERT_TRUE(three.has_value());
auto const down = makeHost()->floatDivide(slice(FloatTest::kOne), slice(*three), 2);
auto const up = makeHost()->floatDivide(slice(FloatTest::kOne), slice(*three), 3);
auto const down = h->floatDivide(slice(FloatTest::kOne), slice(*three), 2);
auto const up = h->floatDivide(slice(FloatTest::kOne), slice(*three), 3);
ASSERT_TRUE(down.has_value() && up.has_value());
EXPECT_NE(*down, *up);
}

View File

@@ -12,8 +12,9 @@ struct FloatFromIntImpl : FloatTest
TEST_F(FloatFromIntImpl, BadModeIsMalformed)
{
expectError(makeHost()->floatFromInt(kMin64, -1), HostFunctionError::FloatInputMalformed);
expectError(makeHost()->floatFromInt(kMin64, 4), HostFunctionError::FloatInputMalformed);
auto h = makeHost();
expectError(h->floatFromInt(kMin64, -1), HostFunctionError::FloatInputMalformed);
expectError(h->floatFromInt(kMin64, 4), HostFunctionError::FloatInputMalformed);
}
TEST_F(FloatFromIntImpl, MinInt)

View File

@@ -16,8 +16,9 @@ struct FloatFromMantExpImpl : FloatTest
TEST_F(FloatFromMantExpImpl, BadModeIsMalformed)
{
expectError(makeHost()->floatFromMantExp(1, 0, -1), HostFunctionError::FloatInputMalformed);
expectError(makeHost()->floatFromMantExp(1, 0, 4), HostFunctionError::FloatInputMalformed);
auto h = makeHost();
expectError(h->floatFromMantExp(1, 0, -1), HostFunctionError::FloatInputMalformed);
expectError(h->floatFromMantExp(1, 0, 4), HostFunctionError::FloatInputMalformed);
}
TEST_F(FloatFromMantExpImpl, ExponentTooHighIsMalformed)

View File

@@ -25,9 +25,10 @@ struct FloatFromStAmountImpl : FloatTest
TEST_F(FloatFromStAmountImpl, BadModeIsMalformed)
{
auto h = makeHost();
auto const amount = STAmount{XRP(100)};
expectError(makeHost()->floatFromSTAmount(amount, -1), HostFunctionError::FloatInputMalformed);
expectError(makeHost()->floatFromSTAmount(amount, 4), HostFunctionError::FloatInputMalformed);
expectError(h->floatFromSTAmount(amount, -1), HostFunctionError::FloatInputMalformed);
expectError(h->floatFromSTAmount(amount, 4), HostFunctionError::FloatInputMalformed);
}
TEST_F(FloatFromStAmountImpl, ZeroXrp)
@@ -38,16 +39,18 @@ TEST_F(FloatFromStAmountImpl, ZeroXrp)
TEST_F(FloatFromStAmountImpl, MinusOneXrp)
{
// -1 XRP == -1'000'000 drops.
auto const expected = makeHost()->floatFromMantExp(-1'000'000, 0, 0);
auto h = makeHost();
auto const expected = h->floatFromMantExp(-1'000'000, 0, 0);
ASSERT_TRUE(expected.has_value());
expectValue(makeHost()->floatFromSTAmount(STAmount{XRP(-1)}, 0), *expected);
expectValue(h->floatFromSTAmount(STAmount{XRP(-1)}, 0), *expected);
}
TEST_F(FloatFromStAmountImpl, MaxDrops)
{
auto const expected = makeHost()->floatFromMantExp(9'223'372'036'854'776, 3, 0);
auto h = makeHost();
auto const expected = h->floatFromMantExp(9'223'372'036'854'776, 3, 0);
ASSERT_TRUE(expected.has_value());
expectValue(makeHost()->floatFromSTAmount(STAmount{noIssue(), kMax64}, 0), *expected);
expectValue(h->floatFromSTAmount(STAmount{noIssue(), kMax64}, 0), *expected);
}
TEST_F(FloatFromStAmountImpl, MinIou)

View File

@@ -18,9 +18,10 @@ struct FloatFromStNumberImpl : FloatTest
TEST_F(FloatFromStNumberImpl, BadModeIsMalformed)
{
auto h = makeHost();
auto const n = STNumber{sfNumber, Number(123, 0)};
expectError(makeHost()->floatFromSTNumber(n, -1), HostFunctionError::FloatInputMalformed);
expectError(makeHost()->floatFromSTNumber(n, 4), HostFunctionError::FloatInputMalformed);
expectError(h->floatFromSTNumber(n, -1), HostFunctionError::FloatInputMalformed);
expectError(h->floatFromSTNumber(n, 4), HostFunctionError::FloatInputMalformed);
}
TEST_F(FloatFromStNumberImpl, MaxUint)

View File

@@ -16,8 +16,9 @@ struct FloatFromUintImpl : FloatTest
TEST_F(FloatFromUintImpl, BadModeIsMalformed)
{
expectError(makeHost()->floatFromUint(0, -1), HostFunctionError::FloatInputMalformed);
expectError(makeHost()->floatFromUint(0, 4), HostFunctionError::FloatInputMalformed);
auto h = makeHost();
expectError(h->floatFromUint(0, -1), HostFunctionError::FloatInputMalformed);
expectError(h->floatFromUint(0, 4), HostFunctionError::FloatInputMalformed);
}
TEST_F(FloatFromUintImpl, Zero)

View File

@@ -57,17 +57,19 @@ TEST_F(FloatPowerImpl, DegreeOneIsIdentity)
TEST_F(FloatPowerImpl, TenSquaredIsHundred)
{
auto const hundred = makeHost()->floatFromMantExp(100, 0, 0);
auto h = makeHost();
auto const hundred = h->floatFromMantExp(100, 0, 0);
ASSERT_TRUE(hundred.has_value());
expectValue(makeHost()->floatPower(slice(FloatTest::kTen), 2, 0), *hundred);
expectValue(h->floatPower(slice(FloatTest::kTen), 2, 0), *hundred);
}
TEST_F(FloatPowerImpl, TenthSquaredIsHundredth)
{
auto const tenth = makeHost()->floatFromMantExp(1, -1, 0);
auto const hundredth = makeHost()->floatFromMantExp(1, -2, 0);
auto h = makeHost();
auto const tenth = h->floatFromMantExp(1, -1, 0);
auto const hundredth = h->floatFromMantExp(1, -2, 0);
ASSERT_TRUE(tenth.has_value() && hundredth.has_value());
expectValue(makeHost()->floatPower(slice(*tenth), 2, 0), *hundredth);
expectValue(h->floatPower(slice(*tenth), 2, 0), *hundredth);
}
} // namespace xrpl::test

View File

@@ -42,24 +42,27 @@ TEST_F(FloatRootImpl, FirstRootIsIdentity)
TEST_F(FloatRootImpl, SquareRootOfHundredIsTen)
{
auto const hundred = makeHost()->floatFromMantExp(100, 0, 0);
auto h = makeHost();
auto const hundred = h->floatFromMantExp(100, 0, 0);
ASSERT_TRUE(hundred.has_value());
expectValue(makeHost()->floatRoot(slice(*hundred), 2, 0), FloatTest::kTen);
expectValue(h->floatRoot(slice(*hundred), 2, 0), FloatTest::kTen);
}
TEST_F(FloatRootImpl, CubeRootOfThousandIsTen)
{
auto const thousand = makeHost()->floatFromMantExp(1000, 0, 0);
auto h = makeHost();
auto const thousand = h->floatFromMantExp(1000, 0, 0);
ASSERT_TRUE(thousand.has_value());
expectValue(makeHost()->floatRoot(slice(*thousand), 3, 0), FloatTest::kTen);
expectValue(h->floatRoot(slice(*thousand), 3, 0), FloatTest::kTen);
}
TEST_F(FloatRootImpl, SquareRootOfHundredthIsTenth)
{
auto const hundredth = makeHost()->floatFromMantExp(1, -2, 0);
auto const tenth = makeHost()->floatFromMantExp(1, -1, 0);
auto h = makeHost();
auto const hundredth = h->floatFromMantExp(1, -2, 0);
auto const tenth = h->floatFromMantExp(1, -1, 0);
ASSERT_TRUE(hundredth.has_value() && tenth.has_value());
expectValue(makeHost()->floatRoot(slice(*hundredth), 2, 0), *tenth);
expectValue(h->floatRoot(slice(*hundredth), 2, 0), *tenth);
}
} // namespace xrpl::test

View File

@@ -15,10 +15,9 @@ struct FloatToIntImpl : FloatTest
TEST_F(FloatToIntImpl, BadModeIsMalformed)
{
expectError(
makeHost()->floatToInt(slice(FloatTest::kOne), -1), HostFunctionError::FloatInputMalformed);
expectError(
makeHost()->floatToInt(slice(FloatTest::kOne), 4), HostFunctionError::FloatInputMalformed);
auto h = makeHost();
expectError(h->floatToInt(slice(FloatTest::kOne), -1), HostFunctionError::FloatInputMalformed);
expectError(h->floatToInt(slice(FloatTest::kOne), 4), HostFunctionError::FloatInputMalformed);
}
TEST_F(FloatToIntImpl, MalformedInputs)
@@ -61,10 +60,11 @@ TEST_F(FloatToIntImpl, OverflowsInt64IsComputationError)
TEST_F(FloatToIntImpl, PiRoundsByMode)
{
expectValue(makeHost()->floatToInt(slice(FloatTest::kPi), 0), std::int64_t{3}); // ToNearest
expectValue(makeHost()->floatToInt(slice(FloatTest::kPi), 1), std::int64_t{3}); // TowardsZero
expectValue(makeHost()->floatToInt(slice(FloatTest::kPi), 2), std::int64_t{3}); // Downward
expectValue(makeHost()->floatToInt(slice(FloatTest::kPi), 3), std::int64_t{4}); // Upward
auto h = makeHost();
expectValue(h->floatToInt(slice(FloatTest::kPi), 0), std::int64_t{3}); // ToNearest
expectValue(h->floatToInt(slice(FloatTest::kPi), 1), std::int64_t{3}); // TowardsZero
expectValue(h->floatToInt(slice(FloatTest::kPi), 2), std::int64_t{3}); // Downward
expectValue(h->floatToInt(slice(FloatTest::kPi), 3), std::int64_t{4}); // Upward
}
} // namespace xrpl::test

View File

@@ -35,13 +35,13 @@ TEST_F(PaychannelKeyletImpl, InvalidAccount)
{
auto const owner = fund("owner");
expectError(
makeHost()->paychannelKeylet(AccountID{}, owner.id(), 1u),
HostFunctionError::InvalidAccount);
auto h = makeHost();
expectError(
makeHost()->paychannelKeylet(owner.id(), AccountID{}, 1u),
HostFunctionError::InvalidAccount);
h->paychannelKeylet(AccountID{}, owner.id(), 1u), HostFunctionError::InvalidAccount);
expectError(
h->paychannelKeylet(owner.id(), AccountID{}, 1u), HostFunctionError::InvalidAccount);
}
} // namespace xrpl::test

View File

@@ -51,13 +51,13 @@ TEST_F(TrustlineKeyletImpl, InvalidAccount)
auto const usd = toCurrency("USD");
expectError(
makeHost()->trustLineKeylet(AccountID{}, owner.id(), usd),
HostFunctionError::InvalidAccount);
auto h = makeHost();
expectError(
makeHost()->trustLineKeylet(owner.id(), AccountID{}, usd),
HostFunctionError::InvalidAccount);
h->trustLineKeylet(AccountID{}, owner.id(), usd), HostFunctionError::InvalidAccount);
expectError(
h->trustLineKeylet(owner.id(), AccountID{}, usd), HostFunctionError::InvalidAccount);
}
} // namespace xrpl::test