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

Implement new ABI "get_matching_keys_for" #3640

Merged
merged 18 commits into from
Mar 31, 2023
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 14 additions & 6 deletions massa-execution-worker/src/interface_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,15 @@ impl Interface for InterfaceImpl {
///
/// # Returns
/// A list of keys (keys are byte arrays)
fn get_keys(&self) -> Result<BTreeSet<Vec<u8>>> {
fn get_keys(&self, prefix_opt: Option<&[u8]>) -> Result<BTreeSet<Vec<u8>>> {
let context = context_guard!(self);
let addr = context.get_current_address()?;
match context.get_keys(&addr) {
Some(value) => Ok(value),
match (context.get_keys(&addr), prefix_opt) {
(Some(value), None) => Ok(value),
(Some(mut value), Some(prefix)) => {
value.retain(|key| key.iter().zip(prefix.iter()).all(|(k, p)| k == p));
Ok(value)
}
_ => bail!("data entry not found"),
}
}
Expand All @@ -272,11 +276,15 @@ impl Interface for InterfaceImpl {
///
/// # Returns
/// A list of keys (keys are byte arrays)
fn get_keys_for(&self, address: &str) -> Result<BTreeSet<Vec<u8>>> {
fn get_keys_for(&self, address: &str, prefix_opt: Option<&[u8]>) -> Result<BTreeSet<Vec<u8>>> {
let addr = &Address::from_str(address)?;
let context = context_guard!(self);
match context.get_keys(addr) {
Some(value) => Ok(value),
match (context.get_keys(addr), prefix_opt) {
(Some(value), None) => Ok(value),
(Some(mut value), Some(prefix)) => {
value.retain(|key| key.iter().zip(prefix.iter()).all(|(k, p)| k == p));
Ok(value)
}
_ => bail!("data entry not found"),
}
}
Expand Down
40 changes: 33 additions & 7 deletions massa-execution-worker/src/tests/scenarios_mandatories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1633,19 +1633,45 @@ mod tests {

let events = controller.get_filtered_sc_output_event(EventFilter::default());
// match the events
assert!(!events.is_empty(), "2 events were expected");
let key: Vec<u8> = [1, 0, 4, 255].iter().cloned().collect();
let keys_str: String = key
println!("{:?}", events);
assert_eq!(events.len(), 4, "Got {} events, expected 4", events.len());
let key_a: Vec<u8> = [1, 0, 4, 255].iter().cloned().collect();
let key_a_str: String = key_a
.iter()
.map(|b| format!("{}", b))
.collect::<Vec<String>>()
.join(",");

assert!(events[0].data.contains(&format!("keys: {}", keys_str)));
assert!(events[1].data.contains(&format!("keys2: {}", keys_str)));
let key_b: Vec<u8> = [2, 0, 254, 255].iter().cloned().collect();
let key_b_str: String = key_b
.iter()
.map(|b| format!("{}", b))
.collect::<Vec<String>>()
.join(",");

assert!(
events[0].data.contains(&format!("keys: {}", key_a_str)),
"{:?}",
events[0].data
);
assert!(
events[1].data.contains(&format!("keys2: {}", key_a_str)),
"{:?}",
events[1].data
);
assert!(
events[2].data.contains(&format!("keys_f: {}", key_b_str)),
"{:?}",
events[2].data
);
assert!(
events[3].data.contains(&format!("keys2_f: {}", key_a_str)),
"{:?}",
events[3].data
);

// Length of the value left in the datastore. See sources for more context.
let value_len = [21, 0, 49].len() as u64;
let value_len = ([21, 0, 49].len() + [5, 12, 241].len()) as u64;

assert_eq!(
sample_state
Expand All @@ -1662,7 +1688,7 @@ mod tests {
exec_cfg
.storage_costs_constants
.ledger_cost_per_byte
.saturating_mul_u64(LEDGER_ENTRY_DATASTORE_BASE_SIZE as u64)
.saturating_mul_u64(2 * LEDGER_ENTRY_DATASTORE_BASE_SIZE as u64)
)
// Storage cost value
.saturating_sub(
Expand Down
Binary file modified massa-execution-worker/src/tests/wasm/datastore.wasm
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/datastore_manipulations.wasm
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/deploy_sc.wasm
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/execution_error.wasm
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/get_call_coins_main.wasm
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/get_call_coins_test.wasm
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/init_sc.wasm
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/local_call.wasm
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/local_execution.wasm
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/local_function.wasm
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/nested_call.wasm
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/receive_message.wasm
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/send_message.wasm
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/send_message_condition.wasm
Binary file not shown.
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/send_message_trigger.wasm
Binary file not shown.
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/set_bytecode_fail.wasm
Binary file not shown.
Binary file modified massa-execution-worker/src/tests/wasm/test.wasm
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion tools/setup_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use glob::glob;
use tar::Archive;

// git tag
const TAG: &str = "TEST.20.2";
const TAG: &str = "TEST.20.3";

// Maximum archive file size to download in bytes (here: 1Mb)
// const ARCHIVE_MAX_SIZE: u64 = 2; // Maximum archive file size to download in bytes (DEBUG)
Expand Down