Skip to content

Commit

Permalink
Promote instruction counts to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Br1ght0ne committed Dec 13, 2023
1 parent 377536a commit e179563
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions packages/fuels-programs/src/call_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,12 @@ mod test {

// movi, movi, lw, movi + call (for gas)
const BASE_INSTRUCTION_COUNT: usize = 5;
// 2 instructions (movi and lw) added in get_single_call_instructions when gas_offset is set
const GAS_OFFSET_INSTRUCTION_COUNT: usize = 2;
// 4 instructions (lw, lw, muli, retd) added by extract_data_receipt
const EXTRACT_DATA_RECEIPT_INSTRUCTION_COUNT: usize = 4;
// 4 instructions (movi, lw, jnef, retd) added by extract_heap_data
const EXTRACT_HEAP_DATA_INSTRUCTION_COUNT: usize = 4;

#[test]
fn test_simple() {
Expand All @@ -971,8 +977,7 @@ mod test {
let instructions_len = compute_calls_instructions_len(&[call]).unwrap();
assert_eq!(
instructions_len,
// 2 instructions (movi and lw) added in get_single_call_instructions when gas_offset is set
Instruction::SIZE * (BASE_INSTRUCTION_COUNT + 2)
Instruction::SIZE * (BASE_INSTRUCTION_COUNT + GAS_OFFSET_INSTRUCTION_COUNT)
);
}

Expand All @@ -989,8 +994,8 @@ mod test {
let instructions_len = compute_calls_instructions_len(&[call]).unwrap();
assert_eq!(
instructions_len,
// 4 instructions (lw, lw, muli, retd) added by extract_data_receipt
Instruction::SIZE * (BASE_INSTRUCTION_COUNT + 4)
Instruction::SIZE
* (BASE_INSTRUCTION_COUNT + EXTRACT_DATA_RECEIPT_INSTRUCTION_COUNT)
);
}
}
Expand All @@ -1004,7 +1009,10 @@ mod test {
assert_eq!(
instructions_len,
// combines extra instructions from two above tests
Instruction::SIZE * (BASE_INSTRUCTION_COUNT + 2 + 4)
Instruction::SIZE
* (BASE_INSTRUCTION_COUNT
+ GAS_OFFSET_INSTRUCTION_COUNT
+ EXTRACT_DATA_RECEIPT_INSTRUCTION_COUNT)
);
}

Expand All @@ -1024,9 +1032,10 @@ mod test {
let instructions_len = compute_calls_instructions_len(&[call]).unwrap();
assert_eq!(
instructions_len,
// 4 instructions (movi, lw, jnef, retd) added by extract_heap_data
// and 4 (lw, lw, muli, retd) added by extract_data_receipt
Instruction::SIZE * (BASE_INSTRUCTION_COUNT + 8)
Instruction::SIZE
* (BASE_INSTRUCTION_COUNT
+ EXTRACT_DATA_RECEIPT_INSTRUCTION_COUNT
+ EXTRACT_HEAP_DATA_INSTRUCTION_COUNT)
);
}
}
Expand Down

0 comments on commit e179563

Please sign in to comment.