This commit is contained in:
Denis Angell
2025-02-26 13:01:57 +01:00
parent b56dc38c22
commit c6a27e895e
4 changed files with 22 additions and 15 deletions

1
src/test/app/.env Normal file
View File

@@ -0,0 +1 @@
HOOKS_COMPILE_HOST=http://localhost:9000

View File

@@ -32,7 +32,7 @@ namespace ripple {
namespace test { namespace test {
class SetHook_test : public beast::unit_test::suite class SetHookV3_test : public beast::unit_test::suite
{ {
private: private:
// helper // helper
@@ -50,13 +50,12 @@ public:
std::string std::string
loadHook() loadHook()
{ {
std::string name = "/Users/darkmatter/projects/ledger-works/xahaud/src/test/app/base.wasm"; std::string name = "/Users/darkmatter/projects/ledger-works/xahaud/src/test/app/wasm/custom.wasm";
if (!std::filesystem::exists(name)) { if (!std::filesystem::exists(name)) {
std::cout << "File does not exist: " << name << "\n"; std::cout << "File does not exist: " << name << "\n";
return ""; return "";
} }
std::ifstream hookFile(name, std::ios::binary); std::ifstream hookFile(name, std::ios::binary);
if (!hookFile) if (!hookFile)
@@ -100,6 +99,7 @@ public:
env.close(); env.close();
std::string hook = loadHook(); std::string hook = loadHook();
std::cout << "Hook: " << hook << "\n";
// install the hook on alice // install the hook on alice
env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0), env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0),
@@ -123,7 +123,7 @@ public:
void void
testWithFeatures(FeatureBitset features) testWithFeatures(FeatureBitset features)
{ {
testSimple(sa); testSimple(features);
} }
void void

View File

@@ -0,0 +1,10 @@
/**
*
*/
#include "hookapi.h"
int64_t hook(uint32_t reserved) {
TRACESTR("Base.c: Called.");
_g(1,1);
return accept(SBUF("base: Finished."), __LINE__);;
}

View File

@@ -9,16 +9,12 @@
// #define GUARD(maxiter) _g((1ULL << 31U) + __LINE__, (maxiter)+1) // #define GUARD(maxiter) _g((1ULL << 31U) + __LINE__, (maxiter)+1)
// #define GUARDM(maxiter, n) _g(( (1ULL << 31U) + (__LINE__ << 16) + n), (maxiter)+1) // #define GUARDM(maxiter, n) _g(( (1ULL << 31U) + (__LINE__ << 16) + n), (maxiter)+1)
// int64_t methodCreate(uint32_t reserved) { // hooks-cli compile-c contracts/custom.c build
// TRACESTR("somefunc.c: Called.");
// for (int i = 0; GUARD(10), i < 10; i++) {
// TRACESTR("somefunc.c: Iterating.");
// }
// return accept(SBUF("somefunc.c: Finished."), __LINE__);
// }
int64_t hook(uint32_t reserved) { int64_t methodCreate(uint32_t reserved) {
TRACESTR("Base.c: Called."); TRACESTR("somefunc.c: Called.");
_g(1,1); for (int i = 0; GUARD(10), i < 10; i++) {
return accept(SBUF("base.c: Finished."), __LINE__);; TRACESTR("somefunc.c: Iterating.");
}
return accept(SBUF("somefunc.c: Finished."), __LINE__);
} }