Skip to content

Commit

Permalink
Add test upgrade from 1.3 to 1.4 (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
gRoussac authored Jun 12, 2023
1 parent 22e9b6d commit 394ab90
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ setup-test: build-contract
mkdir -p tests/wasm/1_0_0; curl -L https://github.com/casper-ecosystem/cep-78-enhanced-nft/releases/download/v1.0.0/cep-78-wasm.tar.gz | tar zxv -C tests/wasm/1_0_0/
mkdir -p tests/wasm/1_1_0; curl -L https://github.com/casper-ecosystem/cep-78-enhanced-nft/releases/download/v1.1.0/cep-78-wasm.tar.gz | tar zxv -C tests/wasm/1_1_0/
mkdir -p tests/wasm/1_2_0; curl -L https://github.com/casper-ecosystem/cep-78-enhanced-nft/releases/download/v1.2.0/cep-78-wasm.tar.gz | tar zxv -C tests/wasm/1_2_0/
mkdir -p tests/wasm/1_3_0; curl -L https://github.com/casper-ecosystem/cep-78-enhanced-nft/releases/download/v1.3.0/cep-78-wasm.tar.gz | tar zxv -C tests/wasm/1_3_0/

cp contract/target/wasm32-unknown-unknown/release/contract.wasm tests/wasm
cp client/mint_session/target/wasm32-unknown-unknown/release/mint_call.wasm tests/wasm
cp client/balance_of_session/target/wasm32-unknown-unknown/release/balance_of_call.wasm tests/wasm
Expand Down
52 changes: 38 additions & 14 deletions tests/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use crate::utility::{
constants::{
ACCOUNT_USER_1, ARG_IS_HASH_IDENTIFIER_MODE, ARG_NFT_CONTRACT_HASH,
ARG_NFT_CONTRACT_PACKAGE_HASH, CONTRACT_1_0_0_WASM, CONTRACT_1_1_0_WASM,
CONTRACT_1_2_0_WASM, MANGLE_NAMED_KEYS, MINT_1_0_0_WASM, MINT_SESSION_WASM,
NFT_CONTRACT_WASM, NFT_TEST_COLLECTION, NFT_TEST_SYMBOL, PAGE_SIZE, TRANSFER_SESSION_WASM,
UPDATED_RECEIPTS_WASM,
CONTRACT_1_2_0_WASM, CONTRACT_1_3_0_WASM, MANGLE_NAMED_KEYS, MINT_1_0_0_WASM,
MINT_SESSION_WASM, NFT_CONTRACT_WASM, NFT_TEST_COLLECTION, NFT_TEST_SYMBOL, PAGE_SIZE,
TRANSFER_SESSION_WASM, UPDATED_RECEIPTS_WASM,
},
installer_request_builder::{
InstallerRequestBuilder, MetadataMutability, NFTIdentifierMode, NFTMetadataKind,
Expand Down Expand Up @@ -698,7 +698,9 @@ fn should_not_upgrade_with_larger_total_token_supply() {
);
}

fn should_safely_upgrade_from_1_2_0_to_current_version_with_reporting_mode(
fn should_safely_upgrade_from_old_version_to_new_version_with_reporting_mode(
old_version: &str,
new_version: &str,
reporting_mode: OwnerReverseLookupMode,
expected_total_token_supply_post_upgrade: u64,
) {
Expand All @@ -707,7 +709,7 @@ fn should_safely_upgrade_from_1_2_0_to_current_version_with_reporting_mode(
.run_genesis(&PRODUCTION_RUN_GENESIS_REQUEST)
.commit();

let install_request = InstallerRequestBuilder::new(*DEFAULT_ACCOUNT_ADDR, CONTRACT_1_2_0_WASM)
let install_request = InstallerRequestBuilder::new(*DEFAULT_ACCOUNT_ADDR, old_version)
.with_collection_name(NFT_TEST_COLLECTION.to_string())
.with_collection_symbol(NFT_TEST_SYMBOL.to_string())
.with_total_token_supply(100u64)
Expand All @@ -721,16 +723,16 @@ fn should_safely_upgrade_from_1_2_0_to_current_version_with_reporting_mode(

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

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

let number_of_tokens_pre_migration = 3usize;

// Build of prestate before migration.
for _i in 0..number_of_tokens_pre_migration {
let register_request = ExecuteRequestBuilder::contract_call_by_hash(
*DEFAULT_ACCOUNT_ADDR,
nft_contract_hash_1_2_0,
nft_contract_hash,
ENTRY_POINT_REGISTER_OWNER,
runtime_args! {
ARG_TOKEN_OWNER => Key::Account(*DEFAULT_ACCOUNT_ADDR),
Expand All @@ -741,7 +743,7 @@ fn should_safely_upgrade_from_1_2_0_to_current_version_with_reporting_mode(
builder.exec(register_request).expect_success().commit();
let mint_request = ExecuteRequestBuilder::contract_call_by_hash(
*DEFAULT_ACCOUNT_ADDR,
nft_contract_hash_1_2_0,
nft_contract_hash,
ENTRY_POINT_MINT,
runtime_args! {
ARG_TOKEN_OWNER => Key::Account(*DEFAULT_ACCOUNT_ADDR),
Expand All @@ -755,9 +757,9 @@ fn should_safely_upgrade_from_1_2_0_to_current_version_with_reporting_mode(

let upgrade_request = ExecuteRequestBuilder::standard(
*DEFAULT_ACCOUNT_ADDR,
NFT_CONTRACT_WASM,
new_version,
runtime_args! {
ARG_NFT_CONTRACT_HASH => nft_contract_key_1_2_0,
ARG_NFT_CONTRACT_HASH => nft_contract_key,
ARG_COLLECTION_NAME => NFT_TEST_COLLECTION.to_string(),
ARG_NAMED_KEY_CONVENTION => NamedKeyConventionMode::V1_0Custom as u8,
ARG_ACCESS_KEY_NAME_1_0_0 => format!("{PREFIX_ACCESS_KEY_NAME}_{NFT_TEST_COLLECTION}"),
Expand Down Expand Up @@ -811,16 +813,38 @@ fn should_safely_upgrade_from_1_2_0_to_current_version_with_reporting_mode(
}

#[test]
fn should_safely_upgrade_from_1_2_0_to_1_3_0() {
//* starting total_token_supply 100u64
let expected_total_token_supply_post_upgrade = 10;
should_safely_upgrade_from_old_version_to_new_version_with_reporting_mode(
CONTRACT_1_2_0_WASM,
CONTRACT_1_3_0_WASM,
OwnerReverseLookupMode::NoLookUp,
expected_total_token_supply_post_upgrade,
);
let expected_total_token_supply_post_upgrade = 100;
should_safely_upgrade_from_old_version_to_new_version_with_reporting_mode(
CONTRACT_1_2_0_WASM,
CONTRACT_1_3_0_WASM,
OwnerReverseLookupMode::Complete,
expected_total_token_supply_post_upgrade,
);
}

fn should_safely_upgrade_from_1_2_0_to_current_version() {
#[test]
fn should_safely_upgrade_from_1_3_0_to_current_version() {
//* starting total_token_supply 100u64
let expected_total_token_supply_post_upgrade = 10;
should_safely_upgrade_from_1_2_0_to_current_version_with_reporting_mode(
should_safely_upgrade_from_old_version_to_new_version_with_reporting_mode(
CONTRACT_1_3_0_WASM,
NFT_CONTRACT_WASM,
OwnerReverseLookupMode::NoLookUp,
expected_total_token_supply_post_upgrade,
);
let expected_total_token_supply_post_upgrade = 100;
should_safely_upgrade_from_1_2_0_to_current_version_with_reporting_mode(
should_safely_upgrade_from_old_version_to_new_version_with_reporting_mode(
CONTRACT_1_3_0_WASM,
NFT_CONTRACT_WASM,
OwnerReverseLookupMode::Complete,
expected_total_token_supply_post_upgrade,
);
Expand Down
1 change: 1 addition & 0 deletions tests/src/utility/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub const BALANCE_OF_SESSION_WASM: &str = "balance_of_call.wasm";
pub const CONTRACT_1_0_0_WASM: &str = "1_0_0/contract.wasm";
pub const CONTRACT_1_1_0_WASM: &str = "1_1_0/contract.wasm";
pub const CONTRACT_1_2_0_WASM: &str = "1_2_0/contract.wasm";
pub const CONTRACT_1_3_0_WASM: &str = "1_3_0/contract.wasm";
pub const GET_APPROVED_WASM: &str = "get_approved_call.wasm";
pub const IS_APPROVED_FOR_ALL_WASM: &str = "is_approved_for_all_call.wasm";
pub const MANGLE_NAMED_KEYS: &str = "mangle_named_keys.wasm";
Expand Down

0 comments on commit 394ab90

Please sign in to comment.