From 70be4b9d20ec646bfc88089d52059b93390eb95a Mon Sep 17 00:00:00 2001 From: Julio <30329843+julio4@users.noreply.github.com> Date: Thu, 3 Oct 2024 16:53:01 +0800 Subject: [PATCH] Improvement: typos check in CI/CD (#248) * fix: typos * ci/cd: typos check in ci * fix: cases * fix: randomness requestor typos --- .github/pull_request_template.md | 5 +- .github/workflows/mdbook.yml | 5 +- .github/workflows/verify_cairo_programs.yml | 6 +++ CONTRIBUTING.md | 7 +++ _typos.toml | 9 ++++ .../advanced_factory/src/contract.cairo | 4 +- .../advanced_factory/src/tests.cairo | 2 +- .../crowdfunding/src/campaign.cairo | 2 +- listings/applications/erc20/src/token.cairo | 48 +++++++++---------- .../upgradeable_contract/src/tests.cairo | 2 +- .../factory/src/simple_factory.cairo | 2 +- .../visibility/src/visibility.cairo | 2 +- po/{messages.pot => messages.po} | 0 src/applications/crowdfunding.md | 2 +- src/getting-started/basics/syscalls.md | 2 +- src/getting-started/cairo_cheatsheet/enums.md | 2 +- src/getting-started/interacting/factory.md | 2 +- .../interacting/how_to_deploy.md | 2 +- 18 files changed, 61 insertions(+), 43 deletions(-) create mode 100644 _typos.toml rename po/{messages.pot => messages.po} (100%) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 6896e30b..f0330a67 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,4 +1,4 @@ -**Issue(s):** +**Issue(s): Close #issue-number ### Description @@ -8,5 +8,4 @@ Please provide a brief description of the changes made in this pull request and - [ ] **CI Verifier:** Run `./scripts/cairo_programs_verifier.sh` successfully - [ ] **Contract Tests:** Added tests to cover the changes - + --> diff --git a/.github/workflows/mdbook.yml b/.github/workflows/mdbook.yml index 6eaf3bfc..e601650b 100644 --- a/.github/workflows/mdbook.yml +++ b/.github/workflows/mdbook.yml @@ -1,7 +1,4 @@ -# Sample workflow for building and deploying a mdBook site to GitHub Pages -# -# To get started with mdBook see: https://rust-lang.github.io/mdBook/index.html -# +# https://rust-lang.github.io/mdBook/index.html name: Deploy mdBook site to Pages on: diff --git a/.github/workflows/verify_cairo_programs.yml b/.github/workflows/verify_cairo_programs.yml index 81a3a802..518a91f8 100644 --- a/.github/workflows/verify_cairo_programs.yml +++ b/.github/workflows/verify_cairo_programs.yml @@ -31,3 +31,9 @@ jobs: run: | chmod +x scripts/cairo_programs_verifier.sh ./scripts/cairo_programs_verifier.sh + + typos: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: crate-ci/typos@master diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 49365e54..d15852c3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,6 +55,13 @@ To add a new chapter, create a new markdown file in the `src` directory. All the Do not write directly Cairo program inside the markdown files. Instead, use code blocks that import the Cairo programs from the `listing` directory. These programs are bundled into scarb projects, which makes it easier to test and build all programs. See the next section for more details. +Be sure to check for typos with `typos`: + +```shell +cargo install typos-cli +typos src/ +``` + ## Adding a new Cairo program You can add or modify examples in the `listings` directory. Each listing is a scarb project. diff --git a/_typos.toml b/_typos.toml new file mode 100644 index 00000000..75bef735 --- /dev/null +++ b/_typos.toml @@ -0,0 +1,9 @@ +[default] +extend-ignore-identifiers-re = ["requestor", "REQUESTOR", "Requestor"] + +[type.po] +extend-glob = ["*.po", "*.css", "*.js"] +check-file = false + +[files] +extend-exclude = ["po/*.po", "listings/**/*.json"] diff --git a/listings/applications/advanced_factory/src/contract.cairo b/listings/applications/advanced_factory/src/contract.cairo index 4c6b4c89..098dda87 100644 --- a/listings/applications/advanced_factory/src/contract.cairo +++ b/listings/applications/advanced_factory/src/contract.cairo @@ -42,7 +42,7 @@ pub mod CampaignFactory { struct Storage { #[substorage(v0)] ownable: ownable_component::Storage, - /// Store all of the created campaign instances' addresses and thei class hashes + /// Store all of the created campaign instances' addresses and their class hashes campaigns: Map<(ContractAddress, ContractAddress), ClassHash>, /// Store the class hash of the contract to deploy campaign_class_hash: ClassHash, @@ -102,7 +102,7 @@ pub mod CampaignFactory { ) -> ContractAddress { let creator = get_caller_address(); - // Create contructor arguments + // Create constructor arguments let mut constructor_calldata: Array:: = array![]; ((creator, title, description, goal), start_time, end_time, token_address) .serialize(ref constructor_calldata); diff --git a/listings/applications/advanced_factory/src/tests.cairo b/listings/applications/advanced_factory/src/tests.cairo index 41588040..4b2b3bf5 100644 --- a/listings/applications/advanced_factory/src/tests.cairo +++ b/listings/applications/advanced_factory/src/tests.cairo @@ -97,7 +97,7 @@ fn test_create_campaign() { } #[test] -fn test_uprade_campaign_class_hash() { +fn test_upgrade_campaign_class_hash() { let factory = deploy_factory(); let old_class_hash = factory.get_campaign_class_hash(); let new_class_hash = *declare("MockContract").unwrap().contract_class().class_hash; diff --git a/listings/applications/crowdfunding/src/campaign.cairo b/listings/applications/crowdfunding/src/campaign.cairo index e4f0b375..e749f7d7 100644 --- a/listings/applications/crowdfunding/src/campaign.cairo +++ b/listings/applications/crowdfunding/src/campaign.cairo @@ -149,7 +149,7 @@ pub mod Campaign { pub const TRANSFER_FAILED: felt252 = 'Transfer failed'; pub const ZERO_ADDRESS_CALLER: felt252 = 'Caller address zero'; pub const ZERO_ADDRESS_PLEDGER: felt252 = 'Pledger address zero'; - pub const ZERO_ADDRESS_TOKEN: felt252 = 'Token address zerp'; + pub const ZERO_ADDRESS_TOKEN: felt252 = 'Token address zero'; pub const ZERO_DONATION: felt252 = 'Donation must be > 0'; pub const ZERO_GOAL: felt252 = 'Goal must be > 0'; pub const ZERO_PLEDGES: felt252 = 'No pledges to claim'; diff --git a/listings/applications/erc20/src/token.cairo b/listings/applications/erc20/src/token.cairo index 69370439..741ae21d 100644 --- a/listings/applications/erc20/src/token.cairo +++ b/listings/applications/erc20/src/token.cairo @@ -233,7 +233,7 @@ mod tests { const symbols: felt252 = 'mtk'; fn deploy() -> (IERC20Dispatcher, ContractAddress) { - let recipient: ContractAddress = contract_address_const::<'initialzed_recipient'>(); + let recipient: ContractAddress = contract_address_const::<'initialized_recipient'>(); let (contract_address, _) = deploy_syscall( erc20::TEST_CLASS_HASH.try_into().unwrap(), @@ -262,7 +262,7 @@ mod tests { } #[test] fn test_deploy_success() { - let recipient = contract_address_const::<'initialzed_recipient'>(); + let recipient = contract_address_const::<'initialized_recipient'>(); let (_, contract_address) = deploy(); assert_eq!( starknet::testing::pop_log(contract_address), @@ -302,7 +302,7 @@ mod tests { #[test] fn test_balance_of_recipient_deployed() { - let recipient = contract_address_const::<'initialzed_recipient'>(); + let recipient = contract_address_const::<'initialized_recipient'>(); let (dispatcher, _) = deploy(); assert( dispatcher.balance_of(recipient) == initial_supply, 'incorrect balance of recipient' @@ -340,7 +340,7 @@ mod tests { #[test] fn test_approval_success() { - let recipient = contract_address_const::<'initialzed_recipient'>(); + let recipient = contract_address_const::<'initialized_recipient'>(); let spender = contract_address_const::<'spender'>(); let value = 100; let (dispatcher, contract_address) = deploy(); @@ -376,7 +376,7 @@ mod tests { #[test] fn test_should_increase_allowance() { let caller = contract_address_const::<'caller'>(); - let recipient = contract_address_const::<'initialzed_recipient'>(); + let recipient = contract_address_const::<'initialized_recipient'>(); let spender = contract_address_const::<'spender'>(); let amount = 100; let (dispatcher, contract_address) = deploy(); @@ -423,7 +423,7 @@ mod tests { #[test] fn test_should_decrease_allowance() { let caller = contract_address_const::<'caller'>(); - let recipient = contract_address_const::<'initialzed_recipient'>(); + let recipient = contract_address_const::<'initialized_recipient'>(); let spender = contract_address_const::<'spender'>(); let amount = 100; let (dispatcher, contract_address) = deploy(); @@ -462,10 +462,10 @@ mod tests { #[test] #[should_panic(expected: ('ERC20: transfer from 0', 'ENTRYPOINT_FAILED'))] fn test_transfer_when_sender_is_address_zero() { - let reciever = contract_address_const::<'spender'>(); + let receiver = contract_address_const::<'spender'>(); let amount = 100; let (dispatcher, _) = deploy(); - dispatcher.transfer(reciever, amount); + dispatcher.transfer(receiver, amount); } #[test] @@ -473,22 +473,22 @@ mod tests { #[should_panic] fn test_transfer_when_recipient_is_address_zero() { let caller = contract_address_const::<'caller'>(); - let reciever = Zero::zero(); + let receiver = Zero::zero(); let amount = 100; let (dispatcher, _) = deploy(); set_contract_address(caller); - dispatcher.transfer(reciever, amount); + dispatcher.transfer(receiver, amount); } #[test] fn test_transfer_success() { - let caller = contract_address_const::<'initialzed_recipient'>(); - let reciever = contract_address_const::<'receiver'>(); + let caller = contract_address_const::<'initialized_recipient'>(); + let receiver = contract_address_const::<'receiver'>(); let amount = 100; let (dispatcher, contract_address) = deploy(); set_contract_address(caller); - dispatcher.transfer(reciever, amount); - assert_eq!(dispatcher.balance_of(reciever), amount); + dispatcher.transfer(receiver, amount); + assert_eq!(dispatcher.balance_of(receiver), amount); // emits two transfer events assert_eq!( @@ -500,7 +500,7 @@ mod tests { assert_eq!( starknet::testing::pop_log(contract_address), - Option::Some(Event::Transfer(Transfer { from: caller, to: reciever, value: amount })) + Option::Some(Event::Transfer(Transfer { from: caller, to: receiver, value: amount })) ); } @@ -511,9 +511,9 @@ mod tests { fn test_transferFrom_when_sender_is_address_zero() { let sender = Zero::zero(); let amount = 100; - let reciever = contract_address_const::<'spender'>(); + let receiver = contract_address_const::<'spender'>(); let (dispatcher, _) = deploy(); - dispatcher.transfer_from(sender, reciever, amount); + dispatcher.transfer_from(sender, receiver, amount); } #[test] @@ -521,22 +521,22 @@ mod tests { #[should_panic] fn test_transferFrom_when_recipient_is_address_zero() { let caller = contract_address_const::<'caller'>(); - let reciever = Zero::zero(); + let receiver = Zero::zero(); let amount = 100; let (dispatcher, _) = deploy(); set_contract_address(caller); - dispatcher.transfer_from(caller, reciever, amount); + dispatcher.transfer_from(caller, receiver, amount); } #[test] fn test_transferFrom_success() { - let caller = contract_address_const::<'initialzed_recipient'>(); - let reciever = contract_address_const::<'receiver'>(); + let caller = contract_address_const::<'initialized_recipient'>(); + let receiver = contract_address_const::<'receiver'>(); let amount = 100; let (dispatcher, contract_address) = deploy(); set_contract_address(caller); - dispatcher.transfer_from(caller, reciever, amount); - assert_eq!(dispatcher.balance_of(reciever), amount); + dispatcher.transfer_from(caller, receiver, amount); + assert_eq!(dispatcher.balance_of(receiver), amount); // emits two transfer events @@ -549,7 +549,7 @@ mod tests { assert_eq!( starknet::testing::pop_log(contract_address), - Option::Some(Event::Transfer(Transfer { from: caller, to: reciever, value: amount })) + Option::Some(Event::Transfer(Transfer { from: caller, to: receiver, value: amount })) ); } } diff --git a/listings/applications/upgradeable_contract/src/tests.cairo b/listings/applications/upgradeable_contract/src/tests.cairo index a60886a6..a3ff7ba0 100644 --- a/listings/applications/upgradeable_contract/src/tests.cairo +++ b/listings/applications/upgradeable_contract/src/tests.cairo @@ -71,7 +71,7 @@ mod tests { } #[test] - fn test_succesful_upgrade_from_v0_to_v1() { + fn test_successful_upgrade_from_v0_to_v1() { let (dispatcher_v0, contract_address, _) = deploy_v0(); let (_, _, class_hash) = deploy_v1(); dispatcher_v0.upgrade(class_hash); diff --git a/listings/getting-started/factory/src/simple_factory.cairo b/listings/getting-started/factory/src/simple_factory.cairo index 6b6452d7..3146cdac 100644 --- a/listings/getting-started/factory/src/simple_factory.cairo +++ b/listings/getting-started/factory/src/simple_factory.cairo @@ -39,7 +39,7 @@ pub mod CounterFactory { impl Factory of super::ICounterFactory { // ANCHOR: deploy fn create_counter_at(ref self: ContractState, init_value: u128) -> ContractAddress { - // Contructor arguments + // Constructor arguments let mut constructor_calldata: Array:: = array![init_value.into()]; // Contract deployment diff --git a/listings/getting-started/visibility/src/visibility.cairo b/listings/getting-started/visibility/src/visibility.cairo index 240b6a6c..e97058af 100644 --- a/listings/getting-started/visibility/src/visibility.cairo +++ b/listings/getting-started/visibility/src/visibility.cairo @@ -96,7 +96,7 @@ mod test { assert_eq!(24, state.value.read()); assert_eq!(24, contract.get()); - // We can also acces internal functions from the state + // We can also access internal functions from the state assert_eq!(state._read_value(), state.value.read()); assert_eq!(state._read_value(), contract.get()); } diff --git a/po/messages.pot b/po/messages.po similarity index 100% rename from po/messages.pot rename to po/messages.po diff --git a/src/applications/crowdfunding.md b/src/applications/crowdfunding.md index 5257a78c..68a3d866 100644 --- a/src/applications/crowdfunding.md +++ b/src/applications/crowdfunding.md @@ -10,7 +10,7 @@ Crowdfunding is a method of raising capital through the collective effort of man 6. After the campaign ends, the campaign creator can claim the funds if the campaign goal is reached. 7. Otherwise, campaign did not reach it's goal, pledgers can retrieve their funds. 8. The creator can at any point cancel the campaign for whatever reason and refund all of the pledgers. -9. The contract admin can upgrade the contract implementation, refunding all of the users and reseting the campaign state (we will use this in the [Advanced Factory chapter](./advanced_factory.md)). +9. The contract admin can upgrade the contract implementation, refunding all of the users and resetting the campaign state (we will use this in the [Advanced Factory chapter](./advanced_factory.md)). Because contract upgrades need to be able to refund all of the pledges, we need to be able to iterate over all of the pledgers and their amounts. Since iteration is not supported by `Map`, we need to create a custom storage type that will encompass pledge management. We use a component for this purpose. diff --git a/src/getting-started/basics/syscalls.md b/src/getting-started/basics/syscalls.md index e79a4468..a524a012 100644 --- a/src/getting-started/basics/syscalls.md +++ b/src/getting-started/basics/syscalls.md @@ -4,7 +4,7 @@ At the protocol level, the Starknet Operating System (OS) is the program that ma Some of the OS functionalities are exposed to smart contracts through the use of syscalls (system calls). Syscalls can be used to get information about the state of the Starknet network, to interact with/deploy contracts, emit events, send messages, and perform other low-level operations. -Syscalls return a `SyscallResult` which is either `Sucess` of `Failure`, allowing the contract to handle errors. +Syscalls return a `SyscallResult` which is either `Success` of `Failure`, allowing the contract to handle errors. Here's the available syscalls: diff --git a/src/getting-started/cairo_cheatsheet/enums.md b/src/getting-started/cairo_cheatsheet/enums.md index 9b48967b..c172f689 100644 --- a/src/getting-started/cairo_cheatsheet/enums.md +++ b/src/getting-started/cairo_cheatsheet/enums.md @@ -18,7 +18,7 @@ Enums can be declared both inside and outside a contract. If declared outside, t 2. Enums as parameters and return values to entrypoints - - It is possible to pass `enums` to contract entrypoints as parameters, as well as return them from entrypoints. For that purpose, the enum needs to be serializable and dropable, hence the derivation of traits `Serde` and `Drop` in the above code snippet. + - It is possible to pass `enums` to contract entrypoints as parameters, as well as return them from entrypoints. For that purpose, the enum needs to be serializable and droppable, hence the derivation of traits `Serde` and `Drop` in the above code snippet. Here is an example of a contract illustrating the above statements : diff --git a/src/getting-started/interacting/factory.md b/src/getting-started/interacting/factory.md index 76e503a6..d8b06870 100644 --- a/src/getting-started/interacting/factory.md +++ b/src/getting-started/interacting/factory.md @@ -6,7 +6,7 @@ In the case of smart contracts, we can use this pattern by defining a factory co ## Class hash and contract instance -In Starknet, there's a separation between contract's classes and instances. A contract class serves as a blueprint, defined by the underling Cairo bytecode, contract's entrypoints, ABI and Sierra program hash. The contract class is identified by a class hash. When you want to add a new class to the network, you first need to declare it. +In Starknet, there's a separation between contract's classes and instances. A contract class serves as a blueprint, defined by the underlying Cairo bytecode, contract's entrypoints, ABI and Sierra program hash. The contract class is identified by a class hash. When you want to add a new class to the network, you first need to declare it. When deploying a contract, you need to specify the class hash of the contract you want to deploy. Each instance of a contract has their own storage regardless of the class hash. diff --git a/src/getting-started/interacting/how_to_deploy.md b/src/getting-started/interacting/how_to_deploy.md index 232d97a0..c07c3f31 100644 --- a/src/getting-started/interacting/how_to_deploy.md +++ b/src/getting-started/interacting/how_to_deploy.md @@ -65,7 +65,7 @@ Class hash declared: ``` Check the [Voyager Class Page](https://sepolia.voyager.online/class/0x05c8c21062a74e3c8f2015311d7431e820a08a6b0a9571422b607429112d2eb4). -Now, it's time to deploy the contract. Add the clash hash given above after `--watch`: +Now, it's time to deploy the contract. Add the class hash given above after `--watch`: ```console $ starkli deploy \