Skip to content

Commit

Permalink
Add test for uncovered validation function
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Jan 23, 2025
1 parent ee86bd7 commit 5b61497
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/snaps-execution-environments/coverage.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"branches": 80.95,
"functions": 88.15,
"lines": 90.28,
"statements": 89.45
"branches": 80.27,
"functions": 89.47,
"lines": 90.7,
"statements": 89.86
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { UserInputEventType } from '@metamask/snaps-sdk';

import {
assertIsOnAssetsConversionRequestArguments,
assertIsOnAssetsLookupRequestArguments,
assertIsOnNameLookupRequestArguments,
assertIsOnSignatureRequestArguments,
assertIsOnTransactionRequestArguments,
Expand Down Expand Up @@ -232,3 +234,81 @@ describe('assertIsOnUserInputRequestArguments', () => {
);
});
});

describe('assertIsOnAssetsLookupRequestArguments', () => {
it.each([
{ assets: ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501'] },
{
assets: [
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501',
'bip122:000000000019d6689c085ae165831e93/slip44:0',
],
},
])('does not throw for a valid assets lookup param object', (value) => {
expect(() => assertIsOnAssetsLookupRequestArguments(value)).not.toThrow();
});

it.each([
true,
false,
null,
undefined,
0,
1,
'',
'foo',
[],
{},
{ assets: [] },
{ assets: ['foo'] },
])(
'throws if the value is not a valid assets lookup params object',
(value) => {
expect(() =>
assertIsOnAssetsLookupRequestArguments(value as any),
).toThrow('Invalid request params:');
},
);
});

describe('assertIsOnAssetsConversionRequestArguments', () => {
it.each([
{
conversions: [
{
from: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501',
to: 'bip122:000000000019d6689c085ae165831e93/slip44:0',
},
],
},
])('does not throw for a valid assets conversion param object', (value) => {
expect(() =>
assertIsOnAssetsConversionRequestArguments(value),
).not.toThrow();
});

it.each([
true,
false,
null,
undefined,
0,
1,
'',
'foo',
[],
{},
{ conversions: [] },
{ conversions: ['foo'] },
{ conversions: [{}] },
{ conversions: [{ from: 'foo' }] },
{ conversions: [{ from: 'foo', to: 'foo' }] },
])(
'throws if the value is not a valid assets conversion params object',
(value) => {
expect(() =>
assertIsOnAssetsConversionRequestArguments(value as any),
).toThrow('Invalid request params:');
},
);
});

0 comments on commit 5b61497

Please sign in to comment.