correctly bill parameters during sethook create mode, update tests

This commit is contained in:
Richard Holland
2022-05-19 11:49:58 +00:00
parent 74eff62713
commit 37da7b23f3
15 changed files with 71 additions and 178 deletions

View File

@@ -6,7 +6,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
t.fundFromGenesis(account2).then(()=>
{
t.api.submit(
t.feeSubmit(account1.seed,
{
Account: account1.classicAddress,
TransactionType: "SetHook",
@@ -19,9 +19,8 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
HookOn: "0000000000000000"
}
}
],
Fee: t.wasmFee('aaw.wasm')
}, {wallet: account1}).then(x=>
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);

View File

@@ -3,7 +3,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
const account = t.randomAccount();
t.fundFromGenesis(account).then(()=>
{
t.api.submit(
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
@@ -16,13 +16,12 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
HookOn: "0000000000000000"
}
}
],
Fee: t.wasmFee('accept.wasm')
}, {wallet: account}).then(x=>
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.api.submit(
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
@@ -35,9 +34,8 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
HookOn: "0000000000000000"
}
}
],
Fee: t.wasmFee('accept.wasm')
}, {wallet: account}).then(x=>
]
}).then(x=>
{
t.assertTxnFailure(x)
process.exit(0);

View File

@@ -5,7 +5,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
t.fundFromGenesis(account).then(()=>
{
t.api.submit(
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
@@ -15,7 +15,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
t.assertTxnSuccess(x)
console.log(x)
t.api.submit(
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
@@ -29,13 +29,12 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
HookOn: "0000000000000000"
}
}
],
Fee: t.wasmFee('accept.wasm')
}, {wallet: account}).then(x=>
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.api.submit(
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
@@ -47,8 +46,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
}
}
],
Fee: "100000"
}, {wallet: account}).then(x=>
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);

View File

@@ -1,59 +0,0 @@
require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
const account = t.randomAccount();
t.fundFromGenesis(account).then(()=>
{
t.api.submit(
{
Account: account.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook: {
CreateCode: t.wasm('accept.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
],
Fee: t.wasmFee('accept.wasm')
}, {wallet: account}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.pay_mock(t.genesisseed, 100, account).then(ser=>
{
t.fee(ser).then(fees =>
{
let base_drops = fees.base_fee
console.log("base_drops", base_drops)
let txn = t.rbc.decode(ser);
delete txn['SigningPubKey']
delete txn['Fee']
txn['Fee'] = base_drops + '';
console.log(txn)
t.api.submit(txn, {wallet: account}).then(s=>
{
t.assertTxnSuccess(s);
console.log(s);
txn['Fee'] = (base_drops - 20) + '';
txn['Sequence'] = (txn['Sequence'] + 1) ;
console.log(txn)
t.api.submit(txn, {wallet: t.genesis}).then(s=>
{
t.assertTxnFailure(s);
console.log(s)
process.exit(0);
});
}).catch(t.err);
});
});
}).catch(t.err);
}).catch(t.err);
})

View File

@@ -1,31 +0,0 @@
require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
const account = t.randomAccount();
t.fundFromGenesis(account).then(()=>
{
t.feeTxn(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
Hooks: [
{
Hook: {
CreateCode: t.wasm('accept.wasm'),
HookApiVersion: 0,
HookNamespace: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
HookOn: "0000000000000000"
}
}
]
}).then(txn => {
console.log(txn)
t.api.submit(txn, {wallet: account}).then(s=>
{
t.assertTxnSuccess(s);
console.log(s);
process.exit(0);
}).catch(t.err);
}).catch(t.err);
}).catch(t.err);
});

View File

@@ -8,7 +8,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
let hash = t.hookHash('checkstate.wasm')
t.api.submit(
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
@@ -20,13 +20,12 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
HookOn: "0000000000000000"
}
}
],
Fee: "100000"
}, {wallet: account}).then(x=>
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x)
t.api.submit(
t.feeSubmit(account2.seed,
{
Account: account2.classicAddress,
TransactionType: "SetHook",
@@ -42,15 +41,14 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
HookHash: hash
}}
]
}, {wallet: account2}).then(x=>
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.api.submit(
t.feeSubmit(account2.seed,
{
Account: account2.classicAddress,
TransactionType: "SetHook",
Fee: "100000",
Flags: 0,
Hooks: [
{ Hook: {
@@ -58,16 +56,15 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
"CreateCode": "",
}}
]
}, {wallet: account2}).then(x=>
}).then(x=>
{
console.log(x);
t.assertTxnSuccess(x);
t.api.submit(
t.feeSubmit(account2.seed,
{
Account: account2.classicAddress,
TransactionType: "SetHook",
Fee: "100000",
Flags: 0,
Hooks: [
{Hook:{}},
@@ -82,7 +79,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
]
}}
]
}, {wallet: account2}).then(x=>
}).then(x=>
{
console.log(x);
t.assertTxnSuccess(x);

View File

@@ -3,7 +3,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
const account = t.randomAccount();
t.fundFromGenesis(account).then(()=>
{
t.api.submit(
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
@@ -16,13 +16,12 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
HookOn: "0000000000000000"
}
}
],
Fee: "100000"
}, {wallet: account}).then(x=>
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.api.submit(
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
@@ -31,9 +30,8 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{ Hook: { } },
{ Hook: { } },
{ Hook: { } }
],
Fee: "100000"
}, {wallet: account}).then(x=>
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);

View File

@@ -3,7 +3,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
const account = t.randomAccount();
t.fundFromGenesis(account).then(()=>
{
t.api.submit(
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
@@ -27,16 +27,15 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
}
],
Fee: "100000"
}, {wallet: account}).then(x=>
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.api.submit(
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
Fee: "100000",
Hooks: [
{
Hook: {
@@ -45,7 +44,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
}
}
]
}, {wallet: account}).then(x=>
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);

View File

@@ -3,7 +3,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
const account = t.randomAccount();
t.fundFromGenesis(account).then(()=>
{
t.api.submit(
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
@@ -25,9 +25,8 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
HookOn: "0000000000000000"
}
}
],
Fee: "100000"
}, {wallet: account}).then(x=>
]
}).then(x=>
{
t.assertTxnSuccess(x)
t.api.submit(
@@ -40,11 +39,10 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
t.assertTxnSuccess(x)
console.log(x);
t.api.submit(
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
Fee: "100000",
Hooks: [
{
Hook: {
@@ -53,7 +51,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
}
}
]
}, {wallet: account}).then(x=>
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);

View File

@@ -3,7 +3,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
const account = t.randomAccount();
t.fundFromGenesis(account).then(()=>
{
t.api.submit(
t.feeSubmit(account.seed,
{
Account: account.classicAddress,
TransactionType: "SetHook",
@@ -32,9 +32,8 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
HookOn: "0000000000000000"
}
}
],
Fee: "100000"
}, {wallet: account}).then(x=>
]
}).then(x=>
{
t.assertTxnSuccess(x)
t.api.submit(

View File

@@ -6,7 +6,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
t.fundFromGenesis(account2).then(()=>
{
t.api.submit(
t.feeSubmit(account1.seed,
{
Account: account1.classicAddress,
TransactionType: "SetHook",
@@ -19,13 +19,12 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
HookOn: "0000000000000000"
}
}
],
Fee: "100000"
}, {wallet: account1}).then(x=>
]
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.api.submit(
t.feeSubmit(account2.seed,
{
Account: account2.classicAddress,
TransactionType: "SignerListSet",
@@ -39,9 +38,8 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
SignerWeight: 1
}
}
],
Fee: "100000"
}, {wallet: account2}).then(x=>
]
}).then(x=>
{
t.assertTxnFailure(x)
process.exit(0);

View File

@@ -6,7 +6,7 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
{
t.fundFromGenesis(account2).then(()=>
{
t.api.submit(
t.feeSubmit(account1.seed,
{
Account: account1.classicAddress,
TransactionType: "SetHook",
@@ -20,12 +20,11 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
}
}
],
Fee: "100000"
}, {wallet: account1}).then(x=>
}).then(x=>
{
t.assertTxnSuccess(x)
console.log(x);
t.api.submit(
t.feeSubmit(account2.seed,
{
Account: account2.classicAddress,
TransactionType: "SignerListSet",
@@ -39,9 +38,8 @@ require('./utils-tests.js').TestRig('ws://localhost:6005').then(t=>
SignerWeight: 1
}
}
],
Fee: "100000"
}, {wallet: account2}).then(x=>
]
}).then(x=>
{
t.assertTxnSuccess(x)
process.exit(0);

View File

@@ -63,13 +63,6 @@ module.exports = {
};
const wasmFee = (x) =>
{
if (x.slice(0,1) != '/')
x = 'wasm/' + x;
return "" + (fs.readFileSync( x).length * 500) + 20;
}
const feeCompute = (account_seed, txn_org) =>
{
return new Promise((resolve, reject) =>
@@ -226,7 +219,6 @@ module.exports = {
fee: fee,
genesisseed: genesisseed,
genesisaddr: genesisaddr,
wasmFee: wasmFee,
feeCompute: feeCompute,
feeSubmit: feeSubmit
});

View File

@@ -5,13 +5,6 @@
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 )
{

View File

@@ -486,6 +486,22 @@ SetHook::calculateBaseFee(ReadView const& view, STTx const& tx)
extraFee += FeeUnit64{
hook::computeCreationFee(
hookSetObj->getFieldVL(sfCreateCode).size())};
// parameters are billed at the same rate as code bytes
if (hookSetObj->isFieldPresent(sfHookParameters))
{
uint64_t paramBytes = 0;
auto const& params = hookSetObj->getFieldArray(sfHookParameters);
for (auto const& param : params)
{
paramBytes +=
(param.isFieldPresent(sfHookParameterName) ?
param.getFieldVL(sfHookParameterName).size() : 0) +
(param.isFieldPresent(sfHookParameterValue) ?
param.getFieldVL(sfHookParameterValue).size() : 0);
}
extraFee += FeeUnit64 { paramBytes };
}
}
return Transactor::calculateBaseFee(view, tx) + extraFee;
@@ -1405,8 +1421,8 @@ SetHook::setHook()
// sfHookDefinition is not reserved because it is an unowned object, rather the uploader is billed via fee
// according to the following:
// sfCreateCode: 1000 drops per byte
// sfHookParameters: 1000 drops per byte
// sfCreateCode: 5000 drops per byte
// sfHookParameters: 5000 drops per byte
// other fields: free
int oldHookReserve = 0;