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=> }, {wallet: account}).then(x=>
{ {
t.assertTxnFailure(x) t.assertTxnFailure(x)
console.log(x);
process.exit(0); process.exit(0);
}).catch(t.err); }).catch(t.err);
}).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, Account: account.classicAddress,
TransactionType: "SetHook", TransactionType: "SetHook",
Hooks: [ Hooks: [{Hook:{}}],
{
Hook: {
CreateCode: "",
Flags: t.hfsOVERRIDE
}
}
],
Fee: "100000" Fee: "100000"
}, {wallet: account}).then(x=> }, {wallet: account}).then(x=>
{ {
t.assertTxnSuccess(x) t.assertTxnSuccess(x)
console.log(x)
t.api.submit( t.api.submit(
{ {
Account: account.classicAddress, Account: account.classicAddress,
@@ -45,8 +39,8 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
Hooks: [ Hooks: [
{ {
Hook: { Hook: {
CreateCode: "", // hook delete Flags: t.hsfOVERRIDE,
Flags: t.hfsOVERRIDE CreateCode: "" // hook delete
} }
} }
], ],

View File

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

View File

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

View File

@@ -1,6 +1,8 @@
const fs = require('fs') const fs = require('fs')
const xrpljs = require('xrpl-hooks'); const xrpljs = require('xrpl-hooks');
const kp = require('ripple-keypairs'); const kp = require('ripple-keypairs');
const crypto = require('crypto')
// Fails via process.exit // Fails via process.exit
module.exports = { module.exports = {
@@ -45,6 +47,12 @@ module.exports = {
return xrpljs.Wallet.fromSeed(kp.generateSeed()); 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) => const fundFromGenesis = (acc) =>
{ {
return new Promise((resolve, reject) => return new Promise((resolve, reject) =>
@@ -56,7 +64,8 @@ module.exports = {
Account: genesis.classicAddress, // fund account from genesis Account: genesis.classicAddress, // fund account from genesis
TransactionType: "Payment", TransactionType: "Payment",
Amount: "1000000000", Amount: "1000000000",
Destination: acc Destination: acc,
Fee: "10000"
}, {wallet: genesis}).then(x=> }, {wallet: genesis}).then(x=>
{ {
assertTxnSuccess(x); assertTxnSuccess(x);
@@ -79,7 +88,10 @@ module.exports = {
fundFromGenesis: fundFromGenesis, fundFromGenesis: fundFromGenesis,
err: err, err: err,
hsfOVERRIDE: 1, hsfOVERRIDE: 1,
hsfNSDELETE: 2 hsfNSDELETE: 2,
hfsOVERRIDE: 1,
hfsNSDELETE: 2,
hookHash: hookHash
}); });
}).catch(err); }).catch(err);
}); });