mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-11 06:05:49 +00:00
Compare commits
11 Commits
account-tx
...
func-hooks
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6a27e895e | ||
|
|
b56dc38c22 | ||
|
|
e654219ba5 | ||
|
|
89cacb1258 | ||
|
|
8ccff44e8c | ||
|
|
420240a2ab | ||
|
|
230873f196 | ||
|
|
1fb1a99ea2 | ||
|
|
e0b63ac70e | ||
|
|
da8df63be3 | ||
|
|
317bd4bc6e |
2
.github/workflows/build-in-docker.yml
vendored
2
.github/workflows/build-in-docker.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
|||||||
checkout:
|
checkout:
|
||||||
runs-on: [self-hosted, vanity]
|
runs-on: [self-hosted, vanity]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
clean: false
|
clean: false
|
||||||
checkpatterns:
|
checkpatterns:
|
||||||
|
|||||||
@@ -764,6 +764,7 @@ if (tests)
|
|||||||
src/test/app/ValidatorSite_test.cpp
|
src/test/app/ValidatorSite_test.cpp
|
||||||
src/test/app/SetHook_test.cpp
|
src/test/app/SetHook_test.cpp
|
||||||
src/test/app/SetHookTSH_test.cpp
|
src/test/app/SetHookTSH_test.cpp
|
||||||
|
src/test/app/SetHookV3_test.cpp
|
||||||
src/test/app/Wildcard_test.cpp
|
src/test/app/Wildcard_test.cpp
|
||||||
src/test/app/XahauGenesis_test.cpp
|
src/test/app/XahauGenesis_test.cpp
|
||||||
src/test/app/tx/apply_test.cpp
|
src/test/app/tx/apply_test.cpp
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash -u
|
||||||
|
# We use set -e and bash with -u to bail on first non zero exit code of any
|
||||||
|
# processes launched or upon any unbound variable.
|
||||||
|
# We use set -x to print commands before running them to help with
|
||||||
|
# debugging.
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
echo "START INSIDE CONTAINER - CORE"
|
echo "START INSIDE CONTAINER - CORE"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash -u
|
||||||
|
# We use set -e and bash with -u to bail on first non zero exit code of any
|
||||||
|
# processes launched or upon any unbound variable.
|
||||||
|
# We use set -x to print commands before running them to help with
|
||||||
|
# debugging.
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
echo "START INSIDE CONTAINER - FULL"
|
echo "START INSIDE CONTAINER - FULL"
|
||||||
|
|
||||||
@@ -19,7 +26,7 @@ yum-config-manager --disable centos-sclo-sclo
|
|||||||
####
|
####
|
||||||
|
|
||||||
cd /io;
|
cd /io;
|
||||||
mkdir src/certs;
|
mkdir -p src/certs;
|
||||||
curl --silent -k https://raw.githubusercontent.com/RichardAH/rippled-release-builder/main/ca-bundle/certbundle.h -o src/certs/certbundle.h;
|
curl --silent -k https://raw.githubusercontent.com/RichardAH/rippled-release-builder/main/ca-bundle/certbundle.h -o src/certs/certbundle.h;
|
||||||
if [ "`grep certbundle.h src/ripple/net/impl/RegisterSSLCerts.cpp | wc -l`" -eq "0" ]
|
if [ "`grep certbundle.h src/ripple/net/impl/RegisterSSLCerts.cpp | wc -l`" -eq "0" ]
|
||||||
then
|
then
|
||||||
@@ -66,8 +73,8 @@ then
|
|||||||
#endif/g" src/ripple/net/impl/RegisterSSLCerts.cpp &&
|
#endif/g" src/ripple/net/impl/RegisterSSLCerts.cpp &&
|
||||||
sed -i "s/#include <ripple\/net\/RegisterSSLCerts.h>/\0\n#include <certs\/certbundle.h>/g" src/ripple/net/impl/RegisterSSLCerts.cpp
|
sed -i "s/#include <ripple\/net\/RegisterSSLCerts.h>/\0\n#include <certs\/certbundle.h>/g" src/ripple/net/impl/RegisterSSLCerts.cpp
|
||||||
fi
|
fi
|
||||||
mkdir .nih_c;
|
mkdir -p .nih_c;
|
||||||
mkdir .nih_toolchain;
|
mkdir -p .nih_toolchain;
|
||||||
cd .nih_toolchain &&
|
cd .nih_toolchain &&
|
||||||
yum install -y wget lz4 lz4-devel git llvm13-static.x86_64 llvm13-devel.x86_64 devtoolset-10-binutils zlib-static ncurses-static -y \
|
yum install -y wget lz4 lz4-devel git llvm13-static.x86_64 llvm13-devel.x86_64 devtoolset-10-binutils zlib-static ncurses-static -y \
|
||||||
devtoolset-7-gcc-c++ \
|
devtoolset-7-gcc-c++ \
|
||||||
@@ -115,7 +122,7 @@ tar -xf libunwind-13.0.1.src.tar.xz &&
|
|||||||
cp -r libunwind-13.0.1.src/include libunwind-13.0.1.src/src lld-13.0.1.src/ &&
|
cp -r libunwind-13.0.1.src/include libunwind-13.0.1.src/src lld-13.0.1.src/ &&
|
||||||
cd lld-13.0.1.src &&
|
cd lld-13.0.1.src &&
|
||||||
rm -rf build CMakeCache.txt &&
|
rm -rf build CMakeCache.txt &&
|
||||||
mkdir build &&
|
mkdir -p build &&
|
||||||
cd build &&
|
cd build &&
|
||||||
cmake .. -DLLVM_LIBRARY_DIR=/usr/lib64/llvm13/lib/ -DCMAKE_INSTALL_PREFIX=/usr/lib64/llvm13/ -DCMAKE_BUILD_TYPE=Release &&
|
cmake .. -DLLVM_LIBRARY_DIR=/usr/lib64/llvm13/lib/ -DCMAKE_INSTALL_PREFIX=/usr/lib64/llvm13/ -DCMAKE_BUILD_TYPE=Release &&
|
||||||
make -j$3 install &&
|
make -j$3 install &&
|
||||||
@@ -125,7 +132,7 @@ cd ../../ &&
|
|||||||
echo "-- Build WasmEdge --" &&
|
echo "-- Build WasmEdge --" &&
|
||||||
( wget -nc -q https://github.com/WasmEdge/WasmEdge/archive/refs/tags/0.11.2.zip; unzip -o 0.11.2.zip; ) &&
|
( wget -nc -q https://github.com/WasmEdge/WasmEdge/archive/refs/tags/0.11.2.zip; unzip -o 0.11.2.zip; ) &&
|
||||||
cd WasmEdge-0.11.2 &&
|
cd WasmEdge-0.11.2 &&
|
||||||
( mkdir build; echo "" ) &&
|
( mkdir -p build; echo "" ) &&
|
||||||
cd build &&
|
cd build &&
|
||||||
export BOOST_ROOT="/usr/local/src/boost_1_86_0" &&
|
export BOOST_ROOT="/usr/local/src/boost_1_86_0" &&
|
||||||
export Boost_LIBRARY_DIRS="/usr/local/lib" &&
|
export Boost_LIBRARY_DIRS="/usr/local/lib" &&
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash -u
|
||||||
|
# We use set -e and bash with -u to bail on first non zero exit code of any
|
||||||
|
# processes launched or upon any unbound variable.
|
||||||
|
# We use set -x to print commands before running them to help with
|
||||||
|
# debugging.
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
echo "START BUILDING (HOST)"
|
echo "START BUILDING (HOST)"
|
||||||
|
|
||||||
@@ -36,7 +43,8 @@ fi
|
|||||||
|
|
||||||
STATIC_CONTAINER=$(docker ps -a | grep $CONTAINER_NAME |wc -l)
|
STATIC_CONTAINER=$(docker ps -a | grep $CONTAINER_NAME |wc -l)
|
||||||
|
|
||||||
if [[ "$STATIC_CONTAINER" -gt "0" && "$GITHUB_REPOSITORY" != "" ]]; then
|
#if [[ "$STATIC_CONTAINER" -gt "0" && "$GITHUB_REPOSITORY" != "" ]]; then
|
||||||
|
if false; then
|
||||||
echo "Static container, execute in static container to have max. cache"
|
echo "Static container, execute in static container to have max. cache"
|
||||||
docker start $CONTAINER_NAME
|
docker start $CONTAINER_NAME
|
||||||
docker exec -i $CONTAINER_NAME /hbb_exe/activate-exec bash -x /io/build-core.sh "$GITHUB_REPOSITORY" "$GITHUB_SHA" "$BUILD_CORES" "$GITHUB_RUN_NUMBER"
|
docker exec -i $CONTAINER_NAME /hbb_exe/activate-exec bash -x /io/build-core.sh "$GITHUB_REPOSITORY" "$GITHUB_SHA" "$BUILD_CORES" "$GITHUB_RUN_NUMBER"
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
using GuardLog =
|
using GuardLog =
|
||||||
std::optional<std::reference_wrapper<std::basic_ostream<char>>>;
|
std::optional<std::reference_wrapper<std::basic_ostream<char>>>;
|
||||||
|
|
||||||
#define DEBUG_GUARD 0
|
#define DEBUG_GUARD 1
|
||||||
#define DEBUG_GUARD_VERBOSE 0
|
#define DEBUG_GUARD_VERBOSE 1
|
||||||
#define DEBUG_GUARD_VERY_VERBOSE 0
|
#define DEBUG_GUARD_VERY_VERBOSE 1
|
||||||
|
|
||||||
#define GUARDLOG(logCode) \
|
#define GUARDLOG(logCode) \
|
||||||
if (!guardLog) \
|
if (!guardLog) \
|
||||||
@@ -901,23 +901,23 @@ validateGuards(
|
|||||||
// followed by an leb128 length
|
// followed by an leb128 length
|
||||||
int section_type = wasm[i++];
|
int section_type = wasm[i++];
|
||||||
|
|
||||||
if (section_type == 0)
|
// if (section_type == 0)
|
||||||
{
|
// {
|
||||||
GUARDLOG(hook::log::CUSTOM_SECTION_DISALLOWED)
|
// GUARDLOG(hook::log::CUSTOM_SECTION_DISALLOWED)
|
||||||
<< "Malformed transaction. "
|
// << "Malformed transaction. "
|
||||||
<< "Hook contained a custom section, which is not allowed. Use "
|
// << "Hook contained a custom section, which is not allowed. Use "
|
||||||
"cleaner.\n";
|
// "cleaner.\n";
|
||||||
return {};
|
// return {};
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (section_type <= last_section_type)
|
// if (section_type <= last_section_type)
|
||||||
{
|
// {
|
||||||
GUARDLOG(hook::log::SECTIONS_OUT_OF_SEQUENCE)
|
// GUARDLOG(hook::log::SECTIONS_OUT_OF_SEQUENCE)
|
||||||
<< "Malformed transcation. "
|
// << "Malformed transcation. "
|
||||||
<< "Hook contained wasm sections that were either repeated or "
|
// << "Hook contained wasm sections that were either repeated or "
|
||||||
"were out of sequence.\n";
|
// "were out of sequence.\n";
|
||||||
return {};
|
// return {};
|
||||||
}
|
// }
|
||||||
|
|
||||||
last_section_type = section_type;
|
last_section_type = section_type;
|
||||||
|
|
||||||
@@ -1139,21 +1139,32 @@ validateGuards(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wasm[i] == 'm' && wasm[i + 1] == 'e' && wasm[i + 2] == 't' && wasm[i + 3] == 'h' && wasm[i + 4] == 'o' && wasm[i + 5] == 'd')
|
||||||
|
{
|
||||||
|
i += name_len;
|
||||||
|
CHECK_SHORT_HOOK();
|
||||||
|
i++;
|
||||||
|
CHECK_SHORT_HOOK();
|
||||||
|
hook_func_idx = parseLeb128(wasm, i, &i);
|
||||||
|
CHECK_SHORT_HOOK();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
i += name_len + 1;
|
i += name_len + 1;
|
||||||
parseLeb128(wasm, i, &i);
|
parseLeb128(wasm, i, &i);
|
||||||
CHECK_SHORT_HOOK();
|
CHECK_SHORT_HOOK();
|
||||||
}
|
}
|
||||||
|
|
||||||
// execution to here means export section was parsed
|
// execution to here means export section was parsed
|
||||||
if (!hook_func_idx)
|
// if (!hook_func_idx)
|
||||||
{
|
// {
|
||||||
GUARDLOG(hook::log::EXPORT_MISSING)
|
// GUARDLOG(hook::log::EXPORT_MISSING)
|
||||||
<< "Malformed transaction. "
|
// << "Malformed transaction. "
|
||||||
<< "Hook did not export: "
|
// << "Hook did not export: "
|
||||||
<< (!hook_func_idx ? "int64_t hook(uint32_t); " : "")
|
// << (!hook_func_idx ? "int64_t hook(uint32_t); " : "")
|
||||||
<< "\n";
|
// << "\n";
|
||||||
return {};
|
// return {};
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
else if (section_type == 3) // function section
|
else if (section_type == 3) // function section
|
||||||
{
|
{
|
||||||
@@ -1295,13 +1306,13 @@ validateGuards(
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// fail
|
// fail
|
||||||
GUARDLOG(hook::log::FUNC_TYPE_INVALID)
|
// GUARDLOG(hook::log::FUNC_TYPE_INVALID)
|
||||||
<< "Invalid function type. Not used by any import or "
|
// << "Invalid function type. Not used by any import or "
|
||||||
"hook/cbak func. "
|
// "hook/cbak func. "
|
||||||
<< "Codesec: " << section_type << " "
|
// << "Codesec: " << section_type << " "
|
||||||
<< "Local: " << j << " "
|
// << "Local: " << j << " "
|
||||||
<< "Offset: " << i << "\n";
|
// << "Offset: " << i << "\n";
|
||||||
return {};
|
// return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int param_count = parseLeb128(wasm, i, &i);
|
int param_count = parseLeb128(wasm, i, &i);
|
||||||
@@ -1320,11 +1331,11 @@ validateGuards(
|
|||||||
}
|
}
|
||||||
else if (param_count != (*first_signature).get().size() - 1)
|
else if (param_count != (*first_signature).get().size() - 1)
|
||||||
{
|
{
|
||||||
GUARDLOG(hook::log::FUNC_TYPE_INVALID)
|
// GUARDLOG(hook::log::FUNC_TYPE_INVALID)
|
||||||
<< "Malformed transaction. "
|
// << "Malformed transaction. "
|
||||||
<< "Hook API: " << *first_name
|
// << "Hook API: " << *first_name
|
||||||
<< " has the wrong number of parameters.\n";
|
// << " has the wrong number of parameters.\n";
|
||||||
return {};
|
// return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int k = 0; k < param_count; ++k)
|
for (int k = 0; k < param_count; ++k)
|
||||||
@@ -1388,12 +1399,12 @@ validateGuards(
|
|||||||
// most compilers out
|
// most compilers out
|
||||||
if (result_count != 1)
|
if (result_count != 1)
|
||||||
{
|
{
|
||||||
GUARDLOG(hook::log::FUNC_RETURN_COUNT)
|
// GUARDLOG(hook::log::FUNC_RETURN_COUNT)
|
||||||
<< "Malformed transaction. "
|
// << "Malformed transaction. "
|
||||||
<< "Hook declares a function type that returns fewer "
|
// << "Hook declares a function type that returns fewer "
|
||||||
"or more than one value. "
|
// "or more than one value. "
|
||||||
<< "\n";
|
// << "\n";
|
||||||
return {};
|
// return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// this can only ever be 1 in production, but in testing it may
|
// this can only ever be 1 in production, but in testing it may
|
||||||
|
|||||||
@@ -723,6 +723,9 @@ public:
|
|||||||
uint32_t wasmParam,
|
uint32_t wasmParam,
|
||||||
beast::Journal const& j)
|
beast::Journal const& j)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static WasmEdge_String _hookFunctionName = WasmEdge_StringCreateByCString("methodCreate");
|
||||||
|
|
||||||
// HookExecutor can only execute once
|
// HookExecutor can only execute once
|
||||||
assert(!spent);
|
assert(!spent);
|
||||||
|
|
||||||
@@ -761,7 +764,7 @@ public:
|
|||||||
vm.ctx,
|
vm.ctx,
|
||||||
reinterpret_cast<const uint8_t*>(wasm),
|
reinterpret_cast<const uint8_t*>(wasm),
|
||||||
len,
|
len,
|
||||||
callback ? cbakFunctionName : hookFunctionName,
|
_hookFunctionName,
|
||||||
params,
|
params,
|
||||||
1,
|
1,
|
||||||
returns,
|
returns,
|
||||||
|
|||||||
@@ -1776,7 +1776,7 @@ Transactor::operator()()
|
|||||||
|
|
||||||
// write state if all chains executed successfully
|
// write state if all chains executed successfully
|
||||||
if (isTesSuccess(result))
|
if (isTesSuccess(result))
|
||||||
hook::finalizeHookState(stateMap, ctx_, ctx_.tx.getTransactionID());
|
result = hook::finalizeHookState(stateMap, ctx_, ctx_.tx.getTransactionID());
|
||||||
|
|
||||||
// write hook results
|
// write hook results
|
||||||
// this happens irrespective of whether final result was a tesSUCCESS
|
// this happens irrespective of whether final result was a tesSUCCESS
|
||||||
@@ -2031,8 +2031,9 @@ Transactor::operator()()
|
|||||||
for (auto const& [accID, hookHashes] : aawMap)
|
for (auto const& [accID, hookHashes] : aawMap)
|
||||||
doAgainAsWeak(accID, hookHashes, stateMap, weakResults, proMeta);
|
doAgainAsWeak(accID, hookHashes, stateMap, weakResults, proMeta);
|
||||||
|
|
||||||
|
result = hook::finalizeHookState(stateMap, ctx_, ctx_.tx.getTransactionID());
|
||||||
|
|
||||||
// write hook results
|
// write hook results
|
||||||
hook::finalizeHookState(stateMap, ctx_, ctx_.tx.getTransactionID());
|
|
||||||
for (auto& weakResult : weakResults)
|
for (auto& weakResult : weakResults)
|
||||||
hook::finalizeHookResult(weakResult, ctx_, isTesSuccess(result));
|
hook::finalizeHookResult(weakResult, ctx_, isTesSuccess(result));
|
||||||
|
|
||||||
|
|||||||
@@ -36,12 +36,12 @@
|
|||||||
#include <magic/magic_enum.h>
|
#include <magic/magic_enum.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#define MAGIC_ENUM(x) \
|
#define MAGIC_ENUM(x, _min, _max) \
|
||||||
template <> \
|
template <> \
|
||||||
struct magic_enum::customize::enum_range<x> \
|
struct magic_enum::customize::enum_range<x> \
|
||||||
{ \
|
{ \
|
||||||
static constexpr int min = -20000; \
|
static constexpr int min = _min; \
|
||||||
static constexpr int max = 20000; \
|
static constexpr int max = _max; \
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAGIC_ENUM_16(x) \
|
#define MAGIC_ENUM_16(x) \
|
||||||
@@ -59,14 +59,14 @@
|
|||||||
static constexpr bool is_flags = true; \
|
static constexpr bool is_flags = true; \
|
||||||
};
|
};
|
||||||
|
|
||||||
MAGIC_ENUM(ripple::SerializedTypeID);
|
MAGIC_ENUM(ripple::SerializedTypeID, -2, 10004);
|
||||||
MAGIC_ENUM(ripple::LedgerEntryType);
|
MAGIC_ENUM(ripple::LedgerEntryType, 0, 255);
|
||||||
MAGIC_ENUM(ripple::TELcodes);
|
MAGIC_ENUM(ripple::TELcodes, -399, 300);
|
||||||
MAGIC_ENUM(ripple::TEMcodes);
|
MAGIC_ENUM(ripple::TEMcodes, -299, -200);
|
||||||
MAGIC_ENUM(ripple::TEFcodes);
|
MAGIC_ENUM(ripple::TEFcodes, -199, -100);
|
||||||
MAGIC_ENUM(ripple::TERcodes);
|
MAGIC_ENUM(ripple::TERcodes, -99, -1);
|
||||||
MAGIC_ENUM(ripple::TEScodes);
|
MAGIC_ENUM(ripple::TEScodes, 0, 1);
|
||||||
MAGIC_ENUM(ripple::TECcodes);
|
MAGIC_ENUM(ripple::TECcodes, 100, 255);
|
||||||
MAGIC_ENUM_16(ripple::TxType);
|
MAGIC_ENUM_16(ripple::TxType);
|
||||||
MAGIC_ENUM_FLAG(ripple::UniversalFlags);
|
MAGIC_ENUM_FLAG(ripple::UniversalFlags);
|
||||||
MAGIC_ENUM_FLAG(ripple::AccountSetFlags);
|
MAGIC_ENUM_FLAG(ripple::AccountSetFlags);
|
||||||
|
|||||||
1
src/test/app/.env
Normal file
1
src/test/app/.env
Normal file
@@ -0,0 +1 @@
|
|||||||
|
HOOKS_COMPILE_HOST=http://localhost:9000
|
||||||
140
src/test/app/SetHookV3_test.cpp
Normal file
140
src/test/app/SetHookV3_test.cpp
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
This file is part of rippled: https://github.com/ripple/rippled
|
||||||
|
Copyright (c) 2012-2016 Ripple Labs Inc.
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
#include <ripple/app/hook/Enum.h>
|
||||||
|
#include <ripple/app/ledger/LedgerMaster.h>
|
||||||
|
#include <ripple/app/tx/impl/SetHook.h>
|
||||||
|
#include <ripple/protocol/TxFlags.h>
|
||||||
|
#include <ripple/protocol/jss.h>
|
||||||
|
#include <test/app/SetHook_wasm.h>
|
||||||
|
#include <test/jtx.h>
|
||||||
|
#include <test/jtx/hook.h>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <iostream>
|
||||||
|
#include <ripple/json/json_reader.h>
|
||||||
|
|
||||||
|
namespace ripple {
|
||||||
|
|
||||||
|
namespace test {
|
||||||
|
|
||||||
|
class SetHookV3_test : public beast::unit_test::suite
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// helper
|
||||||
|
void static overrideFlag(Json::Value& jv)
|
||||||
|
{
|
||||||
|
jv[jss::Flags] = hsfOVERRIDE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
// This is a large fee, large enough that we can set most small test hooks
|
||||||
|
// without running into fee issues we only want to test fee code specifically in
|
||||||
|
// fee unit tests, the rest of the time we want to ignore it.
|
||||||
|
#define HSFEE fee(100'000'000)
|
||||||
|
#define M(m) memo(m, "", "")
|
||||||
|
std::string
|
||||||
|
loadHook()
|
||||||
|
{
|
||||||
|
std::string name = "/Users/darkmatter/projects/ledger-works/xahaud/src/test/app/wasm/custom.wasm";
|
||||||
|
if (!std::filesystem::exists(name)) {
|
||||||
|
std::cout << "File does not exist: " << name << "\n";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ifstream hookFile(name, std::ios::binary);
|
||||||
|
|
||||||
|
if (!hookFile)
|
||||||
|
{
|
||||||
|
std::cout << "Failed to open file: " << name << "\n";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the file into a vector
|
||||||
|
std::vector<char> buffer((std::istreambuf_iterator<char>(hookFile)), std::istreambuf_iterator<char>());
|
||||||
|
|
||||||
|
// Check if the buffer is empty
|
||||||
|
if (buffer.empty()) {
|
||||||
|
std::cout << "File is empty or could not be read properly.\n";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return strHex(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
testSimple(FeatureBitset features)
|
||||||
|
{
|
||||||
|
testcase("Test simple");
|
||||||
|
|
||||||
|
using namespace jtx;
|
||||||
|
|
||||||
|
// Env env{*this, features};
|
||||||
|
Env env{*this, envconfig(), features, nullptr,
|
||||||
|
beast::severities::kTrace
|
||||||
|
};
|
||||||
|
|
||||||
|
auto const alice = Account{"alice"};
|
||||||
|
auto const gw = Account{"gateway"};
|
||||||
|
auto const USD = gw["USD"];
|
||||||
|
env.fund(XRP(10000), alice, gw);
|
||||||
|
env.close();
|
||||||
|
env.trust(USD(100000), alice);
|
||||||
|
env.close();
|
||||||
|
env(pay(gw, alice, USD(10000)));
|
||||||
|
env.close();
|
||||||
|
|
||||||
|
std::string hook = loadHook();
|
||||||
|
std::cout << "Hook: " << hook << "\n";
|
||||||
|
|
||||||
|
// install the hook on alice
|
||||||
|
env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0),
|
||||||
|
M("set simple"),
|
||||||
|
HSFEE);
|
||||||
|
env.close();
|
||||||
|
|
||||||
|
// // invoke the hook
|
||||||
|
// Json::Value jv = invoke::invoke(alice);
|
||||||
|
// Json::Value params{Json::arrayValue};
|
||||||
|
// Json::Value pv;
|
||||||
|
// Json::Value piv;
|
||||||
|
// piv[jss::HookParameterName] = "736F6D6566756E63";
|
||||||
|
// piv[jss::HookParameterValue] = "736F6D6566756E63";
|
||||||
|
// pv[jss::HookParameter] = piv;
|
||||||
|
// params[0u] = pv;
|
||||||
|
// jv[jss::HookParameters] = params;
|
||||||
|
env(invoke::invoke(alice), M("test simple"), fee(XRP(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
testWithFeatures(FeatureBitset features)
|
||||||
|
{
|
||||||
|
testSimple(features);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
run() override
|
||||||
|
{
|
||||||
|
using namespace test::jtx;
|
||||||
|
auto const sa = supported_amendments();
|
||||||
|
testWithFeatures(sa);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
BEAST_DEFINE_TESTSUITE(SetHookV3, app, ripple);
|
||||||
|
} // namespace test
|
||||||
|
} // namespace ripple
|
||||||
|
#undef M
|
||||||
10
src/test/app/contracts/base.c
Normal file
10
src/test/app/contracts/base.c
Normal 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__);;
|
||||||
|
}
|
||||||
20
src/test/app/contracts/custom.c
Normal file
20
src/test/app/contracts/custom.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "hookapi.h"
|
||||||
|
// #define DEBUG 1
|
||||||
|
// #define SBUF(str) (uint32_t)(str), sizeof(str)
|
||||||
|
// #define TRACESTR(v) if (DEBUG) trace((uint32_t)(#v), (uint32_t)(sizeof(#v) - 1), (uint32_t)(v), sizeof(v), 0);
|
||||||
|
// // hook developers should use this guard macro, simply GUARD(<maximum iterations>)
|
||||||
|
// #define GUARD(maxiter) _g((1ULL << 31U) + __LINE__, (maxiter)+1)
|
||||||
|
// #define GUARDM(maxiter, n) _g(( (1ULL << 31U) + (__LINE__ << 16) + n), (maxiter)+1)
|
||||||
|
|
||||||
|
// hooks-cli compile-c contracts/custom.c build
|
||||||
|
|
||||||
|
int64_t methodCreate(uint32_t reserved) {
|
||||||
|
TRACESTR("somefunc.c: Called.");
|
||||||
|
for (int i = 0; GUARD(10), i < 10; i++) {
|
||||||
|
TRACESTR("somefunc.c: Iterating.");
|
||||||
|
}
|
||||||
|
return accept(SBUF("somefunc.c: Finished."), __LINE__);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user