Align all RPC methods with Rust (#264)

* Align all RPC methods with Rust

* Adjust tests for extrinsicUpdate (e2e & working)

* Update transfer.spec.js

Auto-complete imports removed
This commit is contained in:
Jaco Greeff
2018-10-12 14:47:22 +02:00
committed by GitHub
parent eb5fbad5aa
commit f8d9f1c76e
15 changed files with 152 additions and 58 deletions
@@ -0,0 +1 @@
{"jsonrpc":"2.0","method":"author_extrinsicUpdate","params":{"result":{"finalised":"0xc465b92a72b1d20918d64cd4effa70c2bb58b53a3f8c24c3ac8fd8f465f059b4"},"subscription":9}}
@@ -0,0 +1,22 @@
// Copyright 2017-2018 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import rpc from './ExtrinsicStatus.rpc.json';
import ExtrinsicStatus from './ExtrinsicStatus';
describe('ExtrinsicStatus', () => {
const status = new ExtrinsicStatus().fromJSON(rpc.params.result);
it('has the correct type', () => {
expect(
status.type
).toEqual('Finalised');
});
it('has the correct hash', () => {
expect(
status.value.toHex()
).toEqual('0xc465b92a72b1d20918d64cd4effa70c2bb58b53a3f8c24c3ac8fd8f465f059b4');
});
});
@@ -20,7 +20,7 @@ export class Finalised extends Hash {
export class Usurped extends Hash {
}
export default class Status extends EnumType<Finalised | Usurped | Broadcast | Dropped> {
export default class ExtrinsicStatus extends EnumType<Finalised | Usurped | Broadcast | Dropped> {
constructor (index?: number) {
super([
Finalised,
+1 -1
View File
@@ -39,7 +39,7 @@ describe('MisbehaviorReport', () => {
});
it('has the correct misbehavior type', () => {
expect(report.misbehavior.Type).toEqual('BftDoubleCommit');
expect(report.misbehavior.type).toEqual('BftDoubleCommit');
});
it('has the correct parent block', () => {
+27 -2
View File
@@ -2,6 +2,8 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import isUndefined from '@polkadot/util/is/undefined';
import Base from './Base';
type TypesArray = Array<{ new(value?: any): Base }>;
@@ -37,14 +39,37 @@ export default class EnumType <T> extends Base<Base<T>> {
this.setValue(index, value);
}
get Type (): string {
get type (): string {
return this._Types[this._index].name;
}
get value (): Base<T> {
return this.raw;
}
byteLength (): number {
return 1 + this.raw.byteLength();
}
fromJSON (input: any = {}): EnumType<T> {
// JSON comes in the form of { "<type (lowercased)>": "<value for type>" }, here we
// additionally force to lower to ensure forward compat
const key = Object.keys(input)[0];
const lowerKey = key.toLowerCase();
const index = this._indexes.find((value, index) =>
this._Types[index].name.toLowerCase() === lowerKey
);
if (isUndefined(index)) {
throw new Error('Unable to reliably map input on JSON');
}
this.setValue(index);
this.raw.fromJSON(input[key]);
return this;
}
fromU8a (input: Uint8Array): EnumType<T> {
this.setValue(input[0]);
this.raw.fromU8a(input.subarray(1));
@@ -78,6 +103,6 @@ export default class EnumType <T> extends Base<Base<T>> {
}
toString (): string {
return this._Types[this._index].name;
return this.type;
}
}
+1 -1
View File
@@ -27,6 +27,7 @@ export { default as Compact256 } from './Compact256';
export { default as Extrinsic } from './Extrinsic';
export { default as ExtrinsicEra } from './ExtrinsicEra';
export { default as ExtrinsicSignature } from './ExtrinsicSignature';
export { default as ExtrinsicStatus } from './ExtrinsicStatus';
// NOTE Only used internally, exported as PendingExtrinsics
// export { default as Extrinsics } from './Extrinsics';
export { default as Gas } from './Gas';
@@ -58,7 +59,6 @@ export { default as ReferendumIndex } from './ReferendumIndex';
export { default as RuntimeVersion } from './RuntimeVersion';
export { default as Signature } from './Signature';
export { default as SignedBlock } from './SignedBlock';
export { default as Status } from './Status';
export { default as StorageChangeSet } from './StorageChangeSet';
export { default as StorageData } from './StorageData';
export { default as StorageKey } from './StorageKey';