Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typing to polkadot queries and events #1001

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11,013 changes: 11,013 additions & 0 deletions tests/package-lock.json

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,15 @@
"@openzeppelin/contracts": "^4.9.2",
"@polkadot/api": "10.9.1",
"@polkadot/rpc-core": "^10.9.1",
"@polkadot/util": "12.3.2",
"@polkadot/util-crypto": "12.3.2",
"@polkadot/types": "^10.9.1",
"@polkadot/types-codec": "^10.9.1",
"@polkadot/util": "12.5.1",
"@polkadot/util-crypto": "12.5.1",
"@polkadot/wasm-crypto-asmjs": "^7.2.1",
"@polkadot/wasm-crypto-wasm": "^7.2.1",
"@rmrk-team/evm-contracts": "^1.2.1",
"@typechain/web3-v1": "^6.0.3",
"@unique-nft/opal-testnet-types": "^1.0.0",
"chai-as-promised": "^7.1.1",
"chai-like": "^1.1.1",
"csv-writer": "^1.6.0",
Expand All @@ -157,6 +160,9 @@
"resolutions": {
"decode-uri-component": "^0.2.1"
},
"workspaces": [
"src/interfaces"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В интерфейсы нужно добавить package.json с name: @unique-nft/opal-testnet-types

],
"type": "module",
"packageManager": "[email protected]"
}
}
6 changes: 3 additions & 3 deletions tests/src/.outdated/substrate/substrate-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {ApiPromise, WsProvider} from '@polkadot/api';
import {ApiOptions, ApiTypes, SubmittableExtrinsic} from '@polkadot/api/types';
import {ExtrinsicStatus} from '@polkadot/types/interfaces/author/types';
import {EventRecord} from '@polkadot/types/interfaces/system/types';
import {IKeyringPair} from '@polkadot/types/types';
import {IEventLike, IKeyringPair} from '@polkadot/types/types';
import config from '../../config';
import '../../interfaces/augment-api-events';
import * as defs from '../../interfaces/definitions';
Expand Down Expand Up @@ -122,10 +122,10 @@ function getTransactionStatus(events: EventRecord[], status: ExtrinsicStatus): T
return TransactionStatus.NotReady;
}
if (status.isInBlock || status.isFinalized) {
if(events.filter(e => e.event.data.method === 'ExtrinsicFailed').length > 0) {
if(events.find(r => r.event.method === 'ExtrinsicFailed') != null) {
return TransactionStatus.Fail;
}
if(events.filter(e => e.event.data.method === 'ExtrinsicSuccess').length > 0) {
if(events.find(r => r.event.method === 'ExtrinsicSuccess') != null) {
return TransactionStatus.Success;
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/src/adminTransferAndBurn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ describe('Integration Test: ownerCanTransfer allows admins to use only transferF
const {collectionId} = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});
await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});
const limits = await helper.collection.getEffectiveLimits(collectionId);
expect(limits.ownerCanTransfer).to.be.true;
expect(limits?.ownerCanTransfer).to.be.true;

const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
await expect(helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address})).to.be.rejected;

await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: bob.address}, {Substrate: charlie.address});
const newTokenOwner = await helper.nft.getTokenOwner(collectionId, tokenId);
expect(newTokenOwner.Substrate).to.be.equal(charlie.address);
expect(newTokenOwner?.Substrate).to.be.equal(charlie.address);
});

itSub('admin burns other user\'s token', async ({helper}) => {
const {collectionId} = await helper.nft.mintCollection(alice, {name: 'name', description: 'descr', tokenPrefix: 'COL'});

await helper.collection.setLimits(alice, collectionId, {ownerCanTransfer: true});
const limits = await helper.collection.getEffectiveLimits(collectionId);
expect(limits.ownerCanTransfer).to.be.true;
expect(limits?.ownerCanTransfer).to.be.true;

const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});

Expand Down
8 changes: 4 additions & 4 deletions tests/src/allowLists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe('Integration Test ext. Transfer if included in Allow List', () => {
await helper.nft.addToAllowList(alice, collectionId, {Substrate: charlie.address});
await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
expect(owner.Substrate).to.be.equal(charlie.address);
expect(owner?.Substrate).to.be.equal(charlie.address);
});

itSub('If Public Access mode is set to AllowList, tokens can be transferred to a allowlisted address with transferFrom.', async ({helper}) => {
Expand All @@ -190,7 +190,7 @@ describe('Integration Test ext. Transfer if included in Allow List', () => {

await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});
const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
expect(owner.Substrate).to.be.equal(charlie.address);
expect(owner?.Substrate).to.be.equal(charlie.address);
});

itSub('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transfer', async ({helper}) => {
Expand All @@ -202,7 +202,7 @@ describe('Integration Test ext. Transfer if included in Allow List', () => {

await helper.nft.transferToken(alice, collectionId, tokenId, {Substrate: charlie.address});
const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
expect(owner.Substrate).to.be.equal(charlie.address);
expect(owner?.Substrate).to.be.equal(charlie.address);
});

itSub('If Public Access mode is set to AllowList, tokens can be transferred from a allowlisted address with transferFrom', async ({helper}) => {
Expand All @@ -215,7 +215,7 @@ describe('Integration Test ext. Transfer if included in Allow List', () => {

await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: alice.address}, {Substrate: charlie.address});
const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
expect(owner.Substrate).to.be.equal(charlie.address);
expect(owner?.Substrate).to.be.equal(charlie.address);
});
});

Expand Down
3 changes: 3 additions & 0 deletions tests/src/apiConsts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ describe('integration test: API UNIQUE consts', () => {
});

itSub('DEFAULT_NFT_COLLECTION_LIMITS', () => {
// eslint-disable-next-line no-restricted-syntax
expect(api.consts.unique.nftDefaultCollectionLimits.toHuman()).to.deep.equal(DEFAULT_COLLETCTION_LIMIT);
});

itSub('DEFAULT_RFT_COLLECTION_LIMITS', () => {
// eslint-disable-next-line no-restricted-syntax
expect(api.consts.unique.rftDefaultCollectionLimits.toHuman()).to.deep.equal(DEFAULT_COLLETCTION_LIMIT);
});

itSub('DEFAULT_FT_COLLECTION_LIMITS', () => {
// eslint-disable-next-line no-restricted-syntax
expect(api.consts.unique.ftDefaultCollectionLimits.toHuman()).to.deep.equal(DEFAULT_COLLETCTION_LIMIT);
});

Expand Down
8 changes: 4 additions & 4 deletions tests/src/approve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ import {CrossAccountId} from './util/playgrounds/unique';
await (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});
await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address});
const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
expect(owner.Substrate).to.be.equal(alice.address);
expect(owner?.Substrate).to.be.equal(alice.address);
});

itSub('Fungible up to an approved amount', async ({helper}) => {
Expand Down Expand Up @@ -201,7 +201,7 @@ import {CrossAccountId} from './util/playgrounds/unique';
await (helper.nft as any)[testCase.method](bob, collectionId, tokenId, {Substrate: charlie.address});
await helper.nft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address});
const owner = await helper.nft.getTokenOwner(collectionId, tokenId);
expect(owner.Substrate).to.be.equal(alice.address);
expect(owner?.Substrate).to.be.equal(alice.address);
const transferTokenFromTx = () => helper.nft.transferTokenFrom(charlie, collectionId, tokenId, testCase.account(bob), {Substrate: alice.address});
await expect(transferTokenFromTx()).to.be.rejectedWith('common.ApprovedValueTooLow');
});
Expand Down Expand Up @@ -559,12 +559,12 @@ describe('Administrator and collection owner do not need approval in order to ex

await helper.nft.transferTokenFrom(alice, collectionId, tokenId, {Substrate: charlie.address}, {Substrate: dave.address});
const owner1 = await helper.nft.getTokenOwner(collectionId, tokenId);
expect(owner1.Substrate).to.be.equal(dave.address);
expect(owner1?.Substrate).to.be.equal(dave.address);

await helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});
await helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: dave.address}, {Substrate: alice.address});
const owner2 = await helper.nft.getTokenOwner(collectionId, tokenId);
expect(owner2.Substrate).to.be.equal(alice.address);
expect(owner2?.Substrate).to.be.equal(alice.address);
});

itSub('Fungible up to an approved amount', async ({helper}) => {
Expand Down
6 changes: 3 additions & 3 deletions tests/src/benchmarks/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {EthUniqueHelper} from '../../eth/util';
import {ITokenPropertyPermission, TCollectionMode} from '../../util/playgrounds/types';
import {ICreateTokenPropertyPermission, TCollectionMode} from '../../util/playgrounds/types';
import {UniqueNFTCollection, UniqueRFTCollection} from '../../util/playgrounds/unique';
import {IKeyringPair} from '@polkadot/types/types';

Expand All @@ -17,7 +17,7 @@ export const SUBS_PROPERTIES = Array(40)
value: `value_${i}`,
}));

export const PERMISSIONS: ITokenPropertyPermission[] = PROPERTIES.map((p) => ({
export const PERMISSIONS: ICreateTokenPropertyPermission[] = PROPERTIES.map((p) => ({
key: p.key,
permission: {
tokenOwner: true,
Expand All @@ -36,7 +36,7 @@ export async function createCollectionForBenchmarks(
privateKey: (seed: string) => Promise<IKeyringPair>,
ethSigner: string,
proxyContract: string | null,
permissions: ITokenPropertyPermission[],
permissions: ICreateTokenPropertyPermission[],
) {
const donor = await privateKey('//Alice');

Expand Down
14 changes: 7 additions & 7 deletions tests/src/collator-selection/collatorSelection.seqtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {usingPlaygrounds, expect, itSub, Pallets, requirePalletsOrSkip} from '..

async function nodeAddress(name: string) {
// eslint-disable-next-line require-await
return await usingPlaygrounds(async (helper, _) => {
return await usingPlaygrounds(async (helper) => {
const envNodeStash = `RELAY_UNIQUE_NODE_${name.toUpperCase()}_STASH`;

const nodeStash = process.env[envNodeStash];
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('Integration Test: Collator Selection', () => {
let deltaNode: string;

before(async function() {
await usingPlaygrounds(async (helper, privateKey) => {
await usingPlaygrounds(async (helper) => {
// todo:collator see again if blocks start to be finalized in dev mode
// Skip the collator block production in dev mode, since the blocks are sealed automatically.
if(await helper.arrange.isDevNode()) this.skip();
Expand All @@ -118,13 +118,13 @@ describe('Integration Test: Collator Selection', () => {

await helper.wait.newSessions(2);

const newValidators = await helper.callRpc('api.query.session.validators');
const newValidators = await helper.callQuery('api.query.session.validators');
expect(newValidators).to.contain(gammaNode).and.contain(deltaNode).and.be.length(2);

const lastBlockNumber = await helper.chain.getLatestBlockNumber();
await helper.wait.newBlocks(1);
const lastGammaBlock = (await helper.callRpc('api.query.collatorSelection.lastAuthoredBlock', [gammaNode])).toNumber();
const lastDeltaBlock = (await helper.callRpc('api.query.collatorSelection.lastAuthoredBlock', [deltaNode])).toNumber();
const lastGammaBlock = await helper.callQuery('api.query.collatorSelection.lastAuthoredBlock', [gammaNode]);
const lastDeltaBlock = await helper.callQuery('api.query.collatorSelection.lastAuthoredBlock', [deltaNode]);
expect(lastGammaBlock >= lastBlockNumber || lastDeltaBlock >= lastBlockNumber).to.be.true;
});

Expand All @@ -137,7 +137,7 @@ describe('Integration Test: Collator Selection', () => {
let crowd: IKeyringPair[];

before(async function() {
await usingPlaygrounds(async (helper, privateKey) => {
await usingPlaygrounds(async (helper) => {
crowd = await helper.arrange.createCrowd(20, 100n, superuser);

// set session keys for everyone
Expand Down Expand Up @@ -219,7 +219,7 @@ describe('Integration Test: Collator Selection', () => {
let crowd: IKeyringPair[];

before(async function() {
await usingPlaygrounds(async (helper, privateKey) => {
await usingPlaygrounds(async (helper) => {
crowd = await helper.arrange.createCrowd(20, 100n, superuser);

// set session keys for everyone
Expand Down
Loading