Skip to content

Fuzz tests ERC1155 #1348

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions docs/modules/ROOT/pages/api/testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use openzeppelin_testing::common;
* xref:#testing-common-to_base_16_string[`++to_base_16_string(value)++`]
* xref:#testing-common-to_base_16_string_no_padding[`++to_base_16_string_no_padding(value)++`]
* xref:#testing-common-assert_entrypoint_not_found_error[`++assert_entrypoint_not_found_error(result, selector, contract_address)++`]
* xref:#testing-common-repeat[`++repeat(element, n_times)++`]

.Traits
* xref:#testing-common-IntoBase16StringTrait[`++IntoBase16StringTrait++`]
Expand Down Expand Up @@ -75,6 +76,12 @@ prefix.
Asserts that the syscall result of a call failed with an "Entrypoint not found" error,
following the Starknet Foundry emitted error format.

[.contract-item]
[[testing-common-repeat]]
==== `[.contract-item-name]#++repeat++#<T, +Drop<T>>(element: T, n_times: N) → Array<T>` [.item-kind]#function#

Creates and returns a new array consisting of the given `element` repeated `n_times` times.

[#testing-common-Traits]
==== Traits

Expand Down
10 changes: 10 additions & 0 deletions packages/testing/src/common.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,13 @@ pub fn assert_entrypoint_not_found_error<T, +Drop<T>>(
panic!("{selector} call was expected to fail, but succeeded");
}
}

/// Creates and returns a new array consisting of the given `element` repeated `n_times` times.
pub fn repeat<T, N, +Copy<T>, +Drop<T>, +Into<N, u256>>(element: T, n_times: N) -> Array<T> {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should export this as part of our external API from testing, it should be an internal test_common item instead. We don't want the testing API to grow to big, so we should include utilities that will be potentially often used, and I think this is not the case.

let mut result = array![];
let len: u256 = n_times.into();
for _ in 0..len {
result.append(element);
};
result
}
3 changes: 3 additions & 0 deletions packages/token/src/tests/erc1155.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
mod test_erc1155;
mod test_erc1155_receiver;

#[cfg(feature: 'fuzzing')]
mod test_fuzz_erc1155;
Loading