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 more test
  • Loading branch information
mmyyrroonn committed Aug 6, 2024
commit e14f4c6d8cee687cc19f39c7369db0e4a5769e8f
33 changes: 24 additions & 9 deletions packages/web3-utils/test/unit/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,15 +489,6 @@ describe('formatter', () => {
}),
).toBe('123');
});

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

Expand Down Expand Up @@ -873,6 +864,30 @@ describe('formatter', () => {
format(schema, data, { number: FMT_NUMBER.HEX, bytes: FMT_BYTES.HEX }),
).toEqual(result);
});

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

const data ={
from: '0x7ed0e85b8e1e925600b4373e6d108f34ab38a401'
};

const result = { from: '0x7ed0e85b8e1e925600b4373e6d108f34ab38a401'};

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