Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
Daanvdplas committed Apr 23, 2024
1 parent 54e75b3 commit 92cd4d9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
30 changes: 14 additions & 16 deletions pop-api/examples/nfts/lib.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

use pop_api::nfts;
use pop_api::nfts::*;
use enumflags2::BitFlags;

#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum ContractError {
InvalidCollection,
ItemAlreadyExists,
NftsError(nfts::Error),
NftsError(Error),
NotOwner,
}

impl From<nfts::Error> for ContractError {
fn from(value: nfts::Error) -> Self {
impl From<Error> for ContractError {
fn from(value: Error) -> Self {
ContractError::NftsError(value)
}
}

#[ink::contract(env = pop_api::Environment)]
mod pop_api_extension_demo {
mod pop_api_nfts {
use super::*;

#[ink(storage)]
#[derive(Default)]
pub struct PopApiExtensionDemo;
pub struct Nfts;

impl PopApiExtensionDemo {
impl Nfts {
#[ink(constructor, payable)]
pub fn new() -> Self {
ink::env::debug_println!("Contract::new");
ink::env::debug_println!("Nfts::new");
Default::default()
}

#[ink(message)]
pub fn create_nft_collection( &self ) -> Result<(), ContractError>{
ink::env::debug_println!("Contract::create_nft_collection: collection creation started.");
ink::env::debug_println!("Nfts::create_nft_collection: collection creation started.");
let admin = Self::env().caller();
let item_settings = ItemSettings(BitFlags::from(ItemSetting::Transferable));

Expand All @@ -54,19 +52,19 @@ mod pop_api_extension_demo {
mint_settings,
};
pop_api::nfts::create(admin, config)?;
ink::env::debug_println!("Contract::create_nft_collection: collection created successfully.");
ink::env::debug_println!("Nfts::create_nft_collection: collection created successfully.");
Ok(())
}

#[ink(message)]
pub fn mint_through_runtime(
pub fn mint_nft(
&mut self,
collection_id: u32,
item_id: u32,
receiver: AccountId,
) -> Result<(), ContractError> {
ink::env::debug_println!(
"Contract::mint_through_runtime: collection_id: {:?} item_id {:?} receiver: {:?}",
"Nfts::mint_through_runtime: collection_id: {:?} item_id {:?} receiver: {:?}",
collection_id,
item_id,
receiver
Expand All @@ -79,21 +77,21 @@ mod pop_api_extension_demo {

// mint api
pop_api::nfts::mint(collection_id, item_id, receiver)?;
ink::env::debug_println!("Contract::mint_through_runtime: item minted successfully");
ink::env::debug_println!("Nfts::mint_through_runtime: item minted successfully");

// check owner
match pop_api::nfts::owner(collection_id, item_id)? {
Some(owner) if owner == receiver => {
ink::env::debug_println!(
"Contract::mint_through_runtime success: minted item belongs to receiver"
"Nfts::mint_through_runtime success: minted item belongs to receiver"
);
},
_ => {
return Err(ContractError::NotOwner);
},
}

ink::env::debug_println!("Contract::mint_through_runtime end");
ink::env::debug_println!("Nfts::mint_through_runtime end");
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion pop-api/src/v0/nfts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ mod types {
primitives::{CollectionId, ItemId},
Balance, BlockNumber,
};
use enumflags2::{bitflags, BitFlags};
pub use enumflags2::{bitflags, BitFlags};
use scale::{Decode, EncodeLike, MaxEncodedLen};
use scale_info::{build::Fields, meta_type, prelude::vec, Path, Type, TypeInfo, TypeParameter};

Expand Down
5 changes: 2 additions & 3 deletions runtime/devnet/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ mod tests {
)
.unwrap();

let init_value = 100;
let init_value = 100 * UNIT;

let result = Contracts::bare_instantiate(
ALICE,
Expand All @@ -508,8 +508,7 @@ mod tests {

let function = function_selector("create_nft_collection");

let params =
[function].concat();
let params = [function].concat();

let result = Contracts::bare_call(
ALICE,
Expand Down

0 comments on commit 92cd4d9

Please sign in to comment.