Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
fix(test): test_cases/pre_compiled_contracts.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Flouse authored and jjyr committed Nov 7, 2022
1 parent 41ccdeb commit 39e5ed7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions polyjuice-tests/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use gw_traits::CodeStore;
use gw_types::{
bytes::Bytes,
core::{AllowedContractType, AllowedEoaType, ScriptHashType},
offchain::{RunResult, RunResultCycles},
offchain::{RunResult, CycleMeter},
packed::{
AllowedTypeHash, BatchSetMapping, BlockInfo, Fee, LogItem, RawL2Transaction, RollupConfig,
Script, SetMapping, Uint64,
Expand Down Expand Up @@ -725,7 +725,7 @@ pub(crate) fn create_eth_eoa_account(
(account_id, script_hash)
}

pub(crate) fn check_cycles(l2_tx_label: &str, cycles: RunResultCycles, warning_cycles: u64) {
pub(crate) fn check_cycles(l2_tx_label: &str, cycles: CycleMeter, warning_cycles: u64) {
if POLYJUICE_GENERATOR_NAME.contains("_log") {
return; // disable cycles check
}
Expand Down
2 changes: 1 addition & 1 deletion polyjuice-tests/src/test_cases/create2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn test_create2() {
// [Create2Impl.deploy(...)] used cycles: 1197555 < 1230K
helper::check_cycles(
"Create2Impl.deploy(...)",
run_result.cycles,
run_result.cycles.to_owned(),
1_750_000,
);
state.finalise().expect("update state");
Expand Down
28 changes: 14 additions & 14 deletions polyjuice-tests/src/test_cases/pre_compiled_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,14 @@ fn test_bn256_pairing() -> anyhow::Result<()> {
.to_id(contract_account_id.pack())
.args(Bytes::from(args).pack())
.build();
let db = store.begin_transaction();
let db = &store.begin_transaction();
let tip_block_hash = db.get_tip_block_hash().unwrap();

let t = std::time::Instant::now();
let run_result = generator
.execute_transaction(
&gw_store::chain_view::ChainView::new(&db, tip_block_hash),
&state,
&mut state,
&new_block_info(block_producer.clone(), block_number, 0),
&raw_tx,
L2TX_MAX_CYCLES,
Expand All @@ -282,15 +282,15 @@ fn test_bn256_pairing() -> anyhow::Result<()> {
// time consumed
println!("[Bn256Pairing] {case_name} elapsed {}ms", t.elapsed().as_millis());

crate::helper::print_gas_used(case_name, &run_result.write.logs);
crate::helper::print_gas_used(case_name, &run_result.logs);

assert_eq!(run_result.exit_code, crate::constant::EVMC_SUCCESS);
assert_eq!(
run_result.return_data,
hex::decode(expected_output_hex).unwrap()
);

crate::helper::check_cycles(case_name, run_result.cycles, 860_000 + input_len / 192 * 34_000 * 3);
crate::helper::check_cycles(case_name, run_result.cycles, 1_320_000 + input_len / 192 * 34_000 * 3);
}
Ok(())
}
Expand Down Expand Up @@ -346,12 +346,12 @@ fn test_bn256_add() -> anyhow::Result<()> {
.to_id(contract_account_id.pack())
.args(Bytes::from(args).pack())
.build();
let db = store.begin_transaction();
let db = &store.begin_transaction();
let tip_block_hash = db.get_tip_block_hash().unwrap();
let run_result = generator
.execute_transaction(
&gw_store::chain_view::ChainView::new(&db, tip_block_hash),
&state,
&mut state,
&new_block_info(block_producer.clone(), block_number, 0),
&raw_tx,
L2TX_MAX_CYCLES,
Expand Down Expand Up @@ -457,14 +457,14 @@ fn test_bn256_add() -> anyhow::Result<()> {
.to_id(contract_account_id.pack())
.args(Bytes::from(args).pack())
.build();
let db = store.begin_transaction();
let db = &store.begin_transaction();
let tip_block_hash = db.get_tip_block_hash().unwrap();

let t = std::time::Instant::now();
let run_result = generator
.execute_transaction(
&gw_store::chain_view::ChainView::new(&db, tip_block_hash),
&state,
&mut state,
&new_block_info(block_producer.clone(), block_number, 0),
&raw_tx,
L2TX_MAX_CYCLES,
Expand All @@ -474,7 +474,7 @@ fn test_bn256_add() -> anyhow::Result<()> {
// time consumed
println!("[Bn256Add] {case_name} elapsed {}ms", t.elapsed().as_millis());

crate::helper::print_gas_used(case_name, &run_result.write.logs);
crate::helper::print_gas_used(case_name, &run_result.logs);

assert_eq!(run_result.exit_code, crate::constant::EVMC_SUCCESS);
assert_eq!(
Expand Down Expand Up @@ -538,12 +538,12 @@ fn test_bn256_scalar_mul() -> anyhow::Result<()> {
.to_id(contract_account_id.pack())
.args(Bytes::from(args).pack())
.build();
let db = store.begin_transaction();
let db = &store.begin_transaction();
let tip_block_hash = db.get_tip_block_hash().unwrap();
let run_result = generator
.execute_transaction(
&gw_store::chain_view::ChainView::new(&db, tip_block_hash),
&state,
&mut state,
&new_block_info(block_producer.clone(), block_number, 0),
&raw_tx,
L2TX_MAX_CYCLES,
Expand Down Expand Up @@ -668,14 +668,14 @@ fn test_bn256_scalar_mul() -> anyhow::Result<()> {
.to_id(contract_account_id.pack())
.args(Bytes::from(args).pack())
.build();
let db = store.begin_transaction();
let db = &store.begin_transaction();
let tip_block_hash = db.get_tip_block_hash().unwrap();

let t = std::time::Instant::now();
let run_result = generator
.execute_transaction(
&gw_store::chain_view::ChainView::new(&db, tip_block_hash),
&state,
&mut state,
&new_block_info(block_producer.clone(), block_number, 0),
&raw_tx,
L2TX_MAX_CYCLES,
Expand All @@ -684,7 +684,7 @@ fn test_bn256_scalar_mul() -> anyhow::Result<()> {
.expect(case_name);
// time consumed
println!("[bn256ScalarMul] {case_name} elapsed {}ms", t.elapsed().as_millis());
crate::helper::print_gas_used(case_name, &run_result.write.logs);
crate::helper::print_gas_used(case_name, &run_result.logs);

assert_eq!(run_result.exit_code, crate::constant::EVMC_SUCCESS);
assert_eq!(
Expand Down

0 comments on commit 39e5ed7

Please sign in to comment.