Skip to content

Commit

Permalink
lint tests code corrects
Browse files Browse the repository at this point in the history
  • Loading branch information
BuddyGlas committed Dec 24, 2024
1 parent ccfe032 commit a177a04
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 139 deletions.
6 changes: 3 additions & 3 deletions js-packages/playgrounds/unique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,8 @@ export class ChainHelperBase {
if(options !== null) return transaction.signAndSend(sender, options, callback);
return transaction.signAndSend(sender, callback);
};
options = options || { nonce: 0};
if (!options.nonce) {
options = options || {nonce: 0};
if(!options.nonce) {
let nonce = await this.chain.getNonce(sender.address);
options.nonce = nonce++;
}
Expand All @@ -621,7 +621,7 @@ export class ChainHelperBase {
const status = this.getTransactionStatus(result);

if(status === this.transactionStatus.SUCCESS) {
if (!result.status.isFinalized) {
if(!result.status.isFinalized) {
return;
}
this.logger.log(`${label} successful`);
Expand Down
4 changes: 2 additions & 2 deletions js-packages/scripts/authorizeEnactUpgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const code = await readFile(codePath);
await usingPlaygrounds(async (helper, privateKey) => {
const alice = await privateKey('//Alice');
const hex = blake2AsHex(code);
await helper.getSudo().executeExtrinsic(alice, 'api.tx.balances.forceSetBalance', [ alice.address, 1000000000000000000000000000000n ]);
await helper.getSudo().executeExtrinsic(alice, 'api.tx.balances.forceSetBalance', [alice.address, 1000000000000000000000000000000n]);
const balance = await helper.balance.getSubstrate(alice.address);
console.log("Balance:", balance);
console.log('Balance:', balance);
await helper.getSudo().executeExtrinsic(alice, 'api.tx.parachainSystem.authorizeUpgrade', [hex, true]);
await helper.getSudo().executeExtrinsicUncheckedWeight(alice, 'api.tx.parachainSystem.enactAuthorizedUpgrade', [u8aToHex(code)]);
});
Expand Down
18 changes: 8 additions & 10 deletions js-packages/test-utils/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const {dirname} = makeNames(import.meta.url);
const globalSetup = async (): Promise<void> => {
await usingPlaygrounds(async (helper, privateKey) => {
try {
// 1. Wait node producing blocks
console.log('Wait node producing blocks...')
await helper.wait.newBlocks(1, 600_000);
// 1. Wait node producing blocks
console.log('Wait node producing blocks...');
await helper.wait.newBlocks(1, 600_000);

// 2. Create donors for test files
await fundFilenamesWithRetries(3)
Expand Down Expand Up @@ -65,10 +65,8 @@ const fundFilenames = async () => {
const alice = await privateKey('//Alice');
const nonce = await helper.chain.getNonce(alice.address);

const filenames = await getFiles(path.resolve(dirname, '..'));
const filteredFilenames = filenames.filter((f) => {
return f.endsWith('.test.ts') || f.endsWith('seqtest.ts') || f.includes('.outdated');
});
const filenames = await getFiles(path.resolve(dirname, '..'));
const filteredFilenames = filenames.filter((f) => f.endsWith('.test.ts') || f.endsWith('seqtest.ts') || f.includes('.outdated'));

// batching is actually undesireable, it takes away the time while all the transactions actually succeed
const batchSize = 300;
Expand Down Expand Up @@ -118,9 +116,9 @@ const fundFilenamesWithRetries = (retriesLeft: number): Promise<boolean> => {

globalSetup().catch(e => {
console.error('Setup error');
if (e.result) {
console.error("Status:", e.status);
console.error("Result:", JSON.stringify(e.result.toHuman()));
if(e.result) {
console.error('Status:', e.status);
console.error('Result:', JSON.stringify(e.result.toHuman()));
} else
console.error(e);
process.exit(1);
Expand Down
4 changes: 2 additions & 2 deletions js-packages/test-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ class WaitGroup {
}
});
});

try {
await this.waitWithTimeout(promise, timeout);
} catch (error) {
Expand Down Expand Up @@ -1405,7 +1405,7 @@ class WaitGroup {
}
});
});

try {
await this.waitWithTimeout(promise, timeout);
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions js-packages/tests/eth/getCode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ describe('RPC eth_getCode', () => {
expect(contractCodeSub).to.has.length.greaterThan(4);
expect(contractCodeEth).to.has.length.greaterThan(4);
});
itEth(`returns notning for unknown collection: u32::MAX`, async ({helper}) => {

itEth('returns notning for unknown collection: u32::MAX', async ({helper}) => {
const address = helper.ethAddress.fromCollectionId(4_294_967_294);
const contractCodeSub = (await helper.callRpc('api.rpc.eth.getCode', [address])).toJSON();
const contractCodeEth = (await helper.getWeb3().eth.getCode(address));
Expand All @@ -69,7 +69,7 @@ describe('RPC eth_getCode', () => {
const address = helper.ethAddress.fromCollectionId(collection.collectionId);
const contractCodeSub = (await helper.callRpc('api.rpc.eth.getCode', [address])).toJSON();
const contractCodeEth = (await helper.getWeb3().eth.getCode(address));

expect(contractCodeSub).to.has.length.greaterThan(4);
expect(contractCodeEth).to.has.length.greaterThan(4);
}
Expand Down
2 changes: 1 addition & 1 deletion js-packages/tests/sub/appPromotion/appPromotion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('App promotion', () => {
unstakeTxs = [];
}
unstakeTxs.push(helper.staking.unstakeAll(account));
stakedByUsedAccs += await helper.staking.getTotalStaked({ Substrate: account.address });
stakedByUsedAccs += await helper.staking.getTotalStaked({Substrate: account.address});
}
await Promise.all(unstakeTxs);
usedAccounts = [];
Expand Down
46 changes: 21 additions & 25 deletions js-packages/tests/xcm/quartz.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,31 +142,27 @@ describeXCM('[XCM] Integration test: Exchanging tokens with AssetHub', () => {

await usingKusamaAssetHubPlaygrounds(async (helper) => {
await helper.balance.transferToSubstrate(alice, randomAccount.address, SENDER_BUDGET);

const setSafeXcmVersion = helper.constructApiCall(`api.tx.${helper.xcm.palletName}.forceDefaultXcmVersion`, [SAFE_XCM_VERSION]);

const isSufficient = true;
const minBalance = 10000;
const isFrozen = false;

const createUsdtCall = helper.constructApiCall(
'api.tx.assets.forceCreate', [
USDT_ASSET_ID,
alice.address,
isSufficient,
minBalance,
],
);

const setUsdtMetadata = helper.constructApiCall(
'api.tx.assets.forceSetMetadata', [
USDT_ASSET_ID,
USDT_NAME,
USDT_SYM,
USDT_DECIMALS,
isFrozen,
],
);
const createUsdtCall = helper.constructApiCall('api.tx.assets.forceCreate', [
USDT_ASSET_ID,
alice.address,
isSufficient,
minBalance,
]);

const setUsdtMetadata = helper.constructApiCall('api.tx.assets.forceSetMetadata', [
USDT_ASSET_ID,
USDT_NAME,
USDT_SYM,
USDT_DECIMALS,
isFrozen,
]);

setupAssetHubCall = helper.constructApiCall('api.tx.utility.batchAll', [[
setSafeXcmVersion,
Expand Down Expand Up @@ -203,8 +199,8 @@ describeXCM('[XCM] Integration test: Exchanging tokens with AssetHub', () => {
call: {
encoded: setupAssetHubCall.method.toHex(),
},
}
}
},
},
],
},
);
Expand Down Expand Up @@ -331,7 +327,7 @@ describeXCM('[XCM] Integration test: Exchanging QTZ with Moonriver', () => {
randomAccountQuartz = helper.arrange.createEmptyAccount();

await helper.balance.transferToSubstrate(alice, randomAccountQuartz.address, SENDER_BUDGET);

// Set the default version to wrap the first message to other chains.
await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);
});
Expand Down Expand Up @@ -380,7 +376,7 @@ describeXCM('[XCM] Integration test: Exchanging QTZ with Moonriver', () => {
await testHelper.rejectReserveTransferUNQfrom(
alice,
'moonriver',
'quartz',
'quartz',
);
});
});
Expand Down Expand Up @@ -453,7 +449,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {
'shiden',
randomAccount,
randomAccount,
SENDTO_AMOUNT,
SENDTO_AMOUNT,
);
});

Expand All @@ -471,7 +467,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {
await testHelper.sendOnlyOwnedBalance(
alice,
'shiden',
'quartz',
'quartz',
);
});

Expand Down
44 changes: 20 additions & 24 deletions js-packages/tests/xcm/unique.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,31 +144,27 @@ describeXCM('[XCM] Integration test: Exchanging tokens with AssetHub', () => {

await usingPolkadotAssetHubPlaygrounds(async (helper) => {
await helper.balance.transferToSubstrate(alice, randomAccount.address, SENDER_BUDGET);

const setSafeXcmVersion = helper.constructApiCall(`api.tx.${helper.xcm.palletName}.forceDefaultXcmVersion`, [SAFE_XCM_VERSION]);

const isSufficient = true;
const minBalance = 10000;
const isFrozen = false;

const createUsdtCall = helper.constructApiCall(
'api.tx.assets.forceCreate', [
USDT_ASSET_ID,
alice.address,
isSufficient,
minBalance,
],
);

const setUsdtMetadata = helper.constructApiCall(
'api.tx.assets.forceSetMetadata', [
USDT_ASSET_ID,
USDT_NAME,
USDT_SYM,
USDT_DECIMALS,
isFrozen,
],
);
const createUsdtCall = helper.constructApiCall('api.tx.assets.forceCreate', [
USDT_ASSET_ID,
alice.address,
isSufficient,
minBalance,
]);

const setUsdtMetadata = helper.constructApiCall('api.tx.assets.forceSetMetadata', [
USDT_ASSET_ID,
USDT_NAME,
USDT_SYM,
USDT_DECIMALS,
isFrozen,
]);

setupAssetHubCall = helper.constructApiCall('api.tx.utility.batchAll', [[
setSafeXcmVersion,
Expand Down Expand Up @@ -205,8 +201,8 @@ describeXCM('[XCM] Integration test: Exchanging tokens with AssetHub', () => {
call: {
encoded: setupAssetHubCall.method.toHex(),
},
}
}
},
},
],
},
);
Expand Down Expand Up @@ -356,7 +352,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Polkadex', () => {
X1: {Parachain: UNIQUE_CHAIN},
},
},
}
},
);
}

Expand Down Expand Up @@ -411,7 +407,7 @@ describeXCM('[XCM] Integration test: Exchanging UNQ with Moonbeam', () => {
randomAccountUnique = helper.arrange.createEmptyAccount();

await helper.balance.transferToSubstrate(alice, randomAccountUnique.address, SENDER_BUDGET);

// Set the default version to wrap the first message to other chains.
await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);
});
Expand Down Expand Up @@ -642,7 +638,7 @@ describeXCM('[XCM] Integration test: Unique rejects non-native tokens', () => {
await testHelper.rejectNativeTokensFrom(
alice,
'acala',
'unique'
'unique',
);
});

Expand Down
Loading

0 comments on commit a177a04

Please sign in to comment.