mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-30 15:35:49 +00:00
ledger_seq unit test
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
//==============================================================================
|
||||
#include <ripple/app/hook/Enum.h>
|
||||
#include <ripple/app/tx/impl/SetHook.h>
|
||||
#include <ripple/app/ledger/LedgerMaster.h>
|
||||
#include <ripple/protocol/TxFlags.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/app/SetHook_wasm.h>
|
||||
@@ -4015,6 +4016,60 @@ public:
|
||||
void
|
||||
test_ledger_seq()
|
||||
{
|
||||
testcase("Test ledger_seq");
|
||||
using namespace jtx;
|
||||
Env env{*this, supported_amendments()};
|
||||
|
||||
Account const alice{"alice"};
|
||||
Account const bob{"bob"};
|
||||
env.fund(XRP(10000), alice);
|
||||
env.fund(XRP(10000), bob);
|
||||
|
||||
TestHook hook = wasm[R"[test.hook](
|
||||
#include <stdint.h>
|
||||
extern int32_t _g (uint32_t id, uint32_t maxiter);
|
||||
extern int64_t accept (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
|
||||
extern int64_t ledger_seq (void);
|
||||
int64_t hook(uint32_t reserved )
|
||||
{
|
||||
_g(1,1);
|
||||
|
||||
accept(0,0,ledger_seq());
|
||||
}
|
||||
)[test.hook]"];
|
||||
|
||||
// install the hook on alice
|
||||
env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0),
|
||||
M("set ledger_seq"),
|
||||
HSFEE);
|
||||
env.close();
|
||||
|
||||
// invoke the hook a few times
|
||||
for (uint32_t i = 0; i < 3; ++i)
|
||||
{
|
||||
env(pay(bob, alice, XRP(1)), M("test ledger_seq"), fee(XRP(1)));
|
||||
env.close();
|
||||
{
|
||||
auto meta = env.meta();
|
||||
|
||||
// ensure hook execution occured
|
||||
BEAST_REQUIRE(meta);
|
||||
BEAST_REQUIRE(meta->isFieldPresent(sfHookExecutions));
|
||||
|
||||
// ensure there was only one hook execution
|
||||
auto const hookExecutions =
|
||||
meta->getFieldArray(sfHookExecutions);
|
||||
BEAST_REQUIRE(hookExecutions.size() == 1);
|
||||
|
||||
// get the data in the return code of the execution
|
||||
auto const rc =
|
||||
hookExecutions[0].getFieldU64(sfHookReturnCode);
|
||||
|
||||
// check that it matches the last ledger seq number
|
||||
BEAST_EXPECT(env.app().getLedgerMaster().getClosedLedger()->info().seq == rc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
@@ -8492,7 +8547,7 @@ public:
|
||||
test_ledger_last_hash();
|
||||
test_ledger_last_time();
|
||||
test_ledger_nonce();
|
||||
test_ledger_seq();
|
||||
test_ledger_seq(); //
|
||||
|
||||
test_meta_slot();
|
||||
|
||||
@@ -8514,9 +8569,9 @@ public:
|
||||
test_slot_type(); //
|
||||
|
||||
test_state(); //
|
||||
test_state_foreign();
|
||||
test_state_foreign(); //
|
||||
test_state_foreign_set();
|
||||
test_state_set();
|
||||
test_state_set(); //
|
||||
|
||||
test_sto_emplace(); //
|
||||
test_sto_erase(); //
|
||||
|
||||
Reference in New Issue
Block a user