diff --git a/include/xrpl/core/ServiceRegistry.h b/include/xrpl/core/ServiceRegistry.h index 4433fd5121..e8aebe81d2 100644 --- a/include/xrpl/core/ServiceRegistry.h +++ b/include/xrpl/core/ServiceRegistry.h @@ -239,7 +239,7 @@ public: virtual DatabaseCon& getWalletDB() = 0; - virtual Fees + [[nodiscard]] virtual Fees getFees() const = 0; // Temporary: Get the underlying Application for functions that haven't diff --git a/include/xrpl/protocol/TxMeta.h b/include/xrpl/protocol/TxMeta.h index 3f80636c6f..c09645e5e3 100644 --- a/include/xrpl/protocol/TxMeta.h +++ b/include/xrpl/protocol/TxMeta.h @@ -116,7 +116,7 @@ public: gasUsed_ = gasUsed; } - std::optional const& + [[nodiscard]] std::optional const& getGasUsed() const { return gasUsed_; @@ -128,7 +128,7 @@ public: wasmReturnCode_ = wasmReturnCode; } - std::optional const& + [[nodiscard]] std::optional const& getWasmReturnCode() const { return wasmReturnCode_; diff --git a/src/libxrpl/tx/Transactor.cpp b/src/libxrpl/tx/Transactor.cpp index 44d9f63695..b460655a76 100644 --- a/src/libxrpl/tx/Transactor.cpp +++ b/src/libxrpl/tx/Transactor.cpp @@ -1335,7 +1335,7 @@ Transactor::operator()() if (doWasmData && before && after && (before->getType() == ltESCROW)) { - modifiedWasmObjects.push_back(std::make_pair(index, after->getFieldVL(sfData))); + modifiedWasmObjects.emplace_back(index, after->getFieldVL(sfData)); } }); } @@ -1375,8 +1375,10 @@ Transactor::operator()() } if (result == tecWASM_REJECTED) + { modifyWasmDataFields( view(), modifiedWasmObjects, ctx_.registry.get().getJournal("View")); + } applied = isTecClaim(result); } diff --git a/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp b/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp index 05db9921bb..133bb75abd 100644 --- a/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp +++ b/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -32,7 +33,6 @@ #include #include #include -#include #include #include @@ -133,11 +133,9 @@ EscrowCreate::calculateBaseFee(ReadView const& view, STTx const& tx) bool EscrowCreate::checkExtraFeatures(PreflightContext const& ctx) { - if ((ctx.tx.isFieldPresent(sfFinishFunction) || ctx.tx.isFieldPresent(sfData)) && - !ctx.rules.enabled(featureSmartEscrow)) - return false; - - return true; + return !( + (ctx.tx.isFieldPresent(sfFinishFunction) || ctx.tx.isFieldPresent(sfData)) && + !ctx.rules.enabled(featureSmartEscrow)); } NotTEC @@ -224,7 +222,7 @@ EscrowCreate::preflight(PreflightContext const& ctx) } auto const code = ctx.tx.getFieldVL(sfFinishFunction); - if (code.size() == 0 || code.size() > fees.extensionSizeLimit) + if (code.empty() || code.size() > fees.extensionSizeLimit) { JLOG(ctx.j.debug()) << "EscrowCreate.FinishFunction bad size " << code.size(); return temMALFORMED; @@ -244,7 +242,7 @@ EscrowCreate::preflightSigValidated(PreflightContext const& ctx) auto const code = ctx.tx.getFieldVL(sfFinishFunction); // basic checks happen in `preflight` - HostFunctions mock(ctx.j); + HostFunctions const mock(ctx.j); auto const re = preflightEscrowWasm(code, mock, ESCROW_FUNCTION_NAME); if (!isTesSuccess(re)) { diff --git a/src/libxrpl/tx/transactors/escrow/EscrowFinish.cpp b/src/libxrpl/tx/transactors/escrow/EscrowFinish.cpp index 4da100a168..0c6391ec69 100644 --- a/src/libxrpl/tx/transactors/escrow/EscrowFinish.cpp +++ b/src/libxrpl/tx/transactors/escrow/EscrowFinish.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -29,13 +30,16 @@ #include #include #include -#include #include #include +#include +#include #include +#include #include #include +#include namespace xrpl { @@ -164,7 +168,7 @@ EscrowFinish::calculateBaseFee(ReadView const& view, STTx const& tx) // whole drop. // Integer math rounds down by default, so we add 1 to round up. uint64_t const allowanceFee = - ((*allowance) * view.fees().gasPrice) / MICRO_DROPS_PER_DROP + 1; + ((*allowance) * view.fees().gasPrice) / MICRO_DROPS_PER_DROP + 1 = 0; extraFee += allowanceFee; } return Transactor::calculateBaseFee(view, tx) + extraFee; @@ -326,7 +330,7 @@ EscrowFinish::doApply() return tecNO_DST; if (auto err = - verifyDepositPreauth(ctx_.tx, ctx_.view(), account_, destID, sled, ctx_.journal); + verifyDepositPreauth(ctx_.tx, ctx_.view(), accountID_, destID, sled, ctx_.journal); !isTesSuccess(err)) return err; } @@ -404,7 +408,7 @@ EscrowFinish::doApply() auto const wasmStr = slep->getFieldVL(sfFinishFunction); std::vector const wasm(wasmStr.begin(), wasmStr.end()); - WasmHostFunctionsImpl ledgerDataProvider(ctx_, k); + WasmHostFunctionsImpl const ledgerDataProvider(ctx_, k); if (!ctx_.tx.isFieldPresent(sfComputationAllowance)) { diff --git a/src/test/app/EscrowSmart_test.cpp b/src/test/app/EscrowSmart_test.cpp index c12313c0a8..3e35433ef1 100644 --- a/src/test/app/EscrowSmart_test.cpp +++ b/src/test/app/EscrowSmart_test.cpp @@ -1,22 +1,50 @@ #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include +#include + +#include +#include +#include +#include +#include +#include #include #include +#include +#include +#include +#include #include -#include -#include -#include +#include -#include -#include +#include +#include +#include +#include #include +#include -namespace xrpl { -namespace test { +namespace xrpl::test { -struct EscrowSmart_test : public beast::unit_test::suite +struct EscrowSmart_test : public beast::unit_test::Suite { void testCreateFinishFunctionPreflight(FeatureBitset features) @@ -39,18 +67,18 @@ struct EscrowSmart_test : public beast::unit_test::suite XRPAmount const txnFees = env.current()->fees().base + 1000; auto const escrowCreate = escrow::create(alice, carol, XRP(1000)); env(escrowCreate, - escrow::finish_function(ledgerSqnWasmHex), + escrow::FinishFunction(kLedgerSqnWasmHex), escrow::cancel_time(env.now() + 100s), fee(txnFees), - ter(temDISABLED)); + Ter(temDISABLED)); env.close(); env(escrowCreate, - escrow::finish_function(ledgerSqnWasmHex), + escrow::FinishFunction(kLedgerSqnWasmHex), escrow::cancel_time(env.now() + 100s), - escrow::data("00112233"), + escrow::Data("00112233"), fee(txnFees), - ter(temDISABLED)); + Ter(temDISABLED)); env.close(); } @@ -72,10 +100,10 @@ struct EscrowSmart_test : public beast::unit_test::suite // 11-byte string std::string const longWasmHex = "00112233445566778899AA"; env(escrowCreate, - escrow::finish_function(longWasmHex), + escrow::FinishFunction(longWasmHex), escrow::cancel_time(env.now() + 100s), fee(txnFees), - ter(temMALFORMED)); + Ter(temMALFORMED)); env.close(); } @@ -96,11 +124,11 @@ struct EscrowSmart_test : public beast::unit_test::suite auto const escrowCreate = escrow::create(alice, carol, XRP(500)); env(escrowCreate, - escrow::finish_function(ledgerSqnWasmHex), + escrow::FinishFunction(kLedgerSqnWasmHex), escrow::cancel_time(env.now() + 100s), - escrow::comp_allowance(100), + escrow::CompAllowance(100), fee(txnFees), - ter(temMALFORMED)); + Ter(temMALFORMED)); env.close(); } @@ -121,14 +149,14 @@ struct EscrowSmart_test : public beast::unit_test::suite // 2-byte string env(escrowCreate, - escrow::finish_function("AA"), + escrow::FinishFunction("AA"), escrow::cancel_time(env.now() + 100s), fee(txnFees), - ter(temTEMP_DISABLED)); + Ter(temTEMP_DISABLED)); env.close(); env(escrowCreate, - escrow::finish_function(ledgerSqnWasmHex), + escrow::FinishFunction(ledgerSqnWasmHex), escrow::cancel_time(env.now() + 100s), fee(txnFees), ter(temTEMP_DISABLED)); @@ -146,7 +174,7 @@ struct EscrowSmart_test : public beast::unit_test::suite std::string const longData(4, 'A'); env(escrowCreate, - escrow::data(longData), + escrow::Data(longData), escrow::finish_time(env.now() + 100s), fee(txnFees), ter(temMALFORMED)); @@ -165,7 +193,7 @@ struct EscrowSmart_test : public beast::unit_test::suite // string of length maxWasmDataLength * 2 + 2 std::string const longData((maxWasmDataLength + 1) * 2, 'B'); env(escrowCreate, - escrow::data(longData), + escrow::Data(longData), escrow::finish_function(ledgerSqnWasmHex), escrow::cancel_time(env.now() + 100s), fee(txnFees), @@ -326,7 +354,7 @@ struct EscrowSmart_test : public beast::unit_test::suite env.current()->fees().base * 10 + ledgerSqnWasmHex.size() / 2 * 5; env(escrow::finish(carol, alice, 1), fee(txnFees), - escrow::comp_allowance(4), + escrow::CompAllowance(4), ter(temDISABLED)); env.close(); } @@ -350,7 +378,7 @@ struct EscrowSmart_test : public beast::unit_test::suite auto const allowance = 1'001; env(escrow::finish(carol, alice, 1), fee(env.current()->fees().base + allowance), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), ter(temBAD_LIMIT)); } @@ -399,7 +427,7 @@ struct EscrowSmart_test : public beast::unit_test::suite BEAST_EXPECT(env.le(keylet)); env(escrow::finish(alice, alice, seq), - escrow::comp_allowance(1000), + escrow::CompAllowance(1000), fee(env.current()->fees().base + 1000), ter(temTEMP_DISABLED)); } @@ -430,7 +458,7 @@ struct EscrowSmart_test : public beast::unit_test::suite { // ComputationAllowance value of 0 - env(escrow::finish(carol, alice, seq), escrow::comp_allowance(0), ter(temBAD_LIMIT)); + env(escrow::finish(carol, alice, seq), escrow::CompAllowance(0), ter(temBAD_LIMIT)); } { @@ -440,7 +468,7 @@ struct EscrowSmart_test : public beast::unit_test::suite auto const finishFee = env.current()->fees().base + 3; env(escrow::finish(carol, alice, seq), fee(finishFee), - escrow::comp_allowance(4), + escrow::CompAllowance(4), ter(telINSUF_FEE_P)); } @@ -451,7 +479,7 @@ struct EscrowSmart_test : public beast::unit_test::suite auto const finishFee = env.current()->fees().base + 4; env(escrow::finish(carol, alice, seq), fee(finishFee), - escrow::comp_allowance(2), + escrow::CompAllowance(2), ter(tecFAILED_PROCESSING)); } @@ -468,7 +496,7 @@ struct EscrowSmart_test : public beast::unit_test::suite env(escrow::finish(carol, alice, seq2), fee(env.current()->fees().base + (allowance * env.current()->fees().gasPrice) / MICRO_DROPS_PER_DROP + 1), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), ter(tefNO_WASM)); } } @@ -515,23 +543,23 @@ struct EscrowSmart_test : public beast::unit_test::suite env.require(balance(carol, XRP(5000))); env(escrow::finish(carol, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee), ter(tecWASM_REJECTED)); env(escrow::finish(alice, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee), ter(tecWASM_REJECTED)); env(escrow::finish(alice, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee), ter(tecWASM_REJECTED)); env(escrow::finish(carol, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee), ter(tecWASM_REJECTED)); env(escrow::finish(carol, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee), ter(tecWASM_REJECTED)); env.close(); @@ -539,25 +567,31 @@ struct EscrowSmart_test : public beast::unit_test::suite { auto const txMeta = env.meta(); if (BEAST_EXPECT(txMeta->isFieldPresent(sfGasUsed))) + { BEAST_EXPECTS( env.meta()->getFieldU32(sfGasUsed) == allowance, std::to_string(env.meta()->getFieldU32(sfGasUsed))); + } } env(escrow::finish(alice, alice, seq), fee(finishFee), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), ter(tesSUCCESS)); auto const txMeta = env.meta(); if (BEAST_EXPECT(txMeta->isFieldPresent(sfGasUsed))) + { BEAST_EXPECTS( txMeta->getFieldU32(sfGasUsed) == allowance, std::to_string(txMeta->getFieldU32(sfGasUsed))); + } if (BEAST_EXPECT(txMeta->isFieldPresent(sfWasmReturnCode))) + { BEAST_EXPECTS( txMeta->getFieldI32(sfWasmReturnCode) == 5, std::to_string(txMeta->getFieldI32(sfWasmReturnCode))); + } BEAST_EXPECT(env.ownerCount(alice) == 0); } @@ -586,50 +620,56 @@ struct EscrowSmart_test : public beast::unit_test::suite // no fulfillment provided, function fails env(escrow::finish(carol, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee), ter(tecCRYPTOCONDITION_ERROR)); // fulfillment provided, function fails env(escrow::finish(carol, alice, seq), escrow::condition(escrow::cb1), escrow::fulfillment(escrow::fb1), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(conditionFinishFee), ter(tecWASM_REJECTED)); if (BEAST_EXPECT(env.meta()->isFieldPresent(sfGasUsed))) + { BEAST_EXPECTS( env.meta()->getFieldU32(sfGasUsed) == allowance, std::to_string(env.meta()->getFieldU32(sfGasUsed))); + } env.close(); // no fulfillment provided, function succeeds env(escrow::finish(alice, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(conditionFinishFee), ter(tecCRYPTOCONDITION_ERROR)); // wrong fulfillment provided, function succeeds env(escrow::finish(alice, alice, seq), escrow::condition(escrow::cb1), escrow::fulfillment(escrow::fb2), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(conditionFinishFee), ter(tecCRYPTOCONDITION_ERROR)); // fulfillment provided, function succeeds, tx succeeds env(escrow::finish(alice, alice, seq), escrow::condition(escrow::cb1), escrow::fulfillment(escrow::fb1), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(conditionFinishFee), ter(tesSUCCESS)); auto const txMeta = env.meta(); if (BEAST_EXPECT(txMeta->isFieldPresent(sfGasUsed))) + { BEAST_EXPECTS( txMeta->getFieldU32(sfGasUsed) == allowance, std::to_string(txMeta->getFieldU32(sfGasUsed))); + } if (BEAST_EXPECT(txMeta->isFieldPresent(sfWasmReturnCode))) + { BEAST_EXPECTS( txMeta->getFieldI32(sfWasmReturnCode) == 5, std::to_string(txMeta->getFieldI32(sfWasmReturnCode))); + } env.close(); BEAST_EXPECT(env.ownerCount(alice) == 0); @@ -658,19 +698,21 @@ struct EscrowSmart_test : public beast::unit_test::suite // finish time hasn't passed, function fails env(escrow::finish(carol, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee + 1), ter(tecNO_PERMISSION)); env.close(); // finish time hasn't passed, function succeeds for (; env.now() < ts; env.close()) + { env(escrow::finish(carol, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee + 2), ter(tecNO_PERMISSION)); + } env(escrow::finish(carol, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee + 1), ter(tesSUCCESS)); @@ -678,9 +720,11 @@ struct EscrowSmart_test : public beast::unit_test::suite if (BEAST_EXPECT(txMeta->isFieldPresent(sfGasUsed))) BEAST_EXPECT(txMeta->getFieldU32(sfGasUsed) == allowance); if (BEAST_EXPECT(txMeta->isFieldPresent(sfWasmReturnCode))) + { BEAST_EXPECTS( txMeta->getFieldI32(sfWasmReturnCode) == 5, std::to_string(txMeta->getFieldI32(sfWasmReturnCode))); + } BEAST_EXPECT(env.ownerCount(alice) == 0); } @@ -707,24 +751,26 @@ struct EscrowSmart_test : public beast::unit_test::suite // finish time hasn't passed, function fails env(escrow::finish(carol, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee), ter(tecNO_PERMISSION)); env.close(); // finish time has passed, function fails env(escrow::finish(carol, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee), ter(tecWASM_REJECTED)); if (BEAST_EXPECT(env.meta()->isFieldPresent(sfGasUsed))) + { BEAST_EXPECTS( env.meta()->getFieldU32(sfGasUsed) == allowance, std::to_string(env.meta()->getFieldU32(sfGasUsed))); + } env.close(); // finish time has passed, function succeeds, tx succeeds env(escrow::finish(carol, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee), ter(tesSUCCESS)); @@ -732,9 +778,11 @@ struct EscrowSmart_test : public beast::unit_test::suite if (BEAST_EXPECT(txMeta->isFieldPresent(sfGasUsed))) BEAST_EXPECT(txMeta->getFieldU32(sfGasUsed) == allowance); if (BEAST_EXPECT(txMeta->isFieldPresent(sfWasmReturnCode))) + { BEAST_EXPECTS( txMeta->getFieldI32(sfWasmReturnCode) == 5, std::to_string(txMeta->getFieldI32(sfWasmReturnCode))); + } env.close(); BEAST_EXPECT(env.ownerCount(alice) == 0); @@ -761,9 +809,9 @@ struct EscrowSmart_test : public beast::unit_test::suite BEAST_EXPECT(env.ownerCount(alice) == 0); auto escrowCreate = escrow::create(alice, alice, XRP(1000)); XRPAmount const txnFees = - env.current()->fees().base * 10 + updateDataWasmHex.size() / 2 * 5; + env.current()->fees().base * 10 + kUpdateDataWasmHex.size() / 2 * 5; env(escrowCreate, - escrow::finish_function(updateDataWasmHex), + escrow::FinishFunction(kUpdateDataWasmHex), escrow::finish_time(env.now() + 2s), escrow::cancel_time(env.now() + 100s), fee(txnFees)); @@ -771,7 +819,7 @@ struct EscrowSmart_test : public beast::unit_test::suite env.close(); env.close(); - if (BEAST_EXPECT(env.ownerCount(alice) == (1 + updateDataWasmHex.size() / 2 / 500))) + if (BEAST_EXPECT(env.ownerCount(alice) == (1 + kUpdateDataWasmHex.size() / 2 / 500))) { env.require(balance(alice, XRP(4000) - txnFees)); @@ -781,19 +829,23 @@ struct EscrowSmart_test : public beast::unit_test::suite // FinishAfter time hasn't passed env(escrow::finish(alice, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee), ter(tecWASM_REJECTED)); auto const txMeta = env.meta(); if (BEAST_EXPECT(txMeta && txMeta->isFieldPresent(sfGasUsed))) + { BEAST_EXPECTS( txMeta->getFieldU32(sfGasUsed) == allowance, std::to_string(txMeta->getFieldU32(sfGasUsed))); + } if (BEAST_EXPECT(txMeta->isFieldPresent(sfWasmReturnCode))) + { BEAST_EXPECTS( txMeta->getFieldI32(sfWasmReturnCode) == -256, std::to_string(txMeta->getFieldI32(sfWasmReturnCode))); + } auto const sle = env.le(keylet::escrow(alice, seq)); if (BEAST_EXPECT(sle && sle->isFieldPresent(sfData))) @@ -855,8 +907,8 @@ struct EscrowSmart_test : public beast::unit_test::suite auto const bigAllowance = 996'433; uint64_t const partialFeeCalc = - (static_cast(bigAllowance) * 1'000'000) / MICRO_DROPS_PER_DROP + - 1; // to avoid an overflow + (static_cast(bigAllowance) * 1'000'000) / MICRO_DROPS_PER_DROP + 1 = + 0; // to avoid an overflow auto finishFee = env.current()->fees().base + partialFeeCalc; BEAST_EXPECT(finishFee.drops() > bigAllowance); @@ -865,28 +917,32 @@ struct EscrowSmart_test : public beast::unit_test::suite env(escrow::finish(alice, alice, seq), fee(finishFeeOverflow), // enough if there's an overflow - escrow::comp_allowance(bigAllowance), + escrow::CompAllowance(bigAllowance), ter(telINSUF_FEE_P)); env(escrow::finish(alice, alice, seq), fee(finishFee - 1), - escrow::comp_allowance(bigAllowance), + escrow::CompAllowance(bigAllowance), ter(telINSUF_FEE_P)); env(escrow::finish(alice, alice, seq), fee(finishFee), - escrow::comp_allowance(bigAllowance), + escrow::CompAllowance(bigAllowance), ter(tesSUCCESS)); auto const txMeta = env.meta(); if (BEAST_EXPECT(txMeta->isFieldPresent(sfGasUsed))) + { BEAST_EXPECTS( txMeta->getFieldU32(sfGasUsed) == allowance, std::to_string(txMeta->getFieldU32(sfGasUsed))); + } if (BEAST_EXPECT(txMeta->isFieldPresent(sfWasmReturnCode))) + { BEAST_EXPECTS( txMeta->getFieldI32(sfWasmReturnCode) == 5, std::to_string(txMeta->getFieldI32(sfWasmReturnCode))); + } BEAST_EXPECT(env.ownerCount(alice) == 0); } @@ -933,7 +989,7 @@ struct EscrowSmart_test : public beast::unit_test::suite // FinishAfter time hasn't passed env(escrow::finish(carol, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee), ter(tecNO_PERMISSION)); env.close(); @@ -946,15 +1002,17 @@ struct EscrowSmart_test : public beast::unit_test::suite env.close(); env(escrow::finish(alice, alice, seq), - escrow::comp_allowance(allowance), + escrow::CompAllowance(allowance), fee(finishFee), ter(tesSUCCESS)); 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))); + } if (BEAST_EXPECT(txMeta->isFieldPresent(sfWasmReturnCode))) BEAST_EXPECT(txMeta->getFieldI32(sfWasmReturnCode) == 1); @@ -1033,7 +1091,7 @@ struct EscrowSmart_test : public beast::unit_test::suite 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), + escrow::CompAllowance(allowance), fee(finishFee)); env.close(); @@ -1065,6 +1123,7 @@ struct EscrowSmart_test : public beast::unit_test::suite std::source_location const& loc = std::source_location::current()) { auto makeEnv = [&]() -> Env { if (sizeLimit) + { return Env( *this, envconfig([&sizeLimit](std::unique_ptr cfg) { @@ -1072,8 +1131,8 @@ struct EscrowSmart_test : public beast::unit_test::suite return cfg; }), features); - else - return Env(*this, features); + } + return Env(*this, features); }; Env env = makeEnv(); @@ -1085,22 +1144,30 @@ struct EscrowSmart_test : public beast::unit_test::suite try { env(escrow::create(alice, alice, XRP(1000)), - escrow::finish_function(wasmHex), + escrow::FinishFunction(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})); if (expectedStatus == ExpectedStatus::Crash) + { fail("Expected crash", loc.file_name(), loc.line()); + } else + { pass(); + } } catch (std::exception const& e) { if (expectedStatus == ExpectedStatus::Crash) + { pass(); + } else + { fail(e.what(), loc.file_name(), loc.line()); + } } }; @@ -1189,5 +1256,4 @@ public: BEAST_DEFINE_TESTSUITE(EscrowSmart, app, xrpl); -} // namespace test -} // namespace xrpl +} // namespace xrpl::test diff --git a/src/test/app/wasm_fixtures/fixtures.cpp b/src/test/app/wasm_fixtures/fixtures.cpp index 7179019643..97f8392c93 100644 --- a/src/test/app/wasm_fixtures/fixtures.cpp +++ b/src/test/app/wasm_fixtures/fixtures.cpp @@ -1582,7 +1582,7 @@ extern std::string const kImpExpHex = "6d656d6f72790200096578705f66756e63310002096578705f66756e633200030c746573745f696d706f7274730004" "0a2b03040041010b0700200041026c0b1c01027f4120410410001a41202802002100410041201001210120000b"; -extern std::string const updateDataWasmHex = +extern std::string const kUpdateDataWasmHex = "0061736d01000000010e0360027f7f017f6000006000017f02130103656e760b7570646174" "655f64617461000003030201020503010002063f0a7f01419088040b7f004180080b7f0041" "85080b7f004190080b7f00419088040b7f004180080b7f00419088040b7f00418080080b7f" diff --git a/src/test/app/wasm_fixtures/fixtures.h b/src/test/app/wasm_fixtures/fixtures.h index f74b6874f9..75574e2855 100644 --- a/src/test/app/wasm_fixtures/fixtures.h +++ b/src/test/app/wasm_fixtures/fixtures.h @@ -10,7 +10,7 @@ namespace wasm_constants { // Magic + version header -uint8_t const WASM_HEADER[] = { +uint8_t const kWasmHeader[] = { 0x00, 0x61, 0x73, @@ -22,39 +22,39 @@ uint8_t const WASM_HEADER[] = { }; // Type section: () -> () -uint8_t const TYPE_EMPTY_FUNC[] = {0x01, 0x04, 0x01, 0x60, 0x00, 0x00}; +uint8_t const kTypeEmptyFunc[] = {0x01, 0x04, 0x01, 0x60, 0x00, 0x00}; // Function section: one function using type 0 -uint8_t const FUNC_TYPE0[] = {0x03, 0x02, 0x01, 0x00}; +uint8_t const kFuncTypE0[] = {0x03, 0x02, 0x01, 0x00}; // Export section: export func 0 as "finish" -uint8_t const EXPORT_FINISH[] = {0x07, 0x0a, 0x01, 0x06, 'f', 'i', 'n', 'i', 's', 'h', 0x00, 0x00}; +uint8_t const kExportFinish[] = {0x07, 0x0a, 0x01, 0x06, 'f', 'i', 'n', 'i', 's', 'h', 0x00, 0x00}; // Empty function body: 0 locals, end -uint8_t const EMPTY_BODY[] = {0x00, 0x0b}; +uint8_t const kEmptyBody[] = {0x00, 0x0b}; // Data segment offset: i32.const 0, end -uint8_t const DATA_OFFSET_ZERO[] = {0x41, 0x00, 0x0b}; +uint8_t const kDataOffsetZero[] = {0x41, 0x00, 0x0b}; // Section IDs -uint8_t const SECTION_MEMORY = 0x05; -uint8_t const SECTION_CODE = 0x0a; -uint8_t const SECTION_DATA = 0x0b; +uint8_t const kSectionMemory = 0x05; +uint8_t const kSectionCode = 0x0a; +uint8_t const kSectionData = 0x0b; // Instructions -uint8_t const INSTR_NOP = 0x01; -uint8_t const INSTR_END = 0x0b; +uint8_t const kInstrNop = 0x01; +uint8_t const kInstrEnd = 0x0b; // Fill byte for data section bloat -uint8_t const DATA_FILL_BYTE = 0xEE; +uint8_t const kDataFillByte = 0xEE; // Generator for WASM module with large code section (many NOPs) std::vector -generateCodeBlob(uint32_t num_instructions); +generateCodeBlob(uint32_t numInstructions); // Generator for WASM module with large data section std::vector -generateDataBlob(uint32_t data_size); +generateDataBlob(uint32_t dataSize); } // namespace wasm_constants @@ -135,4 +135,4 @@ extern std::string const kFunctions5kHex; extern std::string const kOpcReservedHex; extern std::string const kImpExpHex; -extern std::string const updateDataWasmHex; +extern std::string const kUpdateDataWasmHex; diff --git a/src/test/jtx/escrow.h b/src/test/jtx/escrow.h index 6b8c9d724c..3416aef61b 100644 --- a/src/test/jtx/escrow.h +++ b/src/test/jtx/escrow.h @@ -8,6 +8,8 @@ #include +#include + /** Escrow operations. */ namespace xrpl::test::jtx::escrow { @@ -75,22 +77,22 @@ auto const kCondition = JTxFieldWrapper(sfCondition); auto const kFulfillment = JTxFieldWrapper(sfFulfillment); -struct finish_function +struct FinishFunction { private: std::string value_; public: - explicit finish_function(std::string func) : value_(func) + explicit FinishFunction(std::string func) : value_(std::move(func)) { } - explicit finish_function(Slice const& func) : value_(strHex(func)) + explicit FinishFunction(Slice const& func) : value_(strHex(func)) { } template - explicit finish_function(std::array const& f) : finish_function(makeSlice(f)) + explicit FinishFunction(std::array const& f) : FinishFunction(makeSlice(f)) { } @@ -101,22 +103,22 @@ public: } }; -struct data +struct Data { private: std::string value_; public: - explicit data(std::string func) : value_(func) + explicit Data(std::string func) : value_(std::move(func)) { } - explicit data(Slice const& func) : value_(strHex(func)) + explicit Data(Slice const& func) : value_(strHex(func)) { } template - explicit data(std::array const& f) : data(makeSlice(f)) + explicit Data(std::array const& f) : Data(makeSlice(f)) { } @@ -127,13 +129,13 @@ public: } }; -struct comp_allowance +struct CompAllowance { private: std::uint32_t value_; public: - explicit comp_allowance(std::uint32_t const& value) : value_(value) + explicit CompAllowance(std::uint32_t const& value) : value_(value) { } diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index e3906a51ab..181e2210ca 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -817,7 +817,7 @@ public: return *walletDB_; } - virtual Fees + Fees getFees() const override { XRPL_ASSERT(config_, "xrpl::ApplicationImp::getFees : non-null config");