Update EventRecord tests (#1028)
* Update EventRecord tests * Update metadata with system events exposed * Align new EventRecord and fallback tests
This commit is contained in:
@@ -247,7 +247,22 @@
|
||||
]
|
||||
}
|
||||
],
|
||||
"events": null
|
||||
"events": [
|
||||
{
|
||||
"name": "ExtrinsicSuccess",
|
||||
"args": [],
|
||||
"documentation": [
|
||||
" An extrinsic completed successfully."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ExtrinsicFailed",
|
||||
"args": [],
|
||||
"documentation": [
|
||||
" An extrinsic failed."
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "aura",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -278,5 +278,9 @@ function initType (Type: Constructor, value?: any, isPedantic?: boolean): Codec
|
||||
export default function createType (type: Text | string, value?: any, isPedantic?: boolean): Codec {
|
||||
// l.debug(() => ['createType', { type, value }]);
|
||||
|
||||
return initType(createClass(type), value, isPedantic);
|
||||
try {
|
||||
return initType(createClass(type), value, isPedantic);
|
||||
} catch (error) {
|
||||
throw new Error(`createType(${type}):: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
"method": "state_storage",
|
||||
"params": {
|
||||
"result": {
|
||||
"block": "0xa7f1ac9f18dded8e5825205d3e5260cf53ba01f629d9ebc1b80601b45ed8c358",
|
||||
"block": "0x49e40de6af6524a6bbe1654cd261907073f0d76fc0e73ded942f1fd867096fa8",
|
||||
"changes": [
|
||||
[
|
||||
"0xcc956bdb7605e3547539f321ac2bc95c",
|
||||
"0x140000000000000000010000000203306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc204a83f1c09be797bc3d9adce29818368b276a84e6b545ced492c25c948978d7f83930000000000000000000000000000000000000000000000000000000000000000100000000000103006400000000000000010d000100000001000000000000000000000000000000"
|
||||
"0x0800000000000000000001000000000000"
|
||||
]
|
||||
]
|
||||
},
|
||||
"subscription": 19
|
||||
"subscription": 119
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,17 +5,15 @@
|
||||
import createType from '../codec/createType';
|
||||
import Vector from '../codec/Vector';
|
||||
import json1 from '../json/EventRecord.001.json';
|
||||
import json2 from '../json/EventRecord.002.json';
|
||||
import json3 from '../json/EventRecord.003.json';
|
||||
import Metadata from '../Metadata';
|
||||
import metadataV0 from '../Metadata/v0/static';
|
||||
import metadataV1 from '../Metadata/static';
|
||||
import AccountId from './AccountId';
|
||||
import metadata from '../Metadata/static';
|
||||
import Event from './Event';
|
||||
import EventRecord from './EventRecord';
|
||||
|
||||
describe('EventRecord', () => {
|
||||
describe('v0', () => {
|
||||
describe('EventRecord_0_76', () => {
|
||||
beforeEach(() => {
|
||||
Event.injectMetadata(
|
||||
new Metadata(metadataV0)
|
||||
@@ -28,40 +26,29 @@ describe('EventRecord', () => {
|
||||
|
||||
expect(er.phase.type).toEqual('ApplyExtrinsic');
|
||||
});
|
||||
|
||||
// FIXME skipping this one, need an actual updated sample for the actual new types
|
||||
it.skip('decodes more complex events', () => {
|
||||
const records: Vector<EventRecord> = createType('Vec<EventRecord>', json2.params.result.changes[0][1]) as any;
|
||||
|
||||
expect(records).toHaveLength(4);
|
||||
|
||||
const er = records[2];
|
||||
|
||||
expect(
|
||||
er.event.data.toArray().map((v) => v.toString())
|
||||
).toEqual(
|
||||
[
|
||||
new AccountId('0xd2de7394ae047a5502ad9adb9cc69ff6fe484033bfce874d775da947487cd832').toString(),
|
||||
new AccountId('0x37e027d776cd005c12bcf6722421374a9037167a0ceaf918f341c4ad68d54e59').toString(),
|
||||
'1000',
|
||||
'0'
|
||||
]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('v1', () => {
|
||||
describe('EventRecord (current)', () => {
|
||||
beforeEach(() => {
|
||||
Event.injectMetadata(
|
||||
new Metadata(metadataV1)
|
||||
new Metadata(metadata)
|
||||
);
|
||||
});
|
||||
|
||||
it('decodes correctly', () => {
|
||||
const records: Vector<EventRecord> = createType('Vec<EventRecord>', json3.params.result.changes[0][1]) as any;
|
||||
it('decodes older eventrecord correctly', () => {
|
||||
const records: Vector<EventRecord> = createType('Vec<EventRecord>', json1.params.result.changes[0][1], true) as any;
|
||||
const er = records[0];
|
||||
|
||||
expect(er.phase.type).toEqual('ApplyExtrinsic');
|
||||
});
|
||||
|
||||
it('decodes eventrecord with topics correctly', () => {
|
||||
const hex = json3.params.result.changes[0][1];
|
||||
const records: Vector<EventRecord> = createType('Vec<EventRecord>', hex, true) as any;
|
||||
const er = records[0];
|
||||
|
||||
expect(er.phase.type).toEqual('ApplyExtrinsic');
|
||||
expect(records.toHex()).toEqual(hex);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user