difftreelog
test balances.transfer => balances.transferKeepAlive
in: master
4 files changed
js-packages/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/js-packages/playgrounds/unique.dev.ts
+++ b/js-packages/playgrounds/unique.dev.ts
@@ -696,7 +696,7 @@
const recipient = this.helper.util.fromSeed(mnemonicGenerate(), ss58Format);
accounts.push(recipient);
if(balance !== 0n) {
- const tx = this.helper.constructApiCall('api.tx.balances.transfer', [{Id: recipient.address}, balance * tokenNominal]);
+ const tx = this.helper.constructApiCall('api.tx.balances.transferKeepAlive', [{Id: recipient.address}, balance * tokenNominal]);
transactions.push(this.helper.signTransaction(donor, tx, {nonce}, 'account generation'));
nonce++;
}
@@ -749,7 +749,7 @@
const recipient = this.helper.util.fromSeed(mnemonicGenerate(), ss58Format);
accounts.push(recipient);
if(withBalance !== 0n) {
- const tx = this.helper.constructApiCall('api.tx.balances.transfer', [{Id: recipient.address}, withBalance * tokenNominal]);
+ const tx = this.helper.constructApiCall('api.tx.balances.transferKeepAlive', [{Id: recipient.address}, withBalance * tokenNominal]);
transactions.push(this.helper.signTransaction(donor, tx, {nonce}, 'account generation'));
nonce++;
}
js-packages/playgrounds/unique.tsdiffbeforeafterboth--- a/js-packages/playgrounds/unique.ts
+++ b/js-packages/playgrounds/unique.ts
@@ -2391,7 +2391,7 @@
* @returns ```true``` if extrinsic success, otherwise ```false```
*/
async transferToSubstrate(signer: TSigner, address: TSubstrateAccount, amount: bigint | string): Promise<boolean> {
- const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.transfer', [address, amount], true/*, `Unable to transfer balance from ${this.helper.getSignerAddress(signer)} to ${address}`*/);
+ const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.transferKeepAlive', [address, amount], true/*, `Unable to transfer balance from ${this.helper.getSignerAddress(signer)} to ${address}`*/);
let transfer = {from: null, to: null, amount: 0n} as any;
result.result.events.forEach(({event: {data, method, section}}: any) => {
@@ -2458,7 +2458,7 @@
* @returns ```true``` if extrinsic success, otherwise ```false```
*/
async transferToEthereum(signer: TSigner, address: TEthereumAccount, amount: bigint | string): Promise<boolean> {
- const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.transfer', [address, amount], true);
+ const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.transferKeepAlive', [address, amount], true);
let transfer = {from: null, to: null, amount: 0n} as any;
result.result.events.forEach(({event: {data, method, section}}: any) => {
js-packages/tests/scheduler.seqtest.tsdiffbeforeafterboth--- a/js-packages/tests/scheduler.seqtest.ts
+++ b/js-packages/tests/scheduler.seqtest.ts
@@ -507,7 +507,7 @@
for(let offset = 0; offset < numFilledBlocks; offset ++) {
for(let i = 0; i < maxScheduledPerBlock; i++) {
- const scheduledTx = helper.constructApiCall('api.tx.balances.transfer', [bob.address, 1n]);
+ const scheduledTx = helper.constructApiCall('api.tx.balances.transferKeepAlive', [bob.address, 1n]);
const when = firstExecutionBlockNumber + period + offset;
const mandatoryArgs = [when, null, null, scheduledTx];
@@ -710,7 +710,7 @@
// await addToAllowListExpectSuccess(alice, collectionId, zeroBalance.address);
// // Grace zeroBalance with money, enough to cover future transactions
- // const balanceTx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);
+ // const balanceTx = api.tx.balances.transferKeepAlive(zeroBalance.address, 1n * UNIQUE);
// await submitTransactionAsync(alice, balanceTx);
// // Mint a fresh NFT
@@ -722,7 +722,7 @@
// await scheduleTransferExpectSuccess(api, collectionId, tokenId, zeroBalance, alice, 1, waitForBlocks, scheduledId);
// // Get rid of the account's funds before the scheduled transaction takes place
- // const balanceTx2 = api.tx.balances.transfer(alice.address, UNIQUE * 68n / 100n);
+ // const balanceTx2 = api.tx.balances.transferKeepAlive(alice.address, UNIQUE * 68n / 100n);
// const events = await submitTransactionAsync(zeroBalance, balanceTx2);
// expect(getGenericResult(events).success).to.be.true;
// /*const emptyBalanceTx = api.tx.balances.setBalance(zeroBalance.address, 0, 0); // do not null reserved?
@@ -742,7 +742,7 @@
// await usingApi(async (api, privateKey) => {
// const zeroBalance = await findUnusedAddress(api, privateKey);
- // const balanceTx = api.tx.balances.transfer(zeroBalance.address, 1n * UNIQUE);
+ // const balanceTx = api.tx.balances.transferKeepAlive(zeroBalance.address, 1n * UNIQUE);
// await submitTransactionAsync(alice, balanceTx);
// await setCollectionSponsorExpectSuccess(collectionId, zeroBalance.address);
js-packages/tests/util/globalSetup.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {5 usingPlaygrounds, Pallets, DONOR_FUNDING, MINIMUM_DONOR_FUND, LOCKING_PERIOD, UNLOCKING_PERIOD, makeNames,6} from './index.js';7import * as path from 'path';8import {promises as fs} from 'fs';910const {dirname} = makeNames(import.meta.url);1112// This function should be called before running test suites.13const globalSetup = async (): Promise<void> => {14 await usingPlaygrounds(async (helper, privateKey) => {15 try {16 // 1. Wait node producing blocks17 await helper.wait.newBlocks(1, 600_000);1819 // 2. Create donors for test files20 await fundFilenamesWithRetries(3)21 .then((result) => {22 if(!result) throw Error('Some problems with fundFilenamesWithRetries');23 });2425 // 3. Configure App Promotion26 const missingPallets = helper.fetchMissingPalletNames([Pallets.AppPromotion]);27 if(missingPallets.length === 0) {28 const superuser = await privateKey('//Alice');29 const palletAddress = helper.arrange.calculatePalletAddress('appstake');30 const palletAdmin = await privateKey('//PromotionAdmin');31 const api = helper.getApi();32 await helper.signTransaction(superuser, api.tx.sudo.sudo(api.tx.appPromotion.setAdminAddress({Substrate: palletAdmin.address})));33 const nominal = helper.balance.getOneTokenNominal();34 await helper.balance.transferToSubstrate(superuser, palletAdmin.address, 10000n * nominal);35 await helper.balance.transferToSubstrate(superuser, palletAddress, 10000n * nominal);36 await helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [api.tx.configuration37 .setAppPromotionConfigurationOverride({38 recalculationInterval: LOCKING_PERIOD,39 pendingInterval: UNLOCKING_PERIOD})], true);40 }41 } catch (error) {42 console.error(error);43 throw Error('Error during globalSetup');44 }45 });46};4748async function getFiles(rootPath: string): Promise<string[]> {49 const files = await fs.readdir(rootPath, {withFileTypes: true});50 const filenames: string[] = [];51 for(const entry of files) {52 const res = path.resolve(rootPath, entry.name);53 if(entry.isDirectory()) {54 filenames.push(...await getFiles(res));55 } else {56 filenames.push(res);57 }58 }59 return filenames;60}6162const fundFilenames = async () => {63 await usingPlaygrounds(async (helper, privateKey) => {64 const oneToken = helper.balance.getOneTokenNominal();65 const alice = await privateKey('//Alice');66 const nonce = await helper.chain.getNonce(alice.address);67 const filenames = await getFiles(path.resolve(dirname, '..'));6869 // batching is actually undesireable, it takes away the time while all the transactions actually succeed70 const batchSize = 300;71 let balanceGrantedCounter = 0;72 for(let b = 0; b < filenames.length; b += batchSize) {73 const tx: Promise<boolean>[] = [];74 let batchBalanceGrantedCounter = 0;75 for(let i = 0; batchBalanceGrantedCounter < batchSize && b + i < filenames.length; i++) {76 const f = filenames[b + i];77 if(!f.endsWith('.test.ts') && !f.endsWith('seqtest.ts') || f.includes('.outdated')) continue;78 const account = await privateKey({filename: f, ignoreFundsPresence: true});79 const aliceBalance = await helper.balance.getSubstrate(account.address);8081 if(aliceBalance < MINIMUM_DONOR_FUND * oneToken) {82 tx.push(helper.executeExtrinsic(83 alice,84 'api.tx.balances.transfer',85 [account.address, DONOR_FUNDING * oneToken],86 true,87 {nonce: nonce + balanceGrantedCounter++},88 ).then(() => true).catch(() => {console.error(`Transaction to ${path.basename(f)} registered as failed. Strange.`); return false;}));89 batchBalanceGrantedCounter++;90 }91 }9293 if(tx.length > 0) {94 console.log(`Granting funds to ${batchBalanceGrantedCounter} filename accounts.`);95 const result = await Promise.all(tx);96 if(result && result.lastIndexOf(false) > -1) throw new Error('The transactions actually probably succeeded, should check the balances.');97 }98 }99100 if(balanceGrantedCounter == 0) console.log('No account needs additional funding.');101 });102};103104const fundFilenamesWithRetries = (retriesLeft: number): Promise<boolean> => {105 if(retriesLeft <= 0) return Promise.resolve(false);106 return fundFilenames()107 .then(() => Promise.resolve(true))108 .catch(e => {109 console.error(e);110 console.error(`Some transactions might have failed. ${retriesLeft>1'Retrying...''Something is wrong.'}\n`);111 return fundFilenamesWithRetries(--retriesLeft);112 });113};114115globalSetup().catch(e => {116 console.error('Setup error');117 console.error(e);118 process.exit(1);119});