Add minimal tests to show that new runtime API endpoints exist#2254
Add minimal tests to show that new runtime API endpoints exist#2254
Conversation
| describeDevMoonbeam("TransactionPayment Runtime Queries", (context) => { | ||
| it("should be able to query length fee", async function () { | ||
| const adjusted_length_fee = await context.polkadotApi.call.transactionPaymentApi.queryLengthToFee(1n); | ||
| expect((adjusted_length_fee as any).toBigInt()).to.eq(1_000_000_001n); |
There was a problem hiding this comment.
What can I do to avoid needing as any here?
There was a problem hiding this comment.
Updates the typescript api to match
cd typescript-api
npm ci
cd ../tests
npm run setup-typescript-api
There was a problem hiding this comment.
@notlesh you dont need to build any new types or api-augment pkgs, that's been done already.
All you need todo is update the api-augment package to 2301 which contains the updated interfaces (and removes the need for any locally for me at least)
in: moonbeam/tests
npm i @moonbeam-network/api-augment@latest
tests/util/block.ts
Outdated
| let apiAt = await context.polkadotApi.at(previousBlockHash); // TODO: i think this is right because multiplier is updated in on_finalize | ||
| let lengthFee = (await apiAt.call.transactionPaymentApi.queryLengthToFee(dispatchInfo.encodedLength) as any).toBigInt(); | ||
|
|
||
| let unadjustedWeightFee = (await apiAt.call.transactionPaymentApi.queryWeightToFee(dispatchInfo.weight) as any).toBigInt(); |
There was a problem hiding this comment.
Something seems very broken about dispatchInfo.weight. In this particular case (running test "should be able to calculate entire fee"), it's reporting a refTime of 423314000 which is definitely wrong.
The real value should be 173314000, which is correct in fee.weight. Why is dispatchInfo so wrong?
There was a problem hiding this comment.
Furthermore, why is it used [presumably] correctly (above in the same fn) for Ethereum txns?
tests/util/block.ts
Outdated
| let feePortions = calculateFeePortions(fee.partialFee.toBigInt()); | ||
| txFees = fee.partialFee.toBigInt(); | ||
| txBurnt += feePortions.burnt; | ||
| console.log(`evaluating substrate fee: ${fee}`); |
There was a problem hiding this comment.
Shouldn't this be "debug" instead of console.log?
| describeDevMoonbeam("TransactionPayment Runtime Queries", (context) => { | ||
| it("should be able to query length fee", async function () { | ||
| const adjusted_length_fee = await context.polkadotApi.call.transactionPaymentApi.queryLengthToFee(1n); | ||
| expect((adjusted_length_fee as any).toBigInt()).to.eq(1_000_000_001n); |
There was a problem hiding this comment.
Updates the typescript api to match
cd typescript-api
npm ci
cd ../tests
npm run setup-typescript-api
| refTime: 1, | ||
| proofSize: 1, | ||
| }); | ||
| expect((adjusted_weight_fee as any).toBigInt()).to.eq(50_000n); |
There was a problem hiding this comment.
You can replace this assertion value here is WEIGHT_FEE defined in constants.ts if you feel this is appropriate.
If not, feel free to define some constants in there with appropriate names which you want to assert against (which can then be reusable in other tests).
|
Coverage generated "Thu May 18 21:44:53 UTC 2023": Master coverage: 72.40% |
timbrinded
left a comment
There was a problem hiding this comment.
LGTM, but the doing the previous comment would be the 🍒 on top
* Add minimal tests to show that new runtime API endpoints exist * prettier * WIP: trying to reassemble substrate fees * Basic fee calc works * prettier * Remove dead code * Prefer const over let 🙈 * Validate substrate tips properly (burned) * Remove console.log() * Use well-defined constant * Fix merge conflict 👀 * Remove as any * Reflect substrate tips being handled now 🎉 * prettier * Explain the length fee calculation * Use newly defined constant
What does it do?
This is the first pass at using the new
transaction-paymentruntime API added in Substrate.It will at least add test coverage demonstrating that the API works and how it can be used to calculate the entire fee for a Substrate-based transaction.
As a reminder, this was added so that we can run exhaustive tests around fee calculation, which we were doing until it broke in paritytech/substrate#11415 when it became impossible to know all fee parameters from a client alone.