tsh tests / update setregularkey tsh

This commit is contained in:
Richard Holland
2022-05-09 08:13:04 +00:00
parent 74b0f20108
commit ec78ef7ddb
6 changed files with 144 additions and 3 deletions

View 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);
})

View 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);
})

View File

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

View 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;
}

View File

@@ -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 },

View File

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