Skip to content

Commit

Permalink
chore: clean tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Lindahl committed Oct 12, 2023
1 parent 88337b3 commit a297a7b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 46 deletions.
92 changes: 48 additions & 44 deletions tests/macros/standard/fungible_token.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use near_sdk::{
json_types::Base64VecU8, near_bindgen, test_utils::VMContextBuilder, testing_env, AccountId,
};
use near_sdk::{json_types::Base64VecU8, near_bindgen};
use near_sdk_contract_tools::{
standard::{nep141::*, nep148::*},
FungibleToken,
Expand All @@ -18,7 +16,7 @@ impl MyFungibleTokenContract {
let mut contract = Self {};

contract.set_metadata(
&FungibleTokenMetadata::new("My Fungible Token".into(), "MYFT".into(), 18)
&FungibleTokenMetadata::new("My Fungible Token".into(), "MYFT".into(), 24)
.icon("https://example.com/icon.png".into())
.reference("https://example.com/metadata.json".into())
.reference_hash(Base64VecU8::from([97, 115, 100, 102].to_vec())),
Expand All @@ -28,53 +26,59 @@ impl MyFungibleTokenContract {
}
}

#[test]
fn fungible_token_transfer() {
let mut ft = MyFungibleTokenContract::new();
#[cfg(test)]
mod tests {
use super::*;
use near_sdk::{test_utils::VMContextBuilder, testing_env, AccountId};

let alice: AccountId = "alice".parse().unwrap();
let bob: AccountId = "bob".parse().unwrap();
#[test]
fn fungible_token_transfer() {
let mut ft = MyFungibleTokenContract::new();

assert_eq!(ft.ft_balance_of(alice.clone()).0, 0);
assert_eq!(ft.ft_balance_of(bob.clone()).0, 0);
assert_eq!(ft.ft_total_supply().0, 0);
let alice: AccountId = "alice".parse().unwrap();
let bob: AccountId = "bob".parse().unwrap();

ft.deposit_unchecked(&alice, 100).unwrap();
ft.deposit_unchecked(&bob, 20).unwrap();
assert_eq!(ft.ft_balance_of(alice.clone()).0, 0);
assert_eq!(ft.ft_balance_of(bob.clone()).0, 0);
assert_eq!(ft.ft_total_supply().0, 0);

assert_eq!(ft.ft_balance_of(alice.clone()).0, 100);
assert_eq!(ft.ft_balance_of(bob.clone()).0, 20);
assert_eq!(ft.ft_total_supply().0, 120);
ft.deposit_unchecked(&alice, 100).unwrap();
ft.deposit_unchecked(&bob, 20).unwrap();

let context = VMContextBuilder::new()
.predecessor_account_id(alice.clone())
.attached_deposit(1)
.build();
assert_eq!(ft.ft_balance_of(alice.clone()).0, 100);
assert_eq!(ft.ft_balance_of(bob.clone()).0, 20);
assert_eq!(ft.ft_total_supply().0, 120);

testing_env!(context);
let context = VMContextBuilder::new()
.predecessor_account_id(alice.clone())
.attached_deposit(1)
.build();

ft.ft_transfer(bob.clone(), 50.into(), None);
testing_env!(context);

assert_eq!(ft.ft_balance_of(alice.clone()).0, 50);
assert_eq!(ft.ft_balance_of(bob.clone()).0, 70);
assert_eq!(ft.ft_total_supply().0, 120);
}
ft.ft_transfer(bob.clone(), 50.into(), None);

assert_eq!(ft.ft_balance_of(alice.clone()).0, 50);
assert_eq!(ft.ft_balance_of(bob.clone()).0, 70);
assert_eq!(ft.ft_total_supply().0, 120);
}

#[test]
fn metadata() {
let ft = MyFungibleTokenContract::new();
let meta = ft.ft_metadata();

assert_eq!(meta.decimals, 18);
assert_eq!(meta.name, "My Fungible Token");
assert_eq!(meta.symbol, "MYFT");
assert_eq!(meta.icon, Some("https://example.com/icon.png".into()));
assert_eq!(
meta.reference,
Some("https://example.com/metadata.json".into())
);
assert_eq!(
meta.reference_hash,
Some(Base64VecU8::from([97, 115, 100, 102].to_vec()))
);
#[test]
fn metadata() {
let ft = MyFungibleTokenContract::new();
let meta = ft.ft_metadata();

assert_eq!(meta.decimals, 24);
assert_eq!(meta.name, "My Fungible Token");
assert_eq!(meta.symbol, "MYFT");
assert_eq!(meta.icon, Some("https://example.com/icon.png".into()));
assert_eq!(
meta.reference,
Some("https://example.com/metadata.json".into())
);
assert_eq!(
meta.reference_hash,
Some(Base64VecU8::from([97, 115, 100, 102].to_vec()))
);
}
}
2 changes: 0 additions & 2 deletions tests/macros/standard/nep141.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ impl near_sdk_contract_tools::standard::nep141::Nep141Receiver for FungibleToken
}
}

// TODO: transfer_call testing (not possible without workspaces-rs or something
// like that, and workspaces-rs doesn't work on macOS)
#[test]
fn nep141_transfer() {
let mut ft = FungibleToken {
Expand Down

0 comments on commit a297a7b

Please sign in to comment.