fix tests

This commit is contained in:
Richard Holland
2022-02-18 13:25:02 +00:00
parent 9325e11b14
commit 642ebf34cd
6 changed files with 43 additions and 17 deletions

20
hookstests/hookset/run-all.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
RESULT=""
FAILCOUNT=0
PASSCOUNT=0
for i in `ls test-*.js`; do
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'

View File

@@ -40,7 +40,6 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
}, {wallet: account}).then(x=>
{
t.assertTxnFailure(x)
console.log(x);
process.exit(0);
}).catch(t.err);
}).catch(t.err);

View File

@@ -7,18 +7,12 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
Account: account.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook: {
CreateCode: "",
Flags: t.hfsOVERRIDE
}
}
],
Hooks: [{Hook:{}}],
Fee: "100000"
}, {wallet: account}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x)
t.api.submit(
{
Account: account.classicAddress,
@@ -45,8 +39,8 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
Hooks: [
{
Hook: {
CreateCode: "", // hook delete
Flags: t.hfsOVERRIDE
Flags: t.hsfOVERRIDE,
CreateCode: "" // hook delete
}
}
],

View File

@@ -6,6 +6,8 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
t.fundFromGenesis(account2).then(()=>
{
let hash = t.hookHash('checkstate.wasm')
t.api.submit(
{
Account: account.classicAddress,
@@ -31,14 +33,13 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
Fee: "100000",
Hooks: [
{ Hook: {
HookHash: "348C7966C79737F6254C3D3866DBEE0AE1584E0751771F0588F898E65C7DFB84",
Flags: 0
HookHash: hash
}},
{ Hook: {
}},
{ Hook: {
HookHash: "348C7966C79737F6254C3D3866DBEE0AE1584E0751771F0588F898E65C7DFB84"
HookHash: hash
}}
]
}, {wallet: account2}).then(x=>

View File

@@ -35,7 +35,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
Fee: "100000"
}, {wallet: account}).then(x=>
{
t.assertTxnFailure(x)
t.assertTxnSuccess(x)
console.log(x);
process.exit(0);
}).catch(t.err);

View File

@@ -1,6 +1,8 @@
const fs = require('fs')
const xrpljs = require('xrpl-hooks');
const kp = require('ripple-keypairs');
const crypto = require('crypto')
// Fails via process.exit
module.exports = {
@@ -45,6 +47,12 @@ module.exports = {
return xrpljs.Wallet.fromSeed(kp.generateSeed());
};
const hookHash = fn =>
{
let b = fs.readFileSync('wasm/' + fn);
return crypto.createHash('SHA512').update(b).digest().slice(0,32).toString('hex').toUpperCase()
}
const fundFromGenesis = (acc) =>
{
return new Promise((resolve, reject) =>
@@ -56,7 +64,8 @@ module.exports = {
Account: genesis.classicAddress, // fund account from genesis
TransactionType: "Payment",
Amount: "1000000000",
Destination: acc
Destination: acc,
Fee: "10000"
}, {wallet: genesis}).then(x=>
{
assertTxnSuccess(x);
@@ -79,7 +88,10 @@ module.exports = {
fundFromGenesis: fundFromGenesis,
err: err,
hsfOVERRIDE: 1,
hsfNSDELETE: 2
hsfNSDELETE: 2,
hfsOVERRIDE: 1,
hfsNSDELETE: 2,
hookHash: hookHash
});
}).catch(err);
});