diff --git a/wallet-connect-test-bench/front-end/CHANGELOG.md b/wallet-connect-test-bench/front-end/CHANGELOG.md index 50d463b8..f0e72507 100644 --- a/wallet-connect-test-bench/front-end/CHANGELOG.md +++ b/wallet-connect-test-bench/front-end/CHANGELOG.md @@ -1,5 +1,9 @@ ## Unreleased changes +## 1.5.3 + +Update smart contract to be more efficient. + ## 1.5.2 - Update dependencies. diff --git a/wallet-connect-test-bench/front-end/package.json b/wallet-connect-test-bench/front-end/package.json index f027d696..6b8a5c47 100644 --- a/wallet-connect-test-bench/front-end/package.json +++ b/wallet-connect-test-bench/front-end/package.json @@ -1,7 +1,7 @@ { "name": "test-bench-for-wallets", "packageManager": "yarn@3.2.0", - "version": "1.5.2", + "version": "1.5.3", "license": "Apache-2.0", "type": "module", "engines": { diff --git a/wallet-connect-test-bench/front-end/src/constants.ts b/wallet-connect-test-bench/front-end/src/constants.ts index 6cee2865..90f6aabd 100644 --- a/wallet-connect-test-bench/front-end/src/constants.ts +++ b/wallet-connect-test-bench/front-end/src/constants.ts @@ -86,7 +86,7 @@ export const BASE_64_TEST_BENCH_SMART_CONTRACT_MODULE = export const CONTRACT_NAME = "smart_contract_test_bench"; -export const CONTRACT_INDEX = 4726n; +export const CONTRACT_INDEX = 8649n; export const CONTRACT_SUB_INDEX = 0n; @@ -95,7 +95,7 @@ const WALLET_CONNECT_OPTS: SignClientTypes.Options = { metadata: { name: "Test_Bench", description: "Example dApp for testing.", - url: "#", + url: "https://wallet-test-bench.testnet.concordium.com/", icons: ["https://walletconnect.com/walletconnect-logo.png"], }, }; diff --git a/wallet-connect-test-bench/smart-contract/Cargo.lock b/wallet-connect-test-bench/smart-contract/Cargo.lock index 5bca2d99..6ed6787b 100644 --- a/wallet-connect-test-bench/smart-contract/Cargo.lock +++ b/wallet-connect-test-bench/smart-contract/Cargo.lock @@ -3,17 +3,18 @@ version = 3 [[package]] -name = "cfg-if" -version = "0.1.10" +name = "base64" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "concordium-contracts-common" -version = "6.0.0" +version = "9.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b03d120efcfc1c4b52209d4553302fa71683df4159cf5352927425ae8ed657f" +checksum = "14dfda3a8d06d2d72e74aad650757680a82df4e528c18c66c49efe9f60b646c5" dependencies = [ + "base64", "concordium-contracts-common-derive", "fnv", "hashbrown", @@ -21,9 +22,9 @@ dependencies = [ [[package]] name = "concordium-contracts-common-derive" -version = "2.0.0" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "434938667ab95bd21adb63289008690839d967eb23ead39d82f0dd2cd3b97c68" +checksum = "ee3482ffacf3c18133be976c1b874b6e87e018ac0316e9385888b43df07fa39c" dependencies = [ "proc-macro2", "quote", @@ -32,25 +33,11 @@ dependencies = [ [[package]] name = "concordium-std" -version = "6.2.0" +version = "10.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be15c99a7effe3dccdba34dd666172a1236cbebba1bb29a6c3d47ab653153cd2" +checksum = "8879375db69e8b0f9918faef9b349427c5ae8ba45b31870946780d16bcfe7fe7" dependencies = [ "concordium-contracts-common", - "concordium-std-derive", - "wee_alloc", -] - -[[package]] -name = "concordium-std-derive" -version = "5.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fb31ccffc667d355936f4e0482cee1d393d119e65d1c30ce08fe96f51802031" -dependencies = [ - "concordium-contracts-common", - "proc-macro2", - "quote", - "syn", ] [[package]] @@ -65,48 +52,36 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -[[package]] -name = "libc" -version = "0.2.144" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" - -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "proc-macro2" -version = "1.0.57" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4ec6d5fe0b140acb27c9a0444118cf55bfbb4e0b259739429abb4521dd67c16" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.27" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] [[package]] name = "smart_contract_test_bench" -version = "1.0.0" +version = "1.1.0" dependencies = [ "concordium-std", ] [[package]] name = "syn" -version = "1.0.109" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ "proc-macro2", "quote", @@ -115,40 +90,6 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/wallet-connect-test-bench/smart-contract/Cargo.toml b/wallet-connect-test-bench/smart-contract/Cargo.toml index b2948e6d..d8fe5651 100644 --- a/wallet-connect-test-bench/smart-contract/Cargo.toml +++ b/wallet-connect-test-bench/smart-contract/Cargo.toml @@ -1,17 +1,17 @@ [package] name = "smart_contract_test_bench" -version = "1.0.0" +version = "1.1.0" authors = ["Concordium "] edition = "2021" license = "MPL-2.0" [features] -default = ["std", "wee_alloc"] +default = ["std", "bump_alloc"] std = ["concordium-std/std"] -wee_alloc = ["concordium-std/wee_alloc"] +bump_alloc = ["concordium-std/bump_alloc"] [dependencies] -concordium-std = {version = "6.2.0", default-features = false} +concordium-std = {version = "10", default-features = false} [lib] crate-type=["cdylib", "rlib"] diff --git a/wallet-connect-test-bench/smart-contract/src/lib.rs b/wallet-connect-test-bench/smart-contract/src/lib.rs index 8002a74e..761c3d3b 100644 --- a/wallet-connect-test-bench/smart-contract/src/lib.rs +++ b/wallet-connect-test-bench/smart-contract/src/lib.rs @@ -37,8 +37,25 @@ const HASH: HashSha2256 = concordium_std::HashSha2256([2u8; 32]); const STRING: &str = "abc"; /// The contract state. -#[derive(Serial, Deserial, Clone, SchemaType)] -struct State { +#[derive(Serial, DeserialWithState)] +#[concordium(state_parameter = "S")] +struct State { + u8_value: u8, + u16_value: u16, + address_array: StateBox, S>, + address_value: Address, + account_address_value: AccountAddress, + contract_address_value: ContractAddress, + hash_value: HashSha2256, + signature_value: SignatureEd25519, + public_key_value: PublicKeyEd25519, + timestamp_value: Timestamp, + option_value: Option, + string_value: StateBox, +} + +#[derive(Serial, Deserial, SchemaType)] +struct ReturnState { u8_value: u8, u16_value: u16, address_array: Vec
, @@ -54,13 +71,47 @@ struct State { string_value: String, } +impl<'a, S: HasStateApi> From<&'a State> for ReturnState { + fn from( + State { + u8_value, + u16_value, + address_array, + address_value, + account_address_value, + contract_address_value, + hash_value, + signature_value, + public_key_value, + timestamp_value, + option_value, + string_value, + }: &'a State, + ) -> Self { + Self { + u8_value: *u8_value, + u16_value: *u16_value, + address_array: address_array.to_vec(), + address_value: *address_value, + account_address_value: *account_address_value, + contract_address_value: *contract_address_value, + hash_value: *hash_value, + signature_value: *signature_value, + public_key_value: *public_key_value, + timestamp_value: *timestamp_value, + option_value: *option_value, + string_value: String::from(string_value.as_str()), + } + } +} + /// Init function that creates this smart_contract_test_bench. #[init(contract = "smart_contract_test_bench", parameter = "u16", payable)] fn contract_init( ctx: &impl HasInitContext, - _state_builder: &mut StateBuilder, + state_builder: &mut StateBuilder, _amount: Amount, -) -> InitResult { +) -> InitResult> { let size = ctx.parameter_cursor().size(); let mut u16_value: u16 = 0u16; @@ -71,7 +122,7 @@ fn contract_init( Ok(State { u8_value: 0u8, u16_value, - address_array: vec![], + address_array: state_builder.new_box(vec![]), address_value: Address::Account(AccountAddress([0u8; 32])), account_address_value: AccountAddress([0u8; 32]), contract_address_value: ContractAddress { @@ -83,7 +134,7 @@ fn contract_init( public_key_value: PUBLIC_KEY, timestamp_value: Timestamp::from_timestamp_millis(11), option_value: None, - string_value: STRING.to_string(), + string_value: state_builder.new_box(STRING.to_string()), }) } @@ -96,7 +147,7 @@ fn contract_init( )] fn set_u8( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { let value: u8 = ctx.parameter_cursor().get()?; host.state_mut().u8_value = value; @@ -114,7 +165,7 @@ fn set_u8( )] fn set_u8_payable( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, _amount: Amount, ) -> Result<(), ContractError> { let value: u8 = ctx.parameter_cursor().get()?; @@ -132,7 +183,7 @@ fn set_u8_payable( )] fn get_u8( _ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result { Ok(host.state_mut().u8_value) } @@ -146,7 +197,7 @@ fn get_u8( )] fn set_u16( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { let value: u16 = ctx.parameter_cursor().get()?; host.state_mut().u16_value = value; @@ -164,7 +215,7 @@ fn set_u16( )] fn set_u16_payable( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, _amount: Amount, ) -> Result<(), ContractError> { let value: u16 = ctx.parameter_cursor().get()?; @@ -182,7 +233,7 @@ fn set_u16_payable( )] fn get_u16( _ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result { Ok(host.state_mut().u16_value) } @@ -196,7 +247,7 @@ fn get_u16( )] fn set_address( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { let value: Address = ctx.parameter_cursor().get()?; host.state_mut().address_value = value; @@ -214,7 +265,7 @@ fn set_address( )] fn set_address_payable( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, _amount: Amount, ) -> Result<(), ContractError> { let value: Address = ctx.parameter_cursor().get()?; @@ -232,7 +283,7 @@ fn set_address_payable( )] fn get_address( _ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result { Ok(host.state_mut().address_value) } @@ -246,7 +297,7 @@ fn get_address( )] fn set_contract_address( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { let value: ContractAddress = ctx.parameter_cursor().get()?; host.state_mut().contract_address_value = value; @@ -264,7 +315,7 @@ fn set_contract_address( )] fn set_contract_address_payable( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, _amount: Amount, ) -> Result<(), ContractError> { let value: ContractAddress = ctx.parameter_cursor().get()?; @@ -282,7 +333,7 @@ fn set_contract_address_payable( )] fn get_contract_address( _ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result { Ok(host.state_mut().contract_address_value) } @@ -296,7 +347,7 @@ fn get_contract_address( )] fn set_account_address( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { let value: AccountAddress = ctx.parameter_cursor().get()?; host.state_mut().account_address_value = value; @@ -314,7 +365,7 @@ fn set_account_address( )] fn set_account_address_payable( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, _amount: Amount, ) -> Result<(), ContractError> { let value: AccountAddress = ctx.parameter_cursor().get()?; @@ -332,7 +383,7 @@ fn set_account_address_payable( )] fn get_account_address( _ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result { Ok(host.state_mut().account_address_value) } @@ -346,7 +397,7 @@ fn get_account_address( )] fn set_hash( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { let value: HashSha2256 = ctx.parameter_cursor().get()?; host.state_mut().hash_value = value; @@ -364,7 +415,7 @@ fn set_hash( )] fn set_hash_payable( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, _amount: Amount, ) -> Result<(), ContractError> { let value: HashSha2256 = ctx.parameter_cursor().get()?; @@ -382,7 +433,7 @@ fn set_hash_payable( )] fn get_hash( _ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result { Ok(host.state_mut().hash_value) } @@ -396,7 +447,7 @@ fn get_hash( )] fn set_public_key( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { let value: PublicKeyEd25519 = ctx.parameter_cursor().get()?; host.state_mut().public_key_value = value; @@ -414,7 +465,7 @@ fn set_public_key( )] fn set_public_key_payable( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, _amount: Amount, ) -> Result<(), ContractError> { let value: PublicKeyEd25519 = ctx.parameter_cursor().get()?; @@ -432,7 +483,7 @@ fn set_public_key_payable( )] fn get_public_key( _ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result { Ok(host.state_mut().public_key_value) } @@ -446,7 +497,7 @@ fn get_public_key( )] fn set_signature( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { let value: SignatureEd25519 = ctx.parameter_cursor().get()?; host.state_mut().signature_value = value; @@ -464,7 +515,7 @@ fn set_signature( )] fn set_signature_payable( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, _amount: Amount, ) -> Result<(), ContractError> { let value: SignatureEd25519 = ctx.parameter_cursor().get()?; @@ -482,7 +533,7 @@ fn set_signature_payable( )] fn get_signature( _ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result { Ok(host.state_mut().signature_value) } @@ -496,7 +547,7 @@ fn get_signature( )] fn set_timestamp( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { let value: Timestamp = ctx.parameter_cursor().get()?; host.state_mut().timestamp_value = value; @@ -514,7 +565,7 @@ fn set_timestamp( )] fn set_timestamp_payable( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, _amount: Amount, ) -> Result<(), ContractError> { let value: Timestamp = ctx.parameter_cursor().get()?; @@ -532,7 +583,7 @@ fn set_timestamp_payable( )] fn get_timestamp( _ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result { Ok(host.state_mut().timestamp_value) } @@ -546,10 +597,10 @@ fn get_timestamp( )] fn set_string( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { let value: String = ctx.parameter_cursor().get()?; - host.state_mut().string_value = value; + drop(host.state_mut().string_value.replace(value)); Ok(()) } @@ -564,11 +615,11 @@ fn set_string( )] fn set_string_payable( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, _amount: Amount, ) -> Result<(), ContractError> { let value: String = ctx.parameter_cursor().get()?; - host.state_mut().string_value = value; + drop(host.state_mut().string_value.replace(value)); Ok(()) } @@ -582,7 +633,7 @@ fn set_string_payable( )] fn get_string( _ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result { Ok(host.state_mut().string_value.clone()) } @@ -596,7 +647,7 @@ fn get_string( )] fn set_option_u8( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { let value: Option = ctx.parameter_cursor().get()?; host.state_mut().option_value = value; @@ -614,7 +665,7 @@ fn set_option_u8( )] fn set_option_u8_payable( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, _amount: Amount, ) -> Result<(), ContractError> { let value: Option = ctx.parameter_cursor().get()?; @@ -632,7 +683,7 @@ fn set_option_u8_payable( )] fn get_option_u8( _ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result, ContractError> { Ok(host.state_mut().option_value) } @@ -646,10 +697,10 @@ fn get_option_u8( )] fn set_address_array( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { let value: Vec
= ctx.parameter_cursor().get()?; - host.state_mut().address_array = value; + drop(host.state_mut().address_array.replace(value)); Ok(()) } @@ -664,11 +715,11 @@ fn set_address_array( )] fn set_address_array_payable( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, _amount: Amount, ) -> Result<(), ContractError> { let value: Vec
= ctx.parameter_cursor().get()?; - host.state_mut().address_array = value; + drop(host.state_mut().address_array.replace(value)); Ok(()) } @@ -682,7 +733,7 @@ fn set_address_array_payable( )] fn get_address_array( _ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result, ContractError> { Ok(host.state_mut().address_array.clone()) } @@ -690,27 +741,27 @@ fn get_address_array( #[receive( contract = "smart_contract_test_bench", name = "set_object", - parameter = "State", + parameter = "ReturnState", error = "ContractError", mutable )] fn set_object( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { - let value: State = ctx.parameter_cursor().get()?; + let value: ReturnState = ctx.parameter_cursor().get()?; host.state_mut().account_address_value = value.account_address_value; host.state_mut().contract_address_value = value.contract_address_value; host.state_mut().address_value = value.address_value; host.state_mut().u8_value = value.u8_value; host.state_mut().u16_value = value.u16_value; - host.state_mut().address_array = value.address_array; + drop(host.state_mut().address_array.replace(value.address_array)); host.state_mut().hash_value = value.hash_value; host.state_mut().signature_value = value.signature_value; host.state_mut().public_key_value = value.public_key_value; host.state_mut().timestamp_value = value.timestamp_value; host.state_mut().option_value = value.option_value; - host.state_mut().string_value = value.string_value; + drop(host.state_mut().string_value.replace(value.string_value)); Ok(()) } @@ -718,29 +769,29 @@ fn set_object( #[receive( contract = "smart_contract_test_bench", name = "set_object_payable", - parameter = "State", + parameter = "ReturnState", error = "ContractError", mutable, payable )] fn set_object_payable( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, _amount: Amount, ) -> Result<(), ContractError> { - let value: State = ctx.parameter_cursor().get()?; + let value: ReturnState = ctx.parameter_cursor().get()?; host.state_mut().account_address_value = value.account_address_value; host.state_mut().contract_address_value = value.contract_address_value; host.state_mut().address_value = value.address_value; host.state_mut().u8_value = value.u8_value; host.state_mut().u16_value = value.u16_value; - host.state_mut().address_array = value.address_array; + drop(host.state_mut().address_array.replace(value.address_array)); host.state_mut().hash_value = value.hash_value; host.state_mut().signature_value = value.signature_value; host.state_mut().public_key_value = value.public_key_value; host.state_mut().timestamp_value = value.timestamp_value; host.state_mut().option_value = value.option_value; - host.state_mut().string_value = value.string_value; + drop(host.state_mut().string_value.replace(value.string_value)); Ok(()) } @@ -748,15 +799,15 @@ fn set_object_payable( #[receive( contract = "smart_contract_test_bench", name = "get_object", - return_value = "State", + return_value = "ReturnState", error = "ContractError", mutable )] fn get_object( _ctx: &impl HasReceiveContext, - host: &mut impl HasHost, -) -> Result { - Ok(host.state().clone()) + host: &mut impl HasHost, StateApiType = S>, +) -> Result { + Ok(host.state().into()) } #[receive( @@ -767,7 +818,7 @@ fn get_object( )] fn success( _ctx: &impl HasReceiveContext, - _host: &mut impl HasHost, + _host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { Ok(()) } @@ -780,7 +831,7 @@ fn success( )] fn reverts( _ctx: &impl HasReceiveContext, - _host: &mut impl HasHost, + _host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { bail!(ContractError::SmartContractReverts); } @@ -793,7 +844,7 @@ fn reverts( )] fn internal_call_reverts( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { host.invoke_contract( &ctx.self_address(), @@ -813,7 +864,7 @@ fn internal_call_reverts( )] fn internal_call_success( ctx: &impl HasReceiveContext, - host: &mut impl HasHost, + host: &mut impl HasHost, StateApiType = S>, ) -> Result<(), ContractError> { host.invoke_contract( &ctx.self_address(), @@ -830,53 +881,11 @@ fn internal_call_success( name = "view", parameter = "HashSha2256", error = "ContractError", - return_value = "State" + return_value = "ReturnState" )] fn view( _ctx: &impl HasReceiveContext, - host: &impl HasHost, -) -> ReceiveResult { - Ok(host.state().clone()) -} - -#[concordium_cfg_test] -mod tests { - use super::*; - use test_infrastructure::*; - - const VALUE: u16 = 34u16; - const AMOUNT: concordium_std::Amount = Amount::from_micro_ccd(0); - - #[concordium_test] - /// Test that the smart-contract initialization sets the state correctly - /// without parameter. - fn test_init_without_parameter() { - let mut ctx = TestInitContext::empty(); - - ctx.set_parameter(&[]); - let mut state_builder = TestStateBuilder::new(); - - let state_result = contract_init(&ctx, &mut state_builder, AMOUNT); - let state = state_result.expect_report("Contract initialization results in error"); - - claim_eq!(0u16, state.u16_value, "u16 value should not be set"); - } - - #[concordium_test] - /// Test that the smart-contract initialization sets the state correctly - /// with parameter. - fn test_init_with_parameter() { - let mut ctx = TestInitContext::empty(); - - let parameter_bytes = to_bytes(&VALUE); - - ctx.set_parameter(¶meter_bytes); - - let mut state_builder = TestStateBuilder::new(); - - let state_result = contract_init(&ctx, &mut state_builder, AMOUNT); - let state = state_result.expect_report("Contract initialization results in error"); - - claim_eq!(VALUE, state.u16_value, "u16 value should be set"); - } + host: &impl HasHost, StateApiType = S>, +) -> ReceiveResult { + Ok(host.state().into()) }