1
- import { expect } from ' vitest' ;
1
+ import { expect } from " vitest" ;
2
2
3
3
import { whatsabi } from "../index" ;
4
4
import { autoload } from "../auto" ;
@@ -9,12 +9,12 @@ const TIMEOUT = 15000;
9
9
10
10
test ( 'autoload throws typed error' , async ( ) => {
11
11
// @ts -expect-error: Expected 2 arguments, but got 1
12
- await expect ( autoload ( "0xf00" ) ) . rejects . toThrow ( / c o n f i g i s u n d e f i n e d / ) ;
12
+ await expect ( autoload ( "0xf00" ) ) . rejects . toThrow ( new RegExp ( " config is undefined" ) ) ;
13
13
14
14
const fakeProvider = {
15
15
request : ( ) => { } ,
16
- }
17
- await expect ( autoload ( "abc.eth" , { provider : fakeProvider } ) ) . rejects . toThrow ( / F a i l e d t o r e s o l v e E N S / ) ;
16
+ } ;
17
+ await expect ( autoload ( "abc.eth" , { provider : fakeProvider } ) ) . rejects . toThrow ( new RegExp ( " Failed to resolve ENS" ) ) ;
18
18
} ) ;
19
19
20
20
test ( 'autoload sets hasCode to false if code is empty' , async ( ) => {
@@ -113,7 +113,7 @@ online_test('autoload loadContractResult verified etherscan', async ({ provider,
113
113
expect ( result . contractResult ?. name ) . toBe ( "TransparentUpgradeableProxy" ) ;
114
114
expect ( result . contractResult ?. compilerVersion ) . toBe ( "v0.8.15+commit.e14f2714" ) ;
115
115
expect ( result . contractResult ?. loaderResult ?. Proxy ) . toBe ( "1" ) ;
116
- expect ( result . contractResult ?. loaderResult ?. Implementation ) . toMatch ( / ^ 0 x [ 0 - 9 a - f ] { 40 } $ / ) ;
116
+ expect ( result . contractResult ?. loaderResult ?. Implementation ) . toMatch ( new RegExp ( " ^0x[0-9a-f]{40}$" ) ) ;
117
117
} ) ;
118
118
119
119
cached_test ( 'autoload isFactory' , async ( { provider, env, withCache } ) => {
@@ -126,9 +126,31 @@ cached_test('autoload isFactory', async ({ provider, env, withCache }) => {
126
126
} ,
127
127
)
128
128
const result = await autoload ( address , {
129
- provider : provider ,
129
+ provider : whatsabi . providers . WithCachedCode ( provider , {
130
+ [ address ] : code ,
131
+ } ) ,
130
132
...whatsabi . loaders . defaultsWithEnv ( env ) ,
131
133
} ) ;
132
134
expect ( result . isFactory ) . toBeTruthy ( ) ;
133
135
} ) ;
134
136
137
+ cached_test ( 'autoload ambiguous proxy' , async ( { provider, env, withCache } ) => {
138
+ // Issue #173
139
+ const address = "0xe1164a7a364929c3ba3da9671c8003dd71975d2d" ;
140
+
141
+ const code = await withCache (
142
+ `${ address } _code` ,
143
+ async ( ) => {
144
+ return await provider . getCode ( address )
145
+ } ,
146
+ )
147
+ const result = await autoload ( address , {
148
+ provider : whatsabi . providers . WithCachedCode ( provider , {
149
+ [ address ] : code ,
150
+ } ) ,
151
+ ...whatsabi . loaders . defaultsWithEnv ( env ) ,
152
+ } ) ;
153
+ expect ( result . proxies . length ) . toBe ( 1 ) ;
154
+ expect ( result . followProxies ) . toBeFalsy ( ) ;
155
+ } ) ;
156
+
0 commit comments