Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate erc721 tests #1027

Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f6db8f7
feat: migrate event tests
ericnordelo Jun 26, 2024
b5eb69c
feat: update workflow
ericnordelo Jun 26, 2024
379eebb
feat: add foundry utils
ericnordelo Jun 26, 2024
99cb95c
feat: finish erc20 and erc20votes migration
ericnordelo Jun 26, 2024
6232458
feat: remove dual case tests
ericnordelo Jun 26, 2024
1a94cd0
refactor: format files
ericnordelo Jun 26, 2024
95b27cb
refactor: variable name
ericnordelo Jun 26, 2024
6d0ce26
Update src/tests/token.cairo
ericnordelo Jun 27, 2024
ca87f9d
Update src/tests/token/erc20.cairo
ericnordelo Jun 27, 2024
b874a88
Update src/tests/utils/foundry.cairo
ericnordelo Jun 27, 2024
63ebc7a
Update src/tests/token/erc20/test_erc20_votes.cairo
ericnordelo Jun 27, 2024
422687e
feat: apply review updates
ericnordelo Jun 27, 2024
b8c0419
Merge branch 'feat/migrate-erc20-tests-#1008' of github.com:ericnorde…
ericnordelo Jun 27, 2024
6a53e66
feat: migrate erc721 components tests
ericnordelo Jul 1, 2024
e1f259a
Merge branch 'snforge-migration' of github.com:OpenZeppelin/cairo-con…
ericnordelo Jul 1, 2024
a7f4fbc
refactor: remove extra line
ericnordelo Jul 1, 2024
b2331ea
feat: apply review updates
ericnordelo Jul 2, 2024
96786af
Merge branch 'snforge-migration' of github.com:OpenZeppelin/cairo-con…
ericnordelo Jul 5, 2024
6860275
feat: update utilities
ericnordelo Jul 5, 2024
04759fd
feat: apply review updates
ericnordelo Jul 10, 2024
51c15d5
fix: ignore tests
ericnordelo Jul 10, 2024
0bae522
Merge branch 'snforge-migration' of github.com:OpenZeppelin/cairo-con…
ericnordelo Jul 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tests/token.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// pub(crate) mod erc1155;
pub(crate) mod erc20;
// pub(crate) mod erc721;
pub(crate) mod erc721;
1 change: 1 addition & 0 deletions src/tests/token/erc721.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub(crate) mod common;
mod test_dual721;
mod test_dual721_receiver;
mod test_erc721;
mod test_erc721_receiver;
andrew-fleming marked this conversation as resolved.
Show resolved Hide resolved
81 changes: 40 additions & 41 deletions src/tests/token/erc721/common.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,73 @@ use openzeppelin::tests::utils;
use openzeppelin::token::erc721::ERC721Component::{Approval, ApprovalForAll, Transfer};
use openzeppelin::token::erc721::ERC721Component;
use openzeppelin::utils::serde::SerializedAppend;
use snforge_std::{EventSpy, EventAssertions};
use starknet::ContractAddress;

pub(crate) fn assert_event_approval_for_all(
contract: ContractAddress, owner: ContractAddress, operator: ContractAddress, approved: bool
ref spy: EventSpy,
contract: ContractAddress,
owner: ContractAddress,
operator: ContractAddress,
approved: bool
) {
let event = utils::pop_log::<ERC721Component::Event>(contract).unwrap();
let expected = ERC721Component::Event::ApprovalForAll(
ApprovalForAll { owner, operator, approved }
);
assert!(event == expected);

// Check indexed keys
let mut indexed_keys = array![];
indexed_keys.append_serde(selector!("ApprovalForAll"));
indexed_keys.append_serde(owner);
indexed_keys.append_serde(operator);
utils::assert_indexed_keys(event, indexed_keys.span());
spy.assert_emitted(@array![(contract, expected)]);
}

pub(crate) fn assert_only_event_approval_for_all(
contract: ContractAddress, owner: ContractAddress, operator: ContractAddress, approved: bool
ref spy: EventSpy,
contract: ContractAddress,
owner: ContractAddress,
operator: ContractAddress,
approved: bool
) {
assert_event_approval_for_all(contract, owner, operator, approved);
utils::assert_no_events_left(contract);
assert_event_approval_for_all(ref spy, contract, owner, operator, approved);
assert(spy.events.len() == 0, 'Events remaining on queue');
}

pub(crate) fn assert_event_approval(
contract: ContractAddress, owner: ContractAddress, approved: ContractAddress, token_id: u256
ref spy: EventSpy,
contract: ContractAddress,
owner: ContractAddress,
approved: ContractAddress,
token_id: u256
) {
let event = utils::pop_log::<ERC721Component::Event>(contract).unwrap();
let expected = ERC721Component::Event::Approval(Approval { owner, approved, token_id });
assert!(event == expected);

// Check indexed keys
let mut indexed_keys = array![];
indexed_keys.append_serde(selector!("Approval"));
indexed_keys.append_serde(owner);
indexed_keys.append_serde(approved);
indexed_keys.append_serde(token_id);
utils::assert_indexed_keys(event, indexed_keys.span());
spy.assert_emitted(@array![(contract, expected)]);
}

pub(crate) fn assert_only_event_approval(
contract: ContractAddress, owner: ContractAddress, approved: ContractAddress, token_id: u256
ref spy: EventSpy,
contract: ContractAddress,
owner: ContractAddress,
approved: ContractAddress,
token_id: u256
) {
assert_event_approval(contract, owner, approved, token_id);
utils::assert_no_events_left(contract);
assert_event_approval(ref spy, contract, owner, approved, token_id);
assert(spy.events.len() == 0, 'Events remaining on queue');
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
}

pub(crate) fn assert_event_transfer(
contract: ContractAddress, from: ContractAddress, to: ContractAddress, token_id: u256
ref spy: EventSpy,
contract: ContractAddress,
from: ContractAddress,
to: ContractAddress,
token_id: u256
) {
let event = utils::pop_log::<ERC721Component::Event>(contract).unwrap();
let expected = ERC721Component::Event::Transfer(Transfer { from, to, token_id });
assert!(event == expected);

// Check indexed keys
let mut indexed_keys = array![];
indexed_keys.append_serde(selector!("Transfer"));
indexed_keys.append_serde(from);
indexed_keys.append_serde(to);
indexed_keys.append_serde(token_id);
utils::assert_indexed_keys(event, indexed_keys.span());
spy.assert_emitted(@array![(contract, expected)]);
}

pub(crate) fn assert_only_event_transfer(
contract: ContractAddress, from: ContractAddress, to: ContractAddress, token_id: u256
ref spy: EventSpy,
contract: ContractAddress,
from: ContractAddress,
to: ContractAddress,
token_id: u256
) {
assert_event_transfer(contract, from, to, token_id);
utils::assert_no_events_left(contract);
assert_event_transfer(ref spy, contract, from, to, token_id);
assert(spy.events.len() == 0, 'Events remaining on queue');
}
Loading