Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: api integration tests #280

Merged
merged 9 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
137 changes: 30 additions & 107 deletions pop-api/examples/fungibles/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

/// Local Fungibles:
/// 1. PSP-22 Interface
/// 2. PSP-22 Metadata Interface
/// 3. Asset Management
///
use ink::prelude::vec::Vec;
use pop_api::{
assets::fungibles::{self as api},
primitives::AssetId,
fungibles::{self as api},
primitives::TokenId,
StatusCode,
};

Expand All @@ -25,161 +20,89 @@ mod fungibles {
impl Fungibles {
#[ink(constructor, payable)]
pub fn new() -> Self {
ink::env::debug_println!("PopApiFungiblesExample::new");
Default::default()
}

/// 1. PSP-22 Interface:
/// - total_supply
/// - balance_of
/// - allowance
/// - transfer
/// - transfer_from
/// - approve
/// - increase_allowance
/// - decrease_allowance

#[ink(message)]
pub fn total_supply(&self, id: AssetId) -> Result<Balance> {
api::total_supply(id)
pub fn total_supply(&self, token: TokenId) -> Result<Balance> {
api::total_supply(token)
}

#[ink(message)]
pub fn balance_of(&self, id: AssetId, owner: AccountId) -> Result<Balance> {
api::balance_of(id, owner)
pub fn balance_of(&self, token: TokenId, owner: AccountId) -> Result<Balance> {
api::balance_of(token, owner)
}

#[ink(message)]
pub fn allowance(
&self,
id: AssetId,
token: TokenId,
owner: AccountId,
spender: AccountId,
) -> Result<Balance> {
api::allowance(id, owner, spender)
api::allowance(token, owner, spender)
}

#[ink(message)]
pub fn transfer(&mut self, id: AssetId, to: AccountId, value: Balance) -> Result<()> {
api::transfer(id, to, value)
pub fn transfer(&mut self, token: TokenId, to: AccountId, value: Balance) -> Result<()> {
api::transfer(token, to, value)
}

#[ink(message)]
pub fn transfer_from(
&mut self,
id: AssetId,
token: TokenId,
from: AccountId,
to: AccountId,
value: Balance,
// In the PSP-22 standard a `[u8]`, but the size needs to be known at compile time.
_data: Vec<u8>,
) -> Result<()> {
api::transfer_from(id, from, to, value)
api::transfer_from(token, from, to, value)
}

#[ink(message)]
pub fn approve(&mut self, id: AssetId, spender: AccountId, value: Balance) -> Result<()> {
api::approve(id, spender, value)
pub fn approve(
&mut self,
token: TokenId,
spender: AccountId,
value: Balance,
) -> Result<()> {
api::approve(token, spender, value)
}

#[ink(message)]
pub fn increase_allowance(
&mut self,
id: AssetId,
token: TokenId,
spender: AccountId,
value: Balance,
) -> Result<()> {
api::increase_allowance(id, spender, value)
api::increase_allowance(token, spender, value)
}

#[ink(message)]
pub fn decrease_allowance(
&mut self,
id: AssetId,
token: TokenId,
spender: AccountId,
value: Balance,
) -> Result<()> {
api::decrease_allowance(id, spender, value)
api::decrease_allowance(token, spender, value)
}

/// 2. PSP-22 Metadata Interface:
/// - token_name
/// - token_symbol
/// - token_decimals

#[ink(message)]
pub fn token_name(&self, id: AssetId) -> Result<Vec<u8>> {
api::token_name(id)
pub fn token_name(&self, token: TokenId) -> Result<Vec<u8>> {
api::token_name(token)
}

#[ink(message)]
pub fn token_symbol(&self, id: AssetId) -> Result<Vec<u8>> {
api::token_symbol(id)
pub fn token_symbol(&self, token: TokenId) -> Result<Vec<u8>> {
api::token_symbol(token)
}

#[ink(message)]
pub fn token_decimals(&self, id: AssetId) -> Result<u8> {
api::token_decimals(id)
}

// 3. Asset Management:
// - create
// - start_destroy
// - destroy_accounts
// - destroy_approvals
// - finish_destroy
// - set_metadata
// - clear_metadata

// #[ink(message)]
// pub fn create(&self, id: AssetId, admin: AccountId, min_balance: Balance) -> Result<()> {
// ink::env::debug_println!(
// "PopApiFungiblesExample::create: id: {:?} admin: {:?} min_balance: {:?}",
// id,
// admin,
// min_balance,
// );
// let result = api::create(id, admin, min_balance);
// ink::env::debug_println!("Result: {:?}", result);
// result.map_err(|e| e.into())
// result
// }

// #[ink(message)]
// pub fn set_metadata(
// &self,
// id: AssetId,
// name: Vec<u8>,
// symbol: Vec<u8>,
// decimals: u8,
// ) -> Result<()> {
// ink::env::debug_println!(
// "PopApiFungiblesExample::set_metadata: id: {:?} name: {:?} symbol: {:?}, decimals: {:?}",
// id,
// name,
// symbol,
// decimals,
// );
// let result = api::set_metadata(id, name, symbol, decimals);
// ink::env::debug_println!("Result: {:?}", result);
// // result.map_err(|e| e.into())
// result
// }
//
// #[ink(message)]
// pub fn asset_exists(&self, id: AssetId) -> Result<bool> {
// // api::asset_exists(id).map_err(|e| e.into())
// api::asset_exists(id)
// }
}

#[cfg(test)]
mod tests {
use super::*;

#[ink::test]
fn default_works() {
PopApiFungiblesExample::new();
pub fn token_decimals(&self, token: TokenId) -> Result<u8> {
api::token_decimals(token)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[package]
authors = [ "[your_name] <[your_email]>" ]
edition = "2021"
name = "create_token_in_constructor"
version = "0.1.0"
Expand Down
1 change: 0 additions & 1 deletion pop-api/integration-tests/contracts/fungibles/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[package]
authors = [ "[your_name] <[your_email]>" ]
edition = "2021"
name = "fungibles"
version = "0.1.0"
Expand Down
Loading
Loading