git.delta.rocks / unique-network / refs/commits / 371ee2283952

difftreelog

fix get expected scheduled tx fee

Daniel Shiposha2022-09-11parent: #aa8456e.patch.diff
in: master

1 file changed

modifiedtests/src/.outdated/scheduler.test.tsdiffbeforeafterboth
47 Pallets,47 Pallets,
48} from '../deprecated-helpers/helpers';48} from '../deprecated-helpers/helpers';
49import {IKeyringPair, SignatureOptions} from '@polkadot/types/types';49import {IKeyringPair, SignatureOptions} from '@polkadot/types/types';
50import {RuntimeDispatchInfo} from '@polkadot/types/interfaces';
50import {ApiPromise} from '@polkadot/api';51import {ApiPromise} from '@polkadot/api';
51import {objectSpread} from '@polkadot/util';52import {objectSpread} from '@polkadot/util';
5253
215 });216 });
216 });217 });
217218
218 it.only('Scheduled tasks should take some fees', async function() {219 it('Scheduled tasks should take correct fees', async function() {
219 await requirePallets(this, [Pallets.TestUtils]);220 await requirePallets(this, [Pallets.TestUtils]);
220221
221 await usingApi(async api => {222 await usingApi(async api => {
226227
227 const dummyTx = api.tx.testUtils.justTakeFee();228 const dummyTx = api.tx.testUtils.justTakeFee();
229
228 const expectedFee = (await dummyTx.paymentInfo(alice)).partialFee.toBigInt();230 const signingInfo = await api.derive.tx.signingInfo(alice.address);
231
232 // We need to sign the tx because
233 // unsigned transactions does not have an inclusion fee
234 dummyTx.sign(alice, {
235 blockHash: api.genesisHash,
236 genesisHash: api.genesisHash,
237 runtimeVersion: api.runtimeVersion,
238 nonce: signingInfo.nonce,
239 });
240
241 const scheduledLen = dummyTx.callIndex.length;
242
229 const expFee = (await api.rpc.payment.queryFeeDetails(dummyTx.toHex())).inclusionFee.unwrap().toHuman();243 const queryInfo = await api.call.transactionPaymentApi.queryInfo(
244 dummyTx.toHex(),
245 scheduledLen,
246 );
230247
231 console.log('>>>>>> expFee = ' + JSON.stringify(expFee));248 const expectedScheduledFee = (await queryInfo as RuntimeDispatchInfo)
232249 .partialFee.toBigInt();
233 // const collectionCreate = api.tx.unique.createCollectionEx({
234 // name: 0,
235 // tokenPrefix: 0xfaf,
236 // });
237
238 // const options = makeSignOptions(api);
239 // const signed = collectionCreate.sign(alice, options);
240 // const expFee2 = (await api.rpc.payment.queryFeeDetails(signed.toHex())).inclusionFee.unwrap().toHuman();
241 // console.log('!!!!!!!!!!!! expFee2 = ' + JSON.stringify(expFee2));
242250
243 await expect(scheduleAfter(251 await expect(scheduleAfter(
244 api,252 api,
264 ).to.be.true;272 ).to.be.true;
265273
266 diff = aliceInitBalance - aliceBalanceAfterFirst;274 diff = aliceInitBalance - aliceBalanceAfterFirst;
267 expect(diff).to.be.equal(expectedFee, 'Scheduled task should take the right amount of fees');275 expect(diff).to.be.equal(
276 expectedScheduledFee,
277 'Scheduled task should take the right amount of fees',
278 );
268279
269 await waitNewBlocks(period);280 await waitNewBlocks(period);
275 ).to.be.true;286 ).to.be.true;
276287
277 diff = aliceBalanceAfterFirst - aliceBalanceAfterSecond;288 diff = aliceBalanceAfterFirst - aliceBalanceAfterSecond;
278 expect(diff).to.be.equal(expectedFee, 'Scheduled task should take the right amount of fees');289 expect(diff).to.be.equal(
290 expectedScheduledFee,
291 'Scheduled task should take the right amount of fees',
292 );
279 });293 });
280 });294 });