Skip to content

Commit

Permalink
merge develop (starknet-foundry introduction)
Browse files Browse the repository at this point in the history
  • Loading branch information
augustbleeds committed Sep 4, 2024
1 parent 6d273b8 commit b72a983
Show file tree
Hide file tree
Showing 31 changed files with 548 additions and 267 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.7.1
postgres 15.1
starknet-foundry 0.28.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
}
68 changes: 68 additions & 0 deletions contracts/Scarb.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,66 @@
# 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=e1b080577aaa6889116fc8be5dde72b2fd21e397#e1b080577aaa6889116fc8be5dde72b2fd21e397"
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=e1b080577aaa6889116fc8be5dde72b2fd21e397#e1b080577aaa6889116fc8be5dde72b2fd21e397"
dependencies = [
"alexandria_encoding",
]

[[package]]
name = "alexandria_encoding"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=e1b080577aaa6889116fc8be5dde72b2fd21e397#e1b080577aaa6889116fc8be5dde72b2fd21e397"
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=e1b080577aaa6889116fc8be5dde72b2fd21e397#e1b080577aaa6889116fc8be5dde72b2fd21e397"
dependencies = [
"alexandria_data_structures",
]

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

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

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

[[package]]
Expand Down Expand Up @@ -92,3 +147,16 @@ source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.1#2f
name = "openzeppelin_utils"
version = "0.15.1"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.1#2f8a93d762858714095a1d391afffa9e21df6983"

[[package]]
name = "snforge_scarb_plugin"
version = "0.1.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.28.0#4dfe39d96690ed6b3d56971512700de3f58288ea"

[[package]]
name = "snforge_std"
version = "0.28.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.28.0#4dfe39d96690ed6b3d56971512700de3f58288ea"
dependencies = [
"snforge_scarb_plugin",
]
9 changes: 7 additions & 2 deletions contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ 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.7.1"
starknet = "2.7.1"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.15.1" }
cairo_test = "2.7.1"
alexandria_bytes = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "e1b080577aaa6889116fc8be5dde72b2fd21e397" }
alexandria_encoding = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "e1b080577aaa6889116fc8be5dde72b2fd21e397" }

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.28.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]
}
}
}
18 changes: 12 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,19 @@ use chainlink::libraries::access_control::{
IAccessController, IAccessControllerDispatcher, IAccessControllerDispatcherTrait
};

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


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 +50,10 @@ 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 contract = declare("AccessController").unwrap().contract_class();

let (accessControllerAddr, _) = contract.deploy(@calldata).unwrap();

should_implement_access_control(accessControllerAddr, owner);
}
Expand All @@ -62,7 +68,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 b72a983

Please sign in to comment.