From 5b745109a11416b99719288353a48632f1551d32 Mon Sep 17 00:00:00 2001 From: Bobo Date: Fri, 28 Jul 2023 14:22:37 +0200 Subject: [PATCH 1/3] Uplift to the latest ink! and Openbrush --- contracts/shiden34/Cargo.toml | 18 +- contracts/shiden34/lib.rs | 209 ++++++++++++++-------- logics/Cargo.toml | 12 +- logics/impls/payable_mint/payable_mint.rs | 117 ++++++------ logics/impls/payable_mint/types.rs | 2 +- logics/lib.rs | 1 - 6 files changed, 197 insertions(+), 162 deletions(-) diff --git a/contracts/shiden34/Cargo.toml b/contracts/shiden34/Cargo.toml index 4663b9c..7ccc244 100644 --- a/contracts/shiden34/Cargo.toml +++ b/contracts/shiden34/Cargo.toml @@ -1,25 +1,18 @@ [package] name = "shiden34" -version = "1.0.0" +version = "3.1.0" authors = ["Astar builder"] edition = "2021" [dependencies] -ink = { version = "~4.0.0", default-features = false} - +ink = { version = "4.2.1", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } -scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } - -openbrush = { tag = "3.0.0", git = "https://github.com/727-Ventures/openbrush-contracts", default-features = false, features = ["psp34", "ownable"] } +scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } +openbrush = { tag = "v4.0.0-beta", git = "https://github.com/Brushfam/openbrush-contracts", default-features = false, features = ["psp34", "ownable"] } payable_mint_pkg = { path = "../../logics", default-features = false } [lib] -name = "shiden34" path = "lib.rs" -crate-type = [ - # Used for normal contract Wasm blobs. - "cdylib", -] [features] default = ["std"] @@ -27,8 +20,7 @@ std = [ "ink/std", "scale/std", "scale-info/std", - "openbrush/std", "payable_mint_pkg/std", ] -ink-as-dependency = [] +ink-as-dependency = [] \ No newline at end of file diff --git a/contracts/shiden34/lib.rs b/contracts/shiden34/lib.rs index 6d8bbec..d51cb37 100644 --- a/contracts/shiden34/lib.rs +++ b/contracts/shiden34/lib.rs @@ -1,104 +1,161 @@ -#![cfg_attr(not(feature = "std"), no_std)] -#![feature(min_specialization)] +#![cfg_attr(not(feature = "std"), no_std, no_main)] +#[openbrush::implementation(PSP34, PSP34Enumerable, PSP34Metadata, PSP34Mintable, Ownable)] #[openbrush::contract] pub mod shiden34 { - use openbrush::{ - contracts::ownable::*, - contracts::psp34::extensions::{enumerable::*, metadata::*}, - traits::{Storage, String}, - }; + use openbrush::traits::Storage; use payable_mint_pkg::impls::payable_mint::*; - use payable_mint_pkg::traits::payable_mint::*; #[ink(storage)] #[derive(Default, Storage)] pub struct Shiden34 { #[storage_field] - psp34: psp34::Data, + psp34: psp34::Data, #[storage_field] ownable: ownable::Data, #[storage_field] metadata: metadata::Data, #[storage_field] + enumerable: enumerable::Data, + #[storage_field] payable_mint: types::Data, } - impl PSP34 for Shiden34 {} - impl Ownable for Shiden34 {} - impl PSP34Enumerable for Shiden34 {} - impl PSP34Metadata for Shiden34 {} - impl PayableMint for Shiden34 {} + #[overrider(PSP34Mintable)] + #[openbrush::modifiers(only_owner)] + fn mint(&mut self, account: AccountId, id: Id) -> Result<(), PSP34Error> { + psp34::InternalImpl::_mint_to(self, account, id) + } + + impl payable_mint_pkg::impls::payable_mint::payable_mint::Internal for Shiden34 {} + impl payable_mint::PayableMintImpl for Shiden34 {} impl Shiden34 { #[ink(constructor)] - pub fn new( - name: String, - symbol: String, - base_uri: String, - max_supply: u64, - price_per_mint: Balance, - ) -> Self { - let mut instance = Self::default(); - instance._init_with_owner(instance.env().caller()); - let collection_id = instance.collection_id(); - instance._set_attribute(collection_id.clone(), String::from("name"), name); - instance._set_attribute(collection_id.clone(), String::from("symbol"), symbol); - instance._set_attribute(collection_id, String::from("baseUri"), base_uri); - instance.payable_mint.max_supply = max_supply; - instance.payable_mint.price_per_mint = price_per_mint; - instance.payable_mint.last_token_id = 0; - instance + pub fn new() -> Self { + let mut _instance = Self::default(); + ownable::Internal::_init_with_owner(&mut _instance, Self::env().caller()); + psp34::Internal::_mint_to(&mut _instance, Self::env().caller(), Id::U8(1)) + .expect("Can mint"); + let collection_id = psp34::PSP34Impl::collection_id(&_instance); + metadata::Internal::_set_attribute( + &mut _instance, + collection_id.clone(), + String::from("name"), + String::from("Shiden34"), + ); + metadata::Internal::_set_attribute( + &mut _instance, + collection_id, + String::from("symbol"), + String::from("SH34"), + ); + _instance } } +} - #[cfg(test)] - mod tests { - use super::*; - use crate::shiden34::PSP34Error::*; - use ink::env::test; +// #![cfg_attr(not(feature = "std"), no_std)] +// #![feature(min_specialization)] - const PRICE: Balance = 100_000_000_000_000_000; +// #[openbrush::contract] +// pub mod shiden34 { +// use openbrush::{ +// contracts::ownable::*, +// contracts::psp34::extensions::{enumerable::*, metadata::*}, +// traits::{Storage, String}, +// }; +// use payable_mint_pkg::impls::payable_mint::*; +// use payable_mint_pkg::traits::payable_mint::*; - fn init() -> Shiden34 { - const BASE_URI: &str = "ipfs://myIpfsUri/"; - const MAX_SUPPLY: u64 = 10; - Shiden34::new( - String::from("Shiden34"), - String::from("SH34"), - String::from(BASE_URI), - MAX_SUPPLY, - PRICE, - ) - } +// #[ink(storage)] +// #[derive(Default, Storage)] +// pub struct Shiden34 { +// #[storage_field] +// psp34: psp34::Data, +// #[storage_field] +// ownable: ownable::Data, +// #[storage_field] +// metadata: metadata::Data, +// #[storage_field] +// payable_mint: types::Data, +// } - #[ink::test] - fn mint_multiple_works() { - let mut sh34 = init(); - let accounts = test::default_accounts::(); - set_sender(accounts.bob); - let num_of_mints: u64 = 5; +// impl PSP34 for Shiden34 {} +// impl Ownable for Shiden34 {} +// impl PSP34Enumerable for Shiden34 {} +// impl PSP34Metadata for Shiden34 {} +// impl PayableMint for Shiden34 {} - assert_eq!(sh34.total_supply(), 0); - test::set_value_transferred::( - PRICE * num_of_mints as u128, - ); - assert!(sh34.mint(accounts.bob, num_of_mints).is_ok()); - assert_eq!(sh34.total_supply(), num_of_mints as u128); - assert_eq!(sh34.balance_of(accounts.bob), 5); - assert_eq!(sh34.owners_token_by_index(accounts.bob, 0), Ok(Id::U64(1))); - assert_eq!(sh34.owners_token_by_index(accounts.bob, 1), Ok(Id::U64(2))); - assert_eq!(sh34.owners_token_by_index(accounts.bob, 2), Ok(Id::U64(3))); - assert_eq!(sh34.owners_token_by_index(accounts.bob, 3), Ok(Id::U64(4))); - assert_eq!(sh34.owners_token_by_index(accounts.bob, 4), Ok(Id::U64(5))); - assert_eq!( - sh34.owners_token_by_index(accounts.bob, 5), - Err(TokenNotExists) - ); - } +// impl Shiden34 { +// #[ink(constructor)] +// pub fn new( +// name: String, +// symbol: String, +// base_uri: String, +// max_supply: u64, +// price_per_mint: Balance, +// ) -> Self { +// let mut instance = Self::default(); +// instance._init_with_owner(instance.env().caller()); +// let collection_id = instance.collection_id(); +// instance._set_attribute(collection_id.clone(), String::from("name"), name); +// instance._set_attribute(collection_id.clone(), String::from("symbol"), symbol); +// instance._set_attribute(collection_id, String::from("baseUri"), base_uri); +// instance.payable_mint.max_supply = max_supply; +// instance.payable_mint.price_per_mint = price_per_mint; +// instance.payable_mint.last_token_id = 0; +// instance +// } +// } - fn set_sender(sender: AccountId) { - ink::env::test::set_caller::(sender); - } - } -} +// #[cfg(test)] +// mod tests { +// use super::*; +// use crate::shiden34::PSP34Error::*; +// use ink::env::test; + +// const PRICE: Balance = 100_000_000_000_000_000; + +// fn init() -> Shiden34 { +// const BASE_URI: &str = "ipfs://myIpfsUri/"; +// const MAX_SUPPLY: u64 = 10; +// Shiden34::new( +// String::from("Shiden34"), +// String::from("SH34"), +// String::from(BASE_URI), +// MAX_SUPPLY, +// PRICE, +// ) +// } + +// #[ink::test] +// fn mint_multiple_works() { +// let mut sh34 = init(); +// let accounts = test::default_accounts::(); +// set_sender(accounts.bob); +// let num_of_mints: u64 = 5; + +// assert_eq!(sh34.total_supply(), 0); +// test::set_value_transferred::( +// PRICE * num_of_mints as u128, +// ); +// assert!(sh34.mint(accounts.bob, num_of_mints).is_ok()); +// assert_eq!(sh34.total_supply(), num_of_mints as u128); +// assert_eq!(sh34.balance_of(accounts.bob), 5); +// assert_eq!(sh34.owners_token_by_index(accounts.bob, 0), Ok(Id::U64(1))); +// assert_eq!(sh34.owners_token_by_index(accounts.bob, 1), Ok(Id::U64(2))); +// assert_eq!(sh34.owners_token_by_index(accounts.bob, 2), Ok(Id::U64(3))); +// assert_eq!(sh34.owners_token_by_index(accounts.bob, 3), Ok(Id::U64(4))); +// assert_eq!(sh34.owners_token_by_index(accounts.bob, 4), Ok(Id::U64(5))); +// assert_eq!( +// sh34.owners_token_by_index(accounts.bob, 5), +// Err(TokenNotExists) +// ); +// } + +// fn set_sender(sender: AccountId) { +// ink::env::test::set_caller::(sender); +// } +// } +// } diff --git a/logics/Cargo.toml b/logics/Cargo.toml index 54c938f..422151e 100644 --- a/logics/Cargo.toml +++ b/logics/Cargo.toml @@ -1,16 +1,14 @@ [package] name = "payable_mint_pkg" -version = "0.3.0" +version = "3.1.0" authors = ["Astar builder"] edition = "2021" [dependencies] -ink = { version = "~4.0.0", default-features = false} - +ink = { version = "4.2.1", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } -scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } - -openbrush = { tag = "3.0.0", git = "https://github.com/727-Ventures/openbrush-contracts", default-features = false, features = ["psp34", "ownable"] } +scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } +openbrush = { tag = "v4.0.0-beta", git = "https://github.com/Brushfam/openbrush-contracts", default-features = false, features = ["psp34", "ownable"] } [lib] path = "lib.rs" @@ -23,4 +21,4 @@ std = [ "scale/std", "scale-info", "openbrush/std", -] +] \ No newline at end of file diff --git a/logics/impls/payable_mint/payable_mint.rs b/logics/impls/payable_mint/payable_mint.rs index fd0ac9b..9ea47ef 100644 --- a/logics/impls/payable_mint/payable_mint.rs +++ b/logics/impls/payable_mint/payable_mint.rs @@ -1,36 +1,33 @@ -use ink::prelude::string::{String as PreludeString, ToString}; - use crate::impls::payable_mint::types::Data; -pub use crate::traits::payable_mint::PayableMint; -use openbrush::{ - contracts::{ - ownable::*, - psp34::extensions::{enumerable::*, metadata::*}, +use ink::prelude::string::ToString; +use openbrush::contracts::{ + ownable, + ownable::only_owner, + psp34, + psp34::{ + extensions::{ + metadata, + metadata::{Id, PSP34MetadataImpl}, + }, + PSP34Error, PSP34Impl, }, - modifiers, - traits::{AccountId, Balance, Storage, String}, }; - -pub trait Internal { - /// Check if the transferred mint values is as expected - fn check_value(&self, transferred_value: u128, mint_amount: u64) -> Result<(), PSP34Error>; - - /// Check amount of tokens to be minted - fn check_amount(&self, mint_amount: u64) -> Result<(), PSP34Error>; - - /// Check if token is minted - fn token_exists(&self, id: Id) -> Result<(), PSP34Error>; -} - -impl PayableMint for T -where - T: Storage - + Storage> - + Storage - + Storage - + psp34::Internal, +use openbrush::traits::{AccountId, Balance, Storage, String}; + +#[openbrush::trait_definition] +pub trait PayableMintImpl: + Storage + + Storage + + Storage + + Storage + + Internal + + PSP34Impl + + psp34::InternalImpl + + psp34::extensions::metadata::Internal + + PSP34MetadataImpl { - default fn mint(&mut self, to: AccountId, mint_amount: u64) -> Result<(), PSP34Error> { + #[ink(message, payable)] + fn mint(&mut self, to: AccountId, mint_amount: u64) -> Result<(), PSP34Error> { self.check_value(Self::env().transferred_value(), mint_amount)?; self.check_amount(mint_amount)?; @@ -38,8 +35,7 @@ where let mint_offset = next_to_mint + mint_amount; for mint_id in next_to_mint..mint_offset { - self.data::>() - ._mint_to(to, Id::U64(mint_id))?; + psp34::InternalImpl::_mint_to(self, to, Id::U64(mint_id))?; self.data::().last_token_id += 1; } @@ -47,64 +43,59 @@ where } /// Set new value for the baseUri - #[modifiers(only_owner)] - default fn set_base_uri(&mut self, uri: PreludeString) -> Result<(), PSP34Error> { - let id = self - .data::>() - .collection_id(); - self.data::() - ._set_attribute(id, String::from("baseUri"), uri.into_bytes()); + #[ink(message)] + #[openbrush::modifiers(only_owner)] + fn set_base_uri(&mut self, uri: String) -> Result<(), PSP34Error> { + let id = PSP34Impl::collection_id(self); + metadata::Internal::_set_attribute(self, id, String::from("baseUri"), uri); + Ok(()) } /// Get URI from token ID - default fn token_uri(&self, token_id: u64) -> Result { + #[ink(message)] + fn token_uri(&self, token_id: u64) -> Result { self.token_exists(Id::U64(token_id))?; - let value = self.get_attribute( - self.data::>() - .collection_id(), + let base_uri = PSP34MetadataImpl::get_attribute( + self, + PSP34Impl::collection_id(self), String::from("baseUri"), ); - let mut token_uri = PreludeString::from_utf8(value.unwrap()).unwrap(); - token_uri = token_uri + &token_id.to_string() + &PreludeString::from(".json"); + let token_uri = base_uri.unwrap() + &token_id.to_string() + &String::from(".json"); Ok(token_uri) } /// Withdraws funds to contract owner - #[modifiers(only_owner)] - default fn withdraw(&mut self) -> Result<(), PSP34Error> { + #[ink(message)] + #[openbrush::modifiers(only_owner)] + fn withdraw(&mut self) -> Result<(), PSP34Error> { let balance = Self::env().balance(); let current_balance = balance .checked_sub(Self::env().minimum_balance()) .unwrap_or_default(); + let owner = self.data::().owner.get().unwrap().unwrap(); Self::env() - .transfer(self.data::().owner(), current_balance) + .transfer(owner, current_balance) .map_err(|_| PSP34Error::Custom(String::from("WithdrawalFailed")))?; Ok(()) } /// Get max supply of tokens - default fn max_supply(&self) -> u64 { + #[ink(message)] + fn max_supply(&self) -> u64 { self.data::().max_supply } /// Get token price - default fn price(&self) -> Balance { + #[ink(message)] + fn price(&self) -> Balance { self.data::().price_per_mint } } -/// Helper trait for PayableMint -impl Internal for T -where - T: Storage + Storage>, -{ +pub trait Internal: Storage + psp34::Internal { /// Check if the transferred mint values is as expected - default fn check_value( - &self, - transferred_value: u128, - mint_amount: u64, - ) -> Result<(), PSP34Error> { + fn check_value(&self, transferred_value: u128, mint_amount: u64) -> Result<(), PSP34Error> { if let Some(value) = (mint_amount as u128).checked_mul(self.data::().price_per_mint) { if transferred_value == value { return Ok(()); @@ -114,7 +105,7 @@ where } /// Check amount of tokens to be minted - default fn check_amount(&self, mint_amount: u64) -> Result<(), PSP34Error> { + fn check_amount(&self, mint_amount: u64) -> Result<(), PSP34Error> { if mint_amount == 0 { return Err(PSP34Error::Custom(String::from("CannotMintZeroTokens"))); } @@ -127,10 +118,8 @@ where } /// Check if token is minted - default fn token_exists(&self, id: Id) -> Result<(), PSP34Error> { - self.data::>() - .owner_of(id) - .ok_or(PSP34Error::TokenNotExists)?; + fn token_exists(&self, id: Id) -> Result<(), PSP34Error> { + self._owner_of(&id).ok_or(PSP34Error::TokenNotExists)?; Ok(()) } } diff --git a/logics/impls/payable_mint/types.rs b/logics/impls/payable_mint/types.rs index 103043c..9bf448b 100644 --- a/logics/impls/payable_mint/types.rs +++ b/logics/impls/payable_mint/types.rs @@ -2,7 +2,7 @@ use openbrush::traits::Balance; pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data); #[derive(Default, Debug)] -#[openbrush::upgradeable_storage(STORAGE_KEY)] +#[openbrush::storage_item] pub struct Data { pub last_token_id: u64, pub max_supply: u64, diff --git a/logics/lib.rs b/logics/lib.rs index 77a7eb8..141abba 100644 --- a/logics/lib.rs +++ b/logics/lib.rs @@ -1,5 +1,4 @@ #![cfg_attr(not(feature = "std"), no_std)] -#![feature(min_specialization)] pub mod impls; pub mod traits; From f10e72a7d555a9ccff85148556fefc1b29ad33fb Mon Sep 17 00:00:00 2001 From: Bobo Date: Fri, 28 Jul 2023 15:11:48 +0200 Subject: [PATCH 2/3] Unit test --- contracts/shiden34/lib.rs | 187 +++++++++++++++----------------------- 1 file changed, 73 insertions(+), 114 deletions(-) diff --git a/contracts/shiden34/lib.rs b/contracts/shiden34/lib.rs index d51cb37..c6e850e 100644 --- a/contracts/shiden34/lib.rs +++ b/contracts/shiden34/lib.rs @@ -32,130 +32,89 @@ pub mod shiden34 { impl Shiden34 { #[ink(constructor)] - pub fn new() -> Self { - let mut _instance = Self::default(); - ownable::Internal::_init_with_owner(&mut _instance, Self::env().caller()); - psp34::Internal::_mint_to(&mut _instance, Self::env().caller(), Id::U8(1)) - .expect("Can mint"); - let collection_id = psp34::PSP34Impl::collection_id(&_instance); - metadata::Internal::_set_attribute( - &mut _instance, + pub fn new( + name: String, + symbol: String, + base_uri: String, + max_supply: u64, + price_per_mint: Balance, + ) -> Self { + let mut instance = Self::default(); + let caller = instance.env().caller(); + ownable::InternalImpl::_init_with_owner(&mut instance, caller); + let collection_id = psp34::PSP34Impl::collection_id(&instance); + metadata::InternalImpl::_set_attribute( + &mut instance, collection_id.clone(), String::from("name"), - String::from("Shiden34"), + name, ); - metadata::Internal::_set_attribute( - &mut _instance, - collection_id, + metadata::InternalImpl::_set_attribute( + &mut instance, + collection_id.clone(), String::from("symbol"), - String::from("SH34"), + symbol, + ); + metadata::InternalImpl::_set_attribute( + &mut instance, + collection_id, + String::from("baseUri"), + base_uri, ); - _instance + instance.payable_mint.max_supply = max_supply; + instance.payable_mint.price_per_mint = price_per_mint; + instance.payable_mint.last_token_id = 0; + instance } } -} - -// #![cfg_attr(not(feature = "std"), no_std)] -// #![feature(min_specialization)] - -// #[openbrush::contract] -// pub mod shiden34 { -// use openbrush::{ -// contracts::ownable::*, -// contracts::psp34::extensions::{enumerable::*, metadata::*}, -// traits::{Storage, String}, -// }; -// use payable_mint_pkg::impls::payable_mint::*; -// use payable_mint_pkg::traits::payable_mint::*; - -// #[ink(storage)] -// #[derive(Default, Storage)] -// pub struct Shiden34 { -// #[storage_field] -// psp34: psp34::Data, -// #[storage_field] -// ownable: ownable::Data, -// #[storage_field] -// metadata: metadata::Data, -// #[storage_field] -// payable_mint: types::Data, -// } - -// impl PSP34 for Shiden34 {} -// impl Ownable for Shiden34 {} -// impl PSP34Enumerable for Shiden34 {} -// impl PSP34Metadata for Shiden34 {} -// impl PayableMint for Shiden34 {} -// impl Shiden34 { -// #[ink(constructor)] -// pub fn new( -// name: String, -// symbol: String, -// base_uri: String, -// max_supply: u64, -// price_per_mint: Balance, -// ) -> Self { -// let mut instance = Self::default(); -// instance._init_with_owner(instance.env().caller()); -// let collection_id = instance.collection_id(); -// instance._set_attribute(collection_id.clone(), String::from("name"), name); -// instance._set_attribute(collection_id.clone(), String::from("symbol"), symbol); -// instance._set_attribute(collection_id, String::from("baseUri"), base_uri); -// instance.payable_mint.max_supply = max_supply; -// instance.payable_mint.price_per_mint = price_per_mint; -// instance.payable_mint.last_token_id = 0; -// instance -// } -// } + #[cfg(test)] + mod tests { + use super::*; + use crate::shiden34::PSP34Error::*; + use ink::env::test; -// #[cfg(test)] -// mod tests { -// use super::*; -// use crate::shiden34::PSP34Error::*; -// use ink::env::test; + const PRICE: Balance = 100_000_000_000_000_000; -// const PRICE: Balance = 100_000_000_000_000_000; - -// fn init() -> Shiden34 { -// const BASE_URI: &str = "ipfs://myIpfsUri/"; -// const MAX_SUPPLY: u64 = 10; -// Shiden34::new( -// String::from("Shiden34"), -// String::from("SH34"), -// String::from(BASE_URI), -// MAX_SUPPLY, -// PRICE, -// ) -// } + fn init() -> Shiden34 { + const BASE_URI: &str = "ipfs://myIpfsUri/"; + const MAX_SUPPLY: u64 = 10; + Shiden34::new( + String::from("Shiden34"), + String::from("SH34"), + String::from(BASE_URI), + MAX_SUPPLY, + PRICE, + ) + } -// #[ink::test] -// fn mint_multiple_works() { -// let mut sh34 = init(); -// let accounts = test::default_accounts::(); -// set_sender(accounts.bob); -// let num_of_mints: u64 = 5; + #[ink::test] + fn mint_multiple_works() { + let mut sh34 = init(); + let accounts = test::default_accounts::(); + set_sender(accounts.bob); + let num_of_mints: u64 = 5; -// assert_eq!(sh34.total_supply(), 0); -// test::set_value_transferred::( -// PRICE * num_of_mints as u128, -// ); -// assert!(sh34.mint(accounts.bob, num_of_mints).is_ok()); -// assert_eq!(sh34.total_supply(), num_of_mints as u128); -// assert_eq!(sh34.balance_of(accounts.bob), 5); -// assert_eq!(sh34.owners_token_by_index(accounts.bob, 0), Ok(Id::U64(1))); -// assert_eq!(sh34.owners_token_by_index(accounts.bob, 1), Ok(Id::U64(2))); -// assert_eq!(sh34.owners_token_by_index(accounts.bob, 2), Ok(Id::U64(3))); -// assert_eq!(sh34.owners_token_by_index(accounts.bob, 3), Ok(Id::U64(4))); -// assert_eq!(sh34.owners_token_by_index(accounts.bob, 4), Ok(Id::U64(5))); -// assert_eq!( -// sh34.owners_token_by_index(accounts.bob, 5), -// Err(TokenNotExists) -// ); -// } + assert_eq!(PSP34Impl::total_supply(&sh34), 0); + test::set_value_transferred::( + PRICE * num_of_mints as u128, + ); + assert!(payable_mint::PayableMintImpl::mint(&mut sh34, accounts.bob, num_of_mints).is_ok()); + assert_eq!(PSP34Impl::total_supply(&sh34), num_of_mints as u128); + assert_eq!(PSP34Impl::balance_of(&sh34, accounts.bob), 5); + assert_eq!(PSP34EnumerableImpl::owners_token_by_index(&sh34, accounts.bob, 0), Ok(Id::U64(1))); + assert_eq!(PSP34EnumerableImpl::owners_token_by_index(&sh34, accounts.bob, 1), Ok(Id::U64(2))); + assert_eq!(PSP34EnumerableImpl::owners_token_by_index(&sh34, accounts.bob, 2), Ok(Id::U64(3))); + assert_eq!(PSP34EnumerableImpl::owners_token_by_index(&sh34, accounts.bob, 3), Ok(Id::U64(4))); + assert_eq!(PSP34EnumerableImpl::owners_token_by_index(&sh34, accounts.bob, 4), Ok(Id::U64(5))); + assert_eq!( + PSP34EnumerableImpl::owners_token_by_index(&sh34, accounts.bob, 5), + Err(TokenNotExists) + ); + } -// fn set_sender(sender: AccountId) { -// ink::env::test::set_caller::(sender); -// } -// } -// } + fn set_sender(sender: AccountId) { + ink::env::test::set_caller::(sender); + } + } +} From 7bfa0154e90ccc106ee865d623f10107dee90a7e Mon Sep 17 00:00:00 2001 From: Bobo Date: Fri, 28 Jul 2023 15:52:21 +0200 Subject: [PATCH 3/3] Cleanup --- logics/impls/payable_mint/types.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/logics/impls/payable_mint/types.rs b/logics/impls/payable_mint/types.rs index 9bf448b..baa420c 100644 --- a/logics/impls/payable_mint/types.rs +++ b/logics/impls/payable_mint/types.rs @@ -1,5 +1,4 @@ use openbrush::traits::Balance; -pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data); #[derive(Default, Debug)] #[openbrush::storage_item]