@@ -8,10 +8,11 @@ import Config from "@truffle/config";
8
8
const config = Config . default ( ) ;
9
9
let versionRangeOptions = {
10
10
events : config . events ,
11
- solcConfig : config . compilers . solc
11
+ solcConfig : config . compilers . solc ,
12
+ cache : "fileSystem"
12
13
} ;
13
14
const instance = new LoadingStrategies . VersionRange ( versionRangeOptions ) ;
14
- let fileName , expectedResult ;
15
+ let fileName : string , expectedResult : any ;
15
16
const compilerFileNames = [
16
17
"soljson-v0.4.22+commit.124ca40d.js" ,
17
18
"soljson-v0.4.23+commit.1534a40d.js" ,
@@ -105,32 +106,32 @@ describe("VersionRange loading strategy", () => {
105
106
106
107
describe ( "when a version constraint is specified" , ( ) => {
107
108
beforeEach ( ( ) => {
108
- sinon . stub ( instance , "getAndCacheSolcByUrl " ) ;
109
- sinon . stub ( instance . cache , "has" ) . returns ( false ) ;
109
+ sinon . stub ( instance , "getAndCacheSoljsonByUrl " ) ;
110
+ sinon . stub ( instance . cache ! , "has" ) . returns ( false ) ;
110
111
} ) ;
111
112
afterEach ( ( ) => {
112
- unStub ( instance , "getAndCacheSolcByUrl " ) ;
113
- unStub ( instance . cache , "has" ) ;
113
+ unStub ( instance , "getAndCacheSoljsonByUrl " ) ;
114
+ unStub ( instance . cache ! , "has" ) ;
114
115
} ) ;
115
116
116
117
it ( "calls findNewstValidVersion to determine which version to fetch" , async ( ) => {
117
118
await instance . getSolcFromCacheOrUrl ( "^0.5.0" ) ;
118
119
assert . isTrue (
119
120
// @ts -ignore
120
- instance . getAndCacheSolcByUrl . calledWith (
121
+ instance . getAndCacheSoljsonByUrl . calledWith (
121
122
"soljson-v0.5.4+commit.9549d8ff.js"
122
123
) ,
123
- "getAndCacheSolcByUrl not called with the compiler file name"
124
+ "getAndCacheSoljsonByUrl not called with the compiler file name"
124
125
) ;
125
126
} ) ;
126
127
} ) ;
127
128
128
129
describe ( "when the version is cached" , ( ) => {
129
130
beforeEach ( ( ) => {
130
- sinon . stub ( instance . cache , "has" ) . returns ( true ) ;
131
+ sinon . stub ( instance . cache ! , "has" ) . returns ( true ) ;
131
132
} ) ;
132
133
afterEach ( ( ) => {
133
- unStub ( instance . cache , "has" ) ;
134
+ unStub ( instance . cache ! , "has" ) ;
134
135
} ) ;
135
136
136
137
it ( "calls getCachedSolcByFileName" , async ( ) => {
@@ -146,13 +147,15 @@ describe("VersionRange loading strategy", () => {
146
147
147
148
describe ( "when the version is not cached" , ( ) => {
148
149
beforeEach ( ( ) => {
149
- sinon . stub ( instance . cache , "has" ) . returns ( false ) ;
150
- sinon . stub ( instance . cache , "add" ) ;
151
- sinon . stub ( instance , "compilerFromString" ) . returns ( "compiler" ) ;
150
+ sinon . stub ( instance . cache ! , "has" ) . returns ( false ) ;
151
+ sinon . stub ( instance . cache ! , "add" ) ;
152
+ sinon
153
+ . stub ( instance , "compilerFromString" )
154
+ . returns ( Promise . resolve ( "compiler" ) ) ;
152
155
} ) ;
153
156
afterEach ( ( ) => {
154
- unStub ( instance . cache , "has" ) ;
155
- unStub ( instance . cache , "add" ) ;
157
+ unStub ( instance . cache ! , "has" ) ;
158
+ unStub ( instance . cache ! , "add" ) ;
156
159
unStub ( instance , "compilerFromString" ) ;
157
160
} ) ;
158
161
@@ -178,16 +181,16 @@ describe("VersionRange loading strategy", () => {
178
181
sinon
179
182
. stub ( instance , "compilerFromString" )
180
183
. withArgs ( "requestReturn" )
181
- . returns ( "success" ) ;
184
+ . returns ( Promise . resolve ( "success" ) ) ;
182
185
} ) ;
183
186
afterEach ( ( ) => {
184
187
unStub ( axios , "get" ) ;
185
- unStub ( instance . cache , "add" ) ;
188
+ unStub ( instance . cache ! , "add" ) ;
186
189
unStub ( instance , "compilerFromString" ) ;
187
190
} ) ;
188
191
189
192
it ( "calls add with the response and the file name" , async ( ) => {
190
- const result = await instance . getAndCacheSolcByUrl ( fileName , 0 ) ;
193
+ const result = await instance . getAndCacheSoljsonByUrl ( fileName , 0 ) ;
191
194
assert . isTrue (
192
195
// @ts -ignore
193
196
instance . cache . add . calledWith ( "requestReturn" , "someSolcFile" )
@@ -216,10 +219,10 @@ describe("VersionRange loading strategy", () => {
216
219
217
220
describe ( "versionIsCached(version)" , ( ) => {
218
221
beforeEach ( ( ) => {
219
- sinon . stub ( instance . cache , "list" ) . returns ( compilerFileNames ) ;
222
+ sinon . stub ( instance . cache ! , "list" ) . returns ( compilerFileNames ) ;
220
223
} ) ;
221
224
afterEach ( ( ) => {
222
- unStub ( instance . cache , "list" ) ;
225
+ unStub ( instance . cache ! , "list" ) ;
223
226
} ) ;
224
227
225
228
describe ( "when a cached version of the compiler is present" , ( ) => {
@@ -246,11 +249,11 @@ describe("VersionRange loading strategy", () => {
246
249
describe ( "getCachedSolcByVersionRange(version)" , ( ) => {
247
250
beforeEach ( ( ) => {
248
251
expectedResult = "soljson-v0.4.23+commit.1534a40d.js" ;
249
- sinon . stub ( instance . cache , "list" ) . returns ( compilerFileNames ) ;
252
+ sinon . stub ( instance . cache ! , "list" ) . returns ( compilerFileNames ) ;
250
253
sinon . stub ( instance , "getCachedSolcByFileName" ) ;
251
254
} ) ;
252
255
afterEach ( ( ) => {
253
- unStub ( instance . cache , "list" ) ;
256
+ unStub ( instance . cache ! , "list" ) ;
254
257
unStub ( instance , "getCachedSolcByFileName" ) ;
255
258
} ) ;
256
259
0 commit comments