Make Block, Header & Digest generic (#1196)

* Make Block, Header & Digest generic

* It lints

* Linting passes, tests passes
This commit is contained in:
Jaco Greeff
2019-07-26 14:34:41 +02:00
committed by GitHub
parent 441148889d
commit 70bc823d25
34 changed files with 252 additions and 260 deletions
+6 -5
View File
@@ -3,6 +3,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Header } from '@polkadot/types/interfaces';
import { Codec } from '@polkadot/types/types';
import { ProviderInterface, ProviderInterfaceEmitted, ProviderInterfaceEmitCb } from '../types';
import { MockStateSubscriptions, MockStateSubscriptionCallback, MockStateDb } from './types';
@@ -14,7 +15,7 @@ import testKeyring from '@polkadot/keyring/testing';
import storage from '@polkadot/api-metadata/storage/static';
import rpcMetadata from '@polkadot/types/Metadata/static';
import rpcSignedBlock from '@polkadot/types/json/SignedBlock.004.immortal.json';
import { createType, Header } from '@polkadot/types';
import { createType } from '@polkadot/types';
import { bnToU8a, logger, u8aToHex } from '@polkadot/util';
import { randomAsU8a } from '@polkadot/util-crypto';
@@ -156,12 +157,12 @@ export default class Mock implements ProviderInterface {
}
// create a new header (next block)
newHead = this.makeBlockHeader(newHead.blockNumber.toBn());
newHead = this.makeBlockHeader(newHead.number.toBn());
// increment the balances and nonce for each account
keyring.getPairs().forEach(({ publicKey }, index): void => {
this.setStateBn(storage.balances.freeBalance(publicKey), newHead.blockNumber.muln(3).iaddn(index));
this.setStateBn(storage.system.accountNonce(publicKey), newHead.blockNumber.addn(index));
this.setStateBn(storage.balances.freeBalance(publicKey), newHead.number.toBn().muln(3).iaddn(index));
this.setStateBn(storage.system.accountNonce(publicKey), newHead.number.toBn().addn(index));
});
// set the timestamp for the current block
@@ -182,7 +183,7 @@ export default class Mock implements ProviderInterface {
private makeBlockHeader (prevNumber: BN): Header {
const blockNumber = prevNumber.addn(1);
return new Header({
return createType('Header', {
digest: {
logs: []
},