Skip to content

Commit

Permalink
Add TypedDataUtils.findTypeDependencies tests
Browse files Browse the repository at this point in the history
This function is now comprehensively tested.
  • Loading branch information
Gudahtt committed Aug 11, 2021
1 parent 3f2c83c commit 66ea1b2
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,77 @@ describe('TypedDataUtils.encodeData', function () {
});
});

describe('TypedDataUtils.findTypeDependencies', () => {
it('should return type dependencies of a simple type', function () {
const types = {
Person: [{ name: 'name', type: 'string' }],
};
const primaryType = 'Person';

expect(
sigUtil.TypedDataUtils.findTypeDependencies(primaryType, types),
).toStrictEqual(['Person']);
});

it('should return type dependencies of an array type', function () {
const types = {
Person: [{ name: 'name', type: 'string' }],
};
const primaryType = 'Person[]';

expect(
sigUtil.TypedDataUtils.findTypeDependencies(primaryType, types),
).toStrictEqual(['Person']);
});

it('should return type dependencies of a complex type', function () {
const types = {
Person: [
{ name: 'name', type: 'string' },
{ name: 'wallet', type: 'address' },
],
Mail: [
{ name: 'from', type: 'Person' },
{ name: 'to', type: 'Person[]' },
{ name: 'contents', type: 'string' },
],
};
const primaryType = 'Mail';

expect(
sigUtil.TypedDataUtils.findTypeDependencies(primaryType, types),
).toStrictEqual(['Mail', 'Person']);
});

it('should return type dependencies of a recursive type', function () {
const types = {
Person: [
{ name: 'name', type: 'string' },
{ name: 'wallet', type: 'address' },
],
Mail: [
{ name: 'from', type: 'Person' },
{ name: 'to', type: 'Person[]' },
{ name: 'contents', type: 'string' },
{ name: 'replyTo', type: 'Mail' },
],
};
const primaryType = 'Mail';

expect(
sigUtil.TypedDataUtils.findTypeDependencies(primaryType, types),
).toStrictEqual(['Mail', 'Person']);
});

it('should return empty array if primary type is missing', function () {
const primaryType = 'Person';

expect(
sigUtil.TypedDataUtils.findTypeDependencies(primaryType, {}),
).toStrictEqual([]);
});
});

it('normalize address lower cases', function () {
const initial = '0xA06599BD35921CfB5B71B4BE3869740385b0B306';
const result = sigUtil.normalize(initial);
Expand Down

0 comments on commit 66ea1b2

Please sign in to comment.