decl_storage! check for duplicate config()/get() (#3936)

* `decl_storage!` check for duplicate `config()`/`get()`

* Fix tests
This commit is contained in:
Bastian Köcher
2019-10-28 09:35:09 +01:00
committed by GitHub
parent bb5f406b3b
commit 6beaccdae3
13 changed files with 244 additions and 65 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ support = { package = "srml-support", version = "2", path = "../", default-featu
inherents = { package = "substrate-inherents", path = "../../../core/inherents", default-features = false }
sr-primitives = { package = "sr-primitives", path = "../../../core/sr-primitives", default-features = false }
primitives = { package = "substrate-primitives", path = "../../../core/primitives", default-features = false }
trybuild = "1.0.14"
trybuild = "1.0.17"
pretty_assertions = "0.6.1"
[features]
-6
View File
@@ -16,9 +16,3 @@
//! Test crate for srml_support. Allow to make use of `support::decl_storage`.
//! See tests directory.
#[test]
fn reserved_keyword() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/reserved_keyword/*.rs");
}
@@ -0,0 +1,24 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
#[test]
fn decl_storage_ui() {
// As trybuild is using `cargo check`, we don't need the real WASM binaries.
std::env::set_var("BUILD_DUMMY_WASM_BINARY", "1");
let t = trybuild::TestCases::new();
t.compile_fail("tests/decl_storage_ui/*.rs");
}
@@ -0,0 +1,33 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
pub trait Trait {
type Origin;
type BlockNumber: codec::Codec + codec::EncodeLike + Default + Clone;
}
support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
}
support::decl_storage!{
trait Store for Module<T: Trait> as FinalKeysNone {
pub Value config(value): u32;
pub Value2 config(value): u32;
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: `config()`/`get()` with the same name already defined.
--> $DIR/config_duplicate.rs:29:21
|
29 | pub Value2 config(value): u32;
| ^^^^^
@@ -0,0 +1,33 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
pub trait Trait {
type Origin;
type BlockNumber: codec::Codec + codec::EncodeLike + Default + Clone;
}
support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
}
support::decl_storage!{
trait Store for Module<T: Trait> as FinalKeysNone {
pub Value get(fn value) config(): u32;
pub Value2 config(value): u32;
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: `config()`/`get()` with the same name already defined.
--> $DIR/config_get_duplicate.rs:29:21
|
29 | pub Value2 config(value): u32;
| ^^^^^
@@ -0,0 +1,33 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
pub trait Trait {
type Origin;
type BlockNumber: codec::Codec + codec::EncodeLike + Default + Clone;
}
support::decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {}
}
support::decl_storage!{
trait Store for Module<T: Trait> as FinalKeysNone {
pub Value get(fn value) config(): u32;
pub Value2 get(fn value) config(): u32;
}
}
fn main() {}
@@ -0,0 +1,5 @@
error: `config()`/`get()` with the same name already defined.
--> $DIR/get_duplicate.rs:29:21
|
29 | pub Value2 get(fn value) config(): u32;
| ^^^^^
@@ -13,6 +13,7 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
#![recursion_limit="128"]
use sr_primitives::{generic, BuildStorage, traits::{BlakeTwo256, Block as _, Verify}};
@@ -0,0 +1,24 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
#[test]
fn reserved_keyword() {
// As trybuild is using `cargo check`, we don't need the real WASM binaries.
std::env::set_var("BUILD_DUMMY_WASM_BINARY", "1");
let t = trybuild::TestCases::new();
t.compile_fail("tests/reserved_keyword/*.rs");
}