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

Fix roll sell. #3392

Merged
merged 1 commit into from
Jan 9, 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
6 changes: 3 additions & 3 deletions massa-execution-worker/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,9 @@ impl ExecutionContext {
pub fn settle_slot(&mut self) -> ExecutionOutput {
let slot = self.slot;

// execute the deferred credits coming from roll sells
self.execute_deferred_credits(&slot);

// settle emitted async messages and reimburse the senders of deleted messages
let ledger_changes = self.speculative_ledger.take();
let deleted_messages = self
Expand All @@ -695,9 +698,6 @@ impl ExecutionContext {
self.cancel_async_message(&msg);
}

// execute the deferred credits coming from roll sells
self.execute_deferred_credits(&slot);

// if the current slot is last in cycle check the production stats and act accordingly
if self
.slot
Expand Down
17 changes: 17 additions & 0 deletions massa-execution-worker/src/tests/scenarios_mandatories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,9 @@ pub fn roll_sell() {
let keypair = KeyPair::from_str("S1JJeHiZv1C1zZN5GLFcbz6EXYiccmUPLkYuDFA3kayjxP39kFQ").unwrap();
let address = Address::from_public_key(&keypair.get_public_key());

// get initial balance
let balance_initial = sample_state.read().ledger.get_balance(&address).unwrap();

// get initial roll count
let roll_count_initial = sample_state.read().pos_state.get_rolls_for(&address);
let roll_sell_1 = 10;
Expand Down Expand Up @@ -915,6 +918,20 @@ pub fn roll_sell() {
credits
);

// Now check balance
let balances = controller.get_final_and_candidate_balance(&[address]);
let candidate_balance = balances.get(0).unwrap().1.unwrap();

assert_eq!(
candidate_balance,
exec_cfg
.roll_price
.checked_mul_u64(roll_sell_1 + roll_sell_2)
.unwrap()
.checked_add(balance_initial)
.unwrap()
);

// stop the execution controller
manager.stop();
}
Expand Down