mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-20 02:25:53 +00:00
tsh tests / update setregularkey tsh
This commit is contained in:
55
hookstests/hookset/test-tsh-2.js
Normal file
55
hookstests/hookset/test-tsh-2.js
Normal file
@@ -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);
|
||||
})
|
||||
|
||||
|
||||
|
||||
55
hookstests/hookset/test-tsh.js
Normal file
55
hookstests/hookset/test-tsh.js
Normal file
@@ -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);
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
22
hookstests/hookset/wasm/rollback.c
Normal file
22
hookstests/hookset/wasm/rollback.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 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);
|
||||
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;
|
||||
}
|
||||
@@ -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 },
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user