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

test(erc721): add unit tests #142

Merged
merged 36 commits into from
Jun 24, 2024
Merged

test(erc721): add unit tests #142

merged 36 commits into from
Jun 24, 2024

Conversation

bidzyyys
Copy link
Collaborator

Resolves #69

@bidzyyys bidzyyys self-assigned this Jun 21, 2024
@bidzyyys bidzyyys linked an issue Jun 21, 2024 that may be closed by this pull request
Copy link

netlify bot commented Jun 21, 2024

Deploy Preview for contracts-stylus canceled.

Name Link
🔨 Latest commit f20ec5a
🔍 Latest deploy log https://app.netlify.com/sites/contracts-stylus/deploys/667567846fe4320008f65699

Copy link
Member

@qalisander qalisander left a comment

Choose a reason for hiding this comment

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

Great job!
Erc721 tests are getting better!

contracts/src/token/erc721/mod.rs Show resolved Hide resolved
}

#[motsu::test]
fn error_when_reusing_token_id(contract: Erc721) {
fn mint_error_when_reusing_token_id(contract: Erc721) {
Copy link
Member

Choose a reason for hiding this comment

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

I prefer more when those kind of tests looks like error_when_*.
As I remember previous name have been like error_when_minting_twice or smth but we changed it to what it is right now.
Wdt @alexfertel?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I agree that starting with error or errors is better.

I suggested reusing_token_id because "minting twice" is not something bad, so the test name gets confusing.

Maybe error_when_minting_token_id_twice?

Copy link
Member

Choose a reason for hiding this comment

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

@bidzyyys let's also arrange other test names (e.g. transfer_from_error_when_transfer_to_invalid_receiver) like we discussed here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am renaming it rn @qalisander

lib/e2e/src/error.rs Show resolved Hide resolved
///
/// May panic if fails to parse `ACCOUNT_CODEHASH` as a keccack hash.
#[no_mangle]
pub unsafe extern "C" fn account_codehash(_address: *const u8, dest: *mut u8) {
Copy link
Member

Choose a reason for hiding this comment

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

Hope we will make it work

Copy link

netlify bot commented Jun 21, 2024

Deploy Preview for contracts-stylus canceled.

Name Link
🔨 Latest commit ed1da07
🔍 Latest deploy log https://app.netlify.com/sites/contracts-stylus/deploys/6679468be9ce9b0008318a6f

@bidzyyys bidzyyys marked this pull request as ready for review June 21, 2024 12:13
lib/motsu/src/shims.rs Outdated Show resolved Hide resolved
@@ -157,6 +157,10 @@ pub fn storage_flush_cache(_: bool) {
/// Dummy msg sender set for tests.
pub const MSG_SENDER: &[u8; 42] = b"0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF";

/// Account code hash for tests (only EOAs).
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you mean with only EOAs?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, this is keccak(""). We should be more clear about this.

Copy link
Contributor

@alexfertel alexfertel Jun 21, 2024

Choose a reason for hiding this comment

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

pub const EOA_CODEHASH: &[u8; 66] =
    b"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470";

Copy link

codecov bot commented Jun 24, 2024

Codecov Report

Attention: Patch coverage is 95.07435% with 53 lines in your changes missing coverage. Please review.

Project coverage is 90.4%. Comparing base (2c9a3bd) to head (ed1da07).

Additional details and impacted files
Files Coverage Δ
contracts/src/access/control.rs 90.1% <ø> (ø)
contracts/src/token/erc20/extensions/capped.rs 54.5% <ø> (ø)
contracts/src/token/erc20/mod.rs 95.7% <ø> (ø)
contracts/src/token/erc721/extensions/burnable.rs 100.0% <100.0%> (ø)
...ontracts/src/token/erc721/extensions/enumerable.rs 87.6% <100.0%> (ø)
...ntracts/src/token/erc721/extensions/uri_storage.rs 84.9% <ø> (ø)
contracts/src/token/erc721/mod.rs 96.0% <100.0%> (+31.4%) ⬆️
contracts/src/utils/structs/bitmap.rs 84.0% <ø> (ø)
lib/motsu/src/shims.rs 44.5% <10.1%> (-48.4%) ⬇️

/// [`RETURN_DATA_SIZE`]: https://www.evm.codes/#3d
#[no_mangle]
pub unsafe extern "C" fn return_data_size() -> usize {
// Default value, we do not use this function in our unit-tests.
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this is not entirely accurate: we don't use them explicitly, but indeed the binary does include them, otherwise it wouldn't error when trying to compile.

I think it's fine to return zero here, but we should create a follow-up issue that tackles implementing the ones that make sense, like return_data_size and read_return_data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created issue #156

Copy link
Contributor

@alexfertel alexfertel left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀 Great job!

@bidzyyys
Copy link
Collaborator Author

Created an issue for having consistent naming convention for tests that check errors: #155

@bidzyyys
Copy link
Collaborator Author

Created an issue for filling shims #156

Copy link
Member

@qalisander qalisander left a comment

Choose a reason for hiding this comment

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

Good job!
Just added uint!(..) macro instead of U256::from(..).
I think we can merge it.

@bidzyyys bidzyyys merged commit 831ca0d into main Jun 24, 2024
20 checks passed
@bidzyyys bidzyyys deleted the test/erc721-unit-tests branch June 24, 2024 10:53
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.

Improve ERC721 unit tests
3 participants