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 to multiple packages (workspace) #1065

Merged
merged 51 commits into from
Aug 2, 2024
Merged
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
3cd9ed9
Migrate erc20 tests (#1022)
ericnordelo Jun 28, 2024
a96b50a
Snforge utils and some common changes (#1030)
immrsd Jul 4, 2024
9b333cc
Re-add dual20 tests (#1028)
ericnordelo Jul 4, 2024
0d149da
Migrate security tests (#1034)
andrew-fleming Jul 5, 2024
a9b4eb3
refacto repo into packages
ametel01 Jul 7, 2024
890608e
fmt
ametel01 Jul 7, 2024
c3df288
Migrate erc1155 tests (#1037)
ericnordelo Jul 10, 2024
ef89fb2
Migrate erc721 tests (#1027)
ericnordelo Jul 11, 2024
fbfb819
Check ignored tests (#1049)
ericnordelo Jul 16, 2024
8fe4f80
Migrate Ownable tests (#1033)
immrsd Jul 17, 2024
6f7130f
Migrate Upgrades tests (#1051)
immrsd Jul 17, 2024
4850245
Migrate erc20 preset tests (#1055)
ericnordelo Jul 18, 2024
78aa934
feat: update ignored tests messages (#1056)
ericnordelo Jul 19, 2024
daff8e5
Migrate erc1155 preset tests (#1057)
ericnordelo Jul 19, 2024
c34d4d0
Migrate cryptography and UDC tests (#1059)
andrew-fleming Jul 22, 2024
ba8004c
Migrate eth account tests (#1058)
ericnordelo Jul 23, 2024
9e091d4
Migrate eth account preset tests (#1060)
ericnordelo Jul 23, 2024
a794ca0
Migrate AccessControl Tests (#1044)
immrsd Jul 25, 2024
9e9adf9
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into w…
ericnordelo Jul 26, 2024
bc316ca
Migrate Starknet Account tests (#1050)
immrsd Jul 26, 2024
852c43b
feat: make contracts build
ericnordelo Jul 26, 2024
b8d597a
feat: update packages Scarb.toml
ericnordelo Jul 26, 2024
fddddbd
refactor: remove gitmodules file
ericnordelo Jul 26, 2024
8851d2b
feat: refactor tests
ericnordelo Jul 26, 2024
4ac1903
feat: update workflow
ericnordelo Jul 26, 2024
094ab98
feat: test utils
ericnordelo Jul 26, 2024
6dcdad3
feat: add missing tests
ericnordelo Jul 26, 2024
b0be872
Merge branch 'snforge-migration' of github.com:OpenZeppelin/cairo-con…
ericnordelo Jul 26, 2024
d678419
fix: tests
ericnordelo Jul 26, 2024
47ab176
fix: remaining tests
ericnordelo Jul 29, 2024
cf80dd5
refactor: format files
ericnordelo Jul 29, 2024
05b877d
tmp: workflow update
ericnordelo Jul 29, 2024
6bd4ac8
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into w…
ericnordelo Jul 29, 2024
0af0fff
feat: add entry to CHANGELOG and update README
ericnordelo Jul 29, 2024
15d5fcb
doc: update imports
ericnordelo Jul 29, 2024
2e0f3c6
Migrate Starknet Account Preset tests (#1069)
immrsd Jul 29, 2024
6601f24
Bump scarb, merge changes from main in snforge migration (#1076)
andrew-fleming Jul 31, 2024
e09af84
Migrate timelock tests (#1061)
andrew-fleming Aug 1, 2024
fc8b397
Update docs/modules/ROOT/pages/components.adoc
ericnordelo Aug 1, 2024
25c199b
Update docs/modules/ROOT/pages/components.adoc
ericnordelo Aug 1, 2024
493b426
feat: apply review updates
ericnordelo Aug 1, 2024
29b6e01
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into w…
ericnordelo Aug 1, 2024
fc929c3
Merge branch 'snforge-migration' of github.com:OpenZeppelin/cairo-con…
ericnordelo Aug 1, 2024
530b087
feat: update governance package
ericnordelo Aug 1, 2024
66e6d2f
refactor: format files
ericnordelo Aug 1, 2024
39cf6c1
Merge branch 'workspace-conversion' of github.com:ericnordelo/cairo-c…
ericnordelo Aug 1, 2024
72bd08a
refactor: remove unused files
ericnordelo Aug 1, 2024
44492c7
fix: workflow
ericnordelo Aug 1, 2024
d8b88eb
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into w…
ericnordelo Aug 1, 2024
97b4cac
refactor: remove warnings
ericnordelo Aug 1, 2024
d58c751
feat: remove old tests
ericnordelo Aug 1, 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
Prev Previous commit
Next Next commit
Migrate Starknet Account Preset tests (#1069)
* Update test utils and helpers

* Update signature tests

* Update account tests

* Update dual account tests

* Run linter

* Run linter

* Fix review issues

* Update ignore reason messages

* Run linter

* Support eth account tests changes

* Run linter

* Improve setup functions, remove unused imports

* Remove unnecessary accept_ownership step, make use of serialized_sign fn

* Migrate Starknet Account Preset tests, make some code improvements

* Run linter

* Remove unnecessary clone

* Update the comment for assert_entrypoint_not_found_error function

* Minor review fixes
immrsd authored Jul 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 2e0f3c641feb28796272990c4247ba668296b809
2 changes: 1 addition & 1 deletion src/tests/account/ethereum/test_eth_account.cairo
Original file line number Diff line number Diff line change
@@ -316,7 +316,7 @@ fn test_multicall() {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2.span()
};

// Bundle calls and exeute
// Bundle calls and execute
calls.append(call1);
calls.append(call2);
let ret = account.__execute__(calls);
2 changes: 1 addition & 1 deletion src/tests/account/starknet/test_account.cairo
Original file line number Diff line number Diff line change
@@ -308,7 +308,7 @@ fn test_multicall() {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2.span()
};

// Bundle calls and exeute
// Bundle calls and execute
let calls = array![call1, call2];
let ret = account.__execute__(calls);

2 changes: 1 addition & 1 deletion src/tests/presets.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// mod test_account;
mod test_account;
mod test_erc1155;
mod test_erc20;
mod test_erc721;
442 changes: 238 additions & 204 deletions src/tests/presets/test_account.cairo

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions src/tests/presets/test_erc1155.cairo
Original file line number Diff line number Diff line change
@@ -868,11 +868,9 @@ fn test_v2_missing_camel_selector() {
v1.upgrade(v2_class_hash);

let safe_dispatcher = IERC1155CamelSafeDispatcher { contract_address: v1.contract_address };
let panic_data = safe_dispatcher.balanceOf(owner, TOKEN_ID).unwrap_err();
let result = safe_dispatcher.balanceOf(owner, TOKEN_ID);

utils::assert_entrypoint_not_found_error(
panic_data, selector!("balanceOf"), v1.contract_address
)
utils::assert_entrypoint_not_found_error(result, selector!("balanceOf"), v1.contract_address)
}

#[test]
6 changes: 2 additions & 4 deletions src/tests/presets/test_erc20.cairo
Original file line number Diff line number Diff line change
@@ -480,11 +480,9 @@ fn test_v2_missing_camel_selector() {
let safe_dispatcher = ERC20UpgradeableABISafeDispatcher {
contract_address: v1.contract_address
};
let mut panic_data = safe_dispatcher.totalSupply().unwrap_err();
let result = safe_dispatcher.totalSupply();

utils::assert_entrypoint_not_found_error(
panic_data, selector!("totalSupply"), v1.contract_address
)
utils::assert_entrypoint_not_found_error(result, selector!("totalSupply"), v1.contract_address)
}

#[test]
6 changes: 2 additions & 4 deletions src/tests/presets/test_eth_account.cairo
Original file line number Diff line number Diff line change
@@ -499,11 +499,9 @@ fn test_v2_missing_camel_selector() {
let safe_dispatcher = EthAccountUpgradeableABISafeDispatcher {
contract_address: v1.contract_address
};
let panic_data = safe_dispatcher.getPublicKey().unwrap_err();
let result = safe_dispatcher.getPublicKey();

utils::assert_entrypoint_not_found_error(
panic_data, selector!("getPublicKey"), v1.contract_address
)
utils::assert_entrypoint_not_found_error(result, selector!("getPublicKey"), v1.contract_address)
}

#[test]
32 changes: 20 additions & 12 deletions src/tests/utils/common.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::to_byte_array::FormatAsByteArray;
use starknet::ContractAddress;
use starknet::{ContractAddress, SyscallResult};

/// Converts panic data into a string (ByteArray).
///
@@ -9,7 +9,7 @@ pub fn panic_data_to_byte_array(panic_data: Array<felt252>) -> ByteArray {
let mut panic_data = panic_data.span();

// Remove BYTE_ARRAY_MAGIC from the panic data.
panic_data.pop_front().unwrap();
panic_data.pop_front().expect('Empty panic data provided');

match Serde::<ByteArray>::deserialize(ref panic_data) {
Option::Some(string) => string,
@@ -36,15 +36,23 @@ pub impl IntoBase16String<T, +Into<T, felt252>> of IntoBase16StringTrait<T> {
}
}

/// Asserts that the panic data is an "Entrypoint not found" error, following the starknet foundry
/// emitted error format.
pub fn assert_entrypoint_not_found_error(
panic_data: Array<felt252>, selector: felt252, contract_address: ContractAddress
/// Asserts that the syscall result of a call failed with an "Entrypoint not found" error,
/// following the starknet foundry emitted error format.
pub fn assert_entrypoint_not_found_error<T, +Drop<T>>(
result: SyscallResult<T>, selector: felt252, contract_address: ContractAddress
) {
let expected_panic_message = format!(
"Entry point selector {} not found in contract {}",
selector.into_base_16_string(),
contract_address.into_base_16_string()
);
assert!(panic_data_to_byte_array(panic_data) == expected_panic_message);
if let Result::Err(panic_data) = result {
let expected_panic_message = format!(
"Entry point selector {} not found in contract {}",
selector.into_base_16_string(),
contract_address.into_base_16_string()
);
let actual_panic_message = panic_data_to_byte_array(panic_data);
assert!(
actual_panic_message == expected_panic_message,
"Got unexpected panic message: ${actual_panic_message}"
);
} else {
panic!("${selector} call was expected to fail, but succeeded");
}
}
14 changes: 8 additions & 6 deletions src/tests/utils/deployment.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core::starknet::SyscallResultTrait;
use openzeppelin::tests::utils::panic_data_to_byte_array;
use snforge_std::{declare, get_class_hash, ContractClass, ContractClassTrait};
use snforge_std::{start_cheat_caller_address, stop_cheat_caller_address};
use snforge_std::{ContractClass, ContractClassTrait};
use starknet::ContractAddress;

pub fn deploy(contract_class: ContractClass, calldata: Array<felt252>) -> ContractAddress {
@@ -24,23 +23,26 @@ pub fn deploy_at(
pub fn deploy_another_at(
existing: ContractAddress, target_address: ContractAddress, calldata: Array<felt252>
) {
let class_hash = get_class_hash(existing);
let class_hash = snforge_std::get_class_hash(existing);
let contract_class = ContractClassTrait::new(class_hash);
deploy_at(contract_class, target_address, calldata)
}

pub fn declare_class(contract_name: ByteArray) -> ContractClass {
declare(contract_name).unwrap_syscall()
match snforge_std::declare(contract_name) {
Result::Ok(contract_class) => contract_class,
Result::Err(panic_data) => panic!("{}", panic_data_to_byte_array(panic_data))
}
}

pub fn declare_and_deploy(contract_name: ByteArray, calldata: Array<felt252>) -> ContractAddress {
let contract_class = declare(contract_name).unwrap_syscall();
let contract_class = declare_class(contract_name);
deploy(contract_class, calldata)
}

pub fn declare_and_deploy_at(
contract_name: ByteArray, target_address: ContractAddress, calldata: Array<felt252>
) {
let contract_class = declare(contract_name).unwrap_syscall();
let contract_class = declare_class(contract_name);
deploy_at(contract_class, target_address, calldata)
}