Skip to content

Commit

Permalink
fix: uncomment tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexD10S committed Aug 12, 2024
1 parent 30ed8dc commit 7df9e97
Showing 1 changed file with 134 additions and 136 deletions.
270 changes: 134 additions & 136 deletions crates/extrinsics/src/contract_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,140 +386,138 @@ mod tests {
.ok_or(anyhow!("Type not found"))
}

// #[test]
// fn contract_info_v11_decode_works() {
// // This version of metadata includes the deposit_account field in ContractInfo
// #[subxt::subxt(runtime_metadata_path = "src/test_runtime_api/metadata_v11.scale")]
// mod api_v11 {}

// use api_v11::runtime_types::{
// bounded_collections::bounded_vec::BoundedVec,
// pallet_contracts::storage::{
// ContractInfo as ContractInfoV11,
// DepositAccount,
// },
// };

// let metadata_bytes = std::fs::read("src/test_runtime_api/metadata_v11.scale")
// .expect("the metadata must be present");
// let metadata =
// Metadata::decode(&mut &*metadata_bytes).expect("the metadata must decode");
// let contract_info_type_id = get_metadata_type_index(
// "ContractInfo",
// "pallet_contracts::storage",
// &metadata,
// )
// .expect("the contract info type must be present in the metadata");

// let contract_info_v11 = ContractInfoV11 {
// trie_id: BoundedVec(vec![]),
// deposit_account: DepositAccount(AccountId32([7u8; 32])),
// code_hash: Default::default(),
// storage_bytes: 1,
// storage_items: 1,
// storage_byte_deposit: 1,
// storage_item_deposit: 1,
// storage_base_deposit: 1,
// };

// let contract_info_thunk = DecodedValueThunk::decode_with_metadata(
// &mut &*contract_info_v11.encode(),
// contract_info_type_id as u32,
// &metadata.into(),
// )
// .expect("the contract info must be decoded");

// let contract = AccountId32([0u8; 32]);
// let contract_info_raw =
// ContractInfoRaw::<DefaultConfig, DefaultEnvironment>::new(
// contract,
// contract_info_thunk,
// )
// .expect("the conatract info raw must be created");
// let account_data = AccountData {
// free: 1,
// reserved: 10,
// };

// let contract_info = contract_info_raw.into_contract_info(account_data.clone());
// assert_eq!(
// contract_info,
// ContractInfo {
// trie_id: contract_info_v11.trie_id.0.into(),
// code_hash: contract_info_v11.code_hash,
// storage_items: contract_info_v11.storage_items,
// storage_items_deposit: contract_info_v11.storage_item_deposit,
// storage_total_deposit: account_data.free,
// }
// );
// }

// #[test]
// fn contract_info_v15_decode_works() {
// // This version of metadata does not include the deposit_account field in
// // ContractInfo
// #[subxt::subxt(runtime_metadata_path = "src/test_runtime_api/metadata_v15.scale")]
// mod api_v15 {}

// use api_v15::runtime_types::{
// bounded_collections::{
// bounded_btree_map::BoundedBTreeMap,
// bounded_vec::BoundedVec,
// },
// pallet_contracts::storage::ContractInfo as ContractInfoV15,
// };

// let metadata_bytes = std::fs::read("src/test_runtime_api/metadata_v15.scale")
// .expect("the metadata must be present");
// let metadata =
// Metadata::decode(&mut &*metadata_bytes).expect("the metadata must decode");
// let contract_info_type_id = get_metadata_type_index(
// "ContractInfo",
// "pallet_contracts::storage",
// &metadata,
// )
// .expect("the contract info type must be present in the metadata");

// let contract_info_v15 = ContractInfoV15 {
// trie_id: BoundedVec(vec![]),
// code_hash: Default::default(),
// storage_bytes: 1,
// storage_items: 1,
// storage_byte_deposit: 1,
// storage_item_deposit: 1,
// storage_base_deposit: 1,
// delegate_dependencies: BoundedBTreeMap(vec![]),
// };

// let contract_info_thunk = DecodedValueThunk::decode_with_metadata(
// &mut &*contract_info_v15.encode(),
// contract_info_type_id as u32,
// &metadata.into(),
// )
// .expect("the contract info must be decoded");

// let contract = AccountId32([0u8; 32]);
// let contract_info_raw =
// ContractInfoRaw::<DefaultConfig, DefaultEnvironment>::new(
// contract,
// contract_info_thunk,
// )
// .expect("the conatract info raw must be created");
// let account_data = AccountData {
// free: 1,
// reserved: 10,
// };

// let contract_info = contract_info_raw.into_contract_info(account_data.clone());
// assert_eq!(
// contract_info,
// ContractInfo {
// trie_id: contract_info_v15.trie_id.0.into(),
// code_hash: contract_info_v15.code_hash,
// storage_items: contract_info_v15.storage_items,
// storage_items_deposit: contract_info_v15.storage_item_deposit,
// storage_total_deposit: account_data.reserved,
// }
// );
// }
#[test]
fn contract_info_v11_decode_works() {
// This version of metadata includes the deposit_account field in ContractInfo
#[subxt::subxt(runtime_metadata_path = "src/test_runtime_api/metadata_v11.scale")]
mod api_v11 {}

use api_v11::runtime_types::{
bounded_collections::bounded_vec::BoundedVec,
pallet_contracts::storage::{
ContractInfo as ContractInfoV11, DepositAccount,
},
};

let metadata_bytes = std::fs::read("src/test_runtime_api/metadata_v11.scale")
.expect("the metadata must be present");
let metadata =
Metadata::decode(&mut &*metadata_bytes).expect("the metadata must decode");
let contract_info_type_id = get_metadata_type_index(
"ContractInfo",
"pallet_contracts::storage",
&metadata,
)
.expect("the contract info type must be present in the metadata");

let contract_info_v11 = ContractInfoV11 {
trie_id: BoundedVec(vec![]),
deposit_account: DepositAccount(AccountId32([7u8; 32])),
code_hash: Default::default(),
storage_bytes: 1,
storage_items: 1,
storage_byte_deposit: 1,
storage_item_deposit: 1,
storage_base_deposit: 1,
};

let contract_info_thunk = DecodedValueThunk::decode_with_metadata(
&mut &*contract_info_v11.encode(),
contract_info_type_id as u32,
&metadata.into(),
)
.expect("the contract info must be decoded");

let contract = AccountId32([0u8; 32]);
let contract_info_raw =
ContractInfoRaw::<DefaultConfig, DefaultEnvironment>::new(
contract,
contract_info_thunk,
)
.expect("the conatract info raw must be created");
let account_data = AccountData {
free: 1,
reserved: 10,
};

let contract_info = contract_info_raw.into_contract_info(account_data.clone());
assert_eq!(
contract_info,
ContractInfo {
trie_id: contract_info_v11.trie_id.0.into(),
code_hash: contract_info_v11.code_hash,
storage_items: contract_info_v11.storage_items,
storage_items_deposit: contract_info_v11.storage_item_deposit,
storage_total_deposit: account_data.free,
}
);
}

#[test]
fn contract_info_v15_decode_works() {
// This version of metadata does not include the deposit_account field in
// ContractInfo
#[subxt::subxt(runtime_metadata_path = "src/test_runtime_api/metadata_v15.scale")]
mod api_v15 {}

use api_v15::runtime_types::{
bounded_collections::{
bounded_btree_map::BoundedBTreeMap, bounded_vec::BoundedVec,
},
pallet_contracts::storage::ContractInfo as ContractInfoV15,
};

let metadata_bytes = std::fs::read("src/test_runtime_api/metadata_v15.scale")
.expect("the metadata must be present");
let metadata =
Metadata::decode(&mut &*metadata_bytes).expect("the metadata must decode");
let contract_info_type_id = get_metadata_type_index(
"ContractInfo",
"pallet_contracts::storage",
&metadata,
)
.expect("the contract info type must be present in the metadata");

let contract_info_v15 = ContractInfoV15 {
trie_id: BoundedVec(vec![]),
code_hash: Default::default(),
storage_bytes: 1,
storage_items: 1,
storage_byte_deposit: 1,
storage_item_deposit: 1,
storage_base_deposit: 1,
delegate_dependencies: BoundedBTreeMap(vec![]),
};

let contract_info_thunk = DecodedValueThunk::decode_with_metadata(
&mut &*contract_info_v15.encode(),
contract_info_type_id as u32,
&metadata.into(),
)
.expect("the contract info must be decoded");

let contract = AccountId32([0u8; 32]);
let contract_info_raw =
ContractInfoRaw::<DefaultConfig, DefaultEnvironment>::new(
contract,
contract_info_thunk,
)
.expect("the conatract info raw must be created");
let account_data = AccountData {
free: 1,
reserved: 10,
};

let contract_info = contract_info_raw.into_contract_info(account_data.clone());
assert_eq!(
contract_info,
ContractInfo {
trie_id: contract_info_v15.trie_id.0.into(),
code_hash: contract_info_v15.code_hash,
storage_items: contract_info_v15.storage_items,
storage_items_deposit: contract_info_v15.storage_item_deposit,
storage_total_deposit: account_data.reserved,
}
);
}
}

0 comments on commit 7df9e97

Please sign in to comment.