Properly toJSON() on StorageFunction (#179)
* Properly toJSON() on StorageFunction * Add isZero(), cmp & toStringFormat * Update tests for UInt toString()
This commit is contained in:
@@ -15,7 +15,7 @@ describe('Struct', () => {
|
||||
u32: U32
|
||||
})
|
||||
)({ txt: 'foo', u32: 0x123456 }).toString()
|
||||
).toEqual(`{txt: foo, u32: 0x00123456}`);
|
||||
).toEqual(`{txt: foo, u32: 1193046}`);
|
||||
});
|
||||
|
||||
it('exposes the types', () => {
|
||||
@@ -43,6 +43,6 @@ describe('Struct', () => {
|
||||
test.values().map((v) =>
|
||||
v.toString()
|
||||
)
|
||||
).toEqual(['bazzing', '0x00000045']);
|
||||
).toEqual(['bazzing', '69']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -33,7 +33,7 @@ describe('UInt', () => {
|
||||
const u = new UInt('0x12', 16);
|
||||
|
||||
expect(u.toHex()).toEqual('0x0012');
|
||||
expect(u.toString()).toEqual('0x0012');
|
||||
expect(u.toString()).toEqual('18');
|
||||
});
|
||||
|
||||
it('converts to equivalents', () => {
|
||||
|
||||
@@ -71,7 +71,7 @@ export default class UInt extends Base<BN> {
|
||||
}
|
||||
|
||||
toJSON (): any {
|
||||
return this.toString();
|
||||
return this.toHex();
|
||||
}
|
||||
|
||||
toU8a (isBare?: boolean): Uint8Array {
|
||||
@@ -79,7 +79,7 @@ export default class UInt extends Base<BN> {
|
||||
}
|
||||
|
||||
toString (): string {
|
||||
return this.toHex();
|
||||
return this.raw.toString();
|
||||
}
|
||||
|
||||
toBn (): BN {
|
||||
@@ -98,12 +98,22 @@ export default class UInt extends Base<BN> {
|
||||
: this.raw.add(bnToBn(other));
|
||||
}
|
||||
|
||||
cmp (other: UInt | BN | number): number {
|
||||
return other instanceof UInt
|
||||
? this.raw.cmp(other.raw)
|
||||
: this.raw.cmp(bnToBn(other));
|
||||
}
|
||||
|
||||
div (other: UInt | BN | number): BN {
|
||||
return other instanceof UInt
|
||||
? this.raw.div(other.raw)
|
||||
: this.raw.div(bnToBn(other));
|
||||
}
|
||||
|
||||
isZero (): boolean {
|
||||
return this.raw.isZero();
|
||||
}
|
||||
|
||||
lt (test: UInt | BN | number): boolean {
|
||||
return test instanceof UInt
|
||||
? this.raw.lt(test.raw)
|
||||
|
||||
Reference in New Issue
Block a user