Work around incorrect contracts.call RPC handler (#2998)

This commit is contained in:
Jaco Greeff
2020-12-29 10:53:11 +01:00
committed by GitHub
parent 22e4abc903
commit 6f5b852bf7
4 changed files with 12 additions and 7 deletions
+5 -3
View File
@@ -13,7 +13,7 @@ export const DEFAULT_UINT_BITS = 64;
// Maximum allowed integer for JS is 2^53 - 1, set limit at 52
// 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 FORMATTERS: [string, BN][] = [
@@ -191,8 +191,10 @@ export abstract class AbstractInt extends BN implements Codec {
*/
public toJSON (onlyHex = false): any {
// 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()
return onlyHex || (this.#bitLength > MAX_NUMBER_BITS)
// Options here are
// - 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.toNumber();
}
+1 -1
View File
@@ -74,7 +74,7 @@ describe('UInt', (): void => {
it('converts to JSON representation based on size', (): void => {
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');
});
+5 -2
View File
@@ -33,7 +33,7 @@ describe('createType', (): void => {
}]);
expect(struct.toJSON()).toEqual({
balance: '0x000000000000000000000000000004d2',
balance: 1234, // '0x000000000000000000000000000004d2',
index: 16
});
expect(struct.toRawType()).toEqual(raw);
@@ -78,7 +78,10 @@ describe('createType', (): void => {
it('allows creation of a Tuple', (): void => {
expect(
createTypeUnsafe(registry, '(Balance,u32)', [[1234, 5678]]).toJSON()
).toEqual(['0x000000000000000000000000000004d2', 5678]);
).toEqual([
1234, // '0x000000000000000000000000000004d2',
5678
]);
});
it('allows creation for a UInt<bitLength>', (): void => {
@@ -17,7 +17,7 @@ describe('Registration', (): void => {
'039911039922039944039955039933000003996600'
).toJSON()
).toEqual({
deposit: '0x0000000000000000000009184e72a000',
deposit: 10000000000000, // '0x0000000000000000000009184e72a000',
info: {
additional: [],
display: { Raw: '0x9911' },