Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contracts Bump ApiVersion and add test #3619

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions substrate/frame/contracts/proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,14 @@ fn expand_docs(def: &EnvDef) -> TokenStream2 {
fn expand_env(def: &EnvDef, docs: bool) -> TokenStream2 {
let impls = expand_impls(def);
let docs = docs.then_some(expand_docs(def)).unwrap_or(TokenStream2::new());
let stable_count = def.host_funcs.iter().map(|f| if f.is_stable { 1 } else { 0 }).sum::<u16>();
pgherveou marked this conversation as resolved.
Show resolved Hide resolved

quote! {
pub struct Env;

#[cfg(test)]
pub const STABLE_API_COUNT: u16 = #stable_count;

#impls
/// Documentation of the API (host functions) available to contracts.
///
Expand Down
11 changes: 10 additions & 1 deletion substrate/frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,19 @@ pub struct Environment<T: Config> {
pub struct ApiVersion(u16);
impl Default for ApiVersion {
fn default() -> Self {
Self(1)
Self(2)
}
}

#[test]
fn api_version_is_up_to_date() {
assert_eq!(
107,
crate::wasm::STABLE_API_COUNT,
"Stable API count has changed. Bump the returned value of ApiVersion::default() and update the test."
);
}

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/contracts/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
mod prepare;
mod runtime;

#[cfg(test)]
pub use runtime::STABLE_API_COUNT;

#[cfg(doc)]
pub use crate::wasm::runtime::api_doc;

Expand Down
1 change: 0 additions & 1 deletion substrate/frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,6 @@ impl<'a, E: Ext + 'a> Runtime<'a, E> {
// for every function.
#[define_env(doc)]
pub mod env {

/// Set the value at the given key in the contract storage.
/// See [`pallet_contracts_uapi::HostFn::set_storage`]
#[prefixed_alias]
Expand Down
Loading