@@ -8,8 +8,12 @@ import config from "config";
8
8
import rimraf from "rimraf" ;
9
9
import { StorageService } from "../../src/server/services/StorageService" ;
10
10
import { RWStorageIdentifiers } from "../../src/server/services/storageServices/identifiers" ;
11
+ import sinon from "sinon" ;
12
+ import { EtherscanResult } from "../../src/server/services/utils/etherscan-util" ;
11
13
12
14
describe ( "VerificationService" , function ( ) {
15
+ const sandbox = sinon . createSandbox ( ) ;
16
+
13
17
beforeEach ( function ( ) {
14
18
// Clear any previously nocked interceptors
15
19
nock . cleanAll ( ) ;
@@ -18,6 +22,7 @@ describe("VerificationService", function () {
18
22
afterEach ( function ( ) {
19
23
// Ensure that all nock interceptors have been used
20
24
nock . isDone ( ) ;
25
+ sandbox . restore ( ) ;
21
26
} ) ;
22
27
23
28
it ( "should initialize compilers" , async function ( ) {
@@ -97,4 +102,80 @@ describe("VerificationService", function () {
97
102
expect ( fs . existsSync ( path . join ( downloadDir , release ) ) ) . to . be . true ;
98
103
} ) ;
99
104
} ) ;
105
+
106
+ it ( "should handle workerPool.run errors and set job error as internal_error" , async function ( ) {
107
+ const mockStorageService = {
108
+ performServiceOperation : sandbox . stub ( ) ,
109
+ } as any ;
110
+
111
+ // Mock the storage service calls
112
+ const verificationId = "test-verification-id" ;
113
+ mockStorageService . performServiceOperation
114
+ . withArgs ( "storeVerificationJob" )
115
+ . resolves ( verificationId ) ;
116
+
117
+ mockStorageService . performServiceOperation
118
+ . withArgs ( "setJobError" )
119
+ . resolves ( ) ;
120
+
121
+ const verificationService = new VerificationService (
122
+ {
123
+ initCompilers : false ,
124
+ sourcifyChainMap : { } ,
125
+ solcRepoPath : config . get ( "solcRepo" ) ,
126
+ solJsonRepoPath : config . get ( "solJsonRepo" ) ,
127
+ vyperRepoPath : config . get ( "vyperRepo" ) ,
128
+ } ,
129
+ mockStorageService ,
130
+ ) ;
131
+
132
+ // Mock the workerPool.run to throw an error
133
+ const workerPoolStub = sandbox . stub (
134
+ verificationService [ "workerPool" ] ,
135
+ "run" ,
136
+ ) ;
137
+ workerPoolStub . rejects ( new Error ( "Worker pool error" ) ) ;
138
+
139
+ const mockEtherscanResult : EtherscanResult = {
140
+ ContractName : "TestContract" ,
141
+ SourceCode : "contract TestContract {}" ,
142
+ ABI : "[]" ,
143
+ CompilerVersion : "v0.8.26+commit.8a97fa7a" ,
144
+ OptimizationUsed : "0" ,
145
+ Runs : "200" ,
146
+ ConstructorArguments : "" ,
147
+ EVMVersion : "default" ,
148
+ Library : "" ,
149
+ LicenseType : "" ,
150
+ Proxy : "0" ,
151
+ Implementation : "" ,
152
+ SwarmSource : "" ,
153
+ } ;
154
+
155
+ // Call the method that should handle worker errors
156
+ verificationService . verifyFromEtherscanViaWorker (
157
+ "test-endpoint" ,
158
+ "1" ,
159
+ "0x1234567890123456789012345678901234567890" ,
160
+ mockEtherscanResult ,
161
+ ) ;
162
+
163
+ // Wait for the async task to complete
164
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1 ) ) ;
165
+
166
+ // Verify the job error was set with internal_error
167
+ const setJobErrorCall = mockStorageService . performServiceOperation
168
+ . getCalls ( )
169
+ . find ( ( call : any ) => call . args [ 0 ] === "setJobError" ) ;
170
+ expect ( setJobErrorCall ) . to . not . be . undefined ;
171
+
172
+ // The setJobError call has args: ["setJobError", [verificationId, Date, errorExport]]
173
+ const setJobErrorArgs = setJobErrorCall . args [ 1 ] ;
174
+ expect ( setJobErrorArgs [ 0 ] ) . to . equal ( verificationId ) ;
175
+ expect ( setJobErrorArgs [ 1 ] ) . to . be . instanceOf ( Date ) ;
176
+ expect ( setJobErrorArgs [ 2 ] ) . to . deep . include ( {
177
+ customCode : "internal_error" ,
178
+ } ) ;
179
+ expect ( setJobErrorArgs [ 2 ] . errorId ) . to . be . a ( "string" ) ;
180
+ } ) ;
100
181
} ) ;
0 commit comments