Skip to content

Commit

Permalink
test(runtime): append MemoryWeights and syscalls heuristic tests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteNacked authored Apr 19, 2024
1 parent e1fb708 commit 9c85ad5
Show file tree
Hide file tree
Showing 2 changed files with 246 additions and 3 deletions.
145 changes: 144 additions & 1 deletion runtime/common/src/weights.rs

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

104 changes: 102 additions & 2 deletions runtime/vara/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
use super::*;
use crate::Runtime;
use gear_lazy_pages_common::LazyPagesCosts;
use pallet_gear::{InstructionWeights, MemoryWeights};
use runtime_common::weights::{check_instructions_weights, check_lazy_pages_costs};
use pallet_gear::{InstructionWeights, MemoryWeights, SyscallWeights};
use runtime_common::weights::{
check_instructions_weights, check_lazy_pages_costs, check_pages_costs, check_syscall_weights,
PagesCosts,
};

#[test]
fn instruction_weights_heuristics_test() {
Expand Down Expand Up @@ -129,8 +132,105 @@ fn instruction_weights_heuristics_test() {
check_instructions_weights(weights, expected_weights);
}

#[test]
fn syscall_weights_test() {
let weights = SyscallWeights::<Runtime>::default();

let expected = SyscallWeights {
alloc: 8_000_000.into(),
alloc_per_page: 247_000.into(),
free: 628_000.into(),
free_range: 772_000.into(),
free_range_per_page: 63_000.into(),
gr_reserve_gas: 2_300_000.into(),
gr_unreserve_gas: 1_900_000.into(),
gr_system_reserve_gas: 1_000_000.into(),
gr_gas_available: 932_300.into(),
gr_message_id: 926_500.into(),
gr_program_id: 930_100.into(),
gr_source: 930_700.into(),
gr_value: 945_700.into(),
gr_value_available: 967_900.into(),
gr_size: 926_900.into(),
gr_read: 1_700_000.into(),
gr_read_per_byte: 157.into(),
gr_env_vars: 1_000_000.into(),
gr_block_height: 925_900.into(),
gr_block_timestamp: 933_000.into(),
gr_random: 1_900_000.into(),
gr_reply_deposit: 6_500_000.into(),
gr_send: 3_200_000.into(),
gr_send_per_byte: 373.into(),
gr_send_wgas: 3_300_000.into(),
gr_send_wgas_per_byte: 382.into(),
gr_send_init: 1_000_000.into(),
gr_send_push: 2_000_000.into(),
gr_send_push_per_byte: 379.into(),
gr_send_commit: 2_700_000.into(),
gr_send_commit_wgas: 2_700_000.into(),
gr_reservation_send: 3_400_000.into(),
gr_reservation_send_per_byte: 376.into(),
gr_reservation_send_commit: 2_900_000.into(),
gr_reply_commit: 21_300_000.into(),
gr_reply_commit_wgas: 19_200_000.into(),
gr_reservation_reply: 8_300_000.into(),
gr_reservation_reply_per_byte: 584_500.into(),
gr_reservation_reply_commit: 10_400_000.into(),
gr_reply_push: 1_700_000.into(),
gr_reply: 22_500_000.into(),
gr_reply_per_byte: 564.into(),
gr_reply_wgas: 21_400_000.into(),
gr_reply_wgas_per_byte: 575.into(),
gr_reply_push_per_byte: 640.into(),
gr_reply_to: 950_200.into(),
gr_signal_code: 962_500.into(),
gr_signal_from: 941_500.into(),
gr_reply_input: 25_900_000.into(),
gr_reply_input_wgas: 24_600_000.into(),
gr_reply_push_input: 1_200_000.into(),
gr_reply_push_input_per_byte: 146.into(),
gr_send_input: 3_100_000.into(),
gr_send_input_wgas: 3_100_000.into(),
gr_send_push_input: 1_500_000.into(),
gr_send_push_input_per_byte: 165.into(),
gr_debug: 1_200_000.into(),
gr_debug_per_byte: 316.into(),
gr_reply_code: 919_800.into(),
gr_exit: 24_100_000.into(),
gr_leave: 12_500_000.into(),
gr_wait: 11_400_000.into(),
gr_wait_for: 9_900_000.into(),
gr_wait_up_to: 11_600_000.into(),
gr_wake: 3_700_000.into(),
gr_create_program: 4_100_000.into(),
gr_create_program_payload_per_byte: 78.into(),
gr_create_program_salt_per_byte: 1_900.into(),
gr_create_program_wgas: 4_100_000.into(),
gr_create_program_wgas_payload_per_byte: 88.into(),
gr_create_program_wgas_salt_per_byte: 1_900.into(),
_phantom: Default::default(),
};

check_syscall_weights(weights, expected);
}

#[test]
fn page_costs_heuristic_test() {
let page_costs: PagesCosts = MemoryWeights::<Runtime>::default().into();

let expected_page_costs = PagesCosts {
load_page_data: 10_000_000.into(),
upload_page_data: 105_000_000.into(),
static_page: 100.into(),
mem_grow: 1_100_000.into(),
parachain_read_heuristic: 0.into(),
};

check_pages_costs(page_costs, expected_page_costs);
}

#[test]
fn lazy_page_costs_heuristic_test() {
let lazy_pages_costs: LazyPagesCosts = MemoryWeights::<Runtime>::default().into();

let expected_lazy_pages_costs = LazyPagesCosts {
Expand Down

0 comments on commit 9c85ad5

Please sign in to comment.