trace testcase

This commit is contained in:
Richard Holland
2023-01-10 13:48:15 +00:00
parent 61e0a3766c
commit e299f099d8
2 changed files with 85 additions and 21 deletions

View File

@@ -9078,7 +9078,52 @@ public:
void
test_trace()
{
// TODO
testcase("Test trace");
using namespace jtx;
Env env{*this, supported_amendments()};
auto const alice = Account{"alice"};
auto const bob = Account{"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);
#define GUARD(maxiter) _g((1ULL << 31U) + __LINE__, (maxiter)+1)
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 trace (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
#define OUT_OF_BOUNDS -1
#define ASSERT(x)\
if (!(x))\
rollback((uint32_t)#x, sizeof(#x), __LINE__);
int64_t hook(uint32_t reservmaed )
{
_g(1,1);
// Test out of bounds check
ASSERT(trace(1000000, 10, 0, 10, 0) == OUT_OF_BOUNDS);
ASSERT(trace(0, 1000000, 0, 10, 0) == OUT_OF_BOUNDS);
ASSERT(trace(0, 10, 1000000, 10, 0) == OUT_OF_BOUNDS);
ASSERT(trace(0, 10, 0, 1000000, 0) == OUT_OF_BOUNDS);
ASSERT(trace(0,0,0,0,0) == 0);
ASSERT(trace(0,1,2,3,1) == 0);
return accept(0,0,0);
}
)[test.hook]"];
// install the hook on alice
env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0),
M("set trace"),
HSFEE);
env.close();
// invoke the hook
env(pay(bob, alice, XRP(1)), M("test trace"), fee(XRP(1)));
}
void
@@ -10974,7 +11019,7 @@ public:
test_sto_subfield(); //
test_sto_validate(); //
test_trace();
test_trace(); //
test_trace_float();
test_trace_num();