Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mmyyrroonn committed Jul 25, 2024
1 parent 1cd3d95 commit 4b59c10
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions packages/web3-utils/test/unit/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,26 @@ describe('formatter', () => {
).toEqual(new Uint8Array([16, 11, 202]));
});
});

describe('string', () => {
it('should format string for 123', () => {
expect(
format({ format: 'string' }, 123, {
number: FMT_NUMBER.STR,
bytes: FMT_BYTES.HEX,
}),
).toBe('123');
});

it('should format string for 0x1234', () => {
expect(
format({ format: 'string' }, 0x1234, {
number: FMT_NUMBER.STR,
bytes: FMT_BYTES.UINT8ARRAY,
}),
).toBe('0x1234');
});
});
});

describe('array values', () => {
Expand Down Expand Up @@ -827,6 +847,32 @@ describe('formatter', () => {

expect(result).toEqual(expected);
});

it('should format object with oneOf', () => {
const schema = {
type: 'object',
properties: {
from: {
format: 'address',
},
to: {
oneOf: [{ format: 'string' }, { type: 'null' }],
},
},
};

const data ={
from: '0x7ed0e85b8e1e925600b4373e6d108f34ab38a401',
to: 123,
}
;

const result = { from: '0x7ed0e85b8e1e925600b4373e6d108f34ab38a401', to: '123' };

expect(
format(schema, data, { number: FMT_NUMBER.HEX, bytes: FMT_BYTES.HEX }),
).toEqual(result);
});
});
describe('isDataFormat', () => {
describe('valid cases', () => {
Expand Down

0 comments on commit 4b59c10

Please sign in to comment.