From 4f887bd6e7404f96c82f38c0c1ff30f87892c71f Mon Sep 17 00:00:00 2001 From: Dmitry Osipov Date: Tue, 5 Jul 2022 13:00:22 +0300 Subject: [PATCH] Rename stateChanged field in MessagesDispatched event data (#794) --- api/CHANGELOG.md | 13 +++++++++++++ api/package-lock.json | 4 ++-- api/package.json | 2 +- api/src/events/GearEventData.ts | 6 +++--- api/test/State.test.ts | 24 +++++++++++++++++++++--- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/api/CHANGELOG.md b/api/CHANGELOG.md index faa0debcab..c701032183 100644 --- a/api/CHANGELOG.md +++ b/api/CHANGELOG.md @@ -1,3 +1,16 @@ +## 0.22.3 + +_07/05/2022_ + +https://github.com/gear-tech/gear-js/pull/794 + +### Changes + +- Rename the stateChanged field to stateChanges in the MessagesDispatchedData class +- Set type of expiration in the UserMessageSentData class to Option + +--- + ## 0.22.2 _06/27/2022_ diff --git a/api/package-lock.json b/api/package-lock.json index 993f3b976a..e4bd73d6c8 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -1,12 +1,12 @@ { "name": "@gear-js/api", - "version": "0.22.2", + "version": "0.22.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@gear-js/api", - "version": "0.22.2", + "version": "0.22.3", "license": "GPL-3.0", "devDependencies": { "@babel/plugin-transform-typescript": "7.18.4", diff --git a/api/package.json b/api/package.json index fedd5d326f..3f680ccfd1 100644 --- a/api/package.json +++ b/api/package.json @@ -1,6 +1,6 @@ { "name": "@gear-js/api", - "version": "0.22.2", + "version": "0.22.3", "description": "A JavaScript library that provides functionality to connect GEAR Component APIs.", "main": "lib/index.js", "module": "lib/index.mjs", diff --git a/api/src/events/GearEventData.ts b/api/src/events/GearEventData.ts index c30f3ca96c..a36224ca06 100644 --- a/api/src/events/GearEventData.ts +++ b/api/src/events/GearEventData.ts @@ -1,6 +1,6 @@ -import { u8, u32, u128, Vec, Option, BTreeMap, BTreeSet, GenericEventData, Bool } from '@polkadot/types'; +import { u32, u128, Vec, Option, BTreeMap, BTreeSet, GenericEventData, Bool } from '@polkadot/types'; import { BlockNumber, AccountId32 } from '@polkadot/types/interfaces'; -import { Reply, QueuedDispatch, ProgramDetails } from '../types/interfaces'; +import { QueuedDispatch, ProgramDetails } from '../types/interfaces'; import { MessageId, UserId, @@ -42,7 +42,7 @@ export interface UserMessageReadData extends GenericEventData { export interface MessagesDispatchedData extends GenericEventData { total: u32; statuses: BTreeMap; - stateChanged: BTreeSet; + stateChanges: BTreeSet; } export interface MessageWaitedData extends GenericEventData { diff --git a/api/test/State.test.ts b/api/test/State.test.ts index 009c6da6d1..bdbe33586a 100644 --- a/api/test/State.test.ts +++ b/api/test/State.test.ts @@ -5,15 +5,17 @@ import { checkInit, getAccount, sleep } from './utilsFunctions'; import { GEAR_EXAMPLES_WASM_DIR, TEST_WASM_DIR } from './config'; const api = new GearApi(); + const demo_meta_test = { code: readFileSync(join(GEAR_EXAMPLES_WASM_DIR, 'demo_meta.opt.wasm')), meta: readFileSync(join(GEAR_EXAMPLES_WASM_DIR, 'demo_meta.meta.wasm')), - id: undefined, + id: '0x', + uploadBlock: '0x', }; const timestamp_test = { code: readFileSync(join(TEST_WASM_DIR, 'timestamp.opt.wasm')), meta: readFileSync(join(TEST_WASM_DIR, 'timestamp.meta.wasm')), - id: undefined, + id: '0x', }; beforeAll(async () => { @@ -37,7 +39,11 @@ beforeAll(async () => { await getWasmMetadata(demo_meta_test.meta), ).programId; initStatus = checkInit(api, demo_meta_test.id); - api.program.signAndSend(alice, () => {}); + api.program.signAndSend(alice, ({ status }) => { + if (status.isInBlock) { + demo_meta_test.uploadBlock = status.asInBlock.toHex(); + } + }); expect(await initStatus()).toBe('success'); }); @@ -88,3 +94,15 @@ describe('Read State', () => { expect(state.toHex()).toBe('0x04010000000000000004012c536f6d655375726e616d6520536f6d654e616d65'); }); }); + +describe('Events related to state change', () => { + test('stateChanges should be in MessagesDispatched event data', async () => { + const apiAt = await api.at(demo_meta_test.uploadBlock); + const events = await apiAt.query.system.events(); + const messagesDispatchedEvents = events.filter(({ event }) => api.events.gear.MessagesDispatched.is(event)); + expect(messagesDispatchedEvents).toHaveLength(1); + expect(messagesDispatchedEvents[0].event.data).toHaveProperty('stateChanges'); + expect(messagesDispatchedEvents[0].event.data['stateChanges'].size).toBe(1); + expect(messagesDispatchedEvents[0].event.data['stateChanges'].toHuman()[0]).toEqual(demo_meta_test.id); + }); +});