hook_again test case

This commit is contained in:
Richard Holland
2023-01-03 16:58:54 +00:00
parent 8ede26b000
commit 708a567f10

View File

@@ -4153,6 +4153,70 @@ public:
void
test_hook_again()
{
testcase("Test hook_again");
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 rollback (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
extern int64_t hook_again (void);
#define PREREQUISITE_NOT_MET (-9)
#define ALREADY_SET (-8)
int64_t hook(uint32_t r)
{
_g(1,1);
if (r > 0)
{
if (hook_again() != PREREQUISITE_NOT_MET)
return rollback(0,0,253);
return accept(0,0,1);
}
if (hook_again() != 1)
return rollback(0,0,254);
if (hook_again() != ALREADY_SET)
return rollback(0,0,255);
return accept(0,0,0);
}
)[test.hook]"];
// install the hook on alice
env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0),
M("set hook_again"),
HSFEE);
env.close();
env(pay(bob, alice, XRP(1)), M("test hook_again"), fee(XRP(1)));
env.close();
auto meta = env.meta();
// ensure hook execution occured
BEAST_REQUIRE(meta);
BEAST_REQUIRE(meta->isFieldPresent(sfHookExecutions));
// ensure there were two executions
auto const hookExecutions =
meta->getFieldArray(sfHookExecutions);
BEAST_REQUIRE(hookExecutions.size() == 2);
// get the data in the return code of the execution
BEAST_EXPECT(hookExecutions[0].getFieldU64(sfHookReturnCode) == 0);
BEAST_EXPECT(hookExecutions[1].getFieldU64(sfHookReturnCode) == 1);
// RH TODO: test hook_again on a weak execution not following a strong execution to make sure it fails
}
void
@@ -9493,7 +9557,7 @@ public:
test_float_sum(); //
test_hook_account(); //
test_hook_again();
test_hook_again(); //
test_hook_hash(); //
test_hook_param();
test_hook_param_set();