From 7b37021d19b85ebb26d24e62a2c66c0a3a9ee365 Mon Sep 17 00:00:00 2001 From: Fraser Hutchison Date: Sun, 3 Mar 2024 16:06:37 +0000 Subject: [PATCH 1/4] restructure project and update Makefile --- .travis.yml | 5 --- Cargo.toml | 7 ---- Makefile | 35 ++++++++++--------- {contract => contracts}/.cargo/config.toml | 0 contracts/Cargo.toml | 17 +++++++++ {contract => contracts/cep85}/Cargo.toml | 19 +++++----- {contract => contracts/cep85}/src/balances.rs | 0 .../cep85}/src/constants.rs | 0 .../cep85}/src/entry_points.rs | 0 {contract => contracts/cep85}/src/error.rs | 0 {contract => contracts/cep85}/src/events.rs | 0 {contract => contracts/cep85}/src/lib.rs | 0 {contract => contracts/cep85}/src/main.rs | 0 .../cep85}/src/modalities.rs | 0 .../cep85}/src/operators.rs | 0 {contract => contracts/cep85}/src/security.rs | 0 {contract => contracts/cep85}/src/supply.rs | 0 {contract => contracts/cep85}/src/uri.rs | 0 {contract => contracts/cep85}/src/utils.rs | 0 rust-toolchain => contracts/rust-toolchain | 0 {test-contract => contracts/test}/Cargo.toml | 16 +++++---- .../test}/src/constants.rs | 0 {test-contract => contracts/test}/src/lib.rs | 0 {test-contract => contracts/test}/src/main.rs | 0 .../test}/src/utils.rs | 0 tests/Cargo.toml | 10 +++--- 26 files changed, 58 insertions(+), 51 deletions(-) delete mode 100644 .travis.yml delete mode 100644 Cargo.toml rename {contract => contracts}/.cargo/config.toml (100%) create mode 100644 contracts/Cargo.toml rename {contract => contracts/cep85}/Cargo.toml (50%) rename {contract => contracts/cep85}/src/balances.rs (100%) rename {contract => contracts/cep85}/src/constants.rs (100%) rename {contract => contracts/cep85}/src/entry_points.rs (100%) rename {contract => contracts/cep85}/src/error.rs (100%) rename {contract => contracts/cep85}/src/events.rs (100%) rename {contract => contracts/cep85}/src/lib.rs (100%) rename {contract => contracts/cep85}/src/main.rs (100%) rename {contract => contracts/cep85}/src/modalities.rs (100%) rename {contract => contracts/cep85}/src/operators.rs (100%) rename {contract => contracts/cep85}/src/security.rs (100%) rename {contract => contracts/cep85}/src/supply.rs (100%) rename {contract => contracts/cep85}/src/uri.rs (100%) rename {contract => contracts/cep85}/src/utils.rs (100%) rename rust-toolchain => contracts/rust-toolchain (100%) rename {test-contract => contracts/test}/Cargo.toml (51%) rename {test-contract => contracts/test}/src/constants.rs (100%) rename {test-contract => contracts/test}/src/lib.rs (100%) rename {test-contract => contracts/test}/src/main.rs (100%) rename {test-contract => contracts/test}/src/utils.rs (100%) diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 34a171f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: rust -script: - - make prepare - - make check-lint - - make test diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index 369c518..0000000 --- a/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[workspace] -members = ["contract", "test-contract", "tests"] -default-members = ["contract", "test-contract", "tests"] - -[profile.release] -codegen-units = 1 -lto = true diff --git a/Makefile b/Makefile index 7f54c28..30fadf0 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ALL_CONTRACTS = cep85 cep85-test-contract -CONTRACT_TARGET_DIR = target/wasm32-unknown-unknown/release -PINNED_TOOLCHAIN := $(shell cat rust-toolchain) +CONTRACT_TARGET_DIR = contracts/target/wasm32-unknown-unknown/release +PINNED_TOOLCHAIN := $(shell cat contracts/rust-toolchain) prepare: rustup target add wasm32-unknown-unknown @@ -9,10 +9,15 @@ prepare: .PHONY: build-contract build-contract: - cargo build --release --target wasm32-unknown-unknown $(patsubst %,-p %, $(ALL_CONTRACTS)) + cd contracts/cep85 && cargo build --release + wasm-strip $(CONTRACT_TARGET_DIR)/cep85.wasm + +.PHONY: build-all-contracts +build-all-contracts: + cd contracts && cargo build --release $(patsubst %,-p %, $(ALL_CONTRACTS)) $(foreach WASM, $(ALL_CONTRACTS), wasm-strip $(CONTRACT_TARGET_DIR)/$(subst -,_,$(WASM)).wasm ;) -setup-test: build-contract +setup-test: build-all-contracts mkdir -p tests/wasm cp $(CONTRACT_TARGET_DIR)/cep85.wasm tests/wasm cp $(CONTRACT_TARGET_DIR)/cep85_test_contract.wasm tests/wasm @@ -21,24 +26,20 @@ test: setup-test cd tests && cargo test --release clippy: - cd contract && cargo clippy --target wasm32-unknown-unknown --bins -- -D warnings - cd contract && cargo clippy --lib -- -D warnings - cd contract && cargo clippy --no-default-features --lib -- -D warnings - cd test-contract && cargo clippy --target wasm32-unknown-unknown -- -D warnings + cd contracts && cargo clippy --bins -- -D warnings + cd contracts && cargo clippy --lib -- -D warnings + cd contracts && cargo clippy --lib --no-default-features -- -D warnings cd tests && cargo clippy --all-targets -- -D warnings check-lint: clippy - cd contract && cargo fmt -- --check - cd test-contract && cargo fmt -- --check - cd tests && cargo fmt -- --check + cd contracts && cargo fmt -- --check + cd tests && cargo +$(PINNED_TOOLCHAIN) fmt -- --check -lint: clippy - cd contract && cargo fmt - cd test-contract && cargo fmt - cd tests && cargo fmt +format: + cd contracts && cargo fmt + cd tests && cargo +$(PINNED_TOOLCHAIN) fmt clean: - cd contract && cargo clean - cd test-contract && cargo clean + cd contracts && cargo clean cd tests && cargo clean rm -rf tests/wasm diff --git a/contract/.cargo/config.toml b/contracts/.cargo/config.toml similarity index 100% rename from contract/.cargo/config.toml rename to contracts/.cargo/config.toml diff --git a/contracts/Cargo.toml b/contracts/Cargo.toml new file mode 100644 index 0000000..6c66eaa --- /dev/null +++ b/contracts/Cargo.toml @@ -0,0 +1,17 @@ +[workspace] +members = ["cep85", "test"] +resolver = "2" + +[workspace.package] +edition = "2021" +homepage = "https://casperlabs.io" +license-file = "../LICENSE" +readme = "../README.md" +repository = "https://github.com/casper-ecosystem/cep-85" + +[workspace.dependencies] +casper-types = "3.0.0" + +[profile.release] +codegen-units = 1 +lto = true diff --git a/contract/Cargo.toml b/contracts/cep85/Cargo.toml similarity index 50% rename from contract/Cargo.toml rename to contracts/cep85/Cargo.toml index 62853f6..bba7ac9 100644 --- a/contract/Cargo.toml +++ b/contracts/cep85/Cargo.toml @@ -1,17 +1,16 @@ [package] name = "cep85" version = "1.0.0" -edition = "2018" description = "A library for developing CEP-85 tokens for the Casper network." -readme = "README.md" -documentation = "https://docs.rs/casper-cep-85" -homepage = "https://casperlabs.io" -repository = "https://github.com/casper-ecosystem/cep-85" -license-file = "../LICENSE" +edition.workspace = true +homepage.workspace = true +license-file.workspace = true +readme.workspace = true +repository.workspace = true [dependencies] -casper-contract = { version = "3.0.0", optional = true } -casper-types = "3.0.0" +casper-contract = { version = "3.0.0", optional = true, default-features = false } +casper-types.workspace = true casper-event-standard = { version = "0.4.0", default-features = false } hex = { version = "0.4.3", default-features = false } @@ -23,5 +22,5 @@ doctest = false test = false [features] -default = ["contract-support"] -contract-support = ["dep:casper-contract"] +default = ["contract-support", "casper-contract/no-std-helpers"] +contract-support = ["casper-contract"] diff --git a/contract/src/balances.rs b/contracts/cep85/src/balances.rs similarity index 100% rename from contract/src/balances.rs rename to contracts/cep85/src/balances.rs diff --git a/contract/src/constants.rs b/contracts/cep85/src/constants.rs similarity index 100% rename from contract/src/constants.rs rename to contracts/cep85/src/constants.rs diff --git a/contract/src/entry_points.rs b/contracts/cep85/src/entry_points.rs similarity index 100% rename from contract/src/entry_points.rs rename to contracts/cep85/src/entry_points.rs diff --git a/contract/src/error.rs b/contracts/cep85/src/error.rs similarity index 100% rename from contract/src/error.rs rename to contracts/cep85/src/error.rs diff --git a/contract/src/events.rs b/contracts/cep85/src/events.rs similarity index 100% rename from contract/src/events.rs rename to contracts/cep85/src/events.rs diff --git a/contract/src/lib.rs b/contracts/cep85/src/lib.rs similarity index 100% rename from contract/src/lib.rs rename to contracts/cep85/src/lib.rs diff --git a/contract/src/main.rs b/contracts/cep85/src/main.rs similarity index 100% rename from contract/src/main.rs rename to contracts/cep85/src/main.rs diff --git a/contract/src/modalities.rs b/contracts/cep85/src/modalities.rs similarity index 100% rename from contract/src/modalities.rs rename to contracts/cep85/src/modalities.rs diff --git a/contract/src/operators.rs b/contracts/cep85/src/operators.rs similarity index 100% rename from contract/src/operators.rs rename to contracts/cep85/src/operators.rs diff --git a/contract/src/security.rs b/contracts/cep85/src/security.rs similarity index 100% rename from contract/src/security.rs rename to contracts/cep85/src/security.rs diff --git a/contract/src/supply.rs b/contracts/cep85/src/supply.rs similarity index 100% rename from contract/src/supply.rs rename to contracts/cep85/src/supply.rs diff --git a/contract/src/uri.rs b/contracts/cep85/src/uri.rs similarity index 100% rename from contract/src/uri.rs rename to contracts/cep85/src/uri.rs diff --git a/contract/src/utils.rs b/contracts/cep85/src/utils.rs similarity index 100% rename from contract/src/utils.rs rename to contracts/cep85/src/utils.rs diff --git a/rust-toolchain b/contracts/rust-toolchain similarity index 100% rename from rust-toolchain rename to contracts/rust-toolchain diff --git a/test-contract/Cargo.toml b/contracts/test/Cargo.toml similarity index 51% rename from test-contract/Cargo.toml rename to contracts/test/Cargo.toml index 4863d17..dc0c6ca 100644 --- a/test-contract/Cargo.toml +++ b/contracts/test/Cargo.toml @@ -1,7 +1,16 @@ [package] name = "cep85-test-contract" version = "1.0.0" -edition = "2018" +edition.workspace = true +homepage.workspace = true +license-file.workspace = true +readme.workspace = true +repository.workspace = true + +[dependencies] +cep85 = { path = "../cep85" } +casper-contract = "3.0.0" +casper-types.workspace = true [[bin]] name = "cep85_test_contract" @@ -9,8 +18,3 @@ path = "src/main.rs" bench = false doctest = false test = false - -[dependencies] -cep85 = { path = "../contract" } -casper-contract = "3.0.0" -casper-types = "3.0.0" diff --git a/test-contract/src/constants.rs b/contracts/test/src/constants.rs similarity index 100% rename from test-contract/src/constants.rs rename to contracts/test/src/constants.rs diff --git a/test-contract/src/lib.rs b/contracts/test/src/lib.rs similarity index 100% rename from test-contract/src/lib.rs rename to contracts/test/src/lib.rs diff --git a/test-contract/src/main.rs b/contracts/test/src/main.rs similarity index 100% rename from test-contract/src/main.rs rename to contracts/test/src/main.rs diff --git a/test-contract/src/utils.rs b/contracts/test/src/utils.rs similarity index 100% rename from test-contract/src/utils.rs rename to contracts/test/src/utils.rs diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 6793181..4cff7c4 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -1,14 +1,12 @@ [package] name = "tests" version = "1.0.0" -edition = "2018" +edition = "2021" [dev-dependencies] -cep85 = { path = "../contract", default-features = false } -cep85-test-contract = { path = "../test-contract" } -casper-contract = { version = "3.0.0", default-features = false, features = [ - "std", -] } +cep85 = { path = "../contracts/cep85", default-features = false } +cep85-test-contract = { path = "../contracts/test" } +casper-contract = { version = "3.0.0", default-features = false, features = ["std"] } casper-engine-test-support = "5.0.0" casper-execution-engine = "5.0.0" casper-types = "3.0.0" From a889632ca9e8efa9ad649fc68f313f759659a4d2 Mon Sep 17 00:00:00 2001 From: Fraser Hutchison Date: Sun, 3 Mar 2024 21:44:07 +0000 Subject: [PATCH 2/4] update contract to export required items for testing --- contracts/cep85/src/events.rs | 16 +++++++++----- contracts/cep85/src/lib.rs | 9 +++----- contracts/cep85/src/security.rs | 13 ++++++++++-- contracts/cep85/src/utils.rs | 37 ++++++++++++++++++++++++++------- contracts/test/Cargo.toml | 7 +++++-- tests/Cargo.toml | 3 +-- 6 files changed, 60 insertions(+), 25 deletions(-) diff --git a/contracts/cep85/src/events.rs b/contracts/cep85/src/events.rs index aae3dd9..d3345a7 100644 --- a/contracts/cep85/src/events.rs +++ b/contracts/cep85/src/events.rs @@ -1,11 +1,14 @@ -use crate::{ - constants::ARG_EVENTS_MODE, modalities::EventsMode, security::SecurityBadge, - utils::get_stored_value, -}; +use crate::security::SecurityBadge; +#[cfg(feature = "contract-support")] +use crate::{constants::ARG_EVENTS_MODE, modalities::EventsMode, utils::get_stored_value}; use alloc::{collections::BTreeMap, string::String, vec::Vec}; +#[cfg(feature = "contract-support")] use casper_contract::unwrap_or_revert::UnwrapOrRevert; -use casper_event_standard::{emit, Event, Schemas}; +use casper_event_standard::Event; +#[cfg(feature = "contract-support")] +use casper_event_standard::{emit, Schemas}; use casper_types::{Key, U256}; +#[cfg(feature = "contract-support")] use core::convert::TryFrom; #[derive(Debug)] @@ -22,6 +25,7 @@ pub enum Event { Upgrade(Upgrade), } +#[cfg(feature = "contract-support")] pub fn record_event_dictionary(event: Event) { let events_mode: EventsMode = EventsMode::try_from(get_stored_value::(ARG_EVENTS_MODE)).unwrap_or_revert(); @@ -178,6 +182,7 @@ impl Upgrade { } } +#[cfg(feature = "contract-support")] fn ces(event: Event) { match event { Event::Mint(ev) => emit(ev), @@ -193,6 +198,7 @@ fn ces(event: Event) { } } +#[cfg(feature = "contract-support")] pub fn init_events() { let events_mode = EventsMode::try_from(get_stored_value::(ARG_EVENTS_MODE)).unwrap_or_revert(); diff --git a/contracts/cep85/src/lib.rs b/contracts/cep85/src/lib.rs index 086bfc9..313b05d 100644 --- a/contracts/cep85/src/lib.rs +++ b/contracts/cep85/src/lib.rs @@ -5,19 +5,16 @@ extern crate alloc; pub mod constants; pub mod entry_points; pub mod error; +pub mod events; pub mod modalities; +pub mod security; +pub mod utils; #[cfg(feature = "contract-support")] pub mod balances; #[cfg(feature = "contract-support")] -pub mod events; -#[cfg(feature = "contract-support")] pub mod operators; #[cfg(feature = "contract-support")] -pub mod security; -#[cfg(feature = "contract-support")] pub mod supply; #[cfg(feature = "contract-support")] pub mod uri; -#[cfg(feature = "contract-support")] -pub mod utils; diff --git a/contracts/cep85/src/security.rs b/contracts/cep85/src/security.rs index 3eb73f9..0061aaa 100644 --- a/contracts/cep85/src/security.rs +++ b/contracts/cep85/src/security.rs @@ -1,10 +1,16 @@ -use alloc::{collections::BTreeMap, vec, vec::Vec}; +#[cfg(feature = "contract-support")] +use alloc::collections::BTreeMap; +use alloc::{vec, vec::Vec}; +#[cfg(feature = "contract-support")] use casper_contract::{contract_api::runtime::revert, unwrap_or_revert::UnwrapOrRevert}; +#[cfg(feature = "contract-support")] +use casper_types::Key; use casper_types::{ bytesrepr::{self, FromBytes, ToBytes}, - CLTyped, Key, + CLTyped, }; +#[cfg(feature = "contract-support")] use crate::{ constants::DICT_SECURITY_BADGES, error::Cep85Error, @@ -53,6 +59,7 @@ impl FromBytes for SecurityBadge { } } +#[cfg(feature = "contract-support")] pub fn sec_check(allowed_badge_list: Vec) { let (caller, caller_package) = get_verified_caller(); let caller_badge = get_security_badge(&caller); @@ -69,6 +76,7 @@ pub fn sec_check(allowed_badge_list: Vec) { revert(Cep85Error::InsufficientRights); } +#[cfg(feature = "contract-support")] fn get_security_badge(entity: &Key) -> Option { get_dictionary_value_from_key( DICT_SECURITY_BADGES, @@ -76,6 +84,7 @@ fn get_security_badge(entity: &Key) -> Option { ) } +#[cfg(feature = "contract-support")] pub fn change_sec_badge(badge_map: &BTreeMap) { for (&user, &badge) in badge_map { set_dictionary_value_for_key( diff --git a/contracts/cep85/src/utils.rs b/contracts/cep85/src/utils.rs index 6d91b19..779333f 100644 --- a/contracts/cep85/src/utils.rs +++ b/contracts/cep85/src/utils.rs @@ -1,33 +1,36 @@ +#[cfg(feature = "contract-support")] use crate::{ constants::{ARG_TRANSFER_FILTER_CONTRACT, ARG_TRANSFER_FILTER_METHOD}, error::Cep85Error, }; -use alloc::{ - borrow::ToOwned, - format, - string::{String, ToString}, - vec, - vec::Vec, -}; +#[cfg(feature = "contract-support")] +use alloc::{borrow::ToOwned, string::ToString, vec, vec::Vec}; +use alloc::{format, string::String}; +#[cfg(feature = "contract-support")] use casper_contract::{ contract_api::{self, runtime, storage}, ext_ffi, unwrap_or_revert::UnwrapOrRevert, }; +use casper_types::U256; +#[cfg(feature = "contract-support")] use casper_types::{ account::AccountHash, api_error, bytesrepr::{self, FromBytes, ToBytes}, system::CallStackElement, - ApiError, CLTyped, ContractHash, ContractPackageHash, Key, URef, U256, + ApiError, CLTyped, ContractHash, ContractPackageHash, Key, URef, }; +#[cfg(feature = "contract-support")] use core::{convert::TryInto, mem::MaybeUninit}; +#[cfg(feature = "contract-support")] pub enum Caller { Session(AccountHash), StoredCaller(ContractHash, ContractPackageHash), } +#[cfg(feature = "contract-support")] pub fn get_verified_caller() -> (Key, Option) { let get_verified_caller: Result = match *runtime::get_call_stack() .iter() @@ -57,6 +60,7 @@ pub fn get_verified_caller() -> (Key, Option) { } } +#[cfg(feature = "contract-support")] pub fn get_stored_value(name: &str) -> T where T: FromBytes + CLTyped, @@ -66,6 +70,7 @@ where value } +#[cfg(feature = "contract-support")] pub fn get_named_arg_with_user_errors( name: &str, missing: Cep85Error, @@ -97,6 +102,7 @@ pub fn get_named_arg_with_user_errors( bytesrepr::deserialize(arg_bytes).map_err(|_| invalid) } +#[cfg(feature = "contract-support")] pub fn get_optional_named_arg_with_user_errors( name: &str, invalid: Cep85Error, @@ -107,6 +113,7 @@ pub fn get_optional_named_arg_with_user_errors( } } +#[cfg(feature = "contract-support")] pub fn get_stored_value_with_user_errors( name: &str, missing: Cep85Error, @@ -116,6 +123,7 @@ pub fn get_stored_value_with_user_errors( read_with_user_errors(uref, missing, invalid) } +#[cfg(feature = "contract-support")] pub fn stringify_key(key: Key) -> String { match key { Key::Account(account_hash) => account_hash.to_string(), @@ -124,6 +132,7 @@ pub fn stringify_key(key: Key) -> String { } } +#[cfg(feature = "contract-support")] pub fn make_dictionary_item_key( key: &T, value: &V, @@ -137,6 +146,7 @@ pub fn make_dictionary_item_key( hex::encode(bytes) } +#[cfg(feature = "contract-support")] pub fn get_dictionary_value_from_key( dictionary_name: &str, key: &str, @@ -153,6 +163,7 @@ pub fn get_dictionary_value_from_key( } } +#[cfg(feature = "contract-support")] pub fn set_dictionary_value_for_key( dictionary_name: &str, key: &str, @@ -166,6 +177,7 @@ pub fn set_dictionary_value_for_key( storage::dictionary_put::(seed_uref, key, *value) } +#[cfg(feature = "contract-support")] pub fn get_transfer_filter_contract() -> Option { get_stored_value_with_user_errors( ARG_TRANSFER_FILTER_CONTRACT, @@ -174,6 +186,7 @@ pub fn get_transfer_filter_contract() -> Option { ) } +#[cfg(feature = "contract-support")] pub fn get_transfer_filter_method() -> Option { get_stored_value_with_user_errors( ARG_TRANSFER_FILTER_METHOD, @@ -186,6 +199,7 @@ pub fn replace_token_id_in_uri(raw_uri: &str, id: &U256) -> String { raw_uri.replace("{id}", &format!("{}", id)) } +#[cfg(feature = "contract-support")] fn get_uref(name: &str) -> URef { let key = runtime::get_key(name) .ok_or(ApiError::MissingKey) @@ -193,12 +207,14 @@ fn get_uref(name: &str) -> URef { key.try_into().unwrap_or_revert() } +#[cfg(feature = "contract-support")] fn get_uref_with_user_errors(name: &str, missing: Cep85Error, invalid: Cep85Error) -> URef { let key = get_key_with_user_errors(name, missing, invalid); key.into_uref() .unwrap_or_revert_with(Cep85Error::UnexpectedKeyVariant) } +#[cfg(feature = "contract-support")] fn get_key_with_user_errors(name: &str, missing: Cep85Error, invalid: Cep85Error) -> Key { let (name_ptr, name_size, _bytes) = to_ptr(name); let mut key_bytes = vec![0u8; Key::max_serialized_length()]; @@ -222,6 +238,7 @@ fn get_key_with_user_errors(name: &str, missing: Cep85Error, invalid: Cep85Error bytesrepr::deserialize(key_bytes).unwrap_or_revert_with(invalid) } +#[cfg(feature = "contract-support")] fn read_with_user_errors( uref: URef, missing: Cep85Error, @@ -245,6 +262,7 @@ fn read_with_user_errors( bytesrepr::deserialize(value_bytes).unwrap_or_revert_with(invalid) } +#[cfg(feature = "contract-support")] fn read_host_buffer(size: usize) -> Result, ApiError> { let mut dest: Vec = if size == 0 { Vec::new() @@ -256,6 +274,7 @@ fn read_host_buffer(size: usize) -> Result, ApiError> { Ok(dest) } +#[cfg(feature = "contract-support")] fn read_host_buffer_into(dest: &mut [u8]) -> Result { let mut bytes_written = MaybeUninit::uninit(); let ret = unsafe { @@ -268,6 +287,7 @@ fn read_host_buffer_into(dest: &mut [u8]) -> Result { Ok(unsafe { bytes_written.assume_init() }) } +#[cfg(feature = "contract-support")] fn to_ptr(t: T) -> (*const u8, usize, Vec) { let bytes = t.into_bytes().unwrap_or_revert(); let ptr = bytes.as_ptr(); @@ -275,6 +295,7 @@ fn to_ptr(t: T) -> (*const u8, usize, Vec) { (ptr, size, bytes) } +#[cfg(feature = "contract-support")] fn get_named_arg_size(name: &str) -> Option { let mut arg_size: usize = 0; let ret = unsafe { diff --git a/contracts/test/Cargo.toml b/contracts/test/Cargo.toml index dc0c6ca..86ae4aa 100644 --- a/contracts/test/Cargo.toml +++ b/contracts/test/Cargo.toml @@ -8,8 +8,8 @@ readme.workspace = true repository.workspace = true [dependencies] -cep85 = { path = "../cep85" } -casper-contract = "3.0.0" +cep85 = { path = "../cep85", default-features = false } +casper-contract = { version = "3.0.0", optional = true, default-features = false } casper-types.workspace = true [[bin]] @@ -18,3 +18,6 @@ path = "src/main.rs" bench = false doctest = false test = false + +[features] +default = ["cep85/contract-support", "casper-contract/no-std-helpers"] diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 4cff7c4..c93137a 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -5,8 +5,7 @@ edition = "2021" [dev-dependencies] cep85 = { path = "../contracts/cep85", default-features = false } -cep85-test-contract = { path = "../contracts/test" } -casper-contract = { version = "3.0.0", default-features = false, features = ["std"] } +cep85-test-contract = { path = "../contracts/test", default-features = false } casper-engine-test-support = "5.0.0" casper-execution-engine = "5.0.0" casper-types = "3.0.0" From 307c3e14dd7f39cf5289fde56d2d2817b38593e8 Mon Sep 17 00:00:00 2001 From: Fraser Hutchison Date: Sun, 3 Mar 2024 21:57:26 +0000 Subject: [PATCH 3/4] fix lints --- .../src/utility/installer_request_builders.rs | 88 ++++++++----------- 1 file changed, 38 insertions(+), 50 deletions(-) diff --git a/tests/src/utility/installer_request_builders.rs b/tests/src/utility/installer_request_builders.rs index 4c7286d..62c7268 100644 --- a/tests/src/utility/installer_request_builders.rs +++ b/tests/src/utility/installer_request_builders.rs @@ -1,7 +1,4 @@ -use std::{ - collections::HashMap, - convert::{TryFrom, TryInto}, -}; +use std::{collections::HashMap, convert::TryInto}; use super::{ constants::{ @@ -159,8 +156,7 @@ pub fn get_test_result( let enabled_versions = contract_package.enabled_versions(); let (_version, contract_hash) = enabled_versions .iter() - .rev() - .next() + .next_back() .expect("should have latest version"); builder.get_value(*contract_hash, RESULT_KEY) @@ -610,27 +606,25 @@ pub fn cep85_transfer_from<'a>( let call_package = direct_call_test_contract.is_none() || direct_call_test_contract == Some(false); if call_package { - if let Ok(contract_package_hash) = ContractPackageHash::try_from(*hash_bytes) { - let args = runtime_args! { - ARG_FROM => *from, - ARG_TO => *to, - ARG_ID => ids[0], - ARG_AMOUNT => amounts[0], - ARG_DATA => data, - }; - - ExecuteRequestBuilder::versioned_contract_call_by_hash( - *sender, - contract_package_hash, - None, - ENTRY_POINT_CHECK_SAFE_TRANSFER_FROM, - args, - ) - .build() - } else { - panic!("Unknown variant"); - } - } else if let Ok(contract_hash) = ContractHash::try_from(*hash_bytes) { + let contract_package_hash = ContractPackageHash::from(*hash_bytes); + let args = runtime_args! { + ARG_FROM => *from, + ARG_TO => *to, + ARG_ID => ids[0], + ARG_AMOUNT => amounts[0], + ARG_DATA => data, + }; + + ExecuteRequestBuilder::versioned_contract_call_by_hash( + *sender, + contract_package_hash, + None, + ENTRY_POINT_CHECK_SAFE_TRANSFER_FROM, + args, + ) + .build() + } else { + let contract_hash = ContractHash::from(*hash_bytes); let args = runtime_args! { ARG_FROM => *from, ARG_TO => *to, @@ -646,8 +640,6 @@ pub fn cep85_transfer_from<'a>( args, ) .build() - } else { - panic!("Unknown variant"); } } _ => panic!("Unknown variant"), @@ -728,25 +720,23 @@ pub fn cep85_batch_transfer_from<'a>( let call_package = direct_call_test_contract.is_none() || direct_call_test_contract == Some(false); if call_package { - if let Ok(contract_package_hash) = ContractPackageHash::try_from(*hash_bytes) { - ExecuteRequestBuilder::versioned_contract_call_by_hash( - *sender, - contract_package_hash, - None, - ENTRY_POINT_CHECK_SAFE_BATCH_TRANSFER_FROM, - runtime_args! { - ARG_FROM => *from, - ARG_TO => *to, - ARG_IDS => ids, - ARG_AMOUNTS => amounts, - ARG_DATA => data, - }, - ) - .build() - } else { - panic!("Unknown variant"); - } - } else if let Ok(contract_hash) = ContractHash::try_from(*hash_bytes) { + let contract_package_hash = ContractPackageHash::from(*hash_bytes); + ExecuteRequestBuilder::versioned_contract_call_by_hash( + *sender, + contract_package_hash, + None, + ENTRY_POINT_CHECK_SAFE_BATCH_TRANSFER_FROM, + runtime_args! { + ARG_FROM => *from, + ARG_TO => *to, + ARG_IDS => ids, + ARG_AMOUNTS => amounts, + ARG_DATA => data, + }, + ) + .build() + } else { + let contract_hash = ContractHash::from(*hash_bytes); ExecuteRequestBuilder::contract_call_by_hash( *sender, contract_hash, @@ -760,8 +750,6 @@ pub fn cep85_batch_transfer_from<'a>( }, ) .build() - } else { - panic!("Unknown variant"); } } _ => panic!("Unknown variant"), From 53e413ca4f2f4649f01e653a5a48b44e20a06958 Mon Sep 17 00:00:00 2001 From: Fraser Hutchison Date: Mon, 4 Mar 2024 11:06:21 +0000 Subject: [PATCH 4/4] simplify the cep85 mainfest --- contracts/cep85/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/cep85/Cargo.toml b/contracts/cep85/Cargo.toml index bba7ac9..d9f8c53 100644 --- a/contracts/cep85/Cargo.toml +++ b/contracts/cep85/Cargo.toml @@ -9,7 +9,7 @@ readme.workspace = true repository.workspace = true [dependencies] -casper-contract = { version = "3.0.0", optional = true, default-features = false } +casper-contract = { version = "3.0.0", optional = true } casper-types.workspace = true casper-event-standard = { version = "0.4.0", default-features = false } hex = { version = "0.4.3", default-features = false } @@ -22,5 +22,5 @@ doctest = false test = false [features] -default = ["contract-support", "casper-contract/no-std-helpers"] -contract-support = ["casper-contract"] +default = ["contract-support"] +contract-support = ["dep:casper-contract"]