Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 4b59c10

Browse files
committed
add test
1 parent 1cd3d95 commit 4b59c10

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

packages/web3-utils/test/unit/formatter.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,26 @@ describe('formatter', () => {
479479
).toEqual(new Uint8Array([16, 11, 202]));
480480
});
481481
});
482+
483+
describe('string', () => {
484+
it('should format string for 123', () => {
485+
expect(
486+
format({ format: 'string' }, 123, {
487+
number: FMT_NUMBER.STR,
488+
bytes: FMT_BYTES.HEX,
489+
}),
490+
).toBe('123');
491+
});
492+
493+
it('should format string for 0x1234', () => {
494+
expect(
495+
format({ format: 'string' }, 0x1234, {
496+
number: FMT_NUMBER.STR,
497+
bytes: FMT_BYTES.UINT8ARRAY,
498+
}),
499+
).toBe('0x1234');
500+
});
501+
});
482502
});
483503

484504
describe('array values', () => {
@@ -827,6 +847,32 @@ describe('formatter', () => {
827847

828848
expect(result).toEqual(expected);
829849
});
850+
851+
it('should format object with oneOf', () => {
852+
const schema = {
853+
type: 'object',
854+
properties: {
855+
from: {
856+
format: 'address',
857+
},
858+
to: {
859+
oneOf: [{ format: 'string' }, { type: 'null' }],
860+
},
861+
},
862+
};
863+
864+
const data ={
865+
from: '0x7ed0e85b8e1e925600b4373e6d108f34ab38a401',
866+
to: 123,
867+
}
868+
;
869+
870+
const result = { from: '0x7ed0e85b8e1e925600b4373e6d108f34ab38a401', to: '123' };
871+
872+
expect(
873+
format(schema, data, { number: FMT_NUMBER.HEX, bytes: FMT_BYTES.HEX }),
874+
).toEqual(result);
875+
});
830876
});
831877
describe('isDataFormat', () => {
832878
describe('valid cases', () => {

0 commit comments

Comments
 (0)