Update to latest util for Compact (#511)
* Update to latest util for Compact * Expand FIXME comments
This commit is contained in:
@@ -33,6 +33,6 @@
|
||||
"@polkadot/jsonrpc": "^0.35.5",
|
||||
"@polkadot/rpc-provider": "^0.35.5",
|
||||
"@polkadot/types": "^0.35.5",
|
||||
"@polkadot/util": "^0.33.23"
|
||||
"@polkadot/util": "^0.33.24"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.2.0",
|
||||
"@polkadot/keyring": "^0.33.23",
|
||||
"@polkadot/keyring": "^0.33.24",
|
||||
"@polkadot/storage": "^0.35.5",
|
||||
"@polkadot/util": "^0.33.23",
|
||||
"@polkadot/util-crypto": "^0.33.23",
|
||||
"@polkadot/util": "^0.33.24",
|
||||
"@polkadot/util-crypto": "^0.33.24",
|
||||
"@types/nock": "^9.3.0",
|
||||
"eventemitter3": "^3.1.0",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
|
||||
@@ -12,6 +12,6 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.2.0",
|
||||
"@polkadot/types": "^0.35.5",
|
||||
"@polkadot/util": "^0.33.23"
|
||||
"@polkadot/util": "^0.33.24"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-storage#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.2.0",
|
||||
"@polkadot/keyring": "^0.33.23",
|
||||
"@polkadot/keyring": "^0.33.24",
|
||||
"@polkadot/types": "^0.35.5",
|
||||
"@polkadot/util": "^0.33.23",
|
||||
"@polkadot/util-crypto": "^0.33.23"
|
||||
"@polkadot/util": "^0.33.24",
|
||||
"@polkadot/util-crypto": "^0.33.24"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.2.0",
|
||||
"@polkadot/keyring": "^0.33.23",
|
||||
"@polkadot/util": "^0.33.23",
|
||||
"@polkadot/keyring": "^0.33.24",
|
||||
"@polkadot/util": "^0.33.24",
|
||||
"core-js": "^2.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import Balance from '../Balance';
|
||||
import BlockNumber from '../BlockNumber';
|
||||
import Moment from '../Moment';
|
||||
import U32 from '../U32';
|
||||
@@ -14,7 +15,7 @@ describe('Compact', () => {
|
||||
describe('encodeU8a', () => {
|
||||
it('encodes short u8', () => {
|
||||
expect(
|
||||
Compact.encodeU8a(18, 8)
|
||||
Compact.encodeU8a(18)
|
||||
).toEqual(
|
||||
new Uint8Array([18 << 2])
|
||||
);
|
||||
@@ -22,7 +23,7 @@ describe('Compact', () => {
|
||||
|
||||
it('encodes max u8 values', () => {
|
||||
expect(
|
||||
Compact.encodeU8a(new UInt(63), 16)
|
||||
Compact.encodeU8a(new UInt(63))
|
||||
).toEqual(
|
||||
new Uint8Array([0b11111100])
|
||||
);
|
||||
@@ -30,7 +31,7 @@ describe('Compact', () => {
|
||||
|
||||
it('encodes basic u16 value', () => {
|
||||
expect(
|
||||
Compact.encodeU8a(511, 32)
|
||||
Compact.encodeU8a(511)
|
||||
).toEqual(
|
||||
new Uint8Array([0b11111101, 0b00000111])
|
||||
);
|
||||
@@ -38,7 +39,7 @@ describe('Compact', () => {
|
||||
|
||||
it('encodes basic ua6 (not at edge)', () => {
|
||||
expect(
|
||||
Compact.encodeU8a(111, 32)
|
||||
Compact.encodeU8a(111)
|
||||
).toEqual(
|
||||
new Uint8Array([0xbd, 0x01])
|
||||
);
|
||||
@@ -46,7 +47,7 @@ describe('Compact', () => {
|
||||
|
||||
it('encodes basic u32 values (short)', () => {
|
||||
expect(
|
||||
Compact.encodeU8a(0xffff, 32)
|
||||
Compact.encodeU8a(0xffff)
|
||||
).toEqual(
|
||||
new Uint8Array([254, 255, 3, 0])
|
||||
);
|
||||
@@ -54,11 +55,27 @@ describe('Compact', () => {
|
||||
|
||||
it('encodes basic u32 values (full)', () => {
|
||||
expect(
|
||||
Compact.encodeU8a(0xfffffff9, 32)
|
||||
Compact.encodeU8a(0xfffffff9)
|
||||
).toEqual(
|
||||
new Uint8Array([3, 249, 255, 255, 255])
|
||||
);
|
||||
});
|
||||
|
||||
// FIXME This is _still_ not correct, here it should use the minimum bytes - however, since the
|
||||
// value fits and the encoding is proper, it _should_ be ok on the decoding side.
|
||||
it('condes a large balance', () => {
|
||||
expect(
|
||||
Compact.encodeU8a(new Balance('0x00407a10f35a'))
|
||||
).toEqual(
|
||||
new Uint8Array([
|
||||
// length, as per FIXME, should actually be 6 (as opposed to 16)
|
||||
3 + ((16 - 4) << 2),
|
||||
// useful data
|
||||
0x00, 0x40, 0x7a, 0x10, 0xf3, 0x5a,
|
||||
// padding, extra space used here :(
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('decodeU8a', () => {
|
||||
|
||||
@@ -118,6 +118,6 @@ export default class Compact extends Base<UInt | Moment> implements Codec {
|
||||
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
||||
*/
|
||||
toU8a (isBare?: boolean): Uint8Array {
|
||||
return Compact.encodeU8a(this.raw.toBn(), this.bitLength());
|
||||
return Compact.encodeU8a(this.raw.toBn());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1417,14 +1417,14 @@
|
||||
typedoc-plugin-no-inherit "^1.0.2"
|
||||
typescript "^3.2.2"
|
||||
|
||||
"@polkadot/keyring@^0.33.23":
|
||||
version "0.33.23"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.33.23.tgz#90f19be051b1150056eedf1ce243154d14f6e975"
|
||||
integrity sha512-x/HxJdgal5OZSWnyxsXbLFnkHodr1xp8sx3hjfFbT7dfHQ6Bx0QNBhj/K1sKDyZBBTokqZBQpD+gWjIYhDRvtg==
|
||||
"@polkadot/keyring@^0.33.24":
|
||||
version "0.33.24"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.33.24.tgz#7c68dc06dd53b70f7c3e6bf3ec0acce4486da206"
|
||||
integrity sha512-D1Dtrp4f/S8IRa9ZaSjbnWQ4PjJWK+bs8AOfgqoaHLlrFvXf31ipE8MYgODB0EMFDNCf8RLqr8ftG3vVsRF+vw==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.2.0"
|
||||
"@polkadot/util" "^0.33.23"
|
||||
"@polkadot/util-crypto" "^0.33.23"
|
||||
"@polkadot/util" "^0.33.24"
|
||||
"@polkadot/util-crypto" "^0.33.24"
|
||||
"@types/bs58" "^3.0.30"
|
||||
bs58 "^4.0.1"
|
||||
|
||||
@@ -1433,13 +1433,13 @@
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.44.tgz#2fb28215f10b869bfa544fd8df8fccb4932d64f2"
|
||||
integrity sha512-tor7vSd3ZsRBO9FIuKZQ9hfqEGkNZnanAFVGmoL1iSmdhcoKtYTlQe0BQafjIynqIMOfXdJ7Zes9PlorPtw6yw==
|
||||
|
||||
"@polkadot/util-crypto@^0.33.23":
|
||||
version "0.33.23"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.33.23.tgz#6102ccc7d826f92a62d8d7eec5481eb13c61eed4"
|
||||
integrity sha512-xUGBUI1d4Mtiv5ZLPVgQbYXUiEHdtTm7yb5tw4K6HEPuxt7JgcMTVflMdcbZFZwHTRFUyNKrnraEW5LpQio8Rg==
|
||||
"@polkadot/util-crypto@^0.33.24":
|
||||
version "0.33.24"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.33.24.tgz#9b29f4aaeb2c475b38c3007816c9f0ffb74892ca"
|
||||
integrity sha512-obs13hyBtO9TZ3MkleMvlWinDZUSj+59DkVndbfD8HX9hEzcs6LBWGwzKYh3Ad8wsbfpeebY/cugvtGXswzF3g==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.2.0"
|
||||
"@polkadot/util" "^0.33.23"
|
||||
"@polkadot/util" "^0.33.24"
|
||||
"@types/bip39" "^2.4.1"
|
||||
bip39 "^2.5.0"
|
||||
blakejs "^1.1.0"
|
||||
@@ -1447,10 +1447,10 @@
|
||||
tweetnacl "^1.0.0"
|
||||
xxhashjs "^0.2.2"
|
||||
|
||||
"@polkadot/util@^0.33.23":
|
||||
version "0.33.23"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.33.23.tgz#c96bf22370caac93c939886f15ebbe59066365dc"
|
||||
integrity sha512-Y3QvSO3BVf0MJtkKCXZwf54rvkVNhng5JxoVQgIpYufAJqTywOIXWkWQh6PW6KU/xyynWTseskUfUqVMjJjl0A==
|
||||
"@polkadot/util@^0.33.24":
|
||||
version "0.33.24"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.33.24.tgz#c8d3a765b65e99dca3bc0f8d44f5b0e21a926e92"
|
||||
integrity sha512-AKBmNjwdidJ95DG2alSibO4tDFBuLjYCpPSLWmb5CfU6UFO70vpsskaoBpJPSrvJaT+EgvgcDpDewSUCb4GLbQ==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.2.0"
|
||||
"@types/bn.js" "^4.11.3"
|
||||
|
||||
Reference in New Issue
Block a user