Skip to content

Commit

Permalink
test: update v15 metadata and remove v11
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexD10S committed Aug 16, 2024
1 parent 643bb61 commit e9031fc
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 68 deletions.
68 changes: 0 additions & 68 deletions crates/extrinsics/src/contract_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,74 +406,6 @@ 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
Expand Down
Binary file not shown.
Binary file modified crates/extrinsics/src/test_runtime_api/metadata_v15.scale
Binary file not shown.

0 comments on commit e9031fc

Please sign in to comment.