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

Fixup of escrow clearing after withdrawing, added tests to check #246

Merged
merged 7 commits into from
Oct 14, 2024

Conversation

od-hunter
Copy link
Contributor

@od-hunter od-hunter commented Sep 30, 2024

Resolves #226

Copy link

vercel bot commented Sep 30, 2024

@od-hunter is attempting to deploy a commit to the Screenshot Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Collaborator

@ptisserand ptisserand left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution,
it seems that your new test is failing, maybe you forgot to push some modification.
To ensure indentation is correct, you can run scarb fmt.

Also please take a look at https://foundry-rs.github.io/starknet-foundry/testing/testing-contract-internals.html to avoid adding an useless view in contract ABI.

Comment on lines 374 to 376
fn is_token_escrowed(ref self: ContractState, collection: ContractAddress, token_id: u256) -> bool {
!self.escrow.read((collection, token_id)).is_zero()
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for a ref since there is no state modification

Copy link
Collaborator

Choose a reason for hiding this comment

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

By the way I'm not sure this view is really needed since it's only use for testing purpose.
Please see https://foundry-rs.github.io/starknet-foundry/testing/testing-contract-internals.html for a better solution.

@@ -34,6 +34,7 @@ trait IStarklane<T> {
fn is_enabled(self: @T) -> bool;

fn set_l1_l2_collection_mapping(ref self: T , collection_l1: EthAddress, collection_l2: ContractAddress);
fn is_token_escrowed(ref self: T, collection: ContractAddress, token_id: u256) -> bool;
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for ref since there is no state modification

Copy link
Collaborator

Choose a reason for hiding this comment

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

By the way I'm not sure this view is really needed since it's only use for testing purpose.
Please see https://foundry-rs.github.io/starknet-foundry/testing/testing-contract-internals.html for a better solution.

Copy link
Contributor Author

@od-hunter od-hunter Oct 1, 2024

Choose a reason for hiding this comment

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

hi @ptisserand , i had implemented the view cause the method mentioned in this docs , isnt really working as it should . Something about the mapping being a little more complex to read its value and no clear resource pointing how to go about 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.

@ptisserand please reply

Comment on lines 276 to 277
//get mapping value before withdrawal

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not needed

Comment on lines 300 to 301
//get mapping value after withdrawal , then compare to see if it has been cleared

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not needed

Comment on lines 163 to 165

let null_value = starknet::contract_address_const::<0>();
self.escrow.write((collection_l2, token_id), null_value);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use scarb fmt for indentation

@@ -1214,4 +1215,80 @@ mod tests {
assert_eq!(bridge.get_l1_collection_address(erc721b_address), collection_l1);
assert_eq!(bridge.get_l2_collection_address(collection_l1), erc721b_address);
}

#[test]
fn test_escrow_clearing_after_withdrawal() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is failing on your branch

[FAIL] starklane::tests::bridge_t::tests::test_escrow_clearing_after_withdrawal

Failure data:
    0x526573756c743a3a756e77726170206661696c65642e ('Result::unwrap failed.')

@@ -1214,4 +1215,80 @@ mod tests {
assert_eq!(bridge.get_l1_collection_address(erc721b_address), collection_l1);
assert_eq!(bridge.get_l2_collection_address(collection_l1), erc721b_address);
}

#[test]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use scarb fmt for indentation

@ptisserand
Copy link
Collaborator

With starknet-foundry 0.19.0, you can directly query storage with the following:

    use snforge_std::{load, map_entry_address};
    let escrowed = load(bridge_address, map_entry_address(selector!("escrow"), array![erc721b_address.into(), 0, 0].span()), 1);

For details see https://book.cairo-lang.org/ch14-01-01-storage-mappings.html and https://docs.starknet.io/architecture-and-concepts/cryptography/hash-functions/#array_hashing

@od-hunter
Copy link
Contributor Author

od-hunter commented Oct 11, 2024

@ptisserand Just did a fix , tests are passing on my end.

@ptisserand ptisserand added this pull request to the merge queue Oct 14, 2024
Merged via the queue into ArkProjectNFTs:main with commit 455aba1 Oct 14, 2024
2 of 4 checks passed
@od-hunter
Copy link
Contributor Author

@ptisserand , thanks for the opportunity ser🫡

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.

withdraw_auto_from_l1 escrow is not zeroed
2 participants