Here is the contract that I am trying to run
contract;
pub struct MarketConfiguration {
foo: u64,
bar: u64,
asset_configs: Vec<AssetConfig>,
}
pub struct AssetConfig {
asset: ContractId,
decimals: u8,
blablabla: u64,
}
abi MyContract {
#[storage(write)]
fn initialize(config: MarketConfiguration);
#[storage(read)]
fn get_asset_config_by_asset_id(asset: ContractId) -> AssetConfig;
}
storage {
config: Option<MarketConfiguration> = Option::None,
}
#[storage(read)]
fn get_config() -> MarketConfiguration {
match storage.config {
Option::Some(c) => c,
_ => revert(0),
}
}
#[storage(read)]
fn get_asset_config_by_asset_id_internal(asset: ContractId) -> AssetConfig {
let mut out: Option<AssetConfig> = Option::None;
let config = get_config();
let mut i = 0;
while i < config.asset_configs.len() {
let asset_config = config.asset_configs.get(i).unwrap();
if asset_config.asset == asset {
out = Option::Some(asset_config);
break;
}
i += 1;
}
match out {
Option::Some(v) => v,
Option::None(_) => revert(0),
}
}
impl MyContract for Contract {
#[storage(write)]
fn initialize(config: MarketConfiguration) {
storage.config = Option::Some(config);
}
#[storage(read)]
fn get_asset_config_by_asset_id(asset: ContractId) -> AssetConfig {
get_asset_config_by_asset_id_internal(asset)
}
}
And this is method that should help me to get value out of assets_config
but it fails with the next error:
test can_get_contract_id ... FAILED
failures:
---- can_get_contract_id stdout ----
thread 'can_get_contract_id' panicked at 'called `Result::unwrap()` on an `Err` value: RevertTransactionError("Revert(0)", [Call { id: 0000000000000000000000000000000000000000000000000000000000000000, to: 24a5c44cb5bf5deed72e16117d6c0b1b9a78a15dd16f06a1faff48dcb252fb1f, amount: 0, asset_id: 0000000000000000000000000000000000000000000000000000000000000000, gas: 1000000, param1: 4111974, param2: 10472, pc: 11664, is: 11664 }, Revert { id: 24a5c44cb5bf5deed72e16117d6c0b1b9a78a15dd16f06a1faff48dcb252fb1f, ra: 0, pc: 12368, is: 11664 }, ScriptResult { result: Revert, gas_used: 27264 }])', tests/harness.rs:94:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
can_get_contract_id
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.80s
The repo