Skip to content

Commit

Permalink
Remove potential revert in init and remove cep47 events dict creation…
Browse files Browse the repository at this point in the history
… on install (#240)

* Remove potential revert in init and remove cep47 events dicts creation on installation

* Remove pub on create_dummy_key_pair
  • Loading branch information
gRoussac authored Jun 30, 2023
1 parent 9532eaa commit 013ff85
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 335 deletions.
21 changes: 10 additions & 11 deletions contract/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ use constants::{
ENTRY_POINT_METADATA, ENTRY_POINT_MIGRATE, ENTRY_POINT_MINT, ENTRY_POINT_OWNER_OF,
ENTRY_POINT_REGISTER_OWNER, ENTRY_POINT_REVOKE, ENTRY_POINT_SET_APPROVALL_FOR_ALL,
ENTRY_POINT_SET_TOKEN_METADATA, ENTRY_POINT_SET_VARIABLES, ENTRY_POINT_TRANSFER,
ENTRY_POINT_UPDATED_RECEIPTS, EVENTS, EVENTS_MODE, HASH_BY_INDEX, HASH_KEY_NAME_1_0_0,
HOLDER_MODE, IDENTIFIER_MODE, INDEX_BY_HASH, INSTALLER, JSON_SCHEMA, MAX_TOTAL_TOKEN_SUPPLY,
METADATA_CEP78, METADATA_CUSTOM_VALIDATED, METADATA_MUTABILITY, METADATA_NFT721, METADATA_RAW,
MINTING_MODE, NFT_KIND, NFT_METADATA_KIND, NFT_METADATA_KINDS, NUMBER_OF_MINTED_TOKENS,
OPERATOR, OPERATORS, OWNED_TOKENS, OWNERSHIP_MODE, PAGE_LIMIT, PAGE_TABLE,
PREFIX_ACCESS_KEY_NAME, PREFIX_CEP78, PREFIX_CONTRACT_NAME, PREFIX_CONTRACT_VERSION,
PREFIX_HASH_KEY_NAME, PREFIX_PAGE_DICTIONARY, RECEIPT_NAME, REPORTING_MODE, RLO_MFLAG,
TOKEN_COUNT, TOKEN_ISSUERS, TOKEN_OWNERS, TOTAL_TOKEN_SUPPLY, TRANSFER_FILTER_CONTRACT,
TRANSFER_FILTER_CONTRACT_METHOD, UNMATCHED_HASH_COUNT, WHITELIST_MODE,
ENTRY_POINT_UPDATED_RECEIPTS, EVENTS_MODE, HASH_BY_INDEX, HASH_KEY_NAME_1_0_0, HOLDER_MODE,
IDENTIFIER_MODE, INDEX_BY_HASH, INSTALLER, JSON_SCHEMA, MAX_TOTAL_TOKEN_SUPPLY, METADATA_CEP78,
METADATA_CUSTOM_VALIDATED, METADATA_MUTABILITY, METADATA_NFT721, METADATA_RAW, MINTING_MODE,
NFT_KIND, NFT_METADATA_KIND, NFT_METADATA_KINDS, NUMBER_OF_MINTED_TOKENS, OPERATOR, OPERATORS,
OWNED_TOKENS, OWNERSHIP_MODE, PAGE_LIMIT, PAGE_TABLE, PREFIX_ACCESS_KEY_NAME, PREFIX_CEP78,
PREFIX_CONTRACT_NAME, PREFIX_CONTRACT_VERSION, PREFIX_HASH_KEY_NAME, PREFIX_PAGE_DICTIONARY,
RECEIPT_NAME, REPORTING_MODE, RLO_MFLAG, TOKEN_COUNT, TOKEN_ISSUERS, TOKEN_OWNERS,
TOTAL_TOKEN_SUPPLY, TRANSFER_FILTER_CONTRACT, TRANSFER_FILTER_CONTRACT_METHOD,
UNMATCHED_HASH_COUNT, WHITELIST_MODE,
};

use core::convert::{TryFrom, TryInto};
Expand Down Expand Up @@ -309,7 +309,7 @@ pub extern "C" fn init() {
ARG_TRANSFER_FILTER_CONTRACT,
NFTCoreError::InvalidTransferFilterContract,
)
.unwrap_or_revert();
.unwrap_or_default();

let transfer_filter_contract_contract_hash: Option<ContractHash> =
transfer_filter_contract_contract_key.map(|transfer_filter_contract_contract_key| {
Expand Down Expand Up @@ -425,7 +425,6 @@ pub extern "C" fn init() {
.unwrap_or_revert_with(NFTCoreError::FailedToCreateDictionary);
storage::new_dictionary(PAGE_TABLE)
.unwrap_or_revert_with(NFTCoreError::FailedToCreateDictionary);
storage::new_dictionary(EVENTS).unwrap_or_revert_with(NFTCoreError::FailedToCreateDictionary);
storage::new_dictionary(ACL_WHITELIST)
.unwrap_or_revert_with(NFTCoreError::FailedToCreateDictionary);

Expand Down
5 changes: 2 additions & 3 deletions tests/src/acl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ fn should_be_able_to_update_whitelist_for_minting_with_deprecated_arg_contract_w
nft_contract_hash,
ENTRY_POINT_SET_VARIABLES,
runtime_args! {
ARG_CONTRACT_WHITELIST => vec![minting_contract_hash]
ARG_CONTRACT_WHITELIST => vec![minting_contract_hash]
},
)
.build();
Expand Down Expand Up @@ -1128,8 +1128,7 @@ fn should_upgrade_from_named_keys_to_dict_and_acl_minting_mode() {

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

let nft_contract_hash = support::get_nft_contract_hash(&builder);
let nft_contract_key: Key = nft_contract_hash.into();
let nft_contract_key: Key = support::get_nft_contract_hash(&builder).into();

let is_updated_acl_whitelist = get_dictionary_value_from_key::<bool>(
&builder,
Expand Down
65 changes: 21 additions & 44 deletions tests/src/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use casper_engine_test_support::{
ExecuteRequestBuilder, InMemoryWasmTestBuilder, DEFAULT_ACCOUNT_ADDR,
PRODUCTION_RUN_GENESIS_REQUEST,
};
use casper_types::{account::AccountHash, runtime_args, ContractHash, Key, RuntimeArgs};
use casper_types::{account::AccountHash, runtime_args, Key, RuntimeArgs};
use contract::{
constants::{
ARG_APPROVE_ALL, ARG_COLLECTION_NAME, ARG_OPERATOR, ARG_TOKEN_HASH, ARG_TOKEN_ID,
Expand Down Expand Up @@ -46,13 +46,8 @@ fn should_burn_minted_token(reporting: OwnerReverseLookupMode) {
.expect_success()
.commit();

let installing_account = builder.get_expected_account(*DEFAULT_ACCOUNT_ADDR);
let nft_contract_key = installing_account
.named_keys()
.get(CONTRACT_NAME)
.expect("must have key in named keys");

let nft_contract_hash = get_nft_contract_hash(&builder);
let nft_contract_key: Key = nft_contract_hash.into();
let token_owner: Key = Key::Account(*DEFAULT_ACCOUNT_ADDR);
let token_id = 0u64;

Expand All @@ -62,7 +57,7 @@ fn should_burn_minted_token(reporting: OwnerReverseLookupMode) {
*DEFAULT_ACCOUNT_ADDR,
MINT_SESSION_WASM,
runtime_args! {
ARG_NFT_CONTRACT_HASH => Key::Hash(nft_contract_hash.value()),
ARG_NFT_CONTRACT_HASH => nft_contract_key,
ARG_TOKEN_OWNER => Key::Account(*DEFAULT_ACCOUNT_ADDR),
ARG_TOKEN_META_DATA => TEST_PRETTY_721_META_DATA.to_string(),
ARG_COLLECTION_NAME => NFT_TEST_COLLECTION.to_string()
Expand All @@ -74,7 +69,7 @@ fn should_burn_minted_token(reporting: OwnerReverseLookupMode) {

let token_page = support::get_token_page_by_id(
&builder,
nft_contract_key,
&nft_contract_key,
&Key::Account(*DEFAULT_ACCOUNT_ADDR),
token_id,
);
Expand All @@ -99,7 +94,7 @@ fn should_burn_minted_token(reporting: OwnerReverseLookupMode) {

let actual_balance_before_burn = support::get_dictionary_value_from_key::<u64>(
&builder,
nft_contract_key,
&nft_contract_key,
TOKEN_COUNT,
&DEFAULT_ACCOUNT_ADDR.clone().to_string(),
);
Expand All @@ -121,15 +116,15 @@ fn should_burn_minted_token(reporting: OwnerReverseLookupMode) {
//This will error of token is not registered as burnt.
support::get_dictionary_value_from_key::<()>(
&builder,
nft_contract_key,
&nft_contract_key,
BURNT_TOKENS,
&token_id.to_string(),
);

// This will error of token is not registered as
let actual_balance = support::get_dictionary_value_from_key::<u64>(
&builder,
nft_contract_key,
&nft_contract_key,
TOKEN_COUNT,
&DEFAULT_ACCOUNT_ADDR.clone().to_string(),
);
Expand All @@ -139,7 +134,7 @@ fn should_burn_minted_token(reporting: OwnerReverseLookupMode) {

// Expect Burn event.
let expected_event = Burn::new(token_owner, TokenIdentifier::Index(0));
let actual_event: Burn = support::get_event(&builder, nft_contract_key, 1);
let actual_event: Burn = support::get_event(&builder, &nft_contract_key, 1);
assert_eq!(actual_event, expected_event, "Expected Burn event.");
}

Expand Down Expand Up @@ -171,18 +166,13 @@ fn should_not_burn_previously_burnt_token() {
.expect_success()
.commit();

let installing_account = builder.get_expected_account(*DEFAULT_ACCOUNT_ADDR);
let nft_contract_key = installing_account
.named_keys()
.get(CONTRACT_NAME)
.expect("must have key in named keys");
let nft_contract_key: Key = get_nft_contract_hash(&builder).into();

let nft_contract_hash = get_nft_contract_hash(&builder);
let mint_session_call = ExecuteRequestBuilder::standard(
*DEFAULT_ACCOUNT_ADDR,
MINT_SESSION_WASM,
runtime_args! {
ARG_NFT_CONTRACT_HASH => Key::Hash(nft_contract_hash.value()),
ARG_NFT_CONTRACT_HASH => nft_contract_key,
ARG_TOKEN_OWNER => Key::Account(*DEFAULT_ACCOUNT_ADDR),
ARG_TOKEN_META_DATA => TEST_PRETTY_721_META_DATA.to_string(),
ARG_COLLECTION_NAME => NFT_TEST_COLLECTION.to_string()
Expand All @@ -194,7 +184,7 @@ fn should_not_burn_previously_burnt_token() {

let token_page = support::get_token_page_by_id(
&builder,
nft_contract_key,
&nft_contract_key,
&Key::Account(*DEFAULT_ACCOUNT_ADDR),
0u64,
);
Expand Down Expand Up @@ -291,22 +281,16 @@ fn should_return_expected_error_burning_of_others_users_token() {
.expect_success()
.commit();

let installing_account = builder.get_expected_account(*DEFAULT_ACCOUNT_ADDR);
let nft_contract_key = installing_account
.named_keys()
.get(CONTRACT_NAME)
.expect("must have key in named keys");
let nft_contract_hash = nft_contract_key
.into_hash()
.expect("must convert to hash addr");
let nft_contract_hash = get_nft_contract_hash(&builder);
let nft_contract_key: Key = nft_contract_hash.into();

let account_user_1 = support::create_funded_dummy_account(&mut builder, Some(ACCOUNT_USER_1));

let mint_session_call = ExecuteRequestBuilder::standard(
*DEFAULT_ACCOUNT_ADDR,
MINT_SESSION_WASM,
runtime_args! {
ARG_NFT_CONTRACT_HASH => Key::Hash(nft_contract_hash),
ARG_NFT_CONTRACT_HASH => nft_contract_key,
ARG_TOKEN_OWNER => Key::Account(*DEFAULT_ACCOUNT_ADDR),
ARG_TOKEN_META_DATA => TEST_PRETTY_721_META_DATA.to_string(),
ARG_COLLECTION_NAME => NFT_TEST_COLLECTION.to_string()
Expand All @@ -318,7 +302,7 @@ fn should_return_expected_error_burning_of_others_users_token() {

let token_page = support::get_token_page_by_id(
&builder,
nft_contract_key,
&nft_contract_key,
&Key::Account(*DEFAULT_ACCOUNT_ADDR),
0u64,
);
Expand All @@ -327,7 +311,7 @@ fn should_return_expected_error_burning_of_others_users_token() {

let incorrect_burn_request = ExecuteRequestBuilder::contract_call_by_hash(
account_user_1,
ContractHash::new(nft_contract_hash),
nft_contract_hash,
ENTRY_POINT_BURN,
runtime_args! {
ARG_TOKEN_ID => 0u64,
Expand Down Expand Up @@ -360,23 +344,16 @@ fn should_return_expected_error_when_burning_not_owned_token() {
.expect_success()
.commit();

let installing_account = builder.get_expected_account(*DEFAULT_ACCOUNT_ADDR);
let nft_contract_key = installing_account
.named_keys()
.get(CONTRACT_NAME)
.expect("must have key in named keys");

let nft_contract_hash = nft_contract_key
.into_hash()
.expect("must convert to hash addr");
let nft_contract_hash = get_nft_contract_hash(&builder);
let nft_contract_key: Key = nft_contract_hash.into();

let account_user_1 = support::create_funded_dummy_account(&mut builder, Some(ACCOUNT_USER_1));

let mint_session_call = ExecuteRequestBuilder::standard(
*DEFAULT_ACCOUNT_ADDR,
MINT_SESSION_WASM,
runtime_args! {
ARG_NFT_CONTRACT_HASH => Key::Hash(nft_contract_hash),
ARG_NFT_CONTRACT_HASH => nft_contract_key,
ARG_TOKEN_OWNER => Key::Account(*DEFAULT_ACCOUNT_ADDR),
ARG_TOKEN_META_DATA => TEST_PRETTY_721_META_DATA.to_string(),
ARG_COLLECTION_NAME => NFT_TEST_COLLECTION.to_string()
Expand All @@ -388,7 +365,7 @@ fn should_return_expected_error_when_burning_not_owned_token() {

let token_page = support::get_token_page_by_id(
&builder,
nft_contract_key,
&nft_contract_key,
&Key::Account(*DEFAULT_ACCOUNT_ADDR),
0u64,
);
Expand All @@ -397,7 +374,7 @@ fn should_return_expected_error_when_burning_not_owned_token() {

let incorrect_burn_request = ExecuteRequestBuilder::contract_call_by_hash(
account_user_1,
ContractHash::new(nft_contract_hash),
nft_contract_hash,
ENTRY_POINT_BURN,
runtime_args! {
ARG_TOKEN_ID => 0u64
Expand Down
3 changes: 1 addition & 2 deletions tests/src/costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ fn mint_cost_should_remain_stable() {

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

let nft_contract_hash = support::get_nft_contract_hash(&builder);
let nft_contract_key: Key = nft_contract_hash.into();
let nft_contract_key: Key = support::get_nft_contract_hash(&builder).into();

let first_mint_request = ExecuteRequestBuilder::standard(
*DEFAULT_ACCOUNT_ADDR,
Expand Down
Loading

0 comments on commit 013ff85

Please sign in to comment.