Additional types for latest substrate master (#1016)
* Additional types for latest substrate master * Method tests updated for new structure * Adjust extrinsic test indexes * Adjust type-extrinsics tests * Adapt for new session/era calc * Small comment update * Update with patch for system * Adjust tests with system calls in metadata
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -11,25 +11,27 @@ describe('Method', () => {
|
||||
Method.injectMethods(extrinsics);
|
||||
});
|
||||
|
||||
// FIXME susbtrate master does not currently expose the new system module calls in meta,
|
||||
// once it does the index here will change, so a different method would be refrerred to
|
||||
it('handles decoding correctly (bare)', () => {
|
||||
expect(
|
||||
new Method({
|
||||
args: [],
|
||||
callIndex: [1, 2]
|
||||
callIndex: [3, 1] // balances.setBalance
|
||||
}).toU8a()
|
||||
).toEqual(new Uint8Array([1, 2, 0])); // array of 0
|
||||
).toEqual(new Uint8Array([3, 1, 0, 0, 0]));
|
||||
});
|
||||
|
||||
it('handles creation from a hex value properly', () => {
|
||||
expect(
|
||||
new Method('0x0102').toU8a()
|
||||
).toEqual(new Uint8Array([1, 2, 0])); // array of 0 for consensus.noteOffline
|
||||
new Method('0x0301').toU8a()
|
||||
).toEqual(new Uint8Array([3, 1, 0, 0, 0])); // balances.setBalance
|
||||
});
|
||||
|
||||
describe('hasOrigin', () => {
|
||||
const test = {
|
||||
args: [],
|
||||
callIndex: [1, 2]
|
||||
callIndex: [2, 2] // timestamp
|
||||
};
|
||||
|
||||
it('is false with no arguments', () => {
|
||||
|
||||
@@ -417,3 +417,10 @@ export default class Digest extends Struct {
|
||||
return this.logs.filter(({ type }) => !exclude.includes(type)) as Vector<DigestItem>;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name DigestOf
|
||||
* @description
|
||||
* A [[Header]] Digest
|
||||
*/
|
||||
export class DigestOf extends Digest {}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
*/
|
||||
export { default as Block } from './Block';
|
||||
export { default as ChainProperties } from './ChainProperties';
|
||||
export { default as Digest, DigestItem } from './Digest';
|
||||
export { default as Digest, DigestItem, DigestOf } from './Digest';
|
||||
export { default as ExtrinsicStatus } from './ExtrinsicStatus';
|
||||
export { default as Header } from './Header';
|
||||
export { default as Health } from './Health';
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import U64 from '../primitive/U64';
|
||||
|
||||
/**
|
||||
* @name AuthorityWeight
|
||||
* @description
|
||||
* The weight of an authority
|
||||
*/
|
||||
export default class AuthorityWeight extends U64 {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import U32 from '../primitive/U32';
|
||||
|
||||
/**
|
||||
* @name EraIndex
|
||||
* @description
|
||||
* Index type of eras
|
||||
*/
|
||||
export default class EraIndex extends U32 {
|
||||
}
|
||||
@@ -21,7 +21,9 @@ describe('Extrinsic', () => {
|
||||
});
|
||||
|
||||
it('decodes an actual transaction (new format)', () => {
|
||||
const extrinsic = new Extrinsic('0x250281ffbfc823aa75c30058eeec21abe2c2d6b7247418a4af89d67a2084c2ac864da080c0aa4df3b4926c3cd78bbdced31d8bdccb8604b779b71b90e58b2848df4a9ad6b0aa1aae6be7a05c9413a172b0325e4d214e5ff2b25098028b30f1a50be9c90e0c000300ff4a83f1c09be797bc3d9adce29818368b276a84e6b545ced492c25c948978d7f8e5c0');
|
||||
const extrinsic = new Extrinsic('0x250281ffbfc823aa75c30058eeec21abe2c2d6b7247418a4af89d67a2084c2ac864da080c0aa4df3b4926c3cd78bbdced31d8bdccb8604b779b71b90e58b2848df4a9ad6b0aa1aae6be7a05c9413a172b0325e4d214e5ff2b25098028b30f1a50be9c90e0c00' +
|
||||
'0300' + // balances.transfer
|
||||
'ff4a83f1c09be797bc3d9adce29818368b276a84e6b545ced492c25c948978d7f8e5c0');
|
||||
|
||||
expect(extrinsic.isSigned).toEqual(true);
|
||||
expect(extrinsic.signature.signer.toU8a()).toEqual(new Uint8Array([255, 191, 200, 35, 170, 117, 195, 0, 88, 238, 236, 33, 171, 226, 194, 214, 183, 36, 116, 24, 164, 175, 137, 214, 122, 32, 132, 194, 172, 134, 77, 160, 128]));
|
||||
@@ -29,12 +31,15 @@ describe('Extrinsic', () => {
|
||||
expect(extrinsic.signature.nonce.toNumber()).toEqual(3);
|
||||
expect(extrinsic.signature.era.toU8a()).toEqual(new Uint8Array([0]));
|
||||
expect(extrinsic.callIndex).toEqual(new Uint8Array([3, 0]));
|
||||
expect(`${extrinsic.method.sectionName}.${extrinsic.method.methodName}`).toEqual('balances.transfer');
|
||||
expect(extrinsic.args[0].toString()).toEqual('5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5jzo');
|
||||
});
|
||||
|
||||
it('decodes an actual transaction (old format)', () => {
|
||||
const extrinsic = new Extrinsic(
|
||||
'0x81ffbfc823aa75c30058eeec21abe2c2d6b7247418a4af89d67a2084c2ac864da080c0aa4df3b4926c3cd78bbdced31d8bdccb8604b779b71b90e58b2848df4a9ad6b0aa1aae6be7a05c9413a172b0325e4d214e5ff2b25098028b30f1a50be9c90e0c000300ff4a83f1c09be797bc3d9adce29818368b276a84e6b545ced492c25c948978d7f8e5c0'
|
||||
'0x81ffbfc823aa75c30058eeec21abe2c2d6b7247418a4af89d67a2084c2ac864da080c0aa4df3b4926c3cd78bbdced31d8bdccb8604b779b71b90e58b2848df4a9ad6b0aa1aae6be7a05c9413a172b0325e4d214e5ff2b25098028b30f1a50be9c90e0c00' +
|
||||
'0300' + // balances.transfer
|
||||
'ff4a83f1c09be797bc3d9adce29818368b276a84e6b545ced492c25c948978d7f8e5c0'
|
||||
);
|
||||
|
||||
expect(extrinsic.isSigned).toEqual(true);
|
||||
@@ -43,6 +48,7 @@ describe('Extrinsic', () => {
|
||||
expect(extrinsic.signature.nonce.toNumber()).toEqual(3);
|
||||
expect(extrinsic.signature.era.toU8a()).toEqual(new Uint8Array([0]));
|
||||
expect(extrinsic.callIndex).toEqual(new Uint8Array([3, 0]));
|
||||
expect(`${extrinsic.method.sectionName}.${extrinsic.method.methodName}`).toEqual('balances.transfer');
|
||||
expect(extrinsic.args[0].toString()).toEqual('5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5jzo');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import SessionKeys from './SessionKeys';
|
||||
|
||||
/**
|
||||
* @name Keys
|
||||
* @description
|
||||
* The session keys
|
||||
*/
|
||||
|
||||
export default class Keys extends SessionKeys {
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import Bytes from '../primitive/Bytes';
|
||||
|
||||
/**
|
||||
* @name OpaqueKey
|
||||
* @description
|
||||
* The Substrate OpaqueKey representation as a [[Bytes]] (`vec<u8>`).
|
||||
*/
|
||||
|
||||
export default class OpaqueKey extends Bytes {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import U32 from '../primitive/U32';
|
||||
|
||||
/**
|
||||
* @name SessionIndex
|
||||
* @description
|
||||
* Simple index type with which we can count sessions
|
||||
*/
|
||||
export default class SessionIndex extends U32 {
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import Struct from '../codec/Struct';
|
||||
import AuthorityId from './AuthorityId';
|
||||
import SessionKey from './SessionKey';
|
||||
|
||||
/**
|
||||
* @name SessionKeys
|
||||
* @description
|
||||
* Wrapper for the session and authority ids
|
||||
*/
|
||||
export default class SessionKeys extends Struct {
|
||||
constructor (value?: any) {
|
||||
super({
|
||||
authorityId: AuthorityId,
|
||||
sessionKey: SessionKey
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The Grandpa Authority
|
||||
*/
|
||||
get authorityId (): AuthorityId {
|
||||
return this.get('authorityId') as AuthorityId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The Aura session
|
||||
*/
|
||||
get sessionKey (): SessionKey {
|
||||
return this.get('sessionKey') as SessionKey;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ export { default as ApprovalFlag } from './ApprovalFlag';
|
||||
export { default as AssetOf } from './AssetOf';
|
||||
export { default as AttestedCandidate } from './AttestedCandidate';
|
||||
export { default as AuthorityId } from './AuthorityId';
|
||||
export { default as AuthorityWeight } from './AuthorityWeight';
|
||||
export { default as Balance, BalanceOf } from './Balance';
|
||||
export { default as BalanceLock } from './BalanceLock';
|
||||
// NOTE Bft items are only used in internal structures
|
||||
@@ -22,6 +23,7 @@ export { default as CodeHash } from './CodeHash';
|
||||
export { default as Conviction } from './Conviction';
|
||||
export { default as ContractInfo } from './ContractInfo';
|
||||
export { default as ContractStorageKey } from './ContractStorageKey';
|
||||
export { default as EraIndex } from './EraIndex';
|
||||
export { default as Exposure } from './Exposure';
|
||||
export { default as Extrinsic } from './Extrinsic';
|
||||
export { default as ExtrinsicEra } from './ExtrinsicEra';
|
||||
@@ -32,6 +34,7 @@ export { default as Gas } from './Gas';
|
||||
export { default as IndividualExposure } from './IndividualExposure';
|
||||
export { default as InherentOfflineReport } from './InherentOfflineReport';
|
||||
export { default as Key } from './Key';
|
||||
export { default as Keys } from './Keys';
|
||||
export { default as KeyValue } from './KeyValue';
|
||||
export { default as LockIdentifier } from './LockIdentifier';
|
||||
export { default as LockPeriods } from './LockPeriods';
|
||||
@@ -42,6 +45,7 @@ export { default as Justification } from './Justification';
|
||||
export { default as MemberCount } from './MemberCount';
|
||||
export { default as MisbehaviorReport } from './MisbehaviorReport';
|
||||
export { default as NewAccountOutcome } from './NewAccountOutcome';
|
||||
export { default as OpaqueKey } from './OpaqueKey';
|
||||
export { default as ParaId } from './ParaId';
|
||||
export { default as Permill } from './Permill';
|
||||
export { default as Perbill } from './Perbill';
|
||||
@@ -54,7 +58,9 @@ export { default as ReferendumInfo } from './ReferendumInfo';
|
||||
export { default as RewardDestination } from './RewardDestination';
|
||||
export { default as Schedule } from './Schedule';
|
||||
export { default as SeedOf } from './SeedOf';
|
||||
export { default as SessionIndex } from './SessionIndex';
|
||||
export { default as SessionKey } from './SessionKey';
|
||||
export { default as SessionKeys } from './SessionKeys';
|
||||
export { default as SetIndex } from './SetIndex';
|
||||
export { default as Signature, Ed25519Signature, Sr25519Signature } from './Signature';
|
||||
export { default as SignaturePayload, SignaturePayloadRaw } from './SignaturePayload';
|
||||
|
||||
Reference in New Issue
Block a user