Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse address types with nested with contract phrases. #21

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/simplified_representation/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,17 @@ impl AstConverting for SrEmitter {
};
self.stack.push(StackObject::TypeDefinition(map));
}
NodeTypeMapValue::MapValueAddressType(_value) => unimplemented!(),
NodeTypeMapValue::MapValueAddressType(value) => {
value.visit(self)?;
let value = self.pop_type_definition()?;
let key = self.pop_ir_identifier()?;
let map = SrType {
main_type: "Map".to_string(),
sub_types: vec![key.into(), value],
address_type: None,
};
self.stack.push(StackObject::TypeDefinition(map));
}
};
}
TreeTraversalMode::Exit => {}
Expand Down
8 changes: 7 additions & 1 deletion tests/contracts/ByStr.scilla
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ contract AllByStrVariants
field allowances : Map ByStr20 (Map ByStr20 Uint128),
field balances : Map ByStr20 Uint128,
field total_supply : Uint128
end
end,
complex_contract_address: ByStr20 with contract
field implementation: ByStr20 with contract
field services: Map String ByStr20,
field utility: Map String Uint128 end,
field dns: Map String ByStr20,
field guardians: Map String ByStr20 with contract field verification_methods: Map String ByStr33 end end
)

transition ArbitrageFromXCAD
Expand Down
50 changes: 50 additions & 0 deletions tests/full_contract_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,56 @@ fn test_bystr_contract_parse() {
Field::new("total_supply", Type::Uint128)
])
}
),
Field::new(
"complex_contract_address",
Type::ByStr20With {
type_name: "contract".to_string(),
fields: FieldList(vec![
Field::new(
"implementation",
Type::ByStr20With {
type_name: "contract".to_string(),
fields: FieldList(vec![
Field::new(
"services",
Type::Map(
Box::new(Type::String),
Box::new(Type::ByStr20)
)
),
Field::new(
"utility",
Type::Map(
Box::new(Type::String),
Box::new(Type::Uint128)
)
),
])
}
),
Field::new(
"dns",
Type::Map(Box::new(Type::String), Box::new(Type::ByStr20))
),
Field::new(
"guardians",
Type::Map(
Box::new(Type::String),
Box::new(Type::ByStr20With {
type_name: "contract".to_string(),
fields: FieldList(vec![Field::new(
"verification_methods",
Type::Map(
Box::new(Type::String),
Box::new(Type::ByStrX(33))
)
),])
}),
)
)
])
}
)
]),
fields: FieldList::default(),
Expand Down