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

Conversation

fairax
Copy link
Contributor

@fairax fairax commented Sep 26, 2023

No description provided.

@fairax fairax requested a review from uandysmith September 26, 2023 22:32
@fairax fairax self-assigned this Sep 26, 2023
async function getSubIdentityName(helper: UniqueHelper, address: string) {
return ((await helper.getApi().query.identity.superOf(address)).toHuman() as any);
function instanceOfCodec(obj: any): obj is Codec {
return typeof obj == 'object' && 'registry' in obj;
Copy link
Member

Choose a reason for hiding this comment

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

obj instanceof Codec, не?

}

describe('Integration Test: Identities Manipulation', () => {
let superuser: IKeyringPair;

before(async function() {
if(!process.env.RUN_COLLATOR_TESTS) this.skip();
function equal(this: any, _super: any) {
Copy link
Member

Choose a reason for hiding this comment

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

Неплохо, но надо бы это для всех тестов включить (глобальный before/вообще без обёрток)

@@ -140,6 +140,7 @@
"@polkadot/wasm-crypto-wasm": "^7.2.1",
"@rmrk-team/evm-contracts": "^1.2.1",
"@typechain/web3-v1": "^6.0.3",
"@unique-nft": "workspaces^",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"@unique-nft": "workspaces^",
"@unique-nft/opal-testnet-types": "workspaces^",

@@ -152,6 +153,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

@fairax fairax force-pushed the fix/ts-tests-linter-warnings branch 2 times, most recently from 1f54fc9 to 625bc84 Compare October 2, 2023 15:39
@@ -123,7 +123,7 @@ describe('Integration Test: Identities Manipulation', () => {
const oldIdentities = await getIdentityAccounts(helper);

// delete a couple, check that they are no longer there
const registry = helper.api!.registry;
const registry = helper.getApi().registry;
Copy link
Member

Choose a reason for hiding this comment

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

Почему бы не переименовать поле api в _api/#api, и не создать getter?

Copy link
Member

Choose a reason for hiding this comment

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

В плане,

#api?: ApiPromise;
get api(): ApiPromise {
   if(this.#api) return this.#api;
   this.#api = ApiPromise.create(...);
   return this.#api;
}

Чтобы не писать везде getApi(), это некрасиво)

Copy link
Contributor

Choose a reason for hiding this comment

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

Там в текущей реализации бросает эксцепшен, если коннекта нет, это как раз то поведение, которое хочется сохранить. Через геттеры вроде не очень эксцепшенами бросаться

Copy link
Member

@CertainLach CertainLach Oct 9, 2023

Choose a reason for hiding this comment

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

Какая разница, эксепшон оно кинет, или руганётся на undefined в случае с .api!
У нас коннекшон есть в 99% случаев, я не думаю что ради этого стоит весь код в таком стиле писать

Из геттеров можно бросаться эксепшонами, в стектрейсе они тоже видны

Copy link
Contributor

Choose a reason for hiding this comment

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

У нас - да, однако в скриптах хелпер инициализируется самостоятельно, без using.
Это оттуда пошло и опять же хочу сохранить для пакета.

Copy link
Contributor

Choose a reason for hiding this comment

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

Потом в скриптах у меня было часто

const api = helper.getApi();

Что не так красиво, обращаясь к его свойству

Copy link
Member

Choose a reason for hiding this comment

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

Ну вот да, с get методом напрашивается сделать один раз получение
А если геттером сделать - то можно код как есть оставить

@fairax fairax force-pushed the fix/ts-tests-linter-warnings branch from 6d7420f to 742522c Compare October 9, 2023 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants