Skip to content

Commit

Permalink
hacking
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant Wuerker committed Sep 25, 2023
1 parent 7aab8b1 commit f180956
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
4 changes: 2 additions & 2 deletions crates/codegen/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub trait CodegenDb: MirDb + Upcast<dyn MirDb> + UpcastMut<dyn MirDb> {
fn codegen_abi_event(&self, ty: TypeId) -> AbiEvent;
#[salsa::invoke(queries::abi::abi_contract)]
fn codegen_abi_contract(&self, contract: ContractId) -> AbiContract;
#[salsa::invoke(queries::abi::module_events)]
fn codegen_module_events(&self, module: ModuleId) -> Vec<AbiEvent>;
#[salsa::invoke(queries::abi::abi_module_events)]
fn codegen_abi_module_events(&self, module: ModuleId) -> Vec<AbiEvent>;
#[salsa::invoke(queries::abi::abi_type_maximum_size)]
fn codegen_abi_type_maximum_size(&self, ty: TypeId) -> usize;
#[salsa::invoke(queries::abi::abi_type_minimum_size)]
Expand Down
4 changes: 2 additions & 2 deletions crates/codegen/src/db/queries/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ pub fn abi_contract(db: &dyn CodegenDb, contract: ContractId) -> AbiContract {
}
}

let events = module_events(db, contract.module(db.upcast()));
let events = abi_module_events(db, contract.module(db.upcast()));

AbiContract::new(funcs, events)
}

pub fn module_events(db: &dyn CodegenDb, module: ModuleId) -> Vec<AbiEvent> {
pub fn abi_module_events(db: &dyn CodegenDb, module: ModuleId) -> Vec<AbiEvent> {
let mut events = vec![];
for &s in db.module_structs(module).as_ref() {
let struct_ty = s.as_type(db.upcast());
Expand Down
8 changes: 5 additions & 3 deletions crates/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ fn map_abi_type(typ: &AbiType) -> ParamType {
AbiType::Int(value) => ParamType::Int(*value),
AbiType::Address => ParamType::Address,
AbiType::Bool => ParamType::Bool,
AbiType::Function => panic!("shit"),
AbiType::Array { elem_ty, len } => todo!(),
AbiType::Function => panic!("function cannot be mapped to an actual ABI value type"),
AbiType::Array { elem_ty, len } => {
ParamType::FixedArray(Box::new(map_abi_type(elem_ty)), *len)
}
AbiType::Tuple(params) => ParamType::Tuple(map_abi_types(params)),
AbiType::Bytes => ParamType::Bytes,
AbiType::String => ParamType::String,
Expand Down Expand Up @@ -218,7 +220,7 @@ fn compile_test(db: &mut Db, test: FunctionId, optimize: bool) -> CompiledTest {
.to_string()
.replace('"', "\\\"");
let bytecode = compile_to_evm("test", &yul_test, optimize);
let events = db.codegen_module_events(test.module(db));
let events = db.codegen_abi_module_events(test.module(db));
CompiledTest::new(test.name(db), events, bytecode)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/fe/src/task/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn test_single_file(args: &TestArgs) -> TestSink {
Ok(content) => content,
};

match fe_driver::compile_single_file_tests(&mut db, input_path, &content, true) {
match fe_driver::compile_single_file_tests(&mut db, input_path, &content, optimize) {
Ok((name, tests)) => {
let mut sink = TestSink::new(logs);
execute_tests(&name, &tests, &mut sink);
Expand Down
33 changes: 18 additions & 15 deletions crates/test-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Display for TestSink {
writeln!(f, "{}", self.failure_details())?;
writeln!(f)?;
if self.collect_logs {
writeln!(f, "note: failed tests do not emit logs")?;
writeln!(f, "note: failed tests do not produce logs")?;
writeln!(f)?;
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ pub fn execute(name: &str, events: &[Event], bytecode: &str, sink: &mut TestSink
let logs: Vec<_> = logs
.iter()
.map(|log| {
if let Some(event) = log
if let Some(Some(event)) = log
.topics
.get(0)
.map(|sig| events.get(&Hash::from_slice(sig.as_bytes())))
Expand All @@ -143,18 +143,21 @@ pub fn execute(name: &str, events: &[Event], bytecode: &str, sink: &mut TestSink
.collect();
let data = log.data.clone().to_vec();
let raw_log = RawLog { topics, data };
let parsed_event = event.unwrap().parse_log(raw_log).unwrap();
format!(
" {} emitted by {} with the following parameters [{}]",
event.unwrap().name,
log.address,
parsed_event
.params
.iter()
.map(|param| format!("{}: {}", param.name, param.value))
.collect::<Vec<String>>()
.join(", "),
)
if let Ok(parsed_event) = event.parse_log(raw_log) {
format!(
" {} emitted by {} with the following parameters [{}]",
event.name,
log.address,
parsed_event
.params
.iter()
.map(|param| format!("{}: {}", param.name, param.value))
.collect::<Vec<String>>()
.join(", "),
)
} else {
format!(" {:?}", log)
}
} else {
format!(" {:?}", log)
}
Expand All @@ -167,7 +170,7 @@ pub fn execute(name: &str, events: &[Event], bytecode: &str, sink: &mut TestSink

sink.inc_success_count();
true
} else if let ExecutionResult::Revert { gas_used, output } = result {
} else if let ExecutionResult::Revert { output, .. } = result {
sink.insert_failure(
name,
&if output.is_empty() {
Expand Down

0 comments on commit f180956

Please sign in to comment.