Skip to content

Commit

Permalink
Reproduce compute and gas costs mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
aborg-dev committed Apr 11, 2023
1 parent d362880 commit dfc0bce
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions runtime/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ impl Runtime {

#[cfg(test)]
mod tests {
#[cfg(feature = "protocol_feature_compute_costs")]
// #[cfg(feature = "protocol_feature_compute_costs")]
use assert_matches::assert_matches;
use near_crypto::{InMemorySigner, KeyType, Signer};
use near_primitives::account::AccessKey;
Expand All @@ -1611,7 +1611,7 @@ mod tests {
use near_store::set_access_key;
use near_store::test_utils::create_tries;
use near_store::StoreCompiledContractCache;
#[cfg(feature = "protocol_feature_compute_costs")]
// #[cfg(feature = "protocol_feature_compute_costs")]
use near_vm_logic::{ExtCosts, ParameterCost};
use near_vm_runner::get_contract_cache_key;
use near_vm_runner::internal::VMKind;
Expand Down Expand Up @@ -2513,6 +2513,7 @@ mod tests {
assert_eq!(final_account_state.storage_usage(), 0);
}

#[cfg_attr(all(target_arch = "aarch64", target_vendor = "apple"), ignore)]
#[test]
fn test_contract_precompilation() {
let initial_balance = to_yocto(1_000_000);
Expand Down Expand Up @@ -2553,6 +2554,51 @@ mod tests {
.expect("Compilation result should be non-empty");
}

#[test]
fn test_old_compute_usage_limit() {
let (runtime, tries, root, apply_state, signer, epoch_info_provider) =
setup_runtime(to_yocto(1_000_000), to_yocto(500_000), 10u64.pow(15));

let deploy_contract_receipt = create_receipt_with_actions(
alice_account(),
signer.clone(),
vec![Action::DeployContract(DeployContractAction {
code: near_test_contracts::rs_contract().to_vec(),
})],
);

let first_call_receipt = create_receipt_with_actions(
alice_account(),
signer.clone(),
vec![Action::FunctionCall(FunctionCallAction {
method_name: "ext_sha256".to_string(),
args: b"first".to_vec(),
gas: 1,
deposit: 0,
})],
);

let apply_result = runtime
.apply(
tries.get_trie_for_shard(ShardUId::single_shard(), root),
&None,
&apply_state,
&vec![deploy_contract_receipt.clone(), first_call_receipt.clone()],
&[],
&epoch_info_provider,
Default::default(),
)
.unwrap();

assert_matches!(&apply_result.outcomes[..], [first, second] => {
assert_eq!(first.id, deploy_contract_receipt.receipt_id);
assert_matches!(first.outcome.status, ExecutionStatus::SuccessValue(_));

assert_eq!(second.id, first_call_receipt.receipt_id);
assert_matches!(second.outcome.status, ExecutionStatus::SuccessValue(_));
});
}

#[cfg(feature = "protocol_feature_compute_costs")]
#[test]
fn test_compute_usage_limit() {
Expand Down

0 comments on commit dfc0bce

Please sign in to comment.