-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
2,541 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#![no_std] | ||
#![allow(dead_code)] | ||
|
||
mod contract; | ||
mod contract_token_interface; | ||
mod test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "fungible-token-interface-example" | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
publish = false | ||
version.workspace = true | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
doctest = false | ||
|
||
[dependencies] | ||
soroban-sdk = { workspace = true } | ||
openzeppelin-pausable = { workspace = true } | ||
openzeppelin-pausable-macros = { workspace = true } | ||
openzeppelin-fungible-token = { workspace = true } | ||
|
||
[dev-dependencies] | ||
soroban-sdk = { workspace = true, features = ["testutils"] } |
12 changes: 7 additions & 5 deletions
12
...-pausable/src/contract_token_interface.rs → .../fungible-token-interface/src/contract.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#![no_std] | ||
#![allow(dead_code)] | ||
|
||
mod contract; | ||
mod test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#![cfg(test)] | ||
|
||
extern crate std; | ||
|
||
use soroban_sdk::{testutils::Address as _, Address, Env, String}; | ||
|
||
use crate::contract::{ExampleContract, ExampleContractClient}; | ||
|
||
fn create_client<'a>(e: &Env, owner: &Address, initial_supply: i128) -> ExampleContractClient<'a> { | ||
let address = e.register(ExampleContract, (owner, initial_supply)); | ||
ExampleContractClient::new(e, &address) | ||
} | ||
|
||
#[test] | ||
fn initial_state() { | ||
let e = Env::default(); | ||
let owner = Address::generate(&e); | ||
let client = create_client(&e, &owner, 1000); | ||
|
||
assert_eq!(client.total_supply(), 1000); | ||
assert_eq!(client.balance(&owner), 1000); | ||
assert_eq!(client.symbol(), String::from_str(&e, "TKN")); | ||
assert_eq!(client.name(), String::from_str(&e, "My Token")); | ||
assert_eq!(client.decimals(), 18); | ||
assert!(!client.paused()); | ||
} | ||
|
||
#[test] | ||
fn transfer_works() { | ||
let e = Env::default(); | ||
let owner = Address::generate(&e); | ||
let recipient = Address::generate(&e); | ||
let client = create_client(&e, &owner, 1000); | ||
|
||
e.mock_all_auths(); | ||
client.transfer(&owner, &recipient, &100); | ||
assert_eq!(client.balance(&owner), 900); | ||
assert_eq!(client.balance(&recipient), 100); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Error(Contract, #100)")] | ||
fn transfer_fails_when_paused() { | ||
let e = Env::default(); | ||
let owner = Address::generate(&e); | ||
let recipient = Address::generate(&e); | ||
let client = create_client(&e, &owner, 1000); | ||
|
||
e.mock_all_auths(); | ||
client.pause(&owner); | ||
client.transfer(&owner, &recipient, &100); | ||
} | ||
|
||
#[test] | ||
fn transfer_from_works() { | ||
let e = Env::default(); | ||
let owner = Address::generate(&e); | ||
let spender = Address::generate(&e); | ||
let recipient = Address::generate(&e); | ||
let client = create_client(&e, &owner, 1000); | ||
|
||
e.mock_all_auths(); | ||
client.approve(&owner, &spender, &200, &100); | ||
client.transfer_from(&spender, &owner, &recipient, &200); | ||
assert_eq!(client.balance(&owner), 800); | ||
assert_eq!(client.balance(&recipient), 200); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Error(Contract, #100)")] | ||
fn transfer_from_fails_when_paused() { | ||
let e = Env::default(); | ||
let owner = Address::generate(&e); | ||
let spender = Address::generate(&e); | ||
let recipient = Address::generate(&e); | ||
let client = create_client(&e, &owner, 1000); | ||
|
||
e.mock_all_auths(); | ||
client.pause(&owner); | ||
client.transfer_from(&spender, &owner, &recipient, &200); | ||
} | ||
|
||
#[test] | ||
fn mint_works() { | ||
let e = Env::default(); | ||
let owner = Address::generate(&e); | ||
let client = create_client(&e, &owner, 1000); | ||
|
||
e.mock_all_auths(); | ||
client.mint(&owner, &500); | ||
assert_eq!(client.total_supply(), 1500); | ||
assert_eq!(client.balance(&owner), 1500); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Error(Contract, #100)")] | ||
fn mint_fails_when_paused() { | ||
let e = Env::default(); | ||
let owner = Address::generate(&e); | ||
let client = create_client(&e, &owner, 1000); | ||
|
||
e.mock_all_auths(); | ||
client.pause(&owner); | ||
client.mint(&owner, &500); | ||
} | ||
|
||
#[test] | ||
fn burn_works() { | ||
let e = Env::default(); | ||
let owner = Address::generate(&e); | ||
let client = create_client(&e, &owner, 1000); | ||
|
||
e.mock_all_auths(); | ||
client.burn(&owner, &200); | ||
assert_eq!(client.total_supply(), 800); | ||
assert_eq!(client.balance(&owner), 800); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Error(Contract, #100)")] | ||
fn burn_fails_when_paused() { | ||
let e = Env::default(); | ||
let owner = Address::generate(&e); | ||
let client = create_client(&e, &owner, 1000); | ||
|
||
e.mock_all_auths(); | ||
client.pause(&owner); | ||
client.burn(&owner, &200); | ||
} |
Oops, something went wrong.