more testing

This commit is contained in:
Denis Angell
2024-07-12 22:51:35 +02:00
parent c662a8b0d2
commit 5c7ec5f36f
6 changed files with 3746 additions and 762 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -10,6 +10,123 @@ namespace ripple {
namespace test {
std::map<std::string, std::vector<uint8_t>> jswasm = {
/* ==== WASM: 0 ==== */
{R"[test.hook](
const INVALID_ARGUMENT = -7
const sfAccount = 0x80001
const ASSERT = (x, code) => {
if (!x) {
rollback(x.toString(), code);
}
}
const Hook = (arg) => {
ASSERT(otxn_field(sfAccount) == 20);
ASSERT(otxn_field(1) == INVALID_ARGUMENT);
let acc2 = hook_account();
ASSERT(acc2 == 20);
for (var i = 0; i < 20; ++i)
ASSERT(acc[i] == acc2[i]);
return accept("0", 0);
}
)[test.hook]",
{0x43U, 0x0fU, 0x20U, 0x49U, 0x4eU, 0x56U, 0x41U, 0x4cU, 0x49U, 0x44U,
0x5fU, 0x41U, 0x52U, 0x47U, 0x55U, 0x4dU, 0x45U, 0x4eU, 0x54U, 0x12U,
0x73U, 0x66U, 0x41U, 0x63U, 0x63U, 0x6fU, 0x75U, 0x6eU, 0x74U, 0x0cU,
0x41U, 0x53U, 0x53U, 0x45U, 0x52U, 0x54U, 0x08U, 0x48U, 0x6fU, 0x6fU,
0x6bU, 0x28U, 0x77U, 0x61U, 0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U,
0x65U, 0x73U, 0x74U, 0x2dU, 0x30U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU,
0x6aU, 0x73U, 0x02U, 0x78U, 0x08U, 0x63U, 0x6fU, 0x64U, 0x65U, 0x10U,
0x72U, 0x6fU, 0x6cU, 0x6cU, 0x62U, 0x61U, 0x63U, 0x6bU, 0x06U, 0x61U,
0x72U, 0x67U, 0x08U, 0x61U, 0x63U, 0x63U, 0x32U, 0x02U, 0x69U, 0x14U,
0x6fU, 0x74U, 0x78U, 0x6eU, 0x5fU, 0x66U, 0x69U, 0x65U, 0x6cU, 0x64U,
0x18U, 0x68U, 0x6fU, 0x6fU, 0x6bU, 0x5fU, 0x61U, 0x63U, 0x63U, 0x6fU,
0x75U, 0x6eU, 0x74U, 0x06U, 0x61U, 0x63U, 0x63U, 0x0cU, 0x61U, 0x63U,
0x63U, 0x65U, 0x70U, 0x74U, 0x0cU, 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U,
0x00U, 0x01U, 0x00U, 0x01U, 0x00U, 0x02U, 0x5bU, 0x01U, 0xa4U, 0x01U,
0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3fU,
0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3fU, 0xe5U, 0x00U, 0x00U, 0x00U,
0x80U, 0x3fU, 0xe6U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U,
0x00U, 0x00U, 0x80U, 0x3eU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU,
0xe5U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe6U, 0x00U, 0x00U, 0x00U,
0x80U, 0xbfU, 0xf9U, 0x3aU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x01U, 0x01U,
0x00U, 0x08U, 0x00U, 0x3aU, 0xe4U, 0x00U, 0x00U, 0x00U, 0xc2U, 0x00U,
0x4dU, 0xe5U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe5U, 0x00U, 0x00U, 0x00U,
0xc2U, 0x01U, 0x4dU, 0xe6U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe6U, 0x00U,
0x00U, 0x00U, 0xc7U, 0x28U, 0xceU, 0x03U, 0x01U, 0x09U, 0x79U, 0x7cU,
0x26U, 0x00U, 0x0aU, 0x0cU, 0x00U, 0x0cU, 0x1aU, 0x0cU, 0x02U, 0x06U,
0x00U, 0x00U, 0x02U, 0x00U, 0x02U, 0x03U, 0x00U, 0x00U, 0x16U, 0x02U,
0xd0U, 0x03U, 0x00U, 0x01U, 0x00U, 0xd2U, 0x03U, 0x00U, 0x01U, 0x00U,
0xd3U, 0x97U, 0xecU, 0x12U, 0x38U, 0xeaU, 0x00U, 0x00U, 0x00U, 0xd3U,
0x42U, 0x38U, 0x00U, 0x00U, 0x00U, 0x24U, 0x00U, 0x00U, 0xd4U, 0xf2U,
0x0eU, 0x29U, 0xceU, 0x03U, 0x05U, 0x03U, 0x03U, 0x17U, 0x59U, 0x0cU,
0x02U, 0x06U, 0x00U, 0x00U, 0x01U, 0x02U, 0x01U, 0x04U, 0x00U, 0x01U,
0x6bU, 0x03U, 0xd6U, 0x03U, 0x00U, 0x01U, 0x00U, 0xd8U, 0x03U, 0x01U,
0x00U, 0x20U, 0xdaU, 0x03U, 0x00U, 0x00U, 0x00U, 0x61U, 0x00U, 0x00U,
0x38U, 0xe5U, 0x00U, 0x00U, 0x00U, 0x38U, 0xeeU, 0x00U, 0x00U, 0x00U,
0x38U, 0xe4U, 0x00U, 0x00U, 0x00U, 0xf1U, 0xbfU, 0x14U, 0xaaU, 0xf1U,
0x0eU, 0x38U, 0xe5U, 0x00U, 0x00U, 0x00U, 0x38U, 0xeeU, 0x00U, 0x00U,
0x00U, 0xb8U, 0xf1U, 0x38U, 0xe3U, 0x00U, 0x00U, 0x00U, 0xaaU, 0xf1U,
0x0eU, 0x38U, 0xefU, 0x00U, 0x00U, 0x00U, 0xf0U, 0xcbU, 0x38U, 0xe5U,
0x00U, 0x00U, 0x00U, 0x62U, 0x00U, 0x00U, 0xbfU, 0x14U, 0xaaU, 0xf1U,
0x0eU, 0xb7U, 0xccU, 0xc8U, 0xbfU, 0x14U, 0xa4U, 0xecU, 0x19U, 0x38U,
0xe5U, 0x00U, 0x00U, 0x00U, 0x38U, 0xf0U, 0x00U, 0x00U, 0x00U, 0xc8U,
0x47U, 0x62U, 0x00U, 0x00U, 0xc8U, 0x47U, 0xaaU, 0xf1U, 0x0eU, 0x94U,
0x01U, 0xeeU, 0xe3U, 0x38U, 0xf1U, 0x00U, 0x00U, 0x00U, 0xc1U, 0x00U,
0xb7U, 0x23U, 0x02U, 0x00U, 0xceU, 0x03U, 0x0bU, 0x07U, 0x12U, 0x6cU,
0x68U, 0x26U, 0x45U, 0x2bU, 0x7cU, 0x07U, 0x02U, 0x30U}},
/* ==== WASM: 1 ==== */
{R"[test.hook](
const ASSERT = (x, code) => {
if (!x) {
rollback(x.toString(), code);
}
}
const Hook = (arg) => {
let acc2 = hook_account();
trace("acc2", acc2, false);
ASSERT(acc2.length == 20);
return accept(acc2, 0);
}
)[test.hook]",
{0x43U, 0x0bU, 0x0cU, 0x41U, 0x53U, 0x53U, 0x45U, 0x52U, 0x54U, 0x08U,
0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, 0x73U, 0x6dU, 0x6aU,
0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, 0x31U, 0x2dU, 0x67U,
0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x02U, 0x78U, 0x08U, 0x63U, 0x6fU,
0x64U, 0x65U, 0x10U, 0x72U, 0x6fU, 0x6cU, 0x6cU, 0x62U, 0x61U, 0x63U,
0x6bU, 0x06U, 0x61U, 0x72U, 0x67U, 0x08U, 0x61U, 0x63U, 0x63U, 0x32U,
0x18U, 0x68U, 0x6fU, 0x6fU, 0x6bU, 0x5fU, 0x61U, 0x63U, 0x63U, 0x6fU,
0x75U, 0x6eU, 0x74U, 0x0aU, 0x74U, 0x72U, 0x61U, 0x63U, 0x65U, 0x0cU,
0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x0cU, 0x00U, 0x06U, 0x00U,
0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x00U, 0x02U, 0x32U, 0x01U,
0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U, 0x00U, 0x00U, 0x00U,
0x80U, 0x3fU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U,
0x00U, 0x00U, 0x80U, 0x3eU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x80U, 0xc2U,
0x00U, 0x4dU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe3U, 0x00U, 0x00U,
0x00U, 0xc2U, 0x01U, 0x4dU, 0xe4U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe4U,
0x00U, 0x00U, 0x00U, 0xc7U, 0x28U, 0xcaU, 0x03U, 0x01U, 0x07U, 0x3dU,
0x00U, 0x0cU, 0x0cU, 0x00U, 0x0cU, 0x0eU, 0x0cU, 0x02U, 0x06U, 0x00U,
0x00U, 0x02U, 0x00U, 0x02U, 0x03U, 0x00U, 0x00U, 0x16U, 0x02U, 0xccU,
0x03U, 0x00U, 0x01U, 0x00U, 0xceU, 0x03U, 0x00U, 0x01U, 0x00U, 0xd3U,
0x97U, 0xecU, 0x12U, 0x38U, 0xe8U, 0x00U, 0x00U, 0x00U, 0xd3U, 0x42U,
0x38U, 0x00U, 0x00U, 0x00U, 0x24U, 0x00U, 0x00U, 0xd4U, 0xf2U, 0x0eU,
0x29U, 0xcaU, 0x03U, 0x02U, 0x03U, 0x03U, 0x17U, 0x59U, 0x0cU, 0x02U,
0x06U, 0x00U, 0x00U, 0x01U, 0x01U, 0x01U, 0x04U, 0x00U, 0x00U, 0x34U,
0x02U, 0xd2U, 0x03U, 0x00U, 0x01U, 0x00U, 0xd4U, 0x03U, 0x01U, 0x00U,
0x20U, 0x61U, 0x00U, 0x00U, 0x38U, 0xebU, 0x00U, 0x00U, 0x00U, 0xf0U,
0xcbU, 0x38U, 0xecU, 0x00U, 0x00U, 0x00U, 0x04U, 0xeaU, 0x00U, 0x00U,
0x00U, 0x62U, 0x00U, 0x00U, 0x09U, 0xf3U, 0x0eU, 0x38U, 0xe3U, 0x00U,
0x00U, 0x00U, 0x62U, 0x00U, 0x00U, 0xebU, 0xbfU, 0x14U, 0xaaU, 0xf1U,
0x0eU, 0x38U, 0xedU, 0x00U, 0x00U, 0x00U, 0x62U, 0x00U, 0x00U, 0xb7U,
0x23U, 0x02U, 0x00U, 0xcaU, 0x03U, 0x08U, 0x04U, 0x12U, 0x26U, 0x53U,
0x49U}},
/* ==== WASM: 1 ==== */
{R"[test.hook](
const Hook = (arg) => {
return accept("0", 0);
@@ -17,7 +134,7 @@ std::map<std::string, std::vector<uint8_t>> jswasm = {
)[test.hook]",
{0x43U, 0x04U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U,
0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU,
0x30U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U,
0x31U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U,
0x72U, 0x67U, 0x0cU, 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x0cU,
0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x00U,
0x01U, 0x1aU, 0x01U, 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U,
@@ -29,7 +146,7 @@ std::map<std::string, std::vector<uint8_t>> jswasm = {
0x38U, 0xe6U, 0x00U, 0x00U, 0x00U, 0xc1U, 0x00U, 0xb7U, 0x23U, 0x02U,
0x00U, 0xc8U, 0x03U, 0x02U, 0x01U, 0x03U, 0x07U, 0x02U, 0x30U}},
/* ==== WASM: 1 ==== */
/* ==== WASM: 2 ==== */
{R"[test.hook](
const Hook = (arg) => {
return rollback("0", 0);
@@ -37,7 +154,7 @@ std::map<std::string, std::vector<uint8_t>> jswasm = {
)[test.hook]",
{0x43U, 0x04U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U,
0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU,
0x31U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U,
0x32U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U,
0x72U, 0x67U, 0x10U, 0x72U, 0x6fU, 0x6cU, 0x6cU, 0x62U, 0x61U, 0x63U,
0x6bU, 0x0cU, 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U,
0x01U, 0x00U, 0x01U, 0x1aU, 0x01U, 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U,
@@ -50,7 +167,32 @@ std::map<std::string, std::vector<uint8_t>> jswasm = {
0x23U, 0x02U, 0x00U, 0xc8U, 0x03U, 0x02U, 0x01U, 0x03U, 0x07U, 0x02U,
0x30U}},
/* ==== WASM: 2 ==== */
/* ==== WASM: 3 ==== */
{R"[test.hook](
const Hook = (arg) => {
console.log("HERE");
return accept(ret, 0);
}
)[test.hook]",
{0x43U, 0x08U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U,
0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU,
0x33U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U,
0x72U, 0x67U, 0x0eU, 0x63U, 0x6fU, 0x6eU, 0x73U, 0x6fU, 0x6cU, 0x65U,
0x06U, 0x6cU, 0x6fU, 0x67U, 0x08U, 0x48U, 0x45U, 0x52U, 0x45U, 0x0cU,
0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x06U, 0x72U, 0x65U, 0x74U,
0x0cU, 0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U,
0x00U, 0x01U, 0x1aU, 0x01U, 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU,
0xe3U, 0x00U, 0x00U, 0x00U, 0x80U, 0x3eU, 0xe3U, 0x00U, 0x00U, 0x00U,
0x80U, 0xc2U, 0x00U, 0x4dU, 0xe3U, 0x00U, 0x00U, 0x00U, 0x3aU, 0xe3U,
0x00U, 0x00U, 0x00U, 0xc7U, 0x28U, 0xc8U, 0x03U, 0x01U, 0x04U, 0x1fU,
0x00U, 0x06U, 0x0aU, 0x0cU, 0x02U, 0x06U, 0x00U, 0x00U, 0x01U, 0x00U,
0x01U, 0x03U, 0x00U, 0x00U, 0x21U, 0x01U, 0xcaU, 0x03U, 0x00U, 0x01U,
0x00U, 0x38U, 0xe6U, 0x00U, 0x00U, 0x00U, 0x42U, 0xe7U, 0x00U, 0x00U,
0x00U, 0x04U, 0xe8U, 0x00U, 0x00U, 0x00U, 0x24U, 0x01U, 0x00U, 0x0eU,
0x38U, 0xe9U, 0x00U, 0x00U, 0x00U, 0x38U, 0xeaU, 0x00U, 0x00U, 0x00U,
0xb7U, 0x23U, 0x02U, 0x00U, 0xc8U, 0x03U, 0x02U, 0x02U, 0x03U, 0x62U}},
/* ==== WASM: 4 ==== */
{R"[test.hook](
const M_REPEAT_10 = (X) => X.repeat(10);
const M_REPEAT_100 = (X) => M_REPEAT_10(X).repeat(10);
@@ -65,7 +207,7 @@ std::map<std::string, std::vector<uint8_t>> jswasm = {
0x45U, 0x41U, 0x54U, 0x5fU, 0x31U, 0x30U, 0x30U, 0x1aU, 0x4dU, 0x5fU,
0x52U, 0x45U, 0x50U, 0x45U, 0x41U, 0x54U, 0x5fU, 0x31U, 0x30U, 0x30U,
0x30U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U, 0x73U,
0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, 0x32U,
0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU, 0x34U,
0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x02U, 0x58U, 0x0cU,
0x72U, 0x65U, 0x70U, 0x65U, 0x61U, 0x74U, 0x06U, 0x61U, 0x72U, 0x67U,
0x06U, 0x72U, 0x65U, 0x74U, 0x84U, 0x01U, 0x61U, 0x62U, 0x63U, 0x64U,
@@ -107,7 +249,7 @@ std::map<std::string, std::vector<uint8_t>> jswasm = {
0x00U, 0x62U, 0x00U, 0x00U, 0xb7U, 0x23U, 0x02U, 0x00U, 0xceU, 0x03U,
0x05U, 0x02U, 0x12U, 0x3fU}},
/* ==== WASM: 3 ==== */
/* ==== WASM: 5 ==== */
{R"[test.hook](
const Hook = (arg) => {
const test_key = "0000000000000000000000000000000000000000000000006b657900";
@@ -117,7 +259,7 @@ std::map<std::string, std::vector<uint8_t>> jswasm = {
)[test.hook]",
{0x43U, 0x09U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U,
0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU,
0x33U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U,
0x35U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U,
0x72U, 0x67U, 0x10U, 0x74U, 0x65U, 0x73U, 0x74U, 0x5fU, 0x6bU, 0x65U,
0x79U, 0x14U, 0x74U, 0x65U, 0x73U, 0x74U, 0x5fU, 0x76U, 0x61U, 0x6cU,
0x75U, 0x65U, 0x70U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U,
@@ -143,7 +285,7 @@ std::map<std::string, std::vector<uint8_t>> jswasm = {
0x62U, 0x01U, 0x00U, 0x62U, 0x00U, 0x00U, 0xf2U, 0x23U, 0x02U, 0x00U,
0xc8U, 0x03U, 0x02U, 0x03U, 0x21U, 0x21U, 0x21U, 0x07U, 0x02U, 0x30U}},
/* ==== WASM: 4 ==== */
/* ==== WASM: 6 ==== */
{R"[test.hook](
const Hook = (arg) => {
return accept("0", 2);
@@ -151,7 +293,7 @@ std::map<std::string, std::vector<uint8_t>> jswasm = {
)[test.hook]",
{0x43U, 0x04U, 0x08U, 0x48U, 0x6fU, 0x6fU, 0x6bU, 0x28U, 0x77U, 0x61U,
0x73U, 0x6dU, 0x6aU, 0x73U, 0x2fU, 0x74U, 0x65U, 0x73U, 0x74U, 0x2dU,
0x34U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U,
0x36U, 0x2dU, 0x67U, 0x65U, 0x6eU, 0x2eU, 0x6aU, 0x73U, 0x06U, 0x61U,
0x72U, 0x67U, 0x0cU, 0x61U, 0x63U, 0x63U, 0x65U, 0x70U, 0x74U, 0x0cU,
0x00U, 0x06U, 0x00U, 0xa2U, 0x01U, 0x00U, 0x01U, 0x00U, 0x01U, 0x00U,
0x01U, 0x1aU, 0x01U, 0xa4U, 0x01U, 0x00U, 0x00U, 0x00U, 0x3fU, 0xe3U,

15
src/test/app/build-js-carray.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
# Get the input file name from the command line argument
input_file="$1"
# Generate the hex output
hex_output=$(./qjsc -c -o /dev/stdout "$input_file" | tr -d '\n' | grep -Eo '\{[^}]+\}' | grep -Eo '0x[a-fA-F0-9]+' | sed -e 's/0x//g' | tr -d '\n')
# Convert the hex to a C array format
c_array=""
for ((i=0; i<${#hex_output}; i+=2)); do
c_array+="0x${hex_output:$i:2}U, "
done
c_array="${c_array%, }"
c_array+=""
# Output the C array to the console
echo "$c_array"

View File

@@ -0,0 +1,47 @@
#!/bin/bash
rm -r wasmjs && mkdir wasmjs
echo '
//This file is generated by build_test_hooks.h
#ifndef SETHOOK_JSWASM_INCLUDED
#define SETHOOK_JSWASM_INCLUDED
#include <map>
#include <stdint.h>
#include <string>
#include <vector>
namespace ripple {
namespace test {
std::map<std::string, std::vector<uint8_t>> jswasm = {' > SetJSHook_tmp_wasm.h
COUNTER="0"
cat SetJSHook_test.cpp | tr '\n' '\f' |
ggrep -Po 'R"\[test\.hook\](.*?)\[test\.hook\]"' |
gsed -E 's/R"\[test\.hook\]\(//g' |
gsed -E 's/\)\[test\.hook\]"[\f \t]*/\/*end*\//g' |
while read -r line
do
echo "/* ==== WASM: $COUNTER ==== */" >> SetJSHook_tmp_wasm.h
echo -n '{ R"[test.hook](' >> SetJSHook_tmp_wasm.h
cat <<< $line | gsed -E 's/.{7}$//g' | tr -d '\n' | tr '\f' '\n' >> SetJSHook_tmp_wasm.h
echo ')[test.hook]",' >> SetJSHook_tmp_wasm.h
echo "{" >> SetJSHook_tmp_wasm.h
WAT=`ggrep -Eo '\(module' <<< $line | wc -l`
if [ "$WAT" -eq "0" ]
then
tr '\f' '\n' <<< $line >> wasmjs/test-$COUNTER-gen.js
./build-js-carray.sh wasmjs/test-$COUNTER-gen.js >> SetJSHook_tmp_wasm.h
else
echo "Compilation error ^"
exit 1
fi
if [ "$?" -gt "0" ]
then
echo "Compilation error ^"
exit 1
fi
echo '}},' >> SetJSHook_tmp_wasm.h
echo >> SetJSHook_tmp_wasm.h
COUNTER=`echo $COUNTER + 1 | bc`
done
echo '};
}
}
#endif' >> SetJSHook_tmp_wasm.h

View File

@@ -38,7 +38,7 @@ Json::Value
hso(std::vector<uint8_t> const& wasmBytes, void (*f)(Json::Value& jv) = 0);
Json::Value
hsov1(std::vector<uint8_t> const& wasmBytes, uint16_t apiVersion, void (*f)(Json::Value& jv) = 0);
hsov1(std::vector<uint8_t> const& wasmBytes, uint16_t const& apiVersion, STAmount const& fee, void (*f)(Json::Value& jv) = 0);
Json::Value

View File

@@ -82,10 +82,10 @@ hso(std::vector<uint8_t> const& wasmBytes, void (*f)(Json::Value& jv))
}
Json::Value
hsov1(std::vector<uint8_t> const& wasmBytes, uint16_t apiVersion = 0, void (*f)(Json::Value& jv))
hsov1(std::vector<uint8_t> const& wasmBytes, uint16_t const& apiVersion, STAmount const& fee, void (*f)(Json::Value& jv))
{
if (wasmBytes.size() == 0)
throw std::runtime_error("empty hook wasm passed to hso()");
throw std::runtime_error("empty hook wasm passed to hsov1()");
Json::Value jv;
jv[jss::CreateCode] = strHex(wasmBytes);
@@ -94,6 +94,7 @@ hsov1(std::vector<uint8_t> const& wasmBytes, uint16_t apiVersion = 0, void (*f)(
"0000000000000000000000000000000000000000000000000000000000000000";
jv[jss::HookNamespace] = to_string(uint256{beast::zero});
jv[jss::HookApiVersion] = Json::Value{apiVersion};
jv[jss::Fee] = fee.getJson(JsonOptions::none);
}
if (f)