Work around incorrect contracts.call RPC handler (#2998)
This commit is contained in:
@@ -13,7 +13,7 @@ export const DEFAULT_UINT_BITS = 64;
|
|||||||
|
|
||||||
// Maximum allowed integer for JS is 2^53 - 1, set limit at 52
|
// Maximum allowed integer for JS is 2^53 - 1, set limit at 52
|
||||||
// In this case however, we always print any >32 as hex
|
// In this case however, we always print any >32 as hex
|
||||||
const MAX_NUMBER_BITS = 32;
|
const MAX_NUMBER_BITS = 52;
|
||||||
const MUL_P = new BN(1_00_00);
|
const MUL_P = new BN(1_00_00);
|
||||||
|
|
||||||
const FORMATTERS: [string, BN][] = [
|
const FORMATTERS: [string, BN][] = [
|
||||||
@@ -191,8 +191,10 @@ export abstract class AbstractInt extends BN implements Codec {
|
|||||||
*/
|
*/
|
||||||
public toJSON (onlyHex = false): any {
|
public toJSON (onlyHex = false): any {
|
||||||
// FIXME this return type should by string | number, however BN returns string
|
// FIXME this return type should by string | number, however BN returns string
|
||||||
// Here if we want to have the actual used bits, it is super.bitLength()
|
// Options here are
|
||||||
return onlyHex || (this.#bitLength > MAX_NUMBER_BITS)
|
// - super.bitLength() - the actual used bits
|
||||||
|
// - this.#bitLength - the type bits (this should be used, however contracts RPC is problematic)
|
||||||
|
return onlyHex || (super.bitLength() > MAX_NUMBER_BITS)
|
||||||
? this.toHex()
|
? this.toHex()
|
||||||
: this.toNumber();
|
: this.toNumber();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ describe('UInt', (): void => {
|
|||||||
|
|
||||||
it('converts to JSON representation based on size', (): void => {
|
it('converts to JSON representation based on size', (): void => {
|
||||||
expect(new UInt(registry, '0x12345678', 32).toJSON()).toEqual(0x12345678);
|
expect(new UInt(registry, '0x12345678', 32).toJSON()).toEqual(0x12345678);
|
||||||
expect(new UInt(registry, '0x1234567890', 64).toJSON()).toEqual('0x0000001234567890');
|
expect(new UInt(registry, '0x1234567890', 64).toJSON()).toEqual(78187493520); // '0x0000001234567890');
|
||||||
expect(new UInt(registry, '0x1234567890abcdef', 64).toJSON()).toEqual('0x1234567890abcdef');
|
expect(new UInt(registry, '0x1234567890abcdef', 64).toJSON()).toEqual('0x1234567890abcdef');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ describe('createType', (): void => {
|
|||||||
}]);
|
}]);
|
||||||
|
|
||||||
expect(struct.toJSON()).toEqual({
|
expect(struct.toJSON()).toEqual({
|
||||||
balance: '0x000000000000000000000000000004d2',
|
balance: 1234, // '0x000000000000000000000000000004d2',
|
||||||
index: 16
|
index: 16
|
||||||
});
|
});
|
||||||
expect(struct.toRawType()).toEqual(raw);
|
expect(struct.toRawType()).toEqual(raw);
|
||||||
@@ -78,7 +78,10 @@ describe('createType', (): void => {
|
|||||||
it('allows creation of a Tuple', (): void => {
|
it('allows creation of a Tuple', (): void => {
|
||||||
expect(
|
expect(
|
||||||
createTypeUnsafe(registry, '(Balance,u32)', [[1234, 5678]]).toJSON()
|
createTypeUnsafe(registry, '(Balance,u32)', [[1234, 5678]]).toJSON()
|
||||||
).toEqual(['0x000000000000000000000000000004d2', 5678]);
|
).toEqual([
|
||||||
|
1234, // '0x000000000000000000000000000004d2',
|
||||||
|
5678
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows creation for a UInt<bitLength>', (): void => {
|
it('allows creation for a UInt<bitLength>', (): void => {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ describe('Registration', (): void => {
|
|||||||
'039911039922039944039955039933000003996600'
|
'039911039922039944039955039933000003996600'
|
||||||
).toJSON()
|
).toJSON()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
deposit: '0x0000000000000000000009184e72a000',
|
deposit: 10000000000000, // '0x0000000000000000000009184e72a000',
|
||||||
info: {
|
info: {
|
||||||
additional: [],
|
additional: [],
|
||||||
display: { Raw: '0x9911' },
|
display: { Raw: '0x9911' },
|
||||||
|
|||||||
Reference in New Issue
Block a user