Skip to content

Commit

Permalink
BCI-4128: Use Starknet-Foundry (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
augustbleeds authored Aug 30, 2024
1 parent a5b166d commit 70e50c6
Show file tree
Hide file tree
Showing 23 changed files with 428 additions and 247 deletions.
3 changes: 1 addition & 2 deletions .github/actions/install-starknet-foundry/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A composite action that installs the snforge and sncast binaries
inputs:
starknet_foundry_version:
description: Starknet Foundry release version
default: "0.21.0"
default: "0.27.0"
required: false

runs:
Expand All @@ -16,4 +16,3 @@ runs:
run: |
curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh
snfoundryup -v ${{ inputs.starknet_foundry_version }}
3 changes: 3 additions & 0 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@ jobs:
- name: Install Cairo
uses: ./.github/actions/install-cairo

- name: Install Starknet Foundry
uses: ./.github/actions/install-starknet-foundry

- name: Test
run: nix develop -c make test-cairo-contracts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.snfoundry_cache
.direnv
artifacts/
vendor/
Expand Down
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ actionlint 1.6.12
shellcheck 0.8.0
scarb 2.6.5
postgres 15.1
starknet-foundry 0.27.0

# Kubernetes
k3d 5.4.4
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"editor.formatOnSave": true,
"editor.formatOnSaveTimeout": 1500,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"files.insertFinalNewline": true
}
60 changes: 60 additions & 0 deletions contracts/Scarb.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,74 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "alexandria_bytes"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=bcdca70afdf59c9976148e95cebad5cf63d75a7f#bcdca70afdf59c9976148e95cebad5cf63d75a7f"
dependencies = [
"alexandria_data_structures",
"alexandria_math",
]

[[package]]
name = "alexandria_data_structures"
version = "0.2.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=bcdca70afdf59c9976148e95cebad5cf63d75a7f#bcdca70afdf59c9976148e95cebad5cf63d75a7f"
dependencies = [
"alexandria_encoding",
]

[[package]]
name = "alexandria_encoding"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=bcdca70afdf59c9976148e95cebad5cf63d75a7f#bcdca70afdf59c9976148e95cebad5cf63d75a7f"
dependencies = [
"alexandria_bytes",
"alexandria_math",
"alexandria_numeric",
]

[[package]]
name = "alexandria_math"
version = "0.2.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=bcdca70afdf59c9976148e95cebad5cf63d75a7f#bcdca70afdf59c9976148e95cebad5cf63d75a7f"
dependencies = [
"alexandria_data_structures",
]

[[package]]
name = "alexandria_numeric"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=bcdca70afdf59c9976148e95cebad5cf63d75a7f#bcdca70afdf59c9976148e95cebad5cf63d75a7f"
dependencies = [
"alexandria_math",
"alexandria_searching",
]

[[package]]
name = "alexandria_searching"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=bcdca70afdf59c9976148e95cebad5cf63d75a7f#bcdca70afdf59c9976148e95cebad5cf63d75a7f"
dependencies = [
"alexandria_data_structures",
]

[[package]]
name = "chainlink"
version = "0.1.0"
dependencies = [
"alexandria_bytes",
"alexandria_encoding",
"openzeppelin",
"snforge_std",
]

[[package]]
name = "openzeppelin"
version = "0.10.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.10.0#d77082732daab2690ba50742ea41080eb23299d3"

[[package]]
name = "snforge_std"
version = "0.27.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.27.0#2d99b7c00678ef0363881ee0273550c44a9263de"
4 changes: 4 additions & 0 deletions contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ homepage = "https://github.com/smartcontractkit/chainlink-starknet"

[scripts]
sierra = "cairo-compile . -r"
test = "snforge test"
# Add your own custom commands and run them with scarb run <command>

# Uncomment if you want to use dependencies
# Note: currently testing doesn't work with dependencies
[dependencies]
starknet = ">=2.6.3"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" }
alexandria_bytes = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "bcdca70afdf59c9976148e95cebad5cf63d75a7f" }
alexandria_encoding = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "bcdca70afdf59c9976148e95cebad5cf63d75a7f" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.27.0" }

[lib]

Expand Down
1 change: 1 addition & 0 deletions contracts/src/libraries/mocks.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod mock_upgradeable;
mod mock_non_upgradeable;
mod mock_multisig_target;
16 changes: 16 additions & 0 deletions contracts/src/libraries/mocks/mock_multisig_target.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#[starknet::contract]
mod MockMultisigTarget {
use array::ArrayTrait;

#[storage]
struct Storage {}

#[abi(per_item)]
#[generate_trait]
impl HelperImpl of HelperTrait {
#[external(v0)]
fn increment(ref self: ContractState, val1: felt252, val2: felt252) -> Array<felt252> {
array![val1 + 1, val2 + 1]
}
}
}
15 changes: 9 additions & 6 deletions contracts/src/tests/test_access_controller.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ use chainlink::libraries::access_control::{
IAccessController, IAccessControllerDispatcher, IAccessControllerDispatcherTrait
};

use snforge_std::{
declare, ContractClassTrait, start_cheat_caller_address_global, stop_cheat_caller_address_global
};


fn STATE() -> AccessController::ContractState {
AccessController::contract_state_for_testing()
}

fn setup() -> ContractAddress {
let account: ContractAddress = contract_address_const::<777>();
set_caller_address(account);
start_cheat_caller_address_global(account);
account
}

Expand All @@ -44,10 +49,8 @@ fn test_access_control() {
// Deploy access controller
let calldata = array![owner.into(), // owner
];
let (accessControllerAddr, _) = deploy_syscall(
AccessController::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false
)
.unwrap();

let (accessControllerAddr, _) = declare("AccessController").unwrap().deploy(@calldata).unwrap();

should_implement_access_control(accessControllerAddr, owner);
}
Expand All @@ -62,7 +65,7 @@ fn should_implement_access_control(contract_addr: ContractAddress, owner: Contra
let contract = IAccessControllerDispatcher { contract_address: contract_addr };
let acc2: ContractAddress = contract_address_const::<2222987765>();

set_contract_address(owner); // required to call contract as owner
start_cheat_caller_address_global(owner);

// access check is enabled by default
assert(!contract.has_access(acc2, array![]), 'should not have access');
Expand Down
Loading

0 comments on commit 70e50c6

Please sign in to comment.