//! The module contains implementations and tests for the `ContractsAssets` table. use crate::{ blueprint::sparse::{ PrimaryKey, Sparse, }, codec::{ primitive::Primitive, raw::Raw, }, column::Column, structured_storage::TableWithBlueprint, tables::{ merkle::{ ContractsAssetsMerkleData, ContractsAssetsMerkleMetadata, }, ContractsAssets, }, Mappable, }; /// The key convertor used to convert the key from the `ContractsAssets` table /// to the key of the `ContractsAssetsMerkleMetadata` table. pub struct KeyConverter; impl PrimaryKey for KeyConverter { type InputKey = ::Key; type OutputKey = ::Key; fn primary_key(key: &Self::InputKey) -> &Self::OutputKey { key.contract_id() } } impl TableWithBlueprint for ContractsAssets { type Blueprint = Sparse< Raw, Primitive<8>, ContractsAssetsMerkleMetadata, ContractsAssetsMerkleData, KeyConverter, >; type Column = Column; fn column() -> Column { Column::ContractsAssets } } #[cfg(test)] mod test { use super::*; fn generate_key( primary_key: &::Key, rng: &mut impl rand::Rng, ) -> ::Key { let mut bytes = [0u8; 32]; rng.fill(bytes.as_mut()); ::Key::new(primary_key, &bytes.into()) } fn generate_key_for_same_contract( rng: &mut impl rand::Rng, ) -> ::Key { generate_key(&fuel_core_types::fuel_tx::ContractId::zeroed(), rng) } crate::basic_storage_tests!( ContractsAssets, ::Key::default(), ::Value::default(), ::Value::default(), generate_key_for_same_contract ); fn generate_value(rng: &mut impl rand::Rng) -> ::Value { rng.gen() } crate::root_storage_tests!( ContractsAssets, ContractsAssetsMerkleMetadata, ::Key::from([1u8; 32]), ::Key::from([2u8; 32]), generate_key, generate_value ); }