Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 7055 one of with scalar value and string #7173

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test
  • Loading branch information
mmyyrroonn committed Aug 6, 2024
commit 40ddd19d704f455b2b2e9ab6775597ce04e0a6a8
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, {
mmyyrroonn marked this conversation as resolved.
Show resolved Hide resolved
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', () => {
mmyyrroonn marked this conversation as resolved.
Show resolved Hide resolved
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