@@ -118,8 +118,8 @@ SemanticTest::SemanticTest(
118
118
119
119
if (m_enforceGasCost)
120
120
{
121
- m_compiler. setMetadataFormat (CompilerStack:: MetadataFormat::NoMetadata) ;
122
- m_compiler. setMetadataHash (CompilerStack:: MetadataHash::None) ;
121
+ m_compilerInput. metadataFormat = MetadataFormat::NoMetadata;
122
+ m_compilerInput. metadataHash = MetadataHash::None;
123
123
}
124
124
}
125
125
@@ -196,7 +196,7 @@ std::vector<SideEffectHook> SemanticTest::makeSideEffectHooks() const
196
196
};
197
197
}
198
198
199
- std::string SemanticTest::formatEventParameter (std::optional<AnnotatedEventSignature> _signature, bool _indexed, size_t _index, bytes const & _data)
199
+ std::string SemanticTest::formatEventParameter (EventSignature const * _signature, bool _indexed, size_t _index, bytes const & _data)
200
200
{
201
201
auto isPrintableASCII = [](bytes const & s)
202
202
{
@@ -217,7 +217,7 @@ std::string SemanticTest::formatEventParameter(std::optional<AnnotatedEventSigna
217
217
ABIType abiType (ABIType::Type::Hex);
218
218
if (isPrintableASCII (_data))
219
219
abiType = ABIType (ABIType::Type::String);
220
- if (_signature. has_value () )
220
+ if (_signature)
221
221
{
222
222
std::vector<std::string> const & types = _indexed ? _signature->indexedTypes : _signature->nonIndexedTypes ;
223
223
if (_index < types.size ())
@@ -231,17 +231,19 @@ std::string SemanticTest::formatEventParameter(std::optional<AnnotatedEventSigna
231
231
232
232
std::vector<std::string> SemanticTest::eventSideEffectHook (FunctionCall const &) const
233
233
{
234
+ auto const & output = m_compiler.output ();
235
+
234
236
std::vector<std::string> sideEffects;
235
237
std::vector<LogRecord> recordedLogs = ExecutionFramework::recordedLogs ();
236
238
for (LogRecord const & log : recordedLogs)
237
239
{
238
- std::optional<AnnotatedEventSignature> eventSignature;
240
+ EventSignature const * eventSignature = nullptr ;
239
241
if (!log .topics .empty ())
240
- eventSignature = matchEvent (log .topics [0 ]);
242
+ eventSignature = output. matchEvent (log .topics [0 ]);
241
243
std::stringstream sideEffect;
242
244
sideEffect << " emit " ;
243
- if (eventSignature. has_value () )
244
- sideEffect << eventSignature. value (). signature ;
245
+ if (eventSignature)
246
+ sideEffect << eventSignature-> signature ;
245
247
else
246
248
sideEffect << " <anonymous>" ;
247
249
@@ -252,7 +254,7 @@ std::vector<std::string> SemanticTest::eventSideEffectHook(FunctionCall const&)
252
254
size_t index {0 };
253
255
for (h256 const & topic: log .topics )
254
256
{
255
- if (!eventSignature. has_value () || index != 0 )
257
+ if (!eventSignature || index != 0 )
256
258
eventStrings.push_back (" #" + formatEventParameter (eventSignature, true , index , topic.asBytes ()));
257
259
++index ;
258
260
}
@@ -273,31 +275,6 @@ std::vector<std::string> SemanticTest::eventSideEffectHook(FunctionCall const&)
273
275
return sideEffects;
274
276
}
275
277
276
- std::optional<AnnotatedEventSignature> SemanticTest::matchEvent (util::h256 const & hash) const
277
- {
278
- std::optional<AnnotatedEventSignature> result;
279
- for (std::string& contractName: m_compiler.contractNames ())
280
- {
281
- ContractDefinition const & contract = m_compiler.contractDefinition (contractName);
282
- for (EventDefinition const * event: contract.events () + contract.usedInterfaceEvents ())
283
- {
284
- FunctionTypePointer eventFunctionType = event->functionType (true );
285
- if (!event->isAnonymous () && keccak256 (eventFunctionType->externalSignature ()) == hash)
286
- {
287
- AnnotatedEventSignature eventInfo;
288
- eventInfo.signature = eventFunctionType->externalSignature ();
289
- for (auto const & param: event->parameters ())
290
- if (param->isIndexed ())
291
- eventInfo.indexedTypes .emplace_back (param->type ()->toString (true ));
292
- else
293
- eventInfo.nonIndexedTypes .emplace_back (param->type ()->toString (true ));
294
- result = eventInfo;
295
- }
296
- }
297
- }
298
- return result;
299
- }
300
-
301
278
frontend::OptimiserSettings SemanticTest::optimizerSettingsFor (RequiresYulOptimizer _requiresYulOptimizer)
302
279
{
303
280
switch (_requiresYulOptimizer)
@@ -383,13 +360,14 @@ TestCase::TestResult SemanticTest::runTest(
383
360
}
384
361
else if (test.call ().kind == FunctionCall::Kind::Library)
385
362
{
363
+ std::string name = test.call ().libraryFile + " :" + test.call ().signature ;
386
364
soltestAssert (
387
- deploy (test. call (). signature , 0 , {}, libraries) && m_transactionSuccessful,
365
+ deploy (name , 0 , {}, libraries) && m_transactionSuccessful,
388
366
" Failed to deploy library " + test.call ().signature );
389
367
// For convenience, in semantic tests we assume that an unqualified name like `L` is equivalent to one
390
368
// with an empty source unit name (`:L`). This is fine because the compiler never uses unqualified
391
369
// names in the Yul code it produces and does not allow `linkersymbol()` at all in inline assembly.
392
- libraries[test. call (). libraryFile + " : " + test. call (). signature ] = m_contractAddress;
370
+ libraries[name ] = m_contractAddress;
393
371
continue ;
394
372
}
395
373
else
@@ -416,7 +394,13 @@ TestCase::TestResult SemanticTest::runTest(
416
394
}
417
395
else
418
396
{
397
+ ContractName contractName{m_sources.mainSourceFile , " " };
398
+
399
+ auto contract = m_compiler.output ().contract (contractName);
400
+ soltestAssert (contract);
401
+
419
402
bytes output;
403
+
420
404
if (test.call ().kind == FunctionCall::Kind::LowLevel)
421
405
output = callLowLevel (test.call ().arguments .rawBytes (), test.call ().value .value );
422
406
else if (test.call ().kind == FunctionCall::Kind::Builtin)
@@ -432,9 +416,10 @@ TestCase::TestResult SemanticTest::runTest(
432
416
}
433
417
else
434
418
{
419
+ soltestAssert (contract->interfaceSymbols .has_value ());
435
420
soltestAssert (
436
421
m_allowNonExistingFunctions ||
437
- m_compiler. interfaceSymbols (m_compiler. lastContractName (m_sources. mainSourceFile ) )[" methods" ].contains (test.call ().signature ),
422
+ contract-> interfaceSymbols . value ( )[" methods" ].contains (test.call ().signature ),
438
423
" The function " + test.call ().signature + " is not known to the compiler"
439
424
);
440
425
@@ -462,7 +447,8 @@ TestCase::TestResult SemanticTest::runTest(
462
447
test.setFailure (!m_transactionSuccessful);
463
448
test.setRawBytes (std::move (output));
464
449
if (test.call ().kind != FunctionCall::Kind::LowLevel)
465
- test.setContractABI (m_compiler.contractABI (m_compiler.lastContractName (m_sources.mainSourceFile )));
450
+ if (contract->contractABI .has_value ())
451
+ test.setContractABI (contract->contractABI .value ());
466
452
}
467
453
468
454
std::vector<std::string> effects;
0 commit comments