Skip to content

Commit

Permalink
Rename stateChanged field in MessagesDispatched event data (#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit authored Jul 5, 2022
1 parent 4bd3b65 commit 4f887bd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
13 changes: 13 additions & 0 deletions api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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<BlockNumber>

---

## 0.22.2

_06/27/2022_
Expand Down
4 changes: 2 additions & 2 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions api/src/events/GearEventData.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -42,7 +42,7 @@ export interface UserMessageReadData extends GenericEventData {
export interface MessagesDispatchedData extends GenericEventData {
total: u32;
statuses: BTreeMap<MessageId, DispatchStatus>;
stateChanged: BTreeSet<ProgramId>;
stateChanges: BTreeSet<ProgramId>;
}

export interface MessageWaitedData extends GenericEventData {
Expand Down
24 changes: 21 additions & 3 deletions api/test/State.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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');
});

Expand Down Expand Up @@ -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);
});
});

0 comments on commit 4f887bd

Please sign in to comment.