@@ -7,20 +7,76 @@ const getProviderInfo = () => ({
77 uuid : '1449211e-5560-4235-9ab1-582cbe2b165f' ,
88} ) ;
99
10+ const providerInfoValidationError = ( ) =>
11+ new Error (
12+ 'Invalid EIP-6963 provider info. See https://eips.ethereum.org/EIPS/eip-6963 for requirements.' ,
13+ ) ;
14+
1015describe ( 'EIP6963' , ( ) => {
1116 describe ( 'announceProvider' , ( ) => {
12- it ( 'throws if the UUID is invalid' , ( ) => {
13- [ 'foo' , null , undefined , Symbol ( 'bar' ) ] . forEach ( ( invalidUuid ) => {
14- const provider : any = { name : 'test' } ;
15- const providerDetail = { info : getProviderInfo ( ) , provider } ;
16- providerDetail . info . uuid = invalidUuid as any ;
17-
18- expect ( ( ) => announceProvider ( providerDetail ) ) . toThrow (
19- new Error ( 'Invalid `uuid` field. Must be a v4 UUID.' ) ,
17+ describe ( 'provider info validation' , ( ) => {
18+ it ( 'throws if the info is not a plain object' , ( ) => {
19+ [ null , undefined , Symbol ( 'bar' ) , [ ] ] . forEach ( ( invalidUuid ) => {
20+ const provider : any = { name : 'test' } ;
21+ const providerDetail = { info : getProviderInfo ( ) , provider } ;
22+ providerDetail . info . uuid = invalidUuid as any ;
23+
24+ expect ( ( ) => announceProvider ( providerDetail ) ) . toThrow (
25+ providerInfoValidationError ( ) ,
26+ ) ;
27+ } ) ;
28+ } ) ;
29+
30+ it ( 'throws if the `icon` field is invalid' , ( ) => {
31+ [ null , undefined , '' , 'not-a-url' , Symbol ( 'bar' ) ] . forEach (
32+ ( invalidUuid ) => {
33+ const provider : any = { name : 'test' } ;
34+ const providerDetail = { info : getProviderInfo ( ) , provider } ;
35+ providerDetail . info . uuid = invalidUuid as any ;
36+
37+ expect ( ( ) => announceProvider ( providerDetail ) ) . toThrow (
38+ providerInfoValidationError ( ) ,
39+ ) ;
40+ } ,
2041 ) ;
2142 } ) ;
22- } ) ;
2343
44+ it ( 'throws if the `name` field is invalid' , ( ) => {
45+ [ null , undefined , '' , { } , [ ] , Symbol ( 'bar' ) ] . forEach ( ( invalidUuid ) => {
46+ const provider : any = { name : 'test' } ;
47+ const providerDetail = { info : getProviderInfo ( ) , provider } ;
48+ providerDetail . info . uuid = invalidUuid as any ;
49+
50+ expect ( ( ) => announceProvider ( providerDetail ) ) . toThrow (
51+ providerInfoValidationError ( ) ,
52+ ) ;
53+ } ) ;
54+ } ) ;
55+
56+ it ( 'throws if the `uuid` field is invalid' , ( ) => {
57+ [ null , undefined , '' , 'foo' , Symbol ( 'bar' ) ] . forEach ( ( invalidUuid ) => {
58+ const provider : any = { name : 'test' } ;
59+ const providerDetail = { info : getProviderInfo ( ) , provider } ;
60+ providerDetail . info . uuid = invalidUuid as any ;
61+
62+ expect ( ( ) => announceProvider ( providerDetail ) ) . toThrow (
63+ providerInfoValidationError ( ) ,
64+ ) ;
65+ } ) ;
66+ } ) ;
67+
68+ it ( 'throws if the `walletId` field is invalid' , ( ) => {
69+ [ null , undefined , '' , { } , [ ] , Symbol ( 'bar' ) ] . forEach ( ( invalidUuid ) => {
70+ const provider : any = { name : 'test' } ;
71+ const providerDetail = { info : getProviderInfo ( ) , provider } ;
72+ providerDetail . info . uuid = invalidUuid as any ;
73+
74+ expect ( ( ) => announceProvider ( providerDetail ) ) . toThrow (
75+ providerInfoValidationError ( ) ,
76+ ) ;
77+ } ) ;
78+ } ) ;
79+ } ) ;
2480 it ( 'should announce a provider' , ( ) => {
2581 const provider : any = { name : 'test' } ;
2682 const providerDetail = { info : getProviderInfo ( ) , provider } ;
0 commit comments