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

[compiler-v2]Fix chain, config, rpc, txpool test mod #4278

Merged
merged 2 commits into from
Nov 12, 2024
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
4 changes: 2 additions & 2 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ once_cell = { workspace = true }
serde_json = { features = ["arbitrary_precision"], workspace = true }

[dev-dependencies]
move-core-types = { workspace = true }
proptest = { workspace = true }
proptest-derive = { workspace = true }
starcoin-account-api = { workspace = true }
Expand All @@ -51,7 +52,11 @@ starcoin-force-upgrade = { workspace = true }
[features]
default = []
fuzzing = ["proptest", "proptest-derive", "starcoin-types/fuzzing"]
force-deploy = ["starcoin-vm-runtime/force-deploy", "starcoin-vm-runtime", "starcoin-executor/force-deploy"]
force-deploy = [
"starcoin-vm-runtime/force-deploy",
"starcoin-vm-runtime",
"starcoin-executor/force-deploy",
]

[package]
authors = { workspace = true }
Expand Down
9 changes: 5 additions & 4 deletions chain/tests/test_block_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn test_chain_filter_events() {
address: genesis_address(),
module: Identifier::from_str("Block").unwrap(),
name: Identifier::from_str("NewBlockEventV2").unwrap(),
type_params: vec![],
type_args: vec![],
}));

// Origin block event index is 4, after https://github.com/starcoinorg/starcoin-framework/pull/42 , Genesis account create more event_handles, so the block event index is 7.
Expand Down Expand Up @@ -558,10 +558,11 @@ fn test_gen_dag_chain() -> Result<()> {

let effective_height = chain
.chain_state()
.get_on_chain_config::<FlexiDagConfig>()?
.map(|c| c.effective_height);
.get_on_chain_config::<FlexiDagConfig>()
.unwrap()
.effective_height;

assert_eq!(effective_height, Some(fork_number));
assert_eq!(effective_height, fork_number);
assert_eq!(chain.current_header().number(), 9);

let fork_number = thread_rng().gen_range(0..=9);
Expand Down
4 changes: 2 additions & 2 deletions chain/tests/test_opened_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ pub fn test_open_block() -> Result<()> {
{
let account_reader = opened_block.state_reader();
let account_balance = account_reader.get_balance(receiver)?;
assert_eq!(account_balance, Some(50_000_000));
assert_eq!(account_balance, 50_000_000);

let account_resource = account_reader.get_account_resource(receiver)?.unwrap();
let account_resource = account_reader.get_account_resource(receiver)?;
assert_eq!(account_resource.sequence_number(), 0);
}

Expand Down
2 changes: 1 addition & 1 deletion chain/tests/test_txn_info_and_proof.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::{format_err, Result};
use move_core_types::move_resource::MoveStructType;
use rand::Rng;
use starcoin_account_api::AccountInfo;
use starcoin_accumulator::Accumulator;
Expand All @@ -12,7 +13,6 @@ use starcoin_types::account_config;
use starcoin_vm_types::access_path::AccessPath;
use starcoin_vm_types::account_address::AccountAddress;
use starcoin_vm_types::account_config::AccountResource;
use starcoin_vm_types::move_resource::MoveResource;
use starcoin_vm_types::state_view::StateReaderExt;
use starcoin_vm_types::transaction::{SignedUserTransaction, Transaction};
use std::collections::HashMap;
Expand Down
23 changes: 12 additions & 11 deletions config/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,9 @@ pub static G_VEGA_CONFIG: Lazy<GenesisConfig> = Lazy::new(|| {

#[cfg(test)]
mod tests {
use starcoin_gas_algebra::{CostTable, FromOnChainGasSchedule};
use starcoin_gas_algebra::CostTable;
use starcoin_gas_meter::StarcoinGasParameters;
use starcoin_gas_schedule::FromOnChainGasSchedule;
use starcoin_vm_types::gas_schedule::{
latest_cost_table, G_GAS_CONSTANTS_V1, G_GAS_CONSTANTS_V2, G_LATEST_GAS_COST_TABLE,
G_TEST_GAS_CONSTANTS,
Expand Down Expand Up @@ -1272,9 +1273,9 @@ mod tests {
let gas_schedule = GasSchedule::from(&latest_cost_table(G_TEST_GAS_CONSTANTS.clone()));
assert_eq!(entries, gas_schedule.entries);
let gas_params =
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map());
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map(), 6);
assert_eq!(
gas_params.unwrap().natives.nursery.debug.print.base_cost,
gas_params.unwrap().natives.nursery.debug_print_base_cost,
1.into()
);
}
Expand All @@ -1290,9 +1291,9 @@ mod tests {
let gas_schedule = GasSchedule::from(&G_LATEST_GAS_COST_TABLE.clone());
assert_eq!(entries, gas_schedule.entries);
let gas_params =
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map());
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map(), 6);
assert_eq!(
gas_params.unwrap().natives.nursery.debug.print.base_cost,
gas_params.unwrap().natives.nursery.debug_print_base_cost,
1.into()
);
}
Expand All @@ -1307,9 +1308,9 @@ mod tests {
let gas_schedule = GasSchedule::from(&G_LATEST_GAS_COST_TABLE.clone());
assert_eq!(entries, gas_schedule.entries);
let gas_params =
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map());
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map(), 6);
assert_eq!(
gas_params.unwrap().natives.nursery.debug.print.base_cost,
gas_params.unwrap().natives.nursery.debug_print_base_cost,
1.into()
);
}
Expand All @@ -1328,9 +1329,9 @@ mod tests {
});
assert_eq!(entries, gas_schedule.entries);
let gas_params =
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map());
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map(), 6);
assert_eq!(
gas_params.unwrap().natives.nursery.debug.print.base_cost,
gas_params.unwrap().natives.nursery.debug_print_base_cost,
1.into()
);
}
Expand All @@ -1350,9 +1351,9 @@ mod tests {
});
assert_eq!(entries, gas_schedule.entries);
let gas_params =
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map());
StarcoinGasParameters::from_on_chain_gas_schedule(&gas_schedule.to_btree_map(), 6);
assert_eq!(
gas_params.unwrap().natives.nursery.debug.print.base_cost,
gas_params.unwrap().natives.nursery.debug_print_base_cost,
1.into()
);
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/server/src/module/pubsub/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub async fn test_subscribe_to_events() -> Result<()> {

let reader = block_chain.chain_state_reader();
let balance = reader.get_balance(account_address)?;
assert_eq!(balance, Some(10000));
assert_eq!(balance, 10000);

// now block is applied, we can emit events.

Expand Down
13 changes: 5 additions & 8 deletions state/statedb/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ use starcoin_types::access_path::AccessPath;
use starcoin_types::write_set::{WriteOp, WriteSet, WriteSetMut};
use starcoin_vm_types::account_config::AccountResource;
use starcoin_vm_types::move_resource::MoveResource;
use starcoin_vm_types::state_store::state_key::{StateKey, TableItem};
use starcoin_vm_types::state_store::state_key::StateKey;
use std::collections::HashMap;

fn random_bytes() -> Vec<u8> {
HashValue::random().to_vec()
}

fn to_write_set(access_path: AccessPath, value: Vec<u8>) -> WriteSet {
WriteSetMut::new(vec![(
StateKey::AccessPath(access_path),
WriteOp::Value(value),
)])
.freeze()
.expect("freeze write_set must success.")
fn to_write_set(state_key: StateKey, value: Vec<u8>) -> WriteSet {
WriteSetMut::new(vec![(state_key, WriteOp::Value(value))])
.freeze()
.expect("freeze write_set must success.")
}

fn state_keys_to_write_set(state_keys: Vec<StateKey>, values: Vec<Vec<u8>>) -> WriteSet {
Expand Down
3 changes: 1 addition & 2 deletions txpool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ linked-hash-map = { workspace = true }
log = { workspace = true }
network-api = { workspace = true }
parking_lot = { workspace = true }
rand = { workspace = true }
rand_core = { default-features = false, workspace = true }
serde = { workspace = true }
starcoin-config = { workspace = true }
starcoin-crypto = { workspace = true }
Expand All @@ -33,6 +31,7 @@ proptest-derive = { optional = true, workspace = true }
[dev-dependencies]
proptest = { workspace = true }
proptest-derive = { workspace = true }
rand_0_7_3 = { workspace = true }
starcoin-genesis = { workspace = true }
starcoin-open-block = { workspace = true }
starcoin-transaction-builder = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions txpool/src/pool/listener/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use rand::SeedableRng;
use rand_0_7_3::SeedableRng;
use starcoin_crypto::{ed25519, Uniform};

use starcoin_types::genesis_config::ChainId;
Expand Down Expand Up @@ -88,7 +88,7 @@ fn new_tx() -> Arc<Transaction> {
get_current_timestamp() + 60,
ChainId::test(),
);
let mut rng = rand::rngs::StdRng::from_seed([0; 32]);
let mut rng = rand_0_7_3::rngs::StdRng::from_seed([0; 32]);
let private_key = ed25519::Ed25519PrivateKey::generate(&mut rng);
let public_key = (&private_key).into();

Expand Down
Loading