Ensure large >U32 is encoded as hex (#641)

* Ensure large >U32 is enocoded as hex

* Update U64 test compares to hex

* Update subscribe.spec.ts
This commit is contained in:
Jaco Greeff
2019-01-28 13:11:44 +01:00
committed by GitHub
parent 14a34284d8
commit e798df949b
9 changed files with 20 additions and 9 deletions
@@ -39,7 +39,7 @@ describe('subscribe', () => {
it('calls back with new headers', (done) => { it('calls back with new headers', (done) => {
return mock.subscribe('chain_newHead', 'chain_subscribeNewHead', (_: any, header: any) => { return mock.subscribe('chain_newHead', 'chain_subscribeNewHead', (_: any, header: any) => {
if (header.number === 4) { if (header.number === '0x0000000000000004') {
done(); done();
} }
}); });
@@ -55,7 +55,7 @@ describe('subscribe', () => {
throw new Error('testing'); throw new Error('testing');
} }
if (header.number === 3) { if (header.number === '0x0000000000000003') {
done(); done();
} }
}); });
+1 -1
View File
@@ -15,7 +15,7 @@ describe('Digest', () => {
expect(log.type).toBe('Seal'); expect(log.type).toBe('Seal');
expect(log.value.toJSON()).toEqual([ expect(log.value.toJSON()).toEqual([
256804359, '0x000000000f4e8607',
'0x2c0e0ee8a5d1a073da3f8db002b8eaebcd7b1a7eb25662e09f9ef0ac58d96bf17896256cd5f0bc672f96aab49fe5163ca5cb4c1a0f047dc39e89cd4a9eb2ea05' '0x2c0e0ee8a5d1a073da3f8db002b8eaebcd7b1a7eb25662e09f9ef0ac58d96bf17896256cd5f0bc672f96aab49fe5163ca5cb4c1a0f047dc39e89cd4a9eb2ea05'
]); ]);
}); });
+1 -1
View File
@@ -13,6 +13,6 @@ import Int from './codec/Int';
*/ */
export default class I128 extends Int { export default class I128 extends Int {
constructor (value?: AnyNumber) { constructor (value?: AnyNumber) {
super(value, 128, false); super(value, 128, true);
} }
} }
+1 -1
View File
@@ -13,6 +13,6 @@ import Int from './codec/Int';
*/ */
export default class I256 extends Int { export default class I256 extends Int {
constructor (value?: AnyNumber) { constructor (value?: AnyNumber) {
super(value, 256, false); super(value, 256, true);
} }
} }
+1 -1
View File
@@ -13,6 +13,6 @@ import Int from './codec/Int';
*/ */
export default class I64 extends Int { export default class I64 extends Int {
constructor (value?: AnyNumber) { constructor (value?: AnyNumber) {
super(value, 64, false); super(value, 64, true);
} }
} }
+1 -1
View File
@@ -13,6 +13,6 @@ import UInt from './codec/UInt';
*/ */
export default class U128 extends UInt { export default class U128 extends UInt {
constructor (value?: AnyNumber) { constructor (value?: AnyNumber) {
super(value, 128); super(value, 128, true);
} }
} }
+1 -1
View File
@@ -13,6 +13,6 @@ import UInt from './codec/UInt';
*/ */
export default class U256 extends UInt { export default class U256 extends UInt {
constructor (value?: AnyNumber) { constructor (value?: AnyNumber) {
super(value, 256); super(value, 256, true);
} }
} }
+1 -1
View File
@@ -13,6 +13,6 @@ import UInt from './codec/UInt';
*/ */
export default class U64 extends UInt { export default class U64 extends UInt {
constructor (value?: AnyNumber) { constructor (value?: AnyNumber) {
super(value, 64, false); super(value, 64, true);
} }
} }
+11
View File
@@ -3,7 +3,9 @@
// of the Apache-2.0 license. See the LICENSE file for details. // of the Apache-2.0 license. See the LICENSE file for details.
import { CodecTo } from '../types'; import { CodecTo } from '../types';
import Option from './Option';
import Struct from './Struct'; import Struct from './Struct';
import BlockNumber from '../BlockNumber';
import Text from '../Text'; import Text from '../Text';
import U32 from '../U32'; import U32 from '../U32';
import Vector from './Vector'; import Vector from './Vector';
@@ -172,4 +174,13 @@ describe('Struct', () => {
).toBe(true); ).toBe(true);
}); });
}); });
it('allows toString with large numbers', () => {
// replicate https://github.com/polkadot-js/api/issues/640
expect(
new Struct({
blockNumber: Option.with(BlockNumber)
}, { blockNumber: '0x1234567890abcdef' }).toString()
).toEqual('{"blockNumber":"0x1234567890abcdef"}');
});
}); });