Skip to content

Commit

Permalink
contracts: Refactor trait Ext::*_storage_transparent functions (#13…
Browse files Browse the repository at this point in the history
…600)

* Refactor _transparent methods

rewrote commits, stashed the typo changes to remove some diff noise
fixed my unverified email commit

* remove type alias

* Get rid of From<Fix/VarSizedKey> impl blocks

* Get rid of KeyType impl block

* remove unnecessary Key export

* Update frame/contracts/src/exec.rs

Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>

* PR review comment

---------

Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
  • Loading branch information
pgherveou and agryaznov authored Mar 17, 2023
1 parent 6c3747b commit 8fcd235
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 296 deletions.
6 changes: 1 addition & 5 deletions substrate/bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,11 +710,7 @@ fn deploying_wasm_contract_should_work() {
t.execute_with(|| {
// Verify that the contract does exist by querying some of its storage items
// It does not matter that the storage item itself does not exist.
assert!(&pallet_contracts::Pallet::<Runtime>::get_storage(
addr,
pallet_contracts::StorageKey::<Runtime>::default().to_vec()
)
.is_ok());
assert!(&pallet_contracts::Pallet::<Runtime>::get_storage(addr, vec![]).is_ok());
});
}

Expand Down
28 changes: 14 additions & 14 deletions substrate/frame/contracts/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use self::{
sandbox::Sandbox,
};
use crate::{
exec::{AccountIdOf, FixSizedKey, VarSizedKey},
exec::{AccountIdOf, Key},
wasm::CallFlags,
Pallet as Contracts, *,
};
Expand Down Expand Up @@ -135,10 +135,10 @@ where
}

/// Store the supplied storage items into this contracts storage.
fn store(&self, items: &Vec<(FixSizedKey, Vec<u8>)>) -> Result<(), &'static str> {
fn store(&self, items: &Vec<([u8; 32], Vec<u8>)>) -> Result<(), &'static str> {
let info = self.info()?;
for item in items {
info.write(&item.0 as &FixSizedKey, Some(item.1.clone()), None, false)
info.write(&Key::Fix(item.0), Some(item.1.clone()), None, false)
.map_err(|_| "Failed to write storage to restoration dest")?;
}
<ContractInfoOf<T>>::insert(&self.account_id, info);
Expand Down Expand Up @@ -1044,7 +1044,7 @@ benchmarks! {
let info = instance.info()?;
for key in keys {
info.write(
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
&Key::<T>::try_from_var(key).map_err(|e| "Key has wrong length")?,
Some(vec![]),
None,
false,
Expand Down Expand Up @@ -1088,7 +1088,7 @@ benchmarks! {
let instance = Contract::<T>::new(code, vec![])?;
let info = instance.info()?;
info.write(
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
&Key::<T>::try_from_var(key).map_err(|e| "Key has wrong length")?,
Some(vec![]),
None,
false,
Expand Down Expand Up @@ -1131,7 +1131,7 @@ benchmarks! {
let instance = Contract::<T>::new(code, vec![])?;
let info = instance.info()?;
info.write(
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
&Key::<T>::try_from_var(key).map_err(|e| "Key has wrong length")?,
Some(vec![42u8; n as usize]),
None,
false,
Expand Down Expand Up @@ -1180,7 +1180,7 @@ benchmarks! {
let info = instance.info()?;
for key in keys {
info.write(
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
&Key::<T>::try_from_var(key).map_err(|e| "Key has wrong length")?,
Some(vec![]),
None,
false,
Expand Down Expand Up @@ -1223,7 +1223,7 @@ benchmarks! {
let instance = Contract::<T>::new(code, vec![])?;
let info = instance.info()?;
info.write(
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
&Key::<T>::try_from_var(key).map_err(|e| "Key has wrong length")?,
Some(vec![42u8; n as usize]),
None,
false,
Expand Down Expand Up @@ -1276,7 +1276,7 @@ benchmarks! {
let info = instance.info()?;
for key in keys {
info.write(
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
&Key::<T>::try_from_var(key).map_err(|e| "Key has wrong length")?,
Some(vec![]),
None,
false,
Expand Down Expand Up @@ -1325,7 +1325,7 @@ benchmarks! {
let instance = Contract::<T>::new(code, vec![])?;
let info = instance.info()?;
info.write(
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
&Key::<T>::try_from_var(key).map_err(|e| "Key has wrong length")?,
Some(vec![42u8; n as usize]),
None,
false,
Expand Down Expand Up @@ -1373,7 +1373,7 @@ benchmarks! {
let info = instance.info()?;
for key in keys {
info.write(
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
&Key::<T>::try_from_var(key).map_err(|e| "Key has wrong length")?,
Some(vec![]),
None,
false,
Expand Down Expand Up @@ -1416,7 +1416,7 @@ benchmarks! {
let instance = Contract::<T>::new(code, vec![])?;
let info = instance.info()?;
info.write(
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
&Key::<T>::try_from_var(key).map_err(|e| "Key has wrong length")?,
Some(vec![42u8; n as usize]),
None,
false,
Expand Down Expand Up @@ -1469,7 +1469,7 @@ benchmarks! {
let info = instance.info()?;
for key in keys {
info.write(
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
&Key::<T>::try_from_var(key).map_err(|e| "Key has wrong length")?,
Some(vec![]),
None,
false,
Expand Down Expand Up @@ -1518,7 +1518,7 @@ benchmarks! {
let instance = Contract::<T>::new(code, vec![])?;
let info = instance.info()?;
info.write(
&VarSizedKey::<T>::try_from(key).map_err(|e| "Key has wrong length")?,
&Key::<T>::try_from_var(key).map_err(|e| "Key has wrong length")?,
Some(vec![42u8; n as usize]),
None,
false,
Expand Down
Loading

0 comments on commit 8fcd235

Please sign in to comment.