Skip to content

Commit

Permalink
Feature: output builtin add_attribute method (#1691)
Browse files Browse the repository at this point in the history
Problem: some OS hints need to add attributes to the output builtin. The
Python implementation defines an `add_attribute` method that is not
present in `cairo-vm`.

Solution: port the `add_attribute` method.
  • Loading branch information
odesenfans authored Apr 3, 2024
1 parent 42e0416 commit 1725f0c
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

#### Upcoming Changes

* feat: output builtin add_attribute method [#1691](https://github.com/lambdaclass/cairo-vm/pull/1691)

* feat: Add zero segment [#1668](https://github.com/lambdaclass/cairo-vm/pull/1668)

* feat: Bump cairo_lang to 0.13.1 in testing env [#1687](https://github.com/lambdaclass/cairo-vm/pull/1687)
16 changes: 16 additions & 0 deletions vm/src/vm/runners/builtin_runner/output.rs
Original file line number Diff line number Diff line change
@@ -129,6 +129,10 @@ impl OutputBuiltinRunner {
}
}

pub fn add_attribute(&mut self, name: String, value: Vec<usize>) {
self.attributes.insert(name, value);
}

pub fn get_additional_data(&self) -> BuiltinAdditionalData {
BuiltinAdditionalData::Output(OutputBuiltinAdditionalData {
pages: self.pages.clone(),
@@ -611,6 +615,18 @@ mod tests {
)
}

#[test]
pub fn add_attribute() {
let mut builtin = OutputBuiltinRunner::new(true);
assert!(builtin.attributes.is_empty());

let name = "gps_fact_topology".to_string();
let values = vec![0, 12, 30];
builtin.add_attribute(name.clone(), values.clone());

assert_eq!(builtin.attributes, HashMap::from([(name, values)]));
}

#[test]
fn get_public_memory() {
let mut builtin = OutputBuiltinRunner::new(true);

0 comments on commit 1725f0c

Please sign in to comment.