use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Token {
pub id: String,
pub amount: String,
}
impl Token {
pub fn new(id: String, amount: String) -> Self {
Self { id, amount }
}
pub fn with_amount(id: String, amount: u128) -> Self {
Self {
id,
amount: amount.to_string(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FungibleTokenMetadata {
pub symbol: String,
pub name: String,
pub decimals: u8,
#[serde(rename = "totalSupply")]
pub total_supply: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NFTMetadata {
#[serde(rename = "tokenUri")]
pub token_uri: String,
#[serde(rename = "collectionId")]
pub collection_id: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum TokenType {
Fungible,
NonFungible,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_token_creation() {
let token = Token::new("abc123".to_string(), "1000".to_string());
assert_eq!(token.id, "abc123");
assert_eq!(token.amount, "1000");
}
#[test]
fn test_token_with_amount() {
let token = Token::with_amount("xyz789".to_string(), 5000);
assert_eq!(token.amount, "5000");
}
#[test]
fn test_token_serialization() {
let token = Token::new("test_id".to_string(), "100".to_string());
let json = serde_json::to_string(&token).unwrap();
assert!(json.contains("test_id"));
assert!(json.contains("100"));
}
}