begin rework for js tests and hook examples

This commit is contained in:
Richard Holland
2022-06-06 14:05:17 +00:00
parent d452f9ca5a
commit 5f74392bcb
68 changed files with 4197 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
all:
(cd wasm; make)

View File

@@ -0,0 +1,18 @@
{
"dependencies": {
"ripple-keypairs": "^1.1.3",
"ripple-lib": "^1.10.0",
"xrpl": "^2.1.1",
"xrpl-binary-codec": "^1.4.2",
"xrpl-hooks": "^2.2.1"
},
"name": "hookset",
"description": "This test set pertains to testing the functionality of installing / creating / updating / deleting hooks. In short: everything except running hooks.",
"version": "1.0.0",
"main": "''",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

21
hook/tests/hookset/run-all.sh Executable file
View File

@@ -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'

View File

@@ -0,0 +1,42 @@
require('../../utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
const account1 = t.randomAccount();
const account2 = t.randomAccount();
t.fundFromGenesis(account1).then(()=>
{
t.fundFromGenesis(account2).then(()=>
{
t.feeSubmit(account1.seed,
{
Account: account1.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook: {
CreateCode: t.wasm('aaw.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.feeSubmit(account2.seed,
{
Account: account2.classicAddress,
TransactionType: "AccountSet"
}).then(x=>
{
t.assertTxnSuccess(x)
process.exit(0);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,30 @@
require('../../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('blacklist.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
process.exit(0);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,48 @@
require('../../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('accept.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook: {
CreateCode: t.wasm('accept.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(x=>
{
t.assertTxnFailure(x)
process.exit(0);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,61 @@
require('../../utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
const account = (process.argv.length < 3 ? t.randomAccount() :
t.xrpljs.Wallet.fromSeed(process.argv[2]));
t.fundFromGenesis(account).then(()=>
{
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
Hooks: [{Hook:{}}],
Fee: "100000"
}, {wallet: account}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x)
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook: {
Flags: t.hsfOVERRIDE,
CreateCode: t.wasm('accept.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook: {
Flags: t.hsfOVERRIDE,
CreateCode: "" // hook delete
}
}
],
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
process.exit(0);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,53 @@
require('../../utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
const account = t.randomAccount();
t.fundFromGenesis(account).then(()=>
{
let txn_to_send =
{
SigningPubKey: '',
Account: account.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook: {
CreateCode: t.wasm('accept.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
],
SigningPubKey: ''
};
let wal = t.xrpljs.Wallet.fromSeed(account.seed);
t.api.prepareTransaction(txn_to_send, {wallet: wal}).then(txn =>
{
let ser = t.rbc.encode(txn);
t.fee(ser).then(fees =>
{
console.log(fees)
let base_drops = fees.base_fee
console.log("base_drops", base_drops)
delete txn_to_send['SigningPubKey']
txn_to_send['Fee'] = base_drops + '';
t.api.prepareTransaction(txn_to_send, {wallet: wal}).then(txn =>
{
console.log(txn)
t.api.submit(txn, {wallet: wal}).then(s=>
{
t.assertTxnSuccess(s);
console.log(s);
process.exit(0);
}).catch(t.err);
}).catch(t.err);
});
}).catch(t.err);
}).catch(t.err);
});

View File

@@ -0,0 +1,27 @@
require('../../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('accept.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(s => {
t.assertTxnSuccess(s);
console.log(s);
process.exit(0);
}).catch(t.err);
}).catch(t.err);
});

View File

@@ -0,0 +1,38 @@
require('../../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('multiguard.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "AccountSet"
}).then(x=>
{
t.assertTxnSuccess(x)
process.exit(0);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,99 @@
require('../../utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
const account = t.randomAccount();
const account2 = t.randomAccount();
t.fundFromGenesis(account).then(()=>
{
t.fundFromGenesis(account2).then(()=>
{
let hash = t.hookHash('checkstate.wasm')
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
Hooks: [
{ Hook: {
CreateCode: t.wasm('checkstate.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x)
t.feeSubmit(account2.seed,
{
Account: account2.classicAddress,
TransactionType: "SetHook",
Fee: "100000",
Hooks: [
{ Hook: {
HookHash: hash
}},
{ Hook: {
}},
{ Hook: {
HookHash: hash
}}
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.feeSubmit(account2.seed,
{
Account: account2.classicAddress,
TransactionType: "SetHook",
Flags: 0,
Hooks: [
{ Hook: {
"Flags": t.hsfOVERRIDE,
"CreateCode": "",
}}
]
}).then(x=>
{
console.log(x);
t.assertTxnSuccess(x);
t.feeSubmit(account2.seed,
{
Account: account2.classicAddress,
TransactionType: "SetHook",
Flags: 0,
Hooks: [
{Hook:{}},
{Hook:{}},
{ Hook: {
HookParameters:
[
{HookParameter: {
HookParameterName: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
HookParameterValue: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB"
}}
]
}}
]
}).then(x=>
{
console.log(x);
t.assertTxnSuccess(x);
console.log("account 1 has the creation: ", account.classicAddress);
console.log("account 2 has the install and delete and update: ", account2.classicAddress);
process.exit(0);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,74 @@
require('../../utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
const account1 = t.randomAccount();
const account2 = t.randomAccount();
t.fundFromGenesis([account1, account2]).then(()=>
{
t.ledgerAccept(256).then(x=>
{
t.feeSubmitAccept(account1.seed,
{
NFTokenTaxon: 0,
TransactionType: "NFTokenMint",
Account: account1.classicAddress,
TransferFee: 314,
Flags: 8,
URI: "697066733A2F2F62616679626569676479727A74357366703775646D37687537367568377932366E6634646675796C71616266336F636C67747179353566627A6469",
Memos: [
{
"Memo": {
"MemoType":
"687474703A2F2F6578616D706C652E636F6D2F6D656D6F2F67656E65726963",
"MemoData": "72656E74"
}
}
]
}).then(x=>
{
console.log(x)
t.assertTxnSuccess(x)
const id = t.nftid(account1.classicAddress, 8, 314, 0, 0);
t.feeSubmit(account1.seed,
{
TransactionType: "NFTokenCreateOffer",
Account: account1.classicAddress,
NFTokenID: id,
Amount: "1",
Flags: 1
}).then(x=>
{
console.log(x);
t.assertTxnSuccess(x)
t.fetchMeta(x.result.tx_json.hash).then(m=>
{
// RH UPTO
t.log(m);
process.exit(0);
}).catch(t.err);
/*
t.feeSubmit(account1.seed,
{
TransactionType: "AccountDelete",
Account: account1.classicAddress,
Destination: account2.classicAddress,
Flags: 2147483648
}).then(x=>
{
t.assertTxnSuccess(x)
process.exit(0);
});
*/
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,34 @@
require('../../utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
const account1 = t.randomAccount();
t.fundFromGenesis(account1).then(()=>
{
t.feeSubmit(account1.seed,
{
NFTokenTaxon: 0,
TransactionType: "NFTokenMint",
Account: account1.classicAddress,
TransferFee: 314,
Flags: 8,
URI: "697066733A2F2F62616679626569676479727A74357366703775646D37687537367568377932366E6634646675796C71616266336F636C67747179353566627A6469",
Memos: [
{
"Memo": {
"MemoType":
"687474703A2F2F6578616D706C652E636F6D2F6D656D6F2F67656E65726963",
"MemoData": "72656E74"
}
}
]
}).then(x=>
{
console.log(x);
t.assertTxnSuccess(x)
process.exit(0);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,45 @@
require('../../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('accept.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
Hooks: [
{ Hook: { } },
{ Hook: { } },
{ Hook: { } },
{ Hook: { } }
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
process.exit(0);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,59 @@
require('../../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('makestate.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
},
{ Hook: {} },
{ Hook: {} },
{ Hook: {
CreateCode: t.wasm('checkstate.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
],
Fee: "100000"
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook: {
Flags: t.hsfNSDELETE,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF"
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
process.exit(0);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,67 @@
require('../../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('makestate.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
},
{ Hook: {} },
{ Hook: {} },
{ Hook: {
CreateCode: t.wasm('checkstate.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
t.api.submit(
{
Account: account.classicAddress,
TransactionType: "AccountSet", // trigger hooks
Fee: "100000"
}, {wallet: account}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook: {
Flags: t.hsfNSDELETE,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF"
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
process.exit(0);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,71 @@
require('../../utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
const account = t.randomAccount();
const account2 = t.randomAccount();
t.fundFromGenesis([account, account2]).then(()=>
{
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook: {
CreateCode: t.wasm('makestate.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
},
{
Hook: {
CreateCode: t.wasm('makestate2.wasm'),
HookApiVersion: 0,
HookNamespace: "CAFEF00DCAFEF00DCAFEF00DCAFEF00DCAFEF00DCAFEF00DCAFEF00DCAFEF00D",
HookOn: "0000000000000000"
}
},
{ Hook: {} },
{ Hook: {
CreateCode: t.wasm('checkstate.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
t.api.submit(
{
Account: account.classicAddress,
TransactionType: "AccountSet", // trigger hooks
Fee: "100000"
}, {wallet: account}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.ledgerAccept(255).then(x=>
{
// account delete
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "AccountDelete",
Destination: account2.classicAddress,
Flags: 2147483648
}).then(x=>
{
console.log(x);
t.assertTxnSuccess(x);
process.exit(0);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,83 @@
require('../../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('makestate.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
},
{ Hook: {
CreateCode: t.wasm('checkstate.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
},
{ Hook: {} },
{ Hook: {} }
]
}).then(x=>
{
t.assertTxnSuccess(x)
t.api.submit(
{
Account: account.classicAddress,
TransactionType: "AccountSet", // trigger hooks
Fee: "100000"
}, {wallet: account}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook: {
CreateCode: t.wasm("rmstate.wasm"),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000",
Flags: t.hsfOVERRIDE
},
},
{
Hook: {
Flags: t.hsfOVERRIDE,
CreateCode: ""
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
t.api.submit(
{
Account: account.classicAddress,
TransactionType: "AccountSet", // trigger hooks
Fee: "100000"
}, {wallet: account}).then(x=>
{
t.assertTxnSuccess(x);
process.exit(0);
});
});
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,55 @@
require('../../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('makestate.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
},
{
Hook: {
CreateCode: t.wasm('makestate2.wasm'),
HookApiVersion: 0,
HookNamespace: "CAFEF00DCAFEF00DCAFEF00DCAFEF00DCAFEF00DCAFEF00DCAFEF00DCAFEF00D",
HookOn: "0000000000000000"
}
},
{ Hook: {} },
{ Hook: {
CreateCode: t.wasm('checkstate.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
t.api.submit(
{
Account: account.classicAddress,
TransactionType: "AccountSet", // trigger hooks
Fee: "100000"
}, {wallet: account}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
process.exit(0);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,53 @@
require('../../utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
const account1 = t.randomAccount();
const account2 = t.randomAccount();
t.fundFromGenesis(account1).then(()=>
{
t.fundFromGenesis(account2).then(()=>
{
t.feeSubmit(account1.seed,
{
Account: account1.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook: {
CreateCode: t.wasm('rollback.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.feeSubmit(account2.seed,
{
Account: account2.classicAddress,
TransactionType: "SignerListSet",
SignerQuorum: 1,
SignerEntries:
[
{
SignerEntry:
{
Account: account1.classicAddress,
SignerWeight: 1
}
}
]
}).then(x=>
{
t.assertTxnFailure(x)
process.exit(0);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,115 @@
require('../../utils-tests.js').TestRig('ws://localhost:6005').then(t=>{
const holder1 = t.randomAccount();
const holder2 = t.randomAccount();
const holder3 = t.randomAccount();
const holder4 = t.randomAccount();
const issuer = t.randomAccount();
t.fundFromGenesis([issuer, holder1, holder2, holder3, holder4]).then(()=>
{
t.setTshCollect([holder1, holder2, holder3, holder4]).then(()=>
{
t.trustSet(issuer, "IOU", 10000, [holder1,holder2,holder3,holder4]).then(()=>
{
t.feeSubmitAcceptMultiple(
{
TransactionType: "SetHook",
Hooks: [
{
Hook:
{
CreateCode: t.wasm('aaw.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000",
Flags: t.hsfCOLLECT
}
}
]
}, [holder1,holder2,holder3,holder4]).then(()=>
{
req = {};
req[holder1.classicAddress] = 500;
req[holder2.classicAddress] = 200;
req[holder3.classicAddress] = 80;
t.issueTokens(issuer, "IOU", req).then(()=>
{
const coffer = (offerer, issuer, currency, iouamount, dropsamount, buying) =>
{
if (typeof(issuer.classicAddress) != 'undefined')
issuer = issuer.classicAddress;
return new Promise((resolve, reject) =>
{
let txn =
{
Account: offerer.classicAddress,
TransactionType: "OfferCreate",
};
let key1 = (buying ? "TakerGets" : "TakerPays");
let key2 = (buying ? "TakerPays" : "TakerGets");
txn[key1] = dropsamount + "";
txn[key2] = {
"currency": currency,
"issuer": issuer,
"value": iouamount + ""
};
t.feeSubmitAccept(offerer.seed, txn).then(x=>
{
console.log(x);
t.assertTxnSuccess(x);
resolve(x);
}).catch(e=>reject(e));
});
};
coffer(holder1, issuer, "IOU", 10, 250000, false).then(()=> // q= 25000
{
coffer(holder2, issuer, "IOU", 12, 100000, false).then(()=> // q= 8333
{
coffer(holder3, issuer, "IOU", 14, 80000, false).then(()=> // q= 5714
{
coffer(holder4, issuer, "IOU", 30, 350000, true).then((x)=>
{
t.ledgerAccept().then(()=>
{
t.fetchMetaHookExecutions(x).then(h=>
{
t.fetchMeta(x).then(m=>
{
t.log(x);
delete m.HookExecutions;
t.log(m);
t.log(h);
console.log("Issuer:", issuer.classicAddress);
console.log("Holder 1: ", holder1.classicAddress);
console.log("Holder 2: ", holder2.classicAddress);
console.log("Holder 3: ", holder3.classicAddress);
console.log("Buyer: ", holder4.classicAddress);
console.log("(cd b; ./rippled book_offers XRP 'IOU/" + issuer.classicAddress + "');");
console.log("(cd b; ./rippled account_lines " + issuer.classicAddress + ");");
process.exit(0);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,55 @@
require('../../utils-tests.js').TestRig('ws://localhost:6005').then(t=>{
const holder1 = t.randomAccount();
const issuer = t.randomAccount();
t.fundFromGenesis([issuer, holder1]).then(()=>
{
t.feeSubmitAccept(issuer.seed,
{
Account: issuer.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook:
{
CreateCode: t.wasm('aaw.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000",
Flags: t.hsfCOLLECT
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.feeSubmitAccept(holder1.seed,
{
Account: holder1.classicAddress,
TransactionType: "TrustSet",
LimitAmount: {
"currency": "IOU",
"issuer": issuer.classicAddress,
"value": "1000"
}
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.fetchMetaHookExecutions(x, t.wasmHash('aaw.wasm')).then(m=>
{
t.assert(m.length == 0, "hook executed when it should not");
console.log(m);
process.exit(0);
}).catch(t.err);
}).catch(t.err);
});
}).catch(t.err);
})

View File

@@ -0,0 +1,65 @@
require('../../utils-tests.js').TestRig('ws://localhost:6005').then(t=>{
const holder1 = t.randomAccount();
const issuer = t.randomAccount();
t.fundFromGenesis([issuer, holder1]).then(()=>
{
t.feeSubmitAccept(issuer.seed,
{
Account: issuer.classicAddress,
TransactionType: "AccountSet",
SetFlag: t.asfTshCollect
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.feeSubmitAccept(issuer.seed,
{
Account: issuer.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook:
{
CreateCode: t.wasm('aaw.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x);
console.log(x);
t.feeSubmitAccept(holder1.seed,
{
Account: holder1.classicAddress,
TransactionType: "TrustSet",
LimitAmount: {
"currency": "IOU",
"issuer": issuer.classicAddress,
"value": "1000"
}
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.fetchMetaHookExecutions(x, t.wasmHash('aaw.wasm')).then(m=>
{
console.log(m);
t.assert(m.length == 0, "hook executed when it should not");
process.exit(0);
});
}).catch(t.err);
}).catch(t.err);
});
}).catch(t.err);
})

View File

@@ -0,0 +1,67 @@
require('../../utils-tests.js').TestRig('ws://localhost:6005').then(t=>{
const holder1 = t.randomAccount();
const issuer = t.randomAccount();
t.fundFromGenesis([issuer, holder1]).then(()=>
{
t.feeSubmitAccept(issuer.seed,
{
Account: issuer.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook:
{
CreateCode: t.wasm('aaw.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000",
Flags: t.hsfCOLLECT
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.feeSubmitAccept(issuer.seed,
{
Account: issuer.classicAddress,
TransactionType: "AccountSet",
SetFlag: t.asfTshCollect
}).then(x=>
{
t.assertTxnSuccess(x);
console.log(x);
t.feeSubmitAccept(holder1.seed,
{
Account: holder1.classicAddress,
TransactionType: "TrustSet",
LimitAmount: {
"currency": "IOU",
"issuer": issuer.classicAddress,
"value": "1000"
}
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.fetchMetaHookExecutions(x, t.wasmHash('aaw.wasm')).then(m=>
{
t.assert(m.length == 1, "needed exactly one hook execution");
t.assert(m[0].HookReturnCode == 100, "non-weak execution");
console.log(m);
process.exit(0);
});
}).catch(t.err);
}).catch(t.err);
});
}).catch(t.err);
})

View File

@@ -0,0 +1,53 @@
require('../../utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
const account1 = t.randomAccount();
const account2 = t.randomAccount();
t.fundFromGenesis(account1).then(()=>
{
t.fundFromGenesis(account2).then(()=>
{
t.feeSubmit(account1.seed,
{
Account: account1.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook: {
CreateCode: t.wasm('accept.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
],
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.feeSubmit(account2.seed,
{
Account: account2.classicAddress,
TransactionType: "SignerListSet",
SignerQuorum: 1,
SignerEntries:
[
{
SignerEntry:
{
Account: account1.classicAddress,
SignerWeight: 1
}
}
]
}).then(x=>
{
t.assertTxnSuccess(x)
process.exit(0);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -0,0 +1,52 @@
// RC: 50 : strong execution
// RC: 100 : weak execution (collect call)
// RC: 150 : again as weak (not collect / after strong)
// RC: 200 : callback execution
#include <stdint.h>
extern int32_t _g (uint32_t id, uint32_t maxiter);
extern int64_t accept (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
extern int64_t hook_again (void);
extern int64_t trace( uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
extern int64_t trace_num (uint32_t, uint32_t, uint64_t);
extern int64_t meta_slot(uint32_t);
extern int64_t slot(uint32_t, uint32_t, uint32_t);
#define SBUF(x) (uint32_t)((void*)x), sizeof(x)
int64_t cbak(uint32_t what)
{
accept (SBUF("Callback execution"),200);
}
int64_t hook(uint32_t reserved )
{
if (reserved == 0)
{
hook_again();
accept (SBUF("Strong execution"),50);
}
int64_t result =
meta_slot(1);
trace_num(SBUF("meta_slot(1): "), result);
uint8_t dump[1024];
result = slot(SBUF(dump), 1);
trace_num(SBUF("slot(1): "), result);
trace(SBUF("dumped txmeta:"), dump, result, 1);
if (reserved == 1)
accept(SBUF("Weak execution (COLLECT)"), 100);
else
accept(SBUF("AAW execution"), 150);
_g(1,1); // every hook needs to import guard function and use it at least once
// unreachable
return 0;
}

View File

@@ -0,0 +1,20 @@
/**
* This hook just accepts any transaction coming through it
*/
#include <stdint.h>
extern int32_t _g (uint32_t id, uint32_t maxiter);
extern int64_t accept (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
int64_t cbak(uint32_t what)
{
return 0;
}
int64_t hook(uint32_t reserved )
{
accept (0,0,0);
_g(1,1); // every hook needs to import guard function and use it at least once
// unreachable
return 0;
}

View File

@@ -0,0 +1,20 @@
/**
* This hook just accepts any transaction coming through it
*/
#include <stdint.h>
extern int32_t _g (uint32_t id, uint32_t maxiter);
extern int64_t accept (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
int64_t cbak(int64_t what)
{
return 0;
}
int64_t hook(int64_t reserved )
{
accept (0,0,0);
_g(1,1); // every hook needs to import guard function and use it at least once
// unreachable
return 0;
}

View File

@@ -0,0 +1,42 @@
#include <stdint.h>
extern int32_t _g (uint32_t id, uint32_t maxiter);
extern int64_t rollback (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
extern int64_t accept (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
extern int64_t state (uint32_t read_ptr, uint32_t read_len, uint32_t kread_ptr, uint32_t kread_len);
extern int64_t trace_num (uint32_t a, uint32_t b, uint64_t i);
#define SBUF(x) x, sizeof(x)
#define GUARD(n) _g(__LINE__, n+1)
int64_t cbak(uint32_t what)
{
return 0;
}
int64_t hook(uint32_t reserved )
{
uint8_t test[] = "hello world!";
uint8_t test_key[32];
for (int i = 0; GUARD(32), i < 32; ++i)
test_key[i] = i;
uint8_t buf[128];
int64_t result = state(SBUF(buf), SBUF(test_key));
if (result <= 0)
{
trace_num(SBUF("state call failed"), result);
rollback(SBUF("state call failed"), 2);
}
for (int i = 0; GUARD(sizeof(test)+1), i < sizeof(test); ++i)
if (test[i] != buf[i])
rollback(SBUF("hook state did not match expected value"), 1);
accept(SBUF("hook state matched expected value"),0);
_g(1,1); // every hook needs to import guard function and use it at least once
// unreachable
return 0;
}

View File

@@ -0,0 +1,16 @@
#include <stdint.h>
extern int32_t volatile _g (uint32_t id, uint32_t maxiter);
extern int64_t accept (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
extern int64_t trace_num(uint32_t, uint32_t, int64_t);
int64_t hook(uint32_t r)
{
const int x = r;
for (int i = 0; trace_num(0,0,0), _g(11, 12), i < 5; ++i)
{
trace_num("hi", 2, i);
}
accept(0,0,0);
return 0;
}

View File

@@ -0,0 +1,31 @@
all: accept.wasm makestate.wasm makestate2.wasm checkstate.wasm rollback.wasm aaw.wasm rmstate.wasm ginv.wasm multiguard.wasm
accept.wasm: accept.c
wasmcc accept.c -o accept.wasm -O2 -Wl,--allow-undefined -I../
hook-cleaner accept.wasm
rollback.wasm: rollback.c
wasmcc rollback.c -o rollback.wasm -O2 -Wl,--allow-undefined -I../
hook-cleaner rollback.wasm
makestate.wasm: makestate.c
wasmcc makestate.c -o makestate.wasm -O2 -Wl,--allow-undefined -I../
hook-cleaner makestate.wasm
makestate2.wasm: makestate2.c
wasmcc makestate2.c -o makestate2.wasm -O2 -Wl,--allow-undefined -I../
hook-cleaner makestate2.wasm
checkstate.wasm: checkstate.c
wasmcc checkstate.c -o checkstate.wasm -O2 -Wl,--allow-undefined -I../
hook-cleaner checkstate.wasm
rmstate.wasm: rmstate.c
wasmcc rmstate.c -o rmstate.wasm -O2 -Wl,--allow-undefined -I../
hook-cleaner rmstate.wasm
aaw.wasm: aaw.c
wasmcc aaw.c -o aaw.wasm -O2 -Wl,--allow-undefined -I../
hook-cleaner aaw.wasm
ginv.wasm: ginv.c
wasmcc ginv.c -o ginv.wasm -O2 -Wl,--allow-undefined -I../
hook-cleaner ginv.wasm
multiguard.wasm: multiguard.c
wasmcc multiguard.c -o multiguard.wasm -O2 -Wl,--allow-undefined -I../
hook-cleaner multiguard.wasm

View File

@@ -0,0 +1,31 @@
#include <stdint.h>
extern int32_t _g (uint32_t id, uint32_t maxiter);
extern int64_t accept (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
extern int64_t state_set (uint32_t read_ptr, uint32_t read_len, uint32_t kread_ptr, uint32_t kread_len);
extern int64_t trace_num (uint32_t a, uint32_t b, uint64_t i);
#define SBUF(x) x, sizeof(x)
#define GUARD(n) _g(__LINE__, n+1)
int64_t cbak(uint32_t what)
{
return 0;
}
int64_t hook(uint32_t reserved )
{
uint8_t test[] = "hello world!";
trace_num(SBUF("location of test[]:"), test);
uint8_t test_key[32];
for (int i = 0; GUARD(32), i < 32; ++i)
test_key[i] = i;
int64_t result = state_set(SBUF(test), SBUF(test_key));
trace_num(SBUF("state_set result:"), result);
accept (0,0,0);
_g(1,1); // every hook needs to import guard function and use it at least once
// unreachable
return 0;
}

View File

@@ -0,0 +1,37 @@
#include <stdint.h>
extern int32_t _g (uint32_t id, uint32_t maxiter);
extern int64_t accept (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
extern int64_t state_set (uint32_t read_ptr, uint32_t read_len, uint32_t kread_ptr, uint32_t kread_len);
extern int64_t trace_num (uint32_t a, uint32_t b, uint64_t i);
#define SBUF(x) x, sizeof(x)
#define GUARD(n) _g(__LINE__, n+1)
int64_t cbak(uint32_t what)
{
return 0;
}
int64_t hook(uint32_t reserved )
{
uint8_t test[] = "hello world!";
uint8_t test2[] = "this is a much longer test string";
trace_num(SBUF("location of test[]:"), test);
uint8_t test_key[32];
for (int i = 0; GUARD(32), i < 32; ++i)
test_key[i] = i;
int64_t result = state_set(SBUF(test), SBUF(test_key));
trace_num(SBUF("state_set result:"), result);
uint8_t zero_key[32];
result = state_set(SBUF(test2), SBUF(zero_key));
trace_num(SBUF("state_set result:"), result);
accept (0,0,0);
_g(1,1); // every hook needs to import guard function and use it at least once
// unreachable
return 0;
}

View File

@@ -0,0 +1,31 @@
/**
* This hook just accepts any transaction coming through it
*/
#include <stdint.h>
extern int32_t _g (uint32_t id, uint32_t maxiter);
extern int64_t trace_num(uint32_t, uint32_t, int64_t);
extern int64_t accept (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
int64_t cbak(uint32_t what)
{
return 0;
}
int64_t hook(uint32_t reserved )
{
for (int i = 0; i < 5; ++i)
{
_g(1,60); // every hook needs to import guard function and use it at least once
int c = i * 2;
while(c--)
{
trace_num("hi", 2, c);
_g(2, 60);
}
}
accept (0,0,0);
// unreachable
return 0;
}

View File

@@ -0,0 +1,29 @@
#include <stdint.h>
extern int32_t _g (uint32_t id, uint32_t maxiter);
extern int64_t accept (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
extern int64_t state_set (uint32_t read_ptr, uint32_t read_len, uint32_t kread_ptr, uint32_t kread_len);
extern int64_t trace_num (uint32_t a, uint32_t b, uint64_t i);
#define SBUF(x) x, sizeof(x)
#define GUARD(n) _g(__LINE__, n+1)
int64_t cbak(uint32_t what)
{
return 0;
}
int64_t hook(uint32_t reserved )
{
uint8_t test_key[32];
for (int i = 0; GUARD(32), i < 32; ++i)
test_key[i] = i;
int64_t result = state_set(0,0, SBUF(test_key));
trace_num(SBUF("state_set result:"), result);
accept (0,0,0);
_g(1,1); // every hook needs to import guard function and use it at least once
// unreachable
return 0;
}

View File

@@ -0,0 +1,15 @@
/**
* This hook just accepts any transaction coming through it
*/
#include <stdint.h>
extern int32_t _g (uint32_t id, uint32_t maxiter);
extern int64_t rollback (uint32_t read_ptr, uint32_t read_len, int64_t error_code);
int64_t hook(uint32_t reserved )
{
rollback (0,0,0);
_g(1,1); // every hook needs to import guard function and use it at least once
// unreachable
return 0;
}