-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: integration tests for dynamic supply
- Loading branch information
1 parent
46c4c61
commit 5f6da96
Showing
6 changed files
with
81 additions
and
3 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
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
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,73 @@ | ||
use snforge_std::{EventSpy, spy_events, start_cheat_caller_address}; | ||
use starknet_ibc_apps::transfer::{ERC20Contract, ERC20ContractTrait}; | ||
use starknet_ibc_testkit::dummies::{AMOUNT, OWNER, SN_USER, ZERO}; | ||
use starknet_ibc_testkit::event_spy::{ERC20EventSpyExt, ERC20EventSpyExtImpl}; | ||
use starknet_ibc_testkit::handles::ERC20Handle; | ||
use starknet_ibc_testkit::setup::SetupImpl; | ||
|
||
fn setup() -> (ERC20Contract, EventSpy) { | ||
let setup = SetupImpl::default(); | ||
let erc20 = SetupImpl::deploy_erc20(@setup, OWNER()); | ||
let spy = spy_events(); | ||
(erc20, spy) | ||
} | ||
|
||
#[test] | ||
fn test_deploy_erc20_ok() { | ||
setup(); | ||
} | ||
|
||
#[test] | ||
fn test_erc20_mint_ok() { | ||
let (mut erc20, mut spy) = setup(); | ||
start_cheat_caller_address(erc20.address, OWNER()); | ||
erc20.mint(SN_USER(), AMOUNT); | ||
spy.assert_transfer_event(erc20.address, ZERO(), SN_USER(), AMOUNT); | ||
erc20.assert_balance(OWNER(), 0); | ||
erc20.assert_balance(SN_USER(), AMOUNT); | ||
erc20.assert_total_supply(AMOUNT); | ||
} | ||
|
||
#[test] | ||
fn test_erc20_burn_ok() { | ||
let (mut erc20, mut spy) = setup(); | ||
start_cheat_caller_address(erc20.address, OWNER()); | ||
erc20.mint(SN_USER(), AMOUNT); | ||
erc20.approve(SN_USER(), OWNER(), AMOUNT); | ||
erc20.transfer_from(SN_USER(), OWNER(), AMOUNT); | ||
spy.assert_transfer_event(erc20.address, SN_USER(), OWNER(), AMOUNT); | ||
erc20.burn(AMOUNT); | ||
spy.assert_transfer_event(erc20.address, OWNER(), ZERO(), AMOUNT); | ||
erc20.assert_balance(OWNER(), 0); | ||
erc20.assert_balance(SN_USER(), 0); | ||
erc20.assert_total_supply(0); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: 'Caller is not the owner')] | ||
fn test_erc20_unauthorized_mint() { | ||
let (mut erc20, _) = setup(); | ||
erc20.mint(SN_USER(), AMOUNT); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: 'Caller is not the owner')] | ||
fn test_erc20_unauthorized_burn() { | ||
let (mut erc20, _) = setup(); | ||
start_cheat_caller_address(erc20.address, OWNER()); | ||
erc20.mint(SN_USER(), AMOUNT); | ||
erc20.approve(SN_USER(), OWNER(), AMOUNT); | ||
erc20.transfer_from(SN_USER(), OWNER(), AMOUNT); | ||
start_cheat_caller_address(erc20.address, SN_USER()); | ||
erc20.burn(AMOUNT); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: 'ERC20: insufficient allowance')] | ||
fn test_erc20_transfer_without_user_approval() { | ||
let (mut erc20, _) = setup(); | ||
start_cheat_caller_address(erc20.address, OWNER()); | ||
erc20.mint(SN_USER(), AMOUNT); | ||
erc20.transfer_from(SN_USER(), OWNER(), AMOUNT); | ||
} | ||
|
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