Skip to content

Commit

Permalink
Add comments about new modalities
Browse files Browse the repository at this point in the history
  • Loading branch information
darthsiroftardis committed Jun 14, 2022
1 parent 82004b7 commit 9279b6c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
3 changes: 1 addition & 2 deletions client/transfer_session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
#casper-contract = "1.4.3"
casper-contract = {version = "1.4.3", features = ["test-support"]}
casper-contract = "1.4.3"
casper-types = "1.4.5"

[[bin]]
Expand Down
1 change: 0 additions & 1 deletion contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2018"
casper-contract = {version = "1.4.3", features = ["test-support"]}
casper-types = "1.4.5"
serde = { version = "1", features = ["derive", "alloc"], default-features = false }
#serde-json-wasm = { path = "/home/karandh/casper/serde-json-wasm" }
base16 = { version = "0.2", default-features = false, features = ["alloc"] }
casper-serde-json-wasm = { git = "https://github.com/darthsiroftardis/casper-serde-json-wasm", branch = "casper-no-std"}

Expand Down
22 changes: 22 additions & 0 deletions contract/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,22 +1447,37 @@ pub extern "C" fn call() {
)
.unwrap_or_revert();

// Represents whether Accounts or Contracts, or both can hold NFTs for
// a given contract instance. Refer to the enum `NFTHolderMode`
// in the `src/utils.rs` file for details.
// This value cannot be changed after installation
let holder_mode: u8 =
get_optional_named_arg_with_user_errors(ARG_HOLDER_MODE, NFTCoreError::InvalidHolderMode)
.unwrap_or_revert_with(NFTCoreError::InvalidHolderMode);

// Represents whether a given contract whitelist can be modified
// for a given NFT contract instance. If not provided as an argument
// it will default to unlocked.
// This value cannot be changed after installation
let whitelist_lock: u8 = get_optional_named_arg_with_user_errors(
ARG_WHITELIST_MODE,
NFTCoreError::InvalidWhitelistMode,
)
.unwrap_or(0u8);

// A whitelist of contract hashes specifying which contracts can mint
// NFTs in the contract holder mode with restricted minting.
// This value can only be modified if the whitelist lock is
// set to be unlocked.
let contract_white_list: Vec<ContractHash> = get_optional_named_arg_with_user_errors(
ARG_CONTRACT_WHITELIST,
NFTCoreError::InvalidContractWhitelist,
)
.unwrap_or_default();

// Represents the schema for the metadata for a given NFT contract instance.
// Refer to the `NFTMetadataKind` enum in src/utils for details.
// This value cannot be changed after installation.
let nft_metadata_kind: u8 = get_named_arg_with_user_errors(
ARG_NFT_METADATA_KIND,
NFTCoreError::MissingNFTMetadataKind,
Expand All @@ -1479,6 +1494,9 @@ pub extern "C" fn call() {
)
.unwrap_or_revert();

// Represents whether NFTs minted by a given contract will be identified
// by an ordinal u64 index or a base16 encoded SHA256 hash of an NFTs metadata.
// This value cannot be changed after installation.
let identifier_mode: u8 = get_named_arg_with_user_errors(
ARG_IDENTIFIER_MODE,
NFTCoreError::MissingIdentifierMode,
Expand All @@ -1498,6 +1516,10 @@ pub extern "C" fn call() {
.map(ContractPackageHash::new)
.unwrap();

// A sentinel string value which represents the entry for the addition
// of a read only reference to the NFTs owned by the calling `Account` or `Contract`
// This allows for users to look up a set of named keys and correctly identify
// the contract package from which the NFTs were obtained.
let receipt_name = format!(
"nft-{}-{}",
collection_name,
Expand Down
19 changes: 8 additions & 11 deletions tests/src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,12 +1336,11 @@ fn should_fail_to_mint_when_immediate_caller_is_account_in_contract_mode() {
let mut builder = InMemoryWasmTestBuilder::default();
builder.run_genesis(&DEFAULT_RUN_GENESIS_REQUEST).commit();

let install_request =
InstallerRequestBuilder::new(*DEFAULT_ACCOUNT_ADDR, NFT_CONTRACT_WASM)
.with_total_token_supply(2u64)
.with_holder_mode(NFTHolderMode::Contracts)
.with_whitelist_mode(WhitelistMode::Unlocked)
.build();
let install_request = InstallerRequestBuilder::new(*DEFAULT_ACCOUNT_ADDR, NFT_CONTRACT_WASM)
.with_total_token_supply(2u64)
.with_holder_mode(NFTHolderMode::Contracts)
.with_whitelist_mode(WhitelistMode::Unlocked)
.build();

builder.exec(install_request).expect_success().commit();

Expand All @@ -1356,13 +1355,11 @@ fn should_fail_to_mint_when_immediate_caller_is_account_in_contract_mode() {
ARG_TOKEN_META_DATA => TEST_COMPACT_META_DATA,
},
)
.build();
.build();

builder
.exec(mint_session_call)
.expect_failure();
builder.exec(mint_session_call).expect_failure();

let error = builder.get_error().expect("must have error");

assert_expected_error(error, 76, "InvalidHolderMode(76) must have been raised");
}
}

0 comments on commit 9279b6c

Please sign in to comment.