Seal updated to match master (s/Signature/Bytes/) (#1024)

* Seal updated to match master (s/Signature/Bytes/)

* FR*NK updates
This commit is contained in:
Jaco Greeff
2019-06-15 21:03:40 +02:00
committed by GitHub
parent ce2e40e08a
commit 7e5b09a255
9 changed files with 24 additions and 21 deletions
@@ -1 +0,0 @@
{"jsonrpc":"2.0","method":"chain_newHead","params":{"result":{"digest":{"logs":["0x06617572612089353e1700000000","0x05617572614e869ea59bb040ddd205f7c78ee668d9ca52c28333dc2831f761ed8085417093c42642f6a467e86ad7d81c6f02b8b0064d1a405ed857747d7d905a1fcde1510e"]},"extrinsicsRoot":"0xd2c75ad52726af9fe9aa769006074014afb6a34a541a4adb0604c09f425d7f8b","number":"0x2e2","parentHash":"0x49c071e46b0da9abd957daaff21c895dc5f883c322cf4c7436e99b68653d8bc8","stateRoot":"0x0904ec490acf2419ff90d9966ce8c77054d8f56bed1d2cee74608bf6a0eafccf"},"subscription":22}}
@@ -1 +0,0 @@
{"jsonrpc":"2.0","method":"chain_newHead","params":{"result":{"digest":{"logs":["0x0661757261208a353e1700000000","0x0561757261ae9c37c4b07e97ccb9b40fb966a55ef871ac0aadf7bc8de0b1de00287c7d11f7ce6526e2e1ba95b575a011b09ec4b032c3bb0e7267d613e03b0c9f4f8a7ae701"]},"extrinsicsRoot":"0xde21769bd74ac0fa167989d41b3f059b924da7625212848ca7103bde0413da8f","number":"0x2e3","parentHash":"0xbff2707a02125eb790f8252b96560bb8a7b3ae4f4f2f9d44ac44886d74dfd924","stateRoot":"0x820d7ef1dbbb070c96d340fdb25273f9f30ee8b804ba2804ab88891ed509ea58"},"subscription":22}}
@@ -1 +0,0 @@
{"jsonrpc":"2.0","method":"chain_newHead","params":{"result":{"digest":{"logs":["0x0661757261208b353e1700000000","0x05617572611cf036c978ad8da399e353a8328f2b0959080b12d7e05d45dcd1ff13160b60aecf4324698f4b21d0c056b86290a9197d0b3196a415036b0c7dda27fbeadf7c0f"]},"extrinsicsRoot":"0xc46db6f343b23828b0bf6f999bc13fdc9766d4e010a91a2af7a138d151f140ff","number":"0x2e4","parentHash":"0xec269aab57804cf6004b984c6f281610d2d2c94dc90bf3a8118bbf1e3c4d7f0e","stateRoot":"0xe660e4535a5ac25171dd9280dd8ba861a9c310bfc3bf643cc1229f23f13fd367"},"subscription":22}}
@@ -0,0 +1 @@
{"jsonrpc":"2.0","result":{"block":{"extrinsics":["0x20010100038431055d","0x140109007502"],"header":{"digest":{"logs":["0x066175726120614c411700000000","0x05617572610101c4dd7f7d2a7521a91b821c44d0b8a628e4d804c0428b20a8e281aeaff575001cd55f4540db0fa78e5521b330d1a7ef9e8b922ca723097b4ab83e59a13fb44f0c"]},"extrinsicsRoot":"0x907510396823ad5299bd8b7e3d922e182f117032a0653a85f9ad3cb58044a086","number":"0x9e","parentHash":"0xf17a9ca2e515a68c6e1b0315c5182d237580507c60487f5a6b75c703aa3e84ab","stateRoot":"0x5a4cfd95c29f8db93119a11e012c3905767cc4b7e3a3a2f6bc72879e51a47cd4"}},"justification":null},"id":86}
@@ -0,0 +1 @@
{"jsonrpc":"2.0","result":{"block":{"extrinsics":["0x20010100038831055d","0x140109007902"],"header":{"digest":{"logs":["0x066175726120624c411700000000","0x05617572610101d64f44f8c3bb3deeaa8323aadfa943c3510546bf85817788b55a4aa27e21b8492ea574300966c60bd42571bfbca9f53bb682fb6c7e703aade3489680764bb109"]},"extrinsicsRoot":"0x9ffac24de7dd587cbd38862fa1cef38d47b7cfb82d3313b926d60c855b203405","number":"0x9f","parentHash":"0x78b13ce0daf54a5940554f7dbe4af4e97120e4ab2a073043f48889cee25859cf","stateRoot":"0x2671c3c7bac9098af71ebc15998c2fb5e366da4db5a0b0287ba13d8afc9b2bd4"}},"justification":null},"id":75}
+9 -1
View File
@@ -4,6 +4,7 @@
import extrinsics from '@polkadot/extrinsics/static';
import block00300 from '../json/SignedBlock.003.00.json';
import Method from '../primitive/Method';
import Block from './Block';
@@ -24,11 +25,18 @@ describe('Block', () => {
stateRoot: 'H256',
extrinsicsRoot: 'H256',
digest: JSON.stringify({
logs: 'Vec<{"_enum":{"Other":"Bytes","AuthoritiesChange":"Vec<AccountId>","ChangesTrieRoot":"H256","SealV0":"(u64,H512)","Consensus":"(u32,Bytes)","Seal":"(u32,H512)","PreRuntime":"(u32,Bytes)"}}>'
logs: 'Vec<{"_enum":{"Other":"Bytes","AuthoritiesChange":"Vec<AccountId>","ChangesTrieRoot":"H256","SealV0":"(u64,H512)","Consensus":"(u32,Bytes)","Seal":"(u32,Bytes)","PreRuntime":"(u32,Bytes)"}}>'
})
}),
extrinsics: 'Vec<Extrinsic>'
})
);
});
it('re-encodes digest items correctly', () => {
const digest = new Block(block00300.result.block).header.digest;
expect(digest.logs[0].toHex()).toEqual(block00300.result.block.header.digest.logs[0]);
expect(digest.logs[1].toHex()).toEqual(block00300.result.block.header.digest.logs[1]);
});
});
+4 -4
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import json3 from '../json/Header.003.json';
import json4 from '../json/Header.004.0x2e2.json';
import block1 from '../json/SignedBlock.003.00.json';
import Digest, { ConsensusEngineId, CID_AURA, CID_BABE, CID_GRPA } from './Digest';
describe('Digest', () => {
@@ -22,14 +22,14 @@ describe('Digest', () => {
});
it('filters logs, excluding items', () => {
const logs = new Digest(json4.params.result.digest).logsWith('PreRuntime');
const logs = new Digest(block1.result.block.header.digest).logsWith('PreRuntime');
expect(logs.length).toEqual(1);
expect(logs[0].type).toEqual('PreRuntime');
});
it('filters logs, including items', () => {
const logs = new Digest(json4.params.result.digest).logsWithout('PreRuntime');
const logs = new Digest(block1.result.block.header.digest).logsWithout('PreRuntime');
expect(logs.length).toEqual(1);
expect(logs[0].type).toEqual('Seal');
@@ -37,7 +37,7 @@ describe('Digest', () => {
describe('ConsensusId', () => {
it('creates a valid id for aura', () => {
expect(ConsensusEngineId.stringToId('afg1')).toEqual(CID_GRPA);
expect(ConsensusEngineId.stringToId('FRNK')).toEqual(CID_GRPA);
expect(ConsensusEngineId.stringToId('aura')).toEqual(CID_AURA);
});
+4 -4
View File
@@ -18,7 +18,7 @@ import Signature from '../type/Signature';
const CID_AURA = 0x61727561; // 'aura'
const CID_BABE = 0x65626162; // 'babe'
const CID_GRPA = 0x31676661; // 'afg1'
const CID_GRPA = 0x4b4e5246; // 'FRNK' (don't ask, used to be afg1)
export { CID_AURA, CID_BABE, CID_GRPA };
@@ -171,14 +171,14 @@ export class Seal extends Tuple {
constructor (value: any) {
super({
ConsensusEngineId,
Signature
Bytes
}, value);
}
/**
* @description The wrapped [[Signature]]
* @description The wrapped [[Bytes]]
*/
get signature (): Signature {
get data (): Bytes {
return this[1] as Signature;
}
+5 -9
View File
@@ -8,9 +8,8 @@ import Header from './Header';
import json1 from '../json/Header.001.json';
import json2 from '../json/Header.002.json';
import json3 from '../json/Header.003.json';
import json4x2e2 from '../json/Header.004.0x2e2.json';
import json4x2e3 from '../json/Header.004.0x2e3.json';
import json4x2e4 from '../json/Header.004.0x2e4.json';
import block00300 from '../json/SignedBlock.003.00.json';
import block00301 from '../json/SignedBlock.003.01.json';
describe('Header', () => {
it('decodes an actual JSON response', () => {
@@ -52,12 +51,9 @@ describe('Header', () => {
).toBe(true);
});
it('correctly hashes headers with PreRuntime, aligning with substrate', () => {
const x2e2 = new Header(json4x2e2.params.result);
const x2e3 = new Header(json4x2e3.params.result);
const x2e4 = new Header(json4x2e4.params.result);
it('calculates correct hash, matching with parentHash', () => {
const blockHash = new Header(block00300.result.block.header).hash.toHex();
expect(x2e3.parentHash).toEqual(x2e2.hash);
expect(x2e4.parentHash).toEqual(x2e3.hash);
expect(blockHash).toEqual(block00301.result.block.header.parentHash);
});
});