-
Notifications
You must be signed in to change notification settings - Fork 10
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
12 changed files
with
975 additions
and
4 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
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,54 @@ | ||
// Core imports | ||
|
||
use integer::BoundedInt; | ||
use debug::PrintTrait; | ||
|
||
// Starknet imports | ||
|
||
use starknet::ContractAddress; | ||
use starknet::testing::set_caller_address; | ||
|
||
// External imports | ||
|
||
use openzeppelin::token::erc721::erc721::ERC721; | ||
|
||
// Local imports | ||
|
||
use cairo_erc_3525::tests::mocks::account::Account; | ||
use cairo_erc_3525::module::ERC3525; | ||
use cairo_erc_3525::extensions::metadata::module::ERC3525Metadata; | ||
use cairo_erc_3525::tests::unit::constants::{STATE, STATE_METADATA, VALUE_DECIMALS, SLOT_1, SLOT_2}; | ||
|
||
// Settings | ||
|
||
fn setup() -> ERC3525Metadata::ContractState { | ||
let mut state_metadata = STATE_METADATA(); | ||
ERC3525Metadata::InternalImpl::initializer(ref state_metadata); | ||
state_metadata | ||
} | ||
|
||
#[test] | ||
#[available_gas(20000000)] | ||
fn test_metadata_contract_uri() { | ||
let mut state_metadata = setup(); | ||
let uri = ERC3525Metadata::ERC3525MetadataImpl::contract_uri(@state_metadata); | ||
assert(uri == 0, 'Wrong contract URI'); | ||
let new_uri = 'https://example.com'; | ||
ERC3525Metadata::InternalImpl::_set_contract_uri(ref state_metadata, new_uri); | ||
let uri = ERC3525Metadata::ERC3525MetadataImpl::contract_uri(@state_metadata); | ||
assert(uri == new_uri, 'Wrong contract URI'); | ||
} | ||
|
||
#[test] | ||
#[available_gas(20000000)] | ||
fn test_metadata_slot_uri() { | ||
let mut state_metadata = setup(); | ||
let uri = ERC3525Metadata::ERC3525MetadataImpl::slot_uri(@state_metadata, SLOT_1); | ||
assert(uri == 0, 'Wrong contract URI'); | ||
let new_uri = 'https://example.com'; | ||
ERC3525Metadata::InternalImpl::_set_slot_uri(ref state_metadata, SLOT_1, new_uri); | ||
let uri = ERC3525Metadata::ERC3525MetadataImpl::slot_uri(@state_metadata, SLOT_1); | ||
assert(uri == new_uri, 'Wrong contract URI'); | ||
let uri = ERC3525Metadata::ERC3525MetadataImpl::slot_uri(@state_metadata, SLOT_2); | ||
assert(uri == 0, 'Wrong contract URI'); | ||
} |
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,126 @@ | ||
// Core imports | ||
|
||
use debug::PrintTrait; | ||
|
||
// Starknet imports | ||
|
||
use starknet::testing::set_caller_address; | ||
|
||
// External imports | ||
|
||
use openzeppelin::token::erc721::erc721::ERC721; | ||
|
||
// Local imports | ||
|
||
use cairo_erc_3525::module::ERC3525; | ||
use cairo_erc_3525::extensions::slotapprovable::module::ERC3525SlotApprovable; | ||
use cairo_erc_3525::tests::unit::constants::{ | ||
STATE, STATE_SLOT_APPROVABLE, VALUE_DECIMALS, TOKEN_ID_1, TOKEN_ID_2, SLOT_1, SLOT_2, VALUE, | ||
ZERO, OWNER, OPERATOR, SOMEONE | ||
}; | ||
|
||
// Settings | ||
|
||
fn setup() -> (ERC3525::ContractState, ERC3525SlotApprovable::ContractState) { | ||
let mut state = STATE(); | ||
ERC3525::InternalImpl::initializer(ref state, VALUE_DECIMALS); | ||
let mut state_slot_approvable = STATE_SLOT_APPROVABLE(); | ||
ERC3525SlotApprovable::InternalImpl::initializer(ref state_slot_approvable); | ||
(state, state_slot_approvable) | ||
} | ||
|
||
// Tests approvals | ||
|
||
#[test] | ||
#[available_gas(20000000)] | ||
fn test_slot_approvable_owner_can_approve_slot() { | ||
let (mut state, mut state_slot_approvable) = setup(); | ||
set_caller_address(OWNER()); | ||
ERC3525SlotApprovable::ERC3525SlotApprovableImpl::set_approval_for_slot( | ||
ref state_slot_approvable, OWNER(), SLOT_1, OPERATOR(), true | ||
); | ||
} | ||
|
||
#[test] | ||
#[available_gas(20000000)] | ||
fn test_slot_approvable_operator_can_approve_value() { | ||
let (mut state, mut state_slot_approvable) = setup(); | ||
set_caller_address(OWNER()); | ||
ERC3525::InternalImpl::_mint(ref state, OWNER(), TOKEN_ID_1, SLOT_1, VALUE); | ||
ERC3525SlotApprovable::ERC3525SlotApprovableImpl::set_approval_for_slot( | ||
ref state_slot_approvable, OWNER(), SLOT_1, OPERATOR(), true | ||
); | ||
set_caller_address(OPERATOR()); | ||
ERC3525SlotApprovable::ExternalImpl::approve_value( | ||
ref state_slot_approvable, TOKEN_ID_1, OPERATOR(), VALUE | ||
); | ||
} | ||
|
||
#[test] | ||
#[available_gas(20000000)] | ||
#[should_panic(expected: ('ERC3525: caller not allowed',))] | ||
fn test_slot_approvable_operator_cannot_approve_any_token() { | ||
let (mut state, mut state_slot_approvable) = setup(); | ||
set_caller_address(OWNER()); | ||
ERC3525::InternalImpl::_mint(ref state, OWNER(), TOKEN_ID_1, SLOT_1, VALUE); | ||
ERC3525SlotApprovable::ERC3525SlotApprovableImpl::set_approval_for_slot( | ||
ref state_slot_approvable, OWNER(), SLOT_2, OPERATOR(), true | ||
); | ||
set_caller_address(OPERATOR()); | ||
ERC3525SlotApprovable::ExternalImpl::approve_value( | ||
ref state_slot_approvable, TOKEN_ID_1, OPERATOR(), VALUE | ||
); | ||
} | ||
|
||
#[test] | ||
#[available_gas(20000000)] | ||
#[should_panic(expected: ('ERC3525: insufficient allowance',))] | ||
fn test_slot_approvable_operator_cannot_transfer_anyones_value() { | ||
let (mut state, mut state_slot_approvable) = setup(); | ||
set_caller_address(OWNER()); | ||
ERC3525::InternalImpl::_mint(ref state, OWNER(), TOKEN_ID_1, SLOT_1, VALUE); | ||
ERC3525::InternalImpl::_mint(ref state, SOMEONE(), TOKEN_ID_2, SLOT_1, VALUE); | ||
ERC3525SlotApprovable::ERC3525SlotApprovableImpl::set_approval_for_slot( | ||
ref state_slot_approvable, OWNER(), SLOT_1, OPERATOR(), true | ||
); | ||
set_caller_address(OPERATOR()); | ||
ERC3525SlotApprovable::ExternalImpl::transfer_value_from( | ||
ref state_slot_approvable, TOKEN_ID_2, 0, OPERATOR(), VALUE | ||
); | ||
} | ||
|
||
#[test] | ||
#[available_gas(20000000)] | ||
#[should_panic(expected: ('ERC3525: slot mismatch',))] | ||
fn test_slot_approvable_operator_transfer_value_revert_slot_mismatch() { | ||
let (mut state, mut state_slot_approvable) = setup(); | ||
set_caller_address(OWNER()); | ||
ERC3525::InternalImpl::_mint(ref state, OWNER(), TOKEN_ID_1, SLOT_1, VALUE); | ||
ERC3525::InternalImpl::_mint(ref state, SOMEONE(), TOKEN_ID_2, SLOT_2, VALUE); | ||
ERC3525SlotApprovable::ERC3525SlotApprovableImpl::set_approval_for_slot( | ||
ref state_slot_approvable, OWNER(), SLOT_1, OPERATOR(), true | ||
); | ||
set_caller_address(OPERATOR()); | ||
ERC3525SlotApprovable::ExternalImpl::transfer_value_from( | ||
ref state_slot_approvable, TOKEN_ID_1, TOKEN_ID_2, ZERO(), VALUE | ||
); | ||
} | ||
|
||
#[test] | ||
#[available_gas(20000000)] | ||
#[should_panic(expected: ('ERC3525: caller not allowed',))] | ||
fn test_slot_approvable_revoked_slot_operator_cannot_approve() { | ||
let (mut state, mut state_slot_approvable) = setup(); | ||
set_caller_address(OWNER()); | ||
ERC3525::InternalImpl::_mint(ref state, OWNER(), TOKEN_ID_1, SLOT_1, VALUE); | ||
ERC3525SlotApprovable::ERC3525SlotApprovableImpl::set_approval_for_slot( | ||
ref state_slot_approvable, OWNER(), SLOT_1, OPERATOR(), true | ||
); | ||
ERC3525SlotApprovable::ERC3525SlotApprovableImpl::set_approval_for_slot( | ||
ref state_slot_approvable, OWNER(), SLOT_1, OPERATOR(), false | ||
); | ||
set_caller_address(OPERATOR()); | ||
ERC3525SlotApprovable::ExternalImpl::approve_value( | ||
ref state_slot_approvable, TOKEN_ID_1, OPERATOR(), VALUE | ||
); | ||
} |
Oops, something went wrong.