Skip to content

Commit

Permalink
Merge branch 'derive-macros' into fix-counter-notify
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmus-kirk committed Mar 12, 2024
2 parents b4280e8 + 588717b commit e98ee28
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ name: Clippy & fmt

env:
RUST_FMT: nightly-2023-04-01
RUST_VERSION: "1.66"
RUST_VERSION: "1.72"
RUST_VERSION_TESTING_LIBRARY: "1.72"
CARGO_CONCORDIUM_VERSION: "3.2.0"

Expand Down Expand Up @@ -354,6 +354,7 @@ jobs:
sed -i "s/{version = \"10.0\", default-features = false}/{path = \"..\/..\/concordium-std\", default-features = false}/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
sed -i "s/{version = \"6.1\", default-features = false}/{path = \"..\/..\/concordium-cis2\", default-features = false}/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
sed -i "s/concordium-smart-contract-testing = \"4.0\"/concordium-smart-contract-testing = {path = \"..\/..\/contract-testing\"}/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
sed -i "s/concordium-std-derive = \"6.0\"/concordium-std-derive = {path = \"..\/..\/concordium-std-derive\"}/g" ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml
diff ${{ runner.temp }}/$PROJECT_NAME/Cargo.toml examples/cis2-nft/Cargo.toml
diff ${{ runner.temp }}/$PROJECT_NAME/src/lib.rs examples/cis2-nft/src/lib.rs
diff ${{ runner.temp }}/$PROJECT_NAME/tests/tests.rs examples/cis2-nft/tests/tests.rs
Expand Down
2 changes: 2 additions & 0 deletions concordium-cis2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased changes

- Bump MSRV to 1.72

## concordium-cis2 6.1.0 (2024-02-22)

- Support version 10 of concordium-std.
Expand Down
1 change: 1 addition & 0 deletions concordium-cis2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "concordium-cis2"
version = "6.1.0"
authors = ["Concordium <[email protected]>"]
rust-version = "1.72"
edition = "2021"
license = "MPL-2.0"
description = "A collection of types for implementing CIS-2 Concordium Token Standard."
Expand Down
2 changes: 1 addition & 1 deletion concordium-rust-sdk
2 changes: 2 additions & 0 deletions concordium-std-derive/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

- Added MSRV (1.72)

## Unreleased changes

### Added
Expand Down
6 changes: 4 additions & 2 deletions concordium-std-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[package]
name = "concordium-std-derive"
authors = ["Concordium <[email protected]>"]
version = "0.1.0"
version = "6.0.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.72"
license = "MPL-2.0"
description = "Procedural macros to generate concordium type constants from strings, that makes writing smart contracts on the Concordium blockchain easier."
homepage = "https://github.com/Concordium/concordium-rust-smart-contracts/"
repository = "https://github.com/Concordium/concordium-rust-smart-contracts/"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
Expand Down
12 changes: 12 additions & 0 deletions concordium-std-derive/tests/test-programs/fail-missing-env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! Ensure that the macros generate compilable code.
use concordium_contracts_common::*;
use concordium_std_derive::*;

const ACC: AccountAddress = account_address_env!("TEST");

fn f() {
println!("{:?}", ACC.to_string());
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Environment variable error: NotPresent
--> tests/test-programs/fail-missing-env.rs:6:50
|
6 | const ACC: AccountAddress = account_address_env!("TEST");
| ^^^^^^
26 changes: 16 additions & 10 deletions concordium-std-derive/tests/test-programs/success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ const PK_ECDSA: PublicKeyEcdsaSecp256k1 = public_key_ecdsa!("0214e6a60b8fc58ea70
const SG_25519: SignatureEd25519 = signature_ed25519!("ec076ae7adaf0a8b921cf2bad86a1a5b5346226618637aa0d6b30f9616f108f9f482640a4ceb14235569cd3af05fac00be2c82dc81c6f6b4a6ba4ea7c3b51a0b");
const SG_ECDSA: SignatureEcdsaSecp256k1 = signature_ecdsa!("EC076AE7ADAF0A8B921CF2BAD86A1A5B5346226618637AA0D6B30F9616F108F9F482640A4CEB14235569CD3AF05FAC00BE2C82DC81C6F6B4A6BA4EA7C3B51A0B");

fn f() {
println!("{:?}", ACC.to_string());
println!("{:?}", REF.to_string());
println!("{:?}", CONTRACT.to_string());
println!("{:?}", PK_25519.to_string());
println!("{:?}", PK_ECDSA.to_string());
println!("{:?}", SG_25519.to_string());
println!("{:?}", SG_ECDSA.to_string());
}
const ACC_ENV: AccountAddress = account_address_env!("ACC");
const REF_ENV: ModuleReference = module_reference_env!("REF");
const CONTRACT_ENV: ContractAddress = contract_address_env!("CONTRACT");
const PK_25519_ENV: PublicKeyEd25519 = public_key_ed25519_env!("PK_25519");
const PK_ECDSA_ENV: PublicKeyEcdsaSecp256k1 = public_key_ecdsa_env!("PK_ECDSA");
const SG_25519_ENV: SignatureEd25519 = signature_ed25519_env!("SG_25519");
const SG_ECDSA_ENV: SignatureEcdsaSecp256k1 = signature_ecdsa_env!("SG_ECDSA");

fn main() { }
fn main() {
assert_eq!(ACC, ACC_ENV);
assert_eq!(REF, REF_ENV);
assert_eq!(CONTRACT, CONTRACT_ENV);
assert_eq!(PK_25519, PK_25519_ENV);
assert_eq!(PK_ECDSA, PK_ECDSA_ENV);
assert_eq!(SG_25519, SG_25519_ENV);
assert_eq!(SG_ECDSA, SG_ECDSA_ENV);
}
9 changes: 9 additions & 0 deletions concordium-std-derive/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
//! Test that the macros generates compilable code.
#[test]
fn tests() {
std::env::set_var("MY_CUSTOM_FEATURE", "true");
std::env::set_var("ACC", "3kBx2h5Y2veb4hZgAJWPrr8RyQESKm5TjzF3ti1QQ4VSYLwK1G");
std::env::set_var("REF", "0000000000000000000000000000000000000000000000000000000000000000");
std::env::set_var("CONTRACT", "<1234,0>");
std::env::set_var("PK_25519", "012a7e286063ae5dfcebce40636c0546d367d8c65cd4cb69aae1af77a4d61412");
std::env::set_var("PK_ECDSA", "0214e6a60b8fc58ea707d8ee8fa6ca7b28626d4f6f80b170982644c95d12111853");
std::env::set_var("SG_25519", "ec076ae7adaf0a8b921cf2bad86a1a5b5346226618637aa0d6b30f9616f108f9f482640a4ceb14235569cd3af05fac00be2c82dc81c6f6b4a6ba4ea7c3b51a0b");
std::env::set_var("SG_ECDSA", "EC076AE7ADAF0A8B921CF2BAD86A1A5B5346226618637AA0D6B30F9616F108F9F482640A4CEB14235569CD3AF05FAC00BE2C82DC81C6F6B4A6BA4EA7C3B51A0B");

let t = trybuild::TestCases::new();
t.pass("tests/test-programs/success.rs");
t.compile_fail("tests/test-programs/fail-*.rs");
Expand Down
2 changes: 2 additions & 0 deletions concordium-std/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

- Bump MSRV to 1.72

## Unreleased changes

- Add support for querying the module reference and contract name of an instance,
Expand Down
2 changes: 1 addition & 1 deletion concordium-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "concordium-std"
version = "10.0.0"
authors = ["Concordium <[email protected]>"]
edition = "2021"
rust-version = "1.66"
rust-version = "1.72"
license = "MPL-2.0"
description = "A standard library for writing smart contracts for the Concordium blockchain in Rust."
homepage = "https://github.com/Concordium/concordium-rust-smart-contracts/"
Expand Down
5 changes: 3 additions & 2 deletions concordium-std/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ where
StateApi: HasStateApi,
{
/// Ensures a value is in the entry by inserting the default value if empty.
#[allow(clippy::unwrap_or_default)]
pub fn or_default(self) -> OccupiedEntry<'a, K, V, StateApi> {
self.or_insert_with(Default::default)
}
Expand Down Expand Up @@ -2196,7 +2197,7 @@ fn query_exchange_rates_worker() -> ExchangeRates {
fn query_account_public_keys_worker(address: AccountAddress) -> QueryAccountPublicKeysResult {
let data: &[u8] = address.as_ref();
let response = unsafe {
prims::invoke(INVOKE_QUERY_ACCOUNT_PUBLIC_KEYS_TAG, data.as_ptr() as *const u8, 32)
prims::invoke(INVOKE_QUERY_ACCOUNT_PUBLIC_KEYS_TAG, data.as_ptr(), 32)
};
let mut return_value = parse_query_account_public_keys_response_code(response)?;
Ok(crate::AccountPublicKeys::deserial(&mut return_value).unwrap_abort())
Expand All @@ -2215,7 +2216,7 @@ fn check_account_signature_worker(
let response = unsafe {
prims::invoke(
INVOKE_CHECK_ACCOUNT_SIGNATURE_TAG,
buffer.as_ptr() as *const u8,
buffer.as_ptr(),
buffer.len() as u32,
)
};
Expand Down
2 changes: 1 addition & 1 deletion examples/credential-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ quickcheck = {version = "1"}

[dev-dependencies]
concordium-smart-contract-testing = {path = "../../contract-testing"}
concordium-std-derive = { path = "../../concordium-std-derive" }
concordium-std-derive = {path = "../../concordium-std-derive"}

[lib]
crate-type=["cdylib", "rlib"]
Expand Down
1 change: 1 addition & 0 deletions templates/cis2-nft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ concordium-cis2 = {version = "6.1", default-features = false}

[dev-dependencies]
concordium-smart-contract-testing = "4.0"
concordium-std-derive = "6.0"

[lib]
crate-type=["cdylib", "rlib"]
Expand Down
1 change: 1 addition & 0 deletions templates/credential-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ quickcheck = {version = "1"}

[dev-dependencies]
concordium-smart-contract-testing = "4.0"
concordium-std-derive = "6.0"

[lib]
crate-type=["cdylib", "rlib"]
Expand Down

0 comments on commit e98ee28

Please sign in to comment.