Skip to content

Commit

Permalink
Test : Add 2nd call in scenario and check total_gas
Browse files Browse the repository at this point in the history
  • Loading branch information
modship committed Aug 30, 2024
1 parent d49dda7 commit f43fdea
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions massa-execution-worker/src/tests/scenarios_mandatories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,22 @@ fn deferred_calls() {
cancelled: false,
};

let call2 = DeferredCall {
sender_address: Address::from_str("AU1TyzwHarZMQSVJgxku8co7xjrRLnH74nFbNpoqNd98YhJkWgi")
.unwrap(),
target_slot: Slot {
period: 8,
thread: 1,
},
target_address: destination,
target_function: "tata".to_string(),
parameters: vec![42, 42, 42, 42],
coins: Amount::from_raw(100),
max_gas: 700_000,
fee: Amount::from_raw(1),
cancelled: false,
};

let call_id =
DeferredCallId::new(0, target_slot, 0, "trail_hash".to_string().as_bytes()).unwrap();

Expand Down Expand Up @@ -1060,8 +1076,11 @@ fn deferred_calls() {
// call was executed and then deleted
assert_eq!(set_delete, &SetOrDelete::Delete);

// total gas was set to 0
assert_eq!(changes.deferred_call_changes.total_gas, SetOrKeep::Set(0));
// // total gas was set to 700_000 (call2.max_gas)
assert_eq!(
changes.deferred_call_changes.total_gas,
SetOrKeep::Set(700_000)
);
finalized_waitpoint_trigger_handle2.trigger();
});

Expand All @@ -1075,18 +1094,40 @@ fn deferred_calls() {
gas: massa_deferred_calls::DeferredRegistryGasChange::Set(call.max_gas.into()),

Check failure on line 1094 in massa-execution-worker/src/tests/scenarios_mandatories.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `u64`

error: useless conversion to the same type: `u64` --> massa-execution-worker/src/tests/scenarios_mandatories.rs:1094:67 | 1094 | gas: massa_deferred_calls::DeferredRegistryGasChange::Set(call.max_gas.into()), | ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `call.max_gas` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `-D clippy::useless-conversion` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::useless_conversion)]`
base_fee: massa_deferred_calls::DeferredRegistryBaseFeeChange::Keep,
};

defer_reg_slot_changes.set_call(call_id.clone(), call.clone());

let call_id2 = DeferredCallId::new(
0,
Slot {
period: 8,
thread: 1,
},
0,
"trail_hash".to_string().as_bytes(),
)
.unwrap();

let mut defer_reg_slot_changes2 = defer_reg_slot_changes.clone();
defer_reg_slot_changes2.set_gas(call2.max_gas.into());

Check failure on line 1111 in massa-execution-worker/src/tests/scenarios_mandatories.rs

View workflow job for this annotation

GitHub Actions / clippy

useless conversion to the same type: `u64`

error: useless conversion to the same type: `u64` --> massa-execution-worker/src/tests/scenarios_mandatories.rs:1111:37 | 1111 | defer_reg_slot_changes2.set_gas(call2.max_gas.into()); | ^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `call2.max_gas` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
defer_reg_slot_changes2.set_call(call_id2, call2.clone());

let mut slot_changes = BTreeMap::default();
slot_changes.insert(target_slot, defer_reg_slot_changes);

slot_changes.insert(
Slot {
period: 8,
thread: 1,
},
defer_reg_slot_changes2,
);

let mut db_batch = DBBatch::default();

registry.apply_changes_to_batch(
DeferredCallRegistryChanges {
slots_change: slot_changes,
total_gas: SetOrKeep::Set(call.max_gas.into()),
total_gas: SetOrKeep::Set(call.max_gas.saturating_add(call2.max_gas).into()),
},
&mut db_batch,
);
Expand Down

0 comments on commit f43fdea

Please sign in to comment.