use crate::{
contract::{
custom::preferences::{
DevelopperPreferences,
Preferences,
},
runtime::{
BalancesConfig,
Contracts,
RuntimeGenesisConfig,
},
},
EmptyResult,
};
use anyhow::{
bail,
Context,
};
use pallet_contracts::Determinism;
use sp_core::{
crypto::AccountId32,
storage::Storage,
};
use sp_runtime::BuildStorage;
use std::fs;
impl DevelopperPreferences for Preferences {
fn runtime_storage() -> Storage {
let storage = RuntimeGenesisConfig {
balances: BalancesConfig {
balances: (0..u8::MAX) .map(|i| [i; 32].into())
.collect::<Vec<_>>()
.iter()
.cloned()
.map(|k| (k, 10000000000000000000 * 2))
.collect(),
},
..Default::default()
}
.build_storage()
.unwrap();
storage
}
fn on_contract_initialize() -> EmptyResult {
let ink_fuzzed_path: &str = "/tmp/ink_fuzzed_UfY2T";
let adder = Contracts::bare_upload_code(
AccountId32::new([1; 32]),
fs::read(format!("{ink_fuzzed_path}/target/ink/adder/adder.wasm"))
.with_context(|| "â Error reading adder wasm file")?,
None,
Determinism::Enforced,
);
match adder {
Ok(code) => println!("âšī¸ Adder hash: {:?}", code.code_hash),
Err(_) => bail!("â Error uploading adder code"),
}
let accumulator = Contracts::bare_upload_code(
AccountId32::new([1; 32]),
fs::read(format!(
"{ink_fuzzed_path}/target/ink/accumulator/accumulator.wasm",
))
.with_context(|| "â Error reading accumulator wasm file")?,
None,
Determinism::Enforced,
);
match accumulator {
Ok(code) => println!("âšī¸ Accumulator hash: {:?}", code.code_hash),
Err(_) => bail!("â Error uploading accumulator code"),
}
let subber = Contracts::bare_upload_code(
AccountId32::new([1; 32]),
fs::read(format!("{ink_fuzzed_path}/target/ink/subber/subber.wasm"))
.with_context(|| "â Error reading accumulator wasm file")?,
None,
Determinism::Enforced,
);
match subber {
Ok(code) => println!("âšī¸ Subber hash: {:?}", code.code_hash),
Err(_) => bail!("â Error uploading subber code"),
}
Ok(())
}
}