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

Feat/make transfer #14

Closed
wants to merge 15 commits into from
Closed

Feat/make transfer #14

wants to merge 15 commits into from

Conversation

NehharShah
Copy link
Contributor

No description provided.

@NehharShah NehharShah requested a review from ZackAttax January 24, 2025 20:45
Copy link
Contributor

@ZackAttax ZackAttax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR doesn't have any test for make_transfer and has redundant test

tests/lib.cairo Outdated Show resolved Hide resolved
tests/lib.cairo Outdated Show resolved Hide resolved
tests/lib.cairo Outdated
}

#[test]
fn test_check_owner_and_operator_empty_array() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already check for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove it

tests/lib.cairo Outdated
}

#[test]
fn test_check_owner_and_operator_zero_balance() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks more like a test for a token that doesn't exist than a zero balance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taking a look at it

Copy link
Contributor

@ZackAttax ZackAttax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could make this a little more if you abstracted the transfers

tests/lib.cairo Outdated
fn test_check_owner_and_operator_empty_transfers() {
let (tokenized_bond, _minter) = setup_contract_with_minter();
let transfers = array![];
start_cheat_caller_address(tokenized_bond.contract_address, NOT_MINTER());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we calling this contract with the not_minter address?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to check if check_owner_and_operator functions returns false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't really need to cheat the caller at all here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I just deleted that. Thanks for pointing it out.

tests/lib.cairo Outdated
fn test_check_owner_and_operator_zero_balance() {
let (tokenized_bond, minter) = setup_contract_with_minter();
let receiver1 = setup_receiver();
let other_account = setup_receiver();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other account is a very vague name for a variable and doesn't follow the naming conventions of this function or the others

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change it to receiver2.

tests/lib.cairo Outdated
let other_account = setup_receiver();

start_cheat_caller_address(tokenized_bond.contract_address, OWNER());
tokenized_bond.add_minter(other_account);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we making this other account a minter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for testing transfers from minter who has zero balance.

tests/lib.cairo Outdated

start_cheat_caller_address(tokenized_bond.contract_address, other_account);

let zero_balance_destination = array![
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we testing for a zero balance at the destination?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is to verify that an account cannot transfer tokens if they don't have any tokens to transfer, even if they are a valid minter.

tests/lib.cairo Outdated
Comment on lines 824 to 827
assert(
!tokenized_bond.check_owner_and_operator(zero_balance_transfers),
'Should fail for zero balance',
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell me why this check_owner_and_operator returns a falsey value here and this test pass?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added this to ensure that accounts can't transfer tokens they don't own, even if they have special roles like being a minter.

tests/lib.cairo Outdated

start_cheat_caller_address(tokenized_bond.contract_address, NOT_MINTER());
assert(
!tokenized_bond.check_owner_and_operator(transfers.clone()), 'Should fail as non-operator',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't falsey because they are a non-operator

tests/lib.cairo Outdated
let receiver1 = setup_receiver();
let receiver2 = setup_receiver();

// Create two separate transfers, each with one destination
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment contradicts the code below it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I need to make it as a separate destination. I forgot to change from the previous code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove this comment too. Thanks for pointing it out.

tests/lib.cairo Outdated
}

#[test]
fn test_check_owner_and_operator_nonexistent_token() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we testing for a token that doesn't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this to verify that the contract properly handles actions on tokens that don’t exist/minted

tests/lib.cairo Outdated
Comment on lines 761 to 781
fn test_check_owner_and_operator_as_non_owner_operator() {
let (tokenized_bond, _minter) = setup_contract_with_minter();
let receiver1 = setup_receiver();

let invalid_transfers = array![
TokenizedBond::TransferParam {
from: receiver1,
to: array![
TokenizedBond::TransferDestination {
receiver: receiver1, amount: TRANSFER_AMOUNT(), token_id: TOKEN_ID(),
},
],
},
];

assert(
!tokenized_bond.check_owner_and_operator(invalid_transfers),
'Failed for non-owner/operator',
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this. The name of this test makes it sound like it's testing who calls the contract and then we have a invalid transaction with the same to and from address

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's a bit confusing. I can remove this if you don't want it. I added this to check that a transfer will fail when the from is not the owner nor operator

Copy link

codecov bot commented Jan 30, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

start_cheat_caller_address(tokenized_bond.contract_address, minter);
assert(tokenized_bond.check_owner_and_operator(transfers.clone()), 'Should pass as minter');
assert(!tokenized_bond.check_owner_and_operator(transfers), 'Fail for different from address');
Copy link
Contributor

@ZackAttax ZackAttax Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is returning false because the from address has no balance not because the caller is not the owner of the from address

let erc_1155 = IERC1155Dispatcher { contract_address: tokenized_bond.contract_address };

start_cheat_caller_address(tokenized_bond.contract_address, minter);
erc_1155.safe_transfer_from(minter, non_minter, TOKEN_ID(), TRANSFER_AMOUNT(), array![].span());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's hard to tell who is sending and receiving tokens in this function

@NehharShah NehharShah closed this Jan 31, 2025
@NehharShah NehharShah deleted the feat/make-transfer branch January 31, 2025 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants