fix pre-commit

This commit is contained in:
Mayukha Vadari
2026-03-05 14:49:07 -04:00
parent a76bd834b6
commit fdfdf4fceb
3 changed files with 91 additions and 45 deletions

View File

@@ -15,7 +15,8 @@ ApplyViewImpl::apply(
bool isDryRun,
beast::Journal j)
{
return items_.apply(to, tx, ter, deliver_, parentBatchId, gasUsed_, wasmReturnCode_, isDryRun, j);
return items_.apply(
to, tx, ter, deliver_, parentBatchId, gasUsed_, wasmReturnCode_, isDryRun, j);
}
std::size_t

View File

@@ -228,7 +228,10 @@ struct EscrowSmart_test : public beast::unit_test::suite
// Failure situations (i.e. all other combinations)
{
// only FinishFunction
env(escrowCreate, escrow::finish_function(ledgerSqnWasmHex), fee(txnFees), ter(temBAD_EXPIRATION));
env(escrowCreate,
escrow::finish_function(ledgerSqnWasmHex),
fee(txnFees),
ter(temBAD_EXPIRATION));
env.close();
}
{
@@ -320,8 +323,12 @@ struct EscrowSmart_test : public beast::unit_test::suite
// featureSmartEscrow disabled
Env env(*this, features - featureSmartEscrow);
env.fund(XRP(5000), alice, carol);
XRPAmount const txnFees = env.current()->fees().base * 10 + ledgerSqnWasmHex.size() / 2 * 5;
env(escrow::finish(carol, alice, 1), fee(txnFees), escrow::comp_allowance(4), ter(temDISABLED));
XRPAmount const txnFees =
env.current()->fees().base * 10 + ledgerSqnWasmHex.size() / 2 * 5;
env(escrow::finish(carol, alice, 1),
fee(txnFees),
escrow::comp_allowance(4),
ter(temDISABLED));
env.close();
}
@@ -380,9 +387,9 @@ struct EscrowSmart_test : public beast::unit_test::suite
sle->setFieldU32(sfFlags, 0);
sle->setFieldU64(sfOwnerNode, 0);
uint256 tmp;
BEAST_EXPECT(
tmp.parseHex("F63D1A452A96C19EFD77901FB37D236C59EAA746771A6"
"85D1BBA57A2238B9401"));
BEAST_EXPECT(tmp.parseHex(
"F63D1A452A96C19EFD77901FB37D236C59EAA746771A6"
"85D1BBA57A2238B9401"));
sle->setFieldH256(sfPreviousTxnID, tmp);
sle->setFieldU32(sfPreviousTxnLgrSeq, 4);
sle->setFieldU32(sfSequence, seq);
@@ -432,7 +439,10 @@ struct EscrowSmart_test : public beast::unit_test::suite
// This function takes 4 gas
// In testing, 1 gas costs 1 drop
auto const finishFee = env.current()->fees().base + 3;
env(escrow::finish(carol, alice, seq), fee(finishFee), escrow::comp_allowance(4), ter(telINSUF_FEE_P));
env(escrow::finish(carol, alice, seq),
fee(finishFee),
escrow::comp_allowance(4),
ter(telINSUF_FEE_P));
}
{
@@ -457,8 +467,8 @@ struct EscrowSmart_test : public beast::unit_test::suite
auto const allowance = 100;
env(escrow::finish(carol, alice, seq2),
fee(env.current()->fees().base + (allowance * env.current()->fees().gasPrice) / MICRO_DROPS_PER_DROP +
1),
fee(env.current()->fees().base +
(allowance * env.current()->fees().gasPrice) / MICRO_DROPS_PER_DROP + 1),
escrow::comp_allowance(allowance),
ter(tefNO_WASM));
}
@@ -482,8 +492,8 @@ struct EscrowSmart_test : public beast::unit_test::suite
auto [createFee, finishFee] = [&]() {
Env env(*this, features);
auto createFee = env.current()->fees().base * 10 + ledgerSqnWasmHex.size() / 2 * 5;
auto finishFee =
env.current()->fees().base + (allowance * env.current()->fees().gasPrice) / MICRO_DROPS_PER_DROP + 1;
auto finishFee = env.current()->fees().base +
(allowance * env.current()->fees().gasPrice) / MICRO_DROPS_PER_DROP + 1;
return std::make_pair(createFee, finishFee);
}();
@@ -543,7 +553,8 @@ struct EscrowSmart_test : public beast::unit_test::suite
auto const txMeta = env.meta();
if (BEAST_EXPECT(txMeta->isFieldPresent(sfGasUsed)))
BEAST_EXPECTS(
txMeta->getFieldU32(sfGasUsed) == allowance, std::to_string(txMeta->getFieldU32(sfGasUsed)));
txMeta->getFieldU32(sfGasUsed) == allowance,
std::to_string(txMeta->getFieldU32(sfGasUsed)));
if (BEAST_EXPECT(txMeta->isFieldPresent(sfWasmReturnCode)))
BEAST_EXPECTS(
txMeta->getFieldI32(sfWasmReturnCode) == 5,
@@ -566,7 +577,8 @@ struct EscrowSmart_test : public beast::unit_test::suite
escrow::cancel_time(env.now() + 100s),
fee(createFee));
env.close();
auto const conditionFinishFee = finishFee + env.current()->fees().base * (32 + (escrow::fb1.size() / 16));
auto const conditionFinishFee =
finishFee + env.current()->fees().base * (32 + (escrow::fb1.size() / 16));
if (BEAST_EXPECT(env.ownerCount(alice) == 2))
{
@@ -613,7 +625,8 @@ struct EscrowSmart_test : public beast::unit_test::suite
auto const txMeta = env.meta();
if (BEAST_EXPECT(txMeta->isFieldPresent(sfGasUsed)))
BEAST_EXPECTS(
txMeta->getFieldU32(sfGasUsed) == allowance, std::to_string(txMeta->getFieldU32(sfGasUsed)));
txMeta->getFieldU32(sfGasUsed) == allowance,
std::to_string(txMeta->getFieldU32(sfGasUsed)));
if (BEAST_EXPECT(txMeta->isFieldPresent(sfWasmReturnCode)))
BEAST_EXPECTS(
txMeta->getFieldI32(sfWasmReturnCode) == 5,
@@ -763,8 +776,8 @@ struct EscrowSmart_test : public beast::unit_test::suite
env.require(balance(alice, XRP(4000) - txnFees));
auto const allowance = 1420;
XRPAmount const finishFee =
env.current()->fees().base + (allowance * env.current()->fees().gasPrice) / MICRO_DROPS_PER_DROP + 1;
XRPAmount const finishFee = env.current()->fees().base +
(allowance * env.current()->fees().gasPrice) / MICRO_DROPS_PER_DROP + 1;
// FinishAfter time hasn't passed
env(escrow::finish(alice, alice, seq),
@@ -775,7 +788,8 @@ struct EscrowSmart_test : public beast::unit_test::suite
auto const txMeta = env.meta();
if (BEAST_EXPECT(txMeta && txMeta->isFieldPresent(sfGasUsed)))
BEAST_EXPECTS(
txMeta->getFieldU32(sfGasUsed) == allowance, std::to_string(txMeta->getFieldU32(sfGasUsed)));
txMeta->getFieldU32(sfGasUsed) == allowance,
std::to_string(txMeta->getFieldU32(sfGasUsed)));
if (BEAST_EXPECT(txMeta->isFieldPresent(sfWasmReturnCode)))
BEAST_EXPECTS(
txMeta->getFieldI32(sfWasmReturnCode) == -256,
@@ -840,7 +854,8 @@ struct EscrowSmart_test : public beast::unit_test::suite
env.close();
auto const bigAllowance = 996'433;
uint64_t partialFeeCalc = (static_cast<uint64_t>(bigAllowance) * 1'000'000) / MICRO_DROPS_PER_DROP +
uint64_t partialFeeCalc =
(static_cast<uint64_t>(bigAllowance) * 1'000'000) / MICRO_DROPS_PER_DROP +
1; // to avoid an overflow
auto finishFee = env.current()->fees().base + partialFeeCalc;
BEAST_EXPECT(finishFee.drops() > bigAllowance);
@@ -866,7 +881,8 @@ struct EscrowSmart_test : public beast::unit_test::suite
auto const txMeta = env.meta();
if (BEAST_EXPECT(txMeta->isFieldPresent(sfGasUsed)))
BEAST_EXPECTS(
txMeta->getFieldU32(sfGasUsed) == allowance, std::to_string(txMeta->getFieldU32(sfGasUsed)));
txMeta->getFieldU32(sfGasUsed) == allowance,
std::to_string(txMeta->getFieldU32(sfGasUsed)));
if (BEAST_EXPECT(txMeta->isFieldPresent(sfWasmReturnCode)))
BEAST_EXPECTS(
txMeta->getFieldI32(sfWasmReturnCode) == 5,
@@ -895,7 +911,8 @@ struct EscrowSmart_test : public beast::unit_test::suite
auto const seq = env.seq(alice);
BEAST_EXPECT(env.ownerCount(alice) == 0);
auto escrowCreate = escrow::create(alice, carol, XRP(1000));
XRPAmount txnFees = env.current()->fees().base * 10 + allHostFunctionsWasmHex.size() / 2 * 5;
XRPAmount txnFees =
env.current()->fees().base * 10 + allHostFunctionsWasmHex.size() / 2 * 5;
env(escrowCreate,
escrow::finish_function(allHostFunctionsWasmHex),
escrow::finish_time(env.now() + 11s),
@@ -904,7 +921,8 @@ struct EscrowSmart_test : public beast::unit_test::suite
fee(txnFees));
env.close();
if (BEAST_EXPECT(env.ownerCount(alice) == (1 + allHostFunctionsWasmHex.size() / 2 / 500)))
if (BEAST_EXPECT(
env.ownerCount(alice) == (1 + allHostFunctionsWasmHex.size() / 2 / 500)))
{
env.require(balance(alice, XRP(4000) - txnFees));
env.require(balance(carol, XRP(5000)));
@@ -935,7 +953,8 @@ struct EscrowSmart_test : public beast::unit_test::suite
auto const txMeta = env.meta();
if (BEAST_EXPECT(txMeta && txMeta->isFieldPresent(sfGasUsed)))
BEAST_EXPECTS(
txMeta->getFieldU32(sfGasUsed) == 64'292, std::to_string(txMeta->getFieldU32(sfGasUsed)));
txMeta->getFieldU32(sfGasUsed) == 64'292,
std::to_string(txMeta->getFieldU32(sfGasUsed)));
if (BEAST_EXPECT(txMeta->isFieldPresent(sfWasmReturnCode)))
BEAST_EXPECT(txMeta->getFieldI32(sfWasmReturnCode) == 1);
@@ -999,7 +1018,8 @@ struct EscrowSmart_test : public beast::unit_test::suite
if (BEAST_EXPECTS(env.seq(alice) == 20, std::to_string(env.seq(alice))))
{
auto const seq = env.seq(alice);
XRPAmount txnFees = env.current()->fees().base * 10 + allKeyletsWasmHex.size() / 2 * 5;
XRPAmount txnFees =
env.current()->fees().base * 10 + allKeyletsWasmHex.size() / 2 * 5;
env(escrow::create(alice, carol, XRP(1000)),
escrow::finish_function(allKeyletsWasmHex),
escrow::finish_time(env.now() + 2s),
@@ -1012,7 +1032,9 @@ struct EscrowSmart_test : public beast::unit_test::suite
auto const allowance = 184'444;
auto const finishFee = env.current()->fees().base +
(allowance * env.current()->fees().gasPrice) / MICRO_DROPS_PER_DROP + 1;
env(escrow::finish(carol, alice, seq), escrow::comp_allowance(allowance), fee(finishFee));
env(escrow::finish(carol, alice, seq),
escrow::comp_allowance(allowance),
fee(finishFee));
env.close();
auto const txMeta = env.meta();
@@ -1066,7 +1088,8 @@ struct EscrowSmart_test : public beast::unit_test::suite
escrow::finish_function(wasmHex),
escrow::cancel_time(env.now() + 100s),
fee(env.current()->fees().base * 10 + wasmHex.size() / 2 * 5),
ter(expectedStatus == ExpectedStatus::Success ? TER{tesSUCCESS} : TER{temMALFORMED}));
ter(expectedStatus == ExpectedStatus::Success ? TER{tesSUCCESS}
: TER{temMALFORMED}));
if (expectedStatus == ExpectedStatus::Crash)
fail("Expected crash", loc.file_name(), loc.line());
else
@@ -1093,23 +1116,47 @@ struct EscrowSmart_test : public beast::unit_test::suite
std::vector<TestCase> const testCases = {
// Code blob tests
{TestCase::BlobType::Code, 99'959, std::nullopt, ExpectedStatus::Success}, // just under 100kb
{TestCase::BlobType::Code, 99'961, std::nullopt, ExpectedStatus::Malformed}, // just over 100kb
{TestCase::BlobType::Code, 200'000, 10'000'000, ExpectedStatus::Success}, // ~200kb
{TestCase::BlobType::Code, 490'000, 10'000'000, ExpectedStatus::Success}, // just under 1MB JSON
{TestCase::BlobType::Code, 999'999, 10'000'000, ExpectedStatus::Crash}, // just over 1MB JSON
{TestCase::BlobType::Code,
99'959,
std::nullopt,
ExpectedStatus::Success}, // just under 100kb
{TestCase::BlobType::Code,
99'961,
std::nullopt,
ExpectedStatus::Malformed}, // just over 100kb
{TestCase::BlobType::Code, 200'000, 10'000'000, ExpectedStatus::Success}, // ~200kb
{TestCase::BlobType::Code,
490'000,
10'000'000,
ExpectedStatus::Success}, // just under 1MB JSON
{TestCase::BlobType::Code,
999'999,
10'000'000,
ExpectedStatus::Crash}, // just over 1MB JSON
// Data blob tests
{TestCase::BlobType::Data, 99'946, std::nullopt, ExpectedStatus::Success}, // just under 100kb
{TestCase::BlobType::Data, 99'948, std::nullopt, ExpectedStatus::Malformed}, // just over 100kb
{TestCase::BlobType::Data, 200'000, 10'000'000, ExpectedStatus::Success}, // ~200kb
{TestCase::BlobType::Data, 490'000, 10'000'000, ExpectedStatus::Success}, // just under 1MB JSON
{TestCase::BlobType::Data, 999'950, 10'000'000, ExpectedStatus::Crash}, // just over 1MB JSON
{TestCase::BlobType::Data,
99'946,
std::nullopt,
ExpectedStatus::Success}, // just under 100kb
{TestCase::BlobType::Data,
99'948,
std::nullopt,
ExpectedStatus::Malformed}, // just over 100kb
{TestCase::BlobType::Data, 200'000, 10'000'000, ExpectedStatus::Success}, // ~200kb
{TestCase::BlobType::Data,
490'000,
10'000'000,
ExpectedStatus::Success}, // just under 1MB JSON
{TestCase::BlobType::Data,
999'950,
10'000'000,
ExpectedStatus::Crash}, // just over 1MB JSON
};
for (auto const& tc : testCases)
{
auto const wasm =
tc.type == TestCase::BlobType::Code ? generateCodeBlob(tc.size) : generateDataBlob(tc.size);
auto const wasm = tc.type == TestCase::BlobType::Code ? generateCodeBlob(tc.size)
: generateDataBlob(tc.size);
runTest(wasm, tc.sizeLimit, tc.expected);
}
}

View File

@@ -1,13 +1,11 @@
#include <stdint.h>
int32_t
update_data(uint8_t const*, int32_t);
int32_t update_data(uint8_t const *, int32_t);
int
finish()
int finish()
{
uint8_t buf[] = "Data";
update_data(buf, sizeof(buf) - 1);
uint8_t buf[] = "Data";
update_data(buf, sizeof(buf) - 1);
return -256;
return -256;
}