diff --git a/CHANGELOG.md b/CHANGELOG.md index be9fb0d999..800f356379 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # CHANGELOG +## master + +Changes: + +- Do strict length checking on `[u8; ]` type inputs +- Add upgrade block for Kusama 9040 + + ## 4.13.1 Jun 6, 2021 Upgrade priority: Medium. Required for users connecting to Statemine and future Kusama upgrades. diff --git a/packages/rpc-provider/src/mock/index.ts b/packages/rpc-provider/src/mock/index.ts index f26a7f270d..0aeaafc790 100644 --- a/packages/rpc-provider/src/mock/index.ts +++ b/packages/rpc-provider/src/mock/index.ts @@ -57,7 +57,7 @@ export class MockProvider implements ProviderInterface { // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-unsafe-member-access chain_getBlock: () => this.registry.createType('SignedBlock', rpcSignedBlock.result).toJSON(), // eslint-disable-next-line @typescript-eslint/no-unused-vars - chain_getBlockHash: () => '0x1234', + chain_getBlockHash: () => '0x1234000000000000000000000000000000000000000000000000000000000000', // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access chain_getFinalizedHead: () => this.registry.createType('Header', rpcHeader.result).hash, // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access diff --git a/packages/types/src/codec/U8aFixed.spec.ts b/packages/types/src/codec/U8aFixed.spec.ts index 8cca358154..04ffb72475 100644 --- a/packages/types/src/codec/U8aFixed.spec.ts +++ b/packages/types/src/codec/U8aFixed.spec.ts @@ -30,7 +30,7 @@ describe('U8aFixed', (): void => { it('constructs from number[]', (): void => { expect( - new (U8aFixed.with(32))(registry, [0x02, 0x03]).toU8a() + new (U8aFixed.with(32))(registry, [0x02, 0x03, 0x00, 0x00]).toU8a() ).toEqual( new Uint8Array([0x02, 0x03, 0x00, 0x00]) ); diff --git a/packages/types/src/codec/U8aFixed.ts b/packages/types/src/codec/U8aFixed.ts index 87202b6cfd..6f3fd09559 100644 --- a/packages/types/src/codec/U8aFixed.ts +++ b/packages/types/src/codec/U8aFixed.ts @@ -4,7 +4,7 @@ import type { AnyU8a, Constructor, Registry } from '../types'; import type { U8aBitLength } from './types'; -import { isString, u8aToU8a } from '@polkadot/util'; +import { assert, isString, u8aToU8a } from '@polkadot/util'; import { Raw } from './Raw'; @@ -14,20 +14,16 @@ function decodeU8aFixed (value: AnyU8a, bitLength: U8aBitLength): AnyU8a { return decodeU8aFixed(u8aToU8a(value), bitLength); } - // ensure that we have an actual u8a with the full length as specified by - // the bitLength input (padded with zeros as required) const byteLength = bitLength / 8; - const sub = value.subarray(0, byteLength); - - if (sub.length === byteLength) { - return sub; - } - const u8a = new Uint8Array(byteLength); - u8a.set(sub, 0); + if (!value || !value.length) { + return u8a; + } - return u8a; + assert(value.length >= byteLength, () => `Expected at least ${byteLength} bytes (${bitLength} bits), found ${value.length} bytes`); + + return value.subarray(0, byteLength); } /** diff --git a/packages/types/src/ethereum/AccountId.spec.ts b/packages/types/src/ethereum/AccountId.spec.ts index 309084ad92..7121a27d3b 100644 --- a/packages/types/src/ethereum/AccountId.spec.ts +++ b/packages/types/src/ethereum/AccountId.spec.ts @@ -69,7 +69,7 @@ describe('EthereumAccountId', (): void => { testEncode('toHex', '0x4119b2e6c3cb618f4f0b93ac77f9beec7ff02887'); testEncode('toJSON', '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887'); testEncode('toString', '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887'); - testEncode('toString', '0x0000000000000000000000000000000000000000', '0x00'); + testEncode('toString', '0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000'); testEncode('toU8a', Uint8Array.from([ 0x41, 0x19, 0xb2, 0xe6, 0xc3, 0xcb, 0x61, 0x8f, 0x4f, 0x0b, 0x93, 0xac, 0x77, 0xf9, 0xbe, 0xec, 0x7f, 0xf0, 0x28, 0x87 diff --git a/packages/types/src/interfaces/state/StorageChangeSet.spec.ts b/packages/types/src/interfaces/state/StorageChangeSet.spec.ts index 7f07fd5a7f..12388b80f7 100644 --- a/packages/types/src/interfaces/state/StorageChangeSet.spec.ts +++ b/packages/types/src/interfaces/state/StorageChangeSet.spec.ts @@ -12,7 +12,7 @@ describe('StorageChangeSet', (): void => { describe('construction', (): void => { const set = registry.createType('StorageChangeSet', { - block: '0x1234', + block: '0x1234000000000000000000000000000000000000000000000000000000000000', changes: [ ['0xab', '0xcd'] ] diff --git a/packages/types/src/interfaces/system/EventRecord.spec.ts b/packages/types/src/interfaces/system/EventRecord.spec.ts index 5a8850e359..0aa9d33289 100644 --- a/packages/types/src/interfaces/system/EventRecord.spec.ts +++ b/packages/types/src/interfaces/system/EventRecord.spec.ts @@ -34,8 +34,7 @@ describe('EventRecord', (): void => { const er = records[0]; expect(er.phase.type).toEqual('ApplyExtrinsic'); - // additional payment info, weight u64 (vs u32) - expect(records.toHex()).toEqual(`${hex as string}00000000000000000000`); + expect(records.toHex()).toEqual(hex); }); }); }); diff --git a/packages/types/src/json/EventRecord.003.json b/packages/types/src/json/EventRecord.003.json index 77199df499..b3aaacb53a 100644 --- a/packages/types/src/json/EventRecord.003.json +++ b/packages/types/src/json/EventRecord.003.json @@ -7,7 +7,7 @@ "changes": [ [ "0xcc956bdb7605e3547539f321ac2bc95c", - "0x0800000000000000000001000000000000" + "0x08000000000000000000010000000000000000000000000000000000000000000000000000" ] ] },