From e2f0bdd125afa16a26599f5e641cc4d2d9963b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Bizjak?= Date: Sat, 19 Aug 2023 21:36:23 +0200 Subject: [PATCH] Tests for derivation macros with where clauses. (#325) --- concordium-contracts-common | 2 +- concordium-std/Cargo.toml | 2 +- .../success-generics.rs | 30 ++++++++++++++++++ .../tests/derive-deserial/success-generics.rs | 29 +++++++++++++++++ .../tests/derive-serial/success-generics.rs | 31 +++++++++++++++++++ examples/cis3-nft-sponsored-txs/README.md | 4 +-- 6 files changed, 94 insertions(+), 4 deletions(-) diff --git a/concordium-contracts-common b/concordium-contracts-common index 68c028bb..16e45215 160000 --- a/concordium-contracts-common +++ b/concordium-contracts-common @@ -1 +1 @@ -Subproject commit 68c028bb42a0ba62cf423fac9f6799b6607e9f19 +Subproject commit 16e452154d7ef28a40cec317919bfe6f52d58056 diff --git a/concordium-std/Cargo.toml b/concordium-std/Cargo.toml index 40d27791..6bd7676f 100644 --- a/concordium-std/Cargo.toml +++ b/concordium-std/Cargo.toml @@ -23,7 +23,7 @@ getrandom = { version = "0.2", features = ["custom"], optional = true } [dependencies.concordium-contracts-common] path = "../concordium-contracts-common/concordium-contracts-common" -version = "7.0" +version = "7.1" default-features = false features = ["smart-contract"] diff --git a/concordium-std/tests/derive-deserial-with-state/success-generics.rs b/concordium-std/tests/derive-deserial-with-state/success-generics.rs index a96fcbcf..f373e319 100644 --- a/concordium-std/tests/derive-deserial-with-state/success-generics.rs +++ b/concordium-std/tests/derive-deserial-with-state/success-generics.rs @@ -10,6 +10,36 @@ struct State1 { other: A, } +#[derive(DeserialWithState)] +#[concordium(state_parameter = "S")] +struct WithStateParameterWhere +where + S: HasStateApi, + S: Clone, { + test_map: StateMap, +} + +#[rustfmt::skip] // maintain lack of trailing comma, and empty where clause +mod inner { + use super::*; + #[derive(DeserialWithState)] + #[concordium(state_parameter = "S")] + struct WithStateParameterWhereTwo + where + S: HasStateApi, + S: Clone { // no trailing comma + test_map: StateMap, + } + + #[derive(DeserialWithState)] + #[concordium(state_parameter = "S")] + struct WithStateParameterWhereThree + where //empty where clause + { + test: S, + } +} + trait ProxyTrait { type State: HasStateApi; } diff --git a/concordium-std/tests/derive-deserial/success-generics.rs b/concordium-std/tests/derive-deserial/success-generics.rs index cbe9a797..ae93ebfc 100644 --- a/concordium-std/tests/derive-deserial/success-generics.rs +++ b/concordium-std/tests/derive-deserial/success-generics.rs @@ -25,6 +25,35 @@ enum MyOtherEnum { Two(A, B), } +#[derive(Deserial)] +struct WithStateParameterWhere +where + S: Clone, + S: PartialOrd, { + value: S, +} + +#[rustfmt::skip] // skip formatting to maintain lack of trailing comma +mod inner { + use super::*; + #[derive(Deserial)] + struct WithStateParameterWhereTwo + where + S: Clone, + // note the lack of comma compared to the test above + S: PartialOrd { + value: S, + } + + #[derive(Deserial)] + struct WithStateParameterWhereThree + where // empty where clause + { + value: S, + } +} + + #[derive(Deserial)] #[concordium(bound(deserial = ""))] struct ExplicitBound { diff --git a/concordium-std/tests/derive-serial/success-generics.rs b/concordium-std/tests/derive-serial/success-generics.rs index b8062941..b2f245e6 100644 --- a/concordium-std/tests/derive-serial/success-generics.rs +++ b/concordium-std/tests/derive-serial/success-generics.rs @@ -31,6 +31,37 @@ struct WithStateParameter { test_map: StateMap, } +#[derive(Serial)] +#[concordium(state_parameter = "S")] +struct WithStateParameterWhere +where + S: HasStateApi, + S: Clone, { + test_map: StateMap, +} + +#[rustfmt::skip] // skip formatting to maintain lack of trailing comma +mod inner { + use super::*; + #[derive(Serial)] + #[concordium(state_parameter = "S")] + struct WithStateParameterWhereTwo + where + S: HasStateApi, + S: Clone { // note the lack of comma compared to the test above + test_map: StateMap, + } + + #[derive(Serial)] + #[concordium(state_parameter = "S")] + struct WithStateParameterWhereThree + where // empty where clause + { + test_map: StateMap, + } +} + + trait ProxyTrait { type State: HasStateApi; } diff --git a/examples/cis3-nft-sponsored-txs/README.md b/examples/cis3-nft-sponsored-txs/README.md index f6fa362c..6f9c0ffb 100644 --- a/examples/cis3-nft-sponsored-txs/README.md +++ b/examples/cis3-nft-sponsored-txs/README.md @@ -15,8 +15,8 @@ cargo concordium build -e --out contract.wasm.v1 Run the following command to run the unit and integration tests: ``` -cargo concordium test +cargo concordium test ``` ``` -cargo test +cargo test ```