From f225003091cc9e3a01272e9869013df7d938d037 Mon Sep 17 00:00:00 2001 From: Richard Holland Date: Mon, 30 May 2022 10:29:37 +0000 Subject: [PATCH] testcases for xfl log and root --- hookstests/hookapi/run-all.sh | 21 +++++++++++++++++ hookstests/hookapi/test-log.js | 40 ++++++++++++++++++++++++++++++++ hookstests/hookapi/test-root.js | 40 ++++++++++++++++++++++++++++++++ hookstests/hookapi/wasm/log.c | 19 +++++++++++++++ hookstests/hookapi/wasm/makefile | 7 ++++++ hookstests/hookapi/wasm/root.c | 21 +++++++++++++++++ 6 files changed, 148 insertions(+) create mode 100755 hookstests/hookapi/run-all.sh create mode 100644 hookstests/hookapi/test-log.js create mode 100644 hookstests/hookapi/test-root.js create mode 100644 hookstests/hookapi/wasm/log.c create mode 100644 hookstests/hookapi/wasm/makefile create mode 100644 hookstests/hookapi/wasm/root.c diff --git a/hookstests/hookapi/run-all.sh b/hookstests/hookapi/run-all.sh new file mode 100755 index 000000000..eadccfc66 --- /dev/null +++ b/hookstests/hookapi/run-all.sh @@ -0,0 +1,21 @@ +#!/bin/bash +RESULT="" +FAILCOUNT=0 +PASSCOUNT=0 +for i in `ls test-*.js`; do + echo Running $i + node $i 2>/dev/null >/dev/null; + if [ "$?" -eq "0" ]; + then + RESULT=`echo $RESULT'~'$i' -- PASS'` + PASSCOUNT="`echo $PASSCOUNT + 1 | bc`" + else + RESULT=`echo $RESULT'~'$i' -- FAIL'` + FAILCOUNT="`echo $FAILCOUNT + 1 | bc`" + fi +done +echo +echo "Results:" +RESULT=$RESULT~ +echo Passed: $PASSCOUNT, Failed: $FAILCOUNT, Total: `echo $PASSCOUNT + $FAILCOUNT | bc` +echo $RESULT | sed 's/.js//g' | tr '~' '\n' diff --git a/hookstests/hookapi/test-log.js b/hookstests/hookapi/test-log.js new file mode 100644 index 000000000..0d83dad2b --- /dev/null +++ b/hookstests/hookapi/test-log.js @@ -0,0 +1,40 @@ +const wasmFn = 'log.wasm'; + +require('../hookset/utils-tests.js').TestRig('ws://localhost:6005').then(t=> +{ + const account = t.randomAccount(); + t.fundFromGenesis(account).then(()=> + { + t.feeSubmit(account.seed, + { + Account: account.classicAddress, + TransactionType: "SetHook", + Hooks: [ + { + Hook: { + CreateCode: t.wasm(wasmFn), + HookApiVersion: 0, + HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF", + HookOn: "0000000000000000" + } + } + ] + }).then(x=> + { + t.assertTxnSuccess(x) + console.log(x); + t.feeSubmit(account.seed, + { + TransactionType: "AccountSet", + Account: account.classicAddress + }).then(x=> + { + t.assertTxnSuccess(x) + process.exit(0); + }).catch(t.err); + }).catch(t.err); + }).catch(t.err); +}) + + + diff --git a/hookstests/hookapi/test-root.js b/hookstests/hookapi/test-root.js new file mode 100644 index 000000000..7110b7ce3 --- /dev/null +++ b/hookstests/hookapi/test-root.js @@ -0,0 +1,40 @@ +const wasmFn = 'root.wasm'; + +require('../hookset/utils-tests.js').TestRig('ws://localhost:6005').then(t=> +{ + const account = t.randomAccount(); + t.fundFromGenesis(account).then(()=> + { + t.feeSubmit(account.seed, + { + Account: account.classicAddress, + TransactionType: "SetHook", + Hooks: [ + { + Hook: { + CreateCode: t.wasm(wasmFn), + HookApiVersion: 0, + HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF", + HookOn: "0000000000000000" + } + } + ] + }).then(x=> + { + t.assertTxnSuccess(x) + console.log(x); + t.feeSubmit(account.seed, + { + TransactionType: "AccountSet", + Account: account.classicAddress + }).then(x=> + { + t.assertTxnSuccess(x) + process.exit(0); + }).catch(t.err); + }).catch(t.err); + }).catch(t.err); +}) + + + diff --git a/hookstests/hookapi/wasm/log.c b/hookstests/hookapi/wasm/log.c new file mode 100644 index 000000000..5784419a4 --- /dev/null +++ b/hookstests/hookapi/wasm/log.c @@ -0,0 +1,19 @@ +#include "api.h" + +int64_t hook(uint32_t reserved ) +{ + int64_t x = float_set(0, 1234567890); + int64_t l = float_log(x); + int64_t i = float_int(l, 15, 1); + + ASSERT(i == 9091514977169268ULL); + + ASSERT(float_log(float_one()) == 0); + + // RH TODO: more tests + + accept (0,0,0); + _g(1,1); // every hook needs to import guard function and use it at least once + // unreachable + return 0; +} diff --git a/hookstests/hookapi/wasm/makefile b/hookstests/hookapi/wasm/makefile new file mode 100644 index 000000000..5adcc2b40 --- /dev/null +++ b/hookstests/hookapi/wasm/makefile @@ -0,0 +1,7 @@ +all: log.wasm root.wasm +log.wasm: log.c + wasmcc log.c -o log.wasm -O0 -Wl,--allow-undefined -I../ + hook-cleaner log.wasm +root.wasm: root.c + wasmcc root.c -o root.wasm -O0 -Wl,--allow-undefined -I../ + hook-cleaner root.wasm diff --git a/hookstests/hookapi/wasm/root.c b/hookstests/hookapi/wasm/root.c new file mode 100644 index 000000000..388c4fae4 --- /dev/null +++ b/hookstests/hookapi/wasm/root.c @@ -0,0 +1,21 @@ +#include "api.h" + +int64_t hook(uint32_t reserved ) +{ + int64_t x = float_set(0, 1234567890); + int64_t l = float_root(x, 2); + TRACEXFL(l); + int64_t i = float_int(l, 6, 1); + + TRACEVAR(i); + + ASSERT(i == 35136418286444ULL); + + + // RH TODO: more tests + + accept (0,0,0); + _g(1,1); // every hook needs to import guard function and use it at least once + // unreachable + return 0; +}