Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c90ee6d
chore(api/examples/fungible): bump drink version
chungquantin May 8, 2025
ccc6d98
chore(ci): test contract in examples
chungquantin May 8, 2025
80eaa45
chore: update drink dependency branch
chungquantin May 12, 2025
9adc94a
feat: init test file
chungquantin May 12, 2025
b1d40bf
feat: add tests and helper methods
chungquantin May 13, 2025
dd42f4c
feat(api+drink): derive Debug type and add burn, destroy tests
chungquantin May 13, 2025
5f601cd
feat: finalize the tests
chungquantin May 13, 2025
c0797ee
chore: expose NftsError to public
chungquantin May 13, 2025
a88f9ad
chore: update comments
chungquantin May 15, 2025
c02e4ae
feat(nfts + nonfungibles): sync polkadot stable2503 (#558)
chungquantin May 8, 2025
6b6884f
chore(api/examples/fungible): bump drink version (#562)
chungquantin May 16, 2025
f4688de
Merge branch 'main' into chungquantin/chore-nonfungible_tests
chungquantin May 16, 2025
5d1e587
chore: remove unrelevant changes
chungquantin May 16, 2025
3dd2ad4
refactor(api/examples/nonfungibles): Contract struct
chungquantin May 19, 2025
7607a1a
fix(api/examples/nonfungibles): revert destroy
chungquantin May 19, 2025
3afb908
fix(api/examples/nonfungibles): revert destroy
chungquantin May 19, 2025
712a3a9
Merge branch 'main' into chungquantin/chore-nonfungible_tests
chungquantin May 19, 2025
3e1b812
chore: resolve review comments
chungquantin May 22, 2025
20af3a3
refactor: call_with_address
chungquantin May 22, 2025
6a484d5
fix(ci): pin stable-1.86.0 version (#570)
al3mart May 19, 2025
fc71d84
refactor(ci): build runtimes using production profile (#567)
al3mart May 20, 2025
682eb5d
chore: sync with `polkadot-stable2503-1` (#559)
al3mart May 20, 2025
2256c9d
chore: sync with `polkadot-stable2503-4` (#571)
al3mart May 21, 2025
2c21b2d
chore: `pop-runtime-testnet` v0.5.3 (#569)
al3mart May 22, 2025
b3b9623
chore(api/examples/fungible): bump drink version
chungquantin May 8, 2025
00829c0
chore: bump cargo.lock
chungquantin May 22, 2025
dd7ca2e
chore: update the SessionError
chungquantin May 22, 2025
13d33dd
Merge branch 'main' into chungquantin/chore-nonfungible_tests
chungquantin May 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pop-api/examples/nonfungibles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ pop-api = { path = "../../../pop-api", default-features = false, features = [
"nonfungibles",
] }

[dev-dependencies]
drink = { package = "pop-drink", git = "https://github.com/r0gue-io/pop-drink", branch = "al3mart/chore-stable2503-4", features = [ "devnet" ] }
env_logger = { version = "0.11.3" }
pallet-nfts = { git = "https://github.com/r0gue-io/pop-node" }
serde_json = "1.0.114"

[lib]
path = "lib.rs"

Expand Down
12 changes: 11 additions & 1 deletion pop-api/examples/nonfungibles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ pop up contract \
--args 1000
```

## Test with Pop Drink

Since this contract interacts directly with Pop’s runtime through the Pop API, it requires [Pop Drink](https://github.com/r0gue-io/pop-drink) for testing. See how the contract is tested in [tests](./tests.rs).

To run the tests, run the following command:

```bash
cargo test --release
```

## Support

Be part of our passionate community of Web3 builders. [Join our Telegram](https://t.me/onpopio)!
Expand All @@ -37,4 +47,4 @@ ask the [ink! community](https://t.me/inkathon/1).

[pop-api-nonfungibles]: https://github.com/r0gue-io/pop-node/tree/main/pop-api/src/v0/nonfungibles

[pop-drink]: https://github.com/r0gue-io/pop-drink
[pop-drink]: https://github.com/r0gue-io/pop-drink
17 changes: 11 additions & 6 deletions pop-api/examples/nonfungibles/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ use pop_api::{
primitives::AccountId,
};

#[cfg(test)]
mod tests;

/// By default, Pop API returns errors as [`pop_api::StatusCode`], which are convertible to
/// [`Psp34Error`]. When using [`Psp34Error`], errors follow the PSP34 standard, making them easier
/// to interpret.
pub type Result<T> = core::result::Result<T, Psp34Error>;

/// Event emitted when a collection is created.
#[ink::event]
#[derive(Debug)]
pub struct Created {
/// The collection.
#[ink(topic)]
Expand All @@ -75,6 +79,7 @@ pub struct Created {

/// Event emitted when a collection is destroyed.
#[ink::event]
#[derive(Debug)]
pub struct Destroyed {
/// The collection.
#[ink(topic)]
Expand Down Expand Up @@ -160,20 +165,20 @@ pub mod nonfungibles {

/// Returns the number of items owned by an account.
#[ink(message)]
pub fn balance_of(&self, owner: AccountId) -> Result<u32> {
api::balance_of(self.id, owner).map_err(Psp34Error::from)
pub fn balance_of(&self, owner: AccountId) -> u32 {
api::balance_of(self.id, owner).unwrap_or_default()
}

/// Returns the owner of an item, if any.
#[ink(message)]
pub fn owner_of(&self, item: ItemId) -> Result<Option<AccountId>> {
api::owner_of(self.id, item).map_err(Psp34Error::from)
pub fn owner_of(&self, item: ItemId) -> Option<AccountId> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep it consistent with the fungibles example

api::owner_of(self.id, item).unwrap_or_default()
}

/// Returns the total supply of the collection.
#[ink(message)]
pub fn total_supply(&self) -> Result<u128> {
api::total_supply(self.id).map_err(Psp34Error::from)
pub fn total_supply(&self) -> u128 {
api::total_supply(self.id).unwrap_or_default()
}

/// Mint an item.
Expand Down
Loading
Loading