From ec78ef7ddbe27f145bc1745d67cb7ceb5bb21227 Mon Sep 17 00:00:00 2001 From: Richard Holland Date: Mon, 9 May 2022 08:13:04 +0000 Subject: [PATCH] tsh tests / update setregularkey tsh --- hookstests/hookset/test-tsh-2.js | 55 ++++++++++++++++++++++++++ hookstests/hookset/test-tsh.js | 55 ++++++++++++++++++++++++++ hookstests/hookset/wasm/makefile | 4 +- hookstests/hookset/wasm/rollback.c | 22 +++++++++++ src/ripple/app/hook/applyHook.h | 2 +- src/ripple/app/hook/impl/applyHook.cpp | 9 ++++- 6 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 hookstests/hookset/test-tsh-2.js create mode 100644 hookstests/hookset/test-tsh.js create mode 100644 hookstests/hookset/wasm/rollback.c diff --git a/hookstests/hookset/test-tsh-2.js b/hookstests/hookset/test-tsh-2.js new file mode 100644 index 000000000..e8858b2b9 --- /dev/null +++ b/hookstests/hookset/test-tsh-2.js @@ -0,0 +1,55 @@ +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.api.submit( + { + Account: account1.classicAddress, + TransactionType: "SetHook", + Hooks: [ + { + Hook: { + CreateCode: t.wasm('rollback.wasm'), + HookApiVersion: 0, + HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF", + HookOn: "0000000000000000" + } + } + ], + Fee: "100000" + }, {wallet: account1}).then(x=> + { + t.assertTxnSuccess(x) + console.log(x); + t.api.submit( + { + Account: account2.classicAddress, + TransactionType: "SignerListSet", + SignerQuorum: 1, + SignerEntries: + [ + { + SignerEntry: + { + Account: account1.classicAddress, + SignerWeight: 1 + } + } + ], + Fee: "100000" + }, {wallet: account2}).then(x=> + { + t.assertTxnFailure(x) + process.exit(0); + }).catch(t.err); + }).catch(t.err); + }).catch(t.err); + }).catch(t.err); +}) + + + diff --git a/hookstests/hookset/test-tsh.js b/hookstests/hookset/test-tsh.js new file mode 100644 index 000000000..7d4943213 --- /dev/null +++ b/hookstests/hookset/test-tsh.js @@ -0,0 +1,55 @@ +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.api.submit( + { + Account: account1.classicAddress, + TransactionType: "SetHook", + Hooks: [ + { + Hook: { + CreateCode: t.wasm('accept.wasm'), + HookApiVersion: 0, + HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF", + HookOn: "0000000000000000" + } + } + ], + Fee: "100000" + }, {wallet: account1}).then(x=> + { + t.assertTxnSuccess(x) + console.log(x); + t.api.submit( + { + Account: account2.classicAddress, + TransactionType: "SignerListSet", + SignerQuorum: 1, + SignerEntries: + [ + { + SignerEntry: + { + Account: account1.classicAddress, + SignerWeight: 1 + } + } + ], + Fee: "100000" + }, {wallet: account2}).then(x=> + { + t.assertTxnSuccess(x) + process.exit(0); + }).catch(t.err); + }).catch(t.err); + }).catch(t.err); + }).catch(t.err); +}) + + + diff --git a/hookstests/hookset/wasm/makefile b/hookstests/hookset/wasm/makefile index 288de516c..4c72e062b 100644 --- a/hookstests/hookset/wasm/makefile +++ b/hookstests/hookset/wasm/makefile @@ -1,6 +1,8 @@ -all: accept.wasm makestate.wasm makestate2.wasm checkstate.wasm +all: accept.wasm makestate.wasm makestate2.wasm checkstate.wasm rollback.wasm accept.wasm: accept.c wasmcc accept.c -o accept.wasm -O0 -Wl,--allow-undefined -I../ +rollback.wasm: rollback.c + wasmcc rollback.c -o rollback.wasm -O0 -Wl,--allow-undefined -I../ makestate.wasm: makestate.c wasmcc makestate.c -o makestate.wasm -O0 -Wl,--allow-undefined -I../ makestate2.wasm: makestate2.c diff --git a/hookstests/hookset/wasm/rollback.c b/hookstests/hookset/wasm/rollback.c new file mode 100644 index 000000000..ed29746f6 --- /dev/null +++ b/hookstests/hookset/wasm/rollback.c @@ -0,0 +1,22 @@ +/** + * This hook just accepts any transaction coming through it + */ +#include + +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); + +int64_t cbak(uint32_t reserved) +{ + accept(0,0,0); + return 0; +} + +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; +} diff --git a/src/ripple/app/hook/applyHook.h b/src/ripple/app/hook/applyHook.h index 15f782e2f..61c25644f 100644 --- a/src/ripple/app/hook/applyHook.h +++ b/src/ripple/app/hook/applyHook.h @@ -44,7 +44,7 @@ namespace hook {ttESCROW_FINISH, tshROLLBACK }, {ttACCOUNT_SET, tshNONE }, {ttESCROW_CANCEL, tshCOLLECT }, - {ttREGULAR_KEY_SET, tshNONE }, + {ttREGULAR_KEY_SET, tshROLLBACK }, {ttOFFER_CREATE, tshCOLLECT }, {ttOFFER_CANCEL, tshNONE }, {ttTICKET_CREATE, tshNONE }, diff --git a/src/ripple/app/hook/impl/applyHook.cpp b/src/ripple/app/hook/impl/applyHook.cpp index 61cef8e88..da8968ebe 100644 --- a/src/ripple/app/hook/impl/applyHook.cpp +++ b/src/ripple/app/hook/impl/applyHook.cpp @@ -73,7 +73,6 @@ namespace hook // self transactions case ttACCOUNT_SET: case ttOFFER_CANCEL: - case ttREGULAR_KEY_SET: case ttTICKET_CREATE: case ttHOOK_SET: case ttOFFER_CREATE: // this is handled seperately @@ -81,6 +80,14 @@ namespace hook break; } + case ttREGULAR_KEY_SET: + { + if (!tx.isFieldPresent(sfRegularKey)) + return {}; + ADD_TSH(tx.getAccountID(sfRegularKey), canRollback); + break; + } + case ttDEPOSIT_PREAUTH: { if (!tx.isFieldPresent(sfAuthorize))