Skip to content

Commit

Permalink
Improvement: typos check in CI/CD (#248)
Browse files Browse the repository at this point in the history
* fix: typos

* ci/cd: typos check in ci

* fix: cases

* fix: randomness requestor typos
  • Loading branch information
julio4 authored Oct 3, 2024
1 parent 3698499 commit 70be4b9
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 43 deletions.
5 changes: 2 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**Issue(s):** <!-- Close #issue-number -->
**Issue(s): Close #issue-number

### Description

Expand All @@ -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
<!-- - [ ] **Remix Link:** Added a link to open the contract in Remix
- [ ] **Deployed Contract (Optional):** If possible, include a Voyager link to a deployed contract on Goerli -->
<!-- - [ ] **Deployed Contract (Optional):** If possible, include a Voyager link to a deployed contract on Goerli --> -->
5 changes: 1 addition & 4 deletions .github/workflows/mdbook.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/verify_cairo_programs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 2 additions & 2 deletions listings/applications/advanced_factory/src/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -102,7 +102,7 @@ pub mod CampaignFactory {
) -> ContractAddress {
let creator = get_caller_address();

// Create contructor arguments
// Create constructor arguments
let mut constructor_calldata: Array::<felt252> = array![];
((creator, title, description, goal), start_time, end_time, token_address)
.serialize(ref constructor_calldata);
Expand Down
2 changes: 1 addition & 1 deletion listings/applications/advanced_factory/src/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion listings/applications/crowdfunding/src/campaign.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
48 changes: 24 additions & 24 deletions listings/applications/erc20/src/token.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -462,33 +462,33 @@ 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]
#[should_panic(expected: ('ERC20: transfer to 0', 'ENTRYPOINT_FAILED'))]
#[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!(
Expand All @@ -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 }))
);
}

Expand All @@ -511,32 +511,32 @@ 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]
#[should_panic(expected: ('ERC20: transfer to 0', 'ENTRYPOINT_FAILED'))]
#[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

Expand All @@ -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 }))
);
}
}
2 changes: 1 addition & 1 deletion listings/applications/upgradeable_contract/src/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion listings/getting-started/factory/src/simple_factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub mod CounterFactory {
impl Factory of super::ICounterFactory<ContractState> {
// ANCHOR: deploy
fn create_counter_at(ref self: ContractState, init_value: u128) -> ContractAddress {
// Contructor arguments
// Constructor arguments
let mut constructor_calldata: Array::<felt252> = array![init_value.into()];

// Contract deployment
Expand Down
2 changes: 1 addition & 1 deletion listings/getting-started/visibility/src/visibility.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/applications/crowdfunding.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/getting-started/basics/syscalls.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion src/getting-started/cairo_cheatsheet/enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 :

Expand Down
2 changes: 1 addition & 1 deletion src/getting-started/interacting/factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/getting-started/interacting/how_to_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 70be4b9

Please sign in to comment.