Skip to content

Commit

Permalink
Merge pull request #343 from smartcontractkit/update-dependencies
Browse files Browse the repository at this point in the history
Cairo 2.4.3 + components + starknet.go (RPC v0.6, tx v1)
  • Loading branch information
archseer committed Feb 19, 2024
2 parents 1272736 + e1051e3 commit 6c48b26
Show file tree
Hide file tree
Showing 136 changed files with 3,509 additions and 3,601 deletions.
4 changes: 2 additions & 2 deletions .github/actions/install-cairo/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ description: A composite action that installs cairo and scarb binaries
inputs:
cairo_version:
description: Cairo release version
default: "v2.2.0"
default: "v2.4.3"
required: false
scarb_version:
description: Scarb release version
default: "v0.7.0"
default: "v2.4.3"
required: false

runs:
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ jobs:
- name: Install Cairo
uses: ./.github/actions/install-cairo

- name: Install starknet-devnet (via venv+pip)
run: nix develop -c pip install -r contracts/requirements.txt -c contracts/constraints.txt

- name: Test
run: nix develop -c make test-ts-contracts

Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/integration-tests-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ jobs:
TTL: 3h
TEST_DURATION: 15m
NODE_COUNT: 5
INTERNAL_DOCKER_REPO: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com
CHAINLINK_IMAGE: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com/chainlink
CHAINLINK_VERSION: starknet.${{ github.sha }}${{ matrix.image.tag-suffix }}
permissions:
checks: write
pull-requests: write
Expand All @@ -147,9 +148,9 @@ jobs:
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Run Tests ${{ matrix.image.name }}
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@2c9f401149f6c25fb632067b7e6626aebeee5d69
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@ea889b3133bd7f16ab19ba4ba130de5d9162c669 # v2.3.4
with:
test_command_to_run: nix develop -c make test-integration-smoke-ci
test_command_to_run: nix develop -c helm repo update && make test-integration-smoke-ci
test_download_vendor_packages_command: cd integration-tests && nix develop -c go mod download
cl_repo: ${{ env.CL_ECR }}
cl_image_tag: starknet.${{ github.sha }}${{ matrix.image.tag-suffix }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests-soak.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
QA_AWS_REGION: ${{ secrets.QA_AWS_REGION }}
QA_AWS_ACCOUNT_NUMBER: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}
- name: Run Tests
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@2c9f401149f6c25fb632067b7e6626aebeee5d69 # v2.1.2
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@ea889b3133bd7f16ab19ba4ba130de5d9162c669 # v2.3.4
with:
test_command_to_run: nix develop -c make test-integration-soak-ci
test_download_vendor_packages_command: cd integration-tests && nix develop -c go mod download
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/integration_contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@ jobs:
- name: Install Cairo
uses: ./.github/actions/install-cairo

- name: Install starknet-devnet (via venv+pip)
run: nix develop -c pip install -r contracts/requirements.txt -c contracts/constraints.txt

- name: Test
run: nix develop -c make test-integration-contracts
3 changes: 0 additions & 3 deletions .github/workflows/integration_gauntlet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ jobs:
- name: Install Cairo
uses: ./.github/actions/install-cairo

- name: Install starknet-devnet (via venv+pip)
run: nix develop -c pip install -r contracts/requirements.txt -c contracts/constraints.txt

- name: Test
run: nix develop -c make test-integration-gauntlet

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/relayer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,5 @@ jobs:
./relayer/coverage.txt
./relayer/race_coverage.txt
- name: Install starknet-devnet (via venv+pip)
run: nix develop -c pip install -r contracts/requirements.txt -c contracts/constraints.txt

- name: Integration Test
run: nix develop -c make test-integration-go
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,5 @@ integration-tests/soak/logs
remote.test
ztarrepo.tar.gz
eslint-report.json
.run.id
.local-mock-server
21 changes: 9 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ format: format-go format-cairo format-ts
format-check: format-cairo-check format-ts-check

.PHONY: format-go
format-go: format-go-fmt format-go-mod-tidy
format-go: format-go-fmt gomodtidy

.PHONY: format-go-fmt
format-go-fmt:
cd ./relayer && go fmt ./...
cd ./ops && go fmt ./...
cd ./integration-tests && go fmt ./...

.PHONY: format-go-mod-tidy
format-go-mod-tidy:
.PHONY: gomodtidy
gomodtidy:
cd ./relayer && go mod tidy
cd ./monitoring && go mod tidy
cd ./ops && go mod tidy
Expand Down Expand Up @@ -180,14 +180,12 @@ test-unit-go:

.PHONY: test-integration-go
# only runs tests with TestIntegration_* + //go:build integration
test-integration-go:
test-integration-go: env-devnet-hardhat
cd ./relayer && go test -v ./... -run TestIntegration -tags integration

.PHONY: test-integration-prep
test-integration-prep:
python -m venv ~/cairo_venv && \
. ~/cairo_venv/bin/activate
cd ./contracts && pip install -r requirements.txt
cd ./contracts
make build

.PHONY: test-integration
Expand All @@ -202,7 +200,7 @@ test-integration-smoke: test-integration-prep
.PHONY: test-integration-smoke-ci
test-integration-smoke-ci:
cd integration-tests/ && \
go test --timeout=2h -v -count=1 -json ./smoke
go test --timeout=2h -v -count=1 -json ./smoke 2>&1 | tee /tmp/gotest.log | gotestfmt

.PHONY: test-integration-soak
test-integration-soak: test-integration-prep
Expand All @@ -221,17 +219,16 @@ test-integration-soak-ci:
# cd examples/contracts/aggregator-consumer/ && \
# yarn test
test-integration-contracts: build-ts env-devnet-hardhat
cd packages-ts/integration-multisig/ && \
yarn test
echo "Tests currently broken because of starknet-hardhat-plugin"
exit 1
cd packages-ts/starknet/ && \
yarn test

.PHONY: test-integration-gauntlet
# TODO: better network lifecycle setup - tests setup/run their own network (L1 + conflict w/ above if not cleaned up)
# TODO: fix example
# cd packages-ts/starknet-gauntlet-example/ && \
# yarn test
test-integration-gauntlet: build-ts env-devnet-hardhat-down
test-integration-gauntlet: build-ts env-devnet-hardhat
cd packages-ts/starknet-gauntlet/ && \
yarn test
cd packages-ts/starknet-gauntlet-argent/ && \
Expand Down
14 changes: 14 additions & 0 deletions contracts/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Code generated by scarb DO NOT EDIT.
version = 1

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

[[package]]
name = "openzeppelin"
version = "0.8.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.8.0#c23e8e96de60e6e3159b1ff8591a1187269c0eb7"
4 changes: 2 additions & 2 deletions contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ sierra = "cairo-compile . -r"
# Uncomment if you want to use dependencies
# Note: currently testing doesn't work with dependencies
[dependencies]
starknet = ">=1.0.0"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.7.0-rc.0" }
starknet = ">=1.3.0"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.8.0" }

[lib]

Expand Down
Empty file removed contracts/constraints.txt
Empty file.
5 changes: 0 additions & 5 deletions contracts/requirements.txt

This file was deleted.

122 changes: 37 additions & 85 deletions contracts/src/access_control/access_controller.cairo
Original file line number Diff line number Diff line change
@@ -1,107 +1,59 @@
use starknet::ContractAddress;

#[starknet::contract]
mod AccessController {
use starknet::ContractAddress;
use starknet::class_hash::ClassHash;

use chainlink::libraries::access_control::{AccessControl, IAccessController};
use chainlink::libraries::ownable::{Ownable, IOwnable};
use chainlink::libraries::access_control::{AccessControlComponent, IAccessController};
use chainlink::libraries::ownable::{OwnableComponent, IOwnable};
use chainlink::libraries::type_and_version::ITypeAndVersion;
use chainlink::libraries::upgradeable::{Upgradeable, IUpgradeable};

component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
component!(path: AccessControlComponent, storage: access_control, event: AccessControlEvent);

#[abi(embed_v0)]
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
impl InternalImpl = OwnableComponent::InternalImpl<ContractState>;

#[abi(embed_v0)]
impl AccessControlImpl =
AccessControlComponent::AccessControlImpl<ContractState>;
impl AccessControlInternalImpl = AccessControlComponent::InternalImpl<ContractState>;

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
OwnableEvent: OwnableComponent::Event,
#[flat]
AccessControlEvent: AccessControlComponent::Event,
}

#[storage]
struct Storage {}
struct Storage {
#[substorage(v0)]
ownable: OwnableComponent::Storage,
#[substorage(v0)]
access_control: AccessControlComponent::Storage,
}

#[constructor]
fn constructor(ref self: ContractState, owner_address: ContractAddress) {
let mut ownable = Ownable::unsafe_new_contract_state();
Ownable::constructor(ref ownable, owner_address);
let mut access_control = AccessControl::unsafe_new_contract_state();
AccessControl::constructor(ref access_control);
self.ownable.initializer(owner_address);
self.access_control.initializer();
}

#[external(v0)]
impl AccessControllerImpl of IAccessController<ContractState> {
fn has_access(self: @ContractState, user: ContractAddress, data: Array<felt252>) -> bool {
let state = AccessControl::unsafe_new_contract_state();
AccessControl::has_access(@state, user, data)
}

fn add_access(ref self: ContractState, user: ContractAddress) {
let ownable = Ownable::unsafe_new_contract_state();
Ownable::assert_only_owner(@ownable);
let mut state = AccessControl::unsafe_new_contract_state();
AccessControl::add_access(ref state, user);
#[abi(embed_v0)]
impl TypeAndVersionImpl of ITypeAndVersion<ContractState> {
fn type_and_version(self: @ContractState) -> felt252 {
'AccessController 1.0.0'
}

fn remove_access(ref self: ContractState, user: ContractAddress) {
let ownable = Ownable::unsafe_new_contract_state();
Ownable::assert_only_owner(@ownable);
let mut state = AccessControl::unsafe_new_contract_state();
AccessControl::remove_access(ref state, user);
}

fn enable_access_check(ref self: ContractState) {
let ownable = Ownable::unsafe_new_contract_state();
Ownable::assert_only_owner(@ownable);
let mut state = AccessControl::unsafe_new_contract_state();
AccessControl::enable_access_check(ref state);
}

fn disable_access_check(ref self: ContractState) {
let ownable = Ownable::unsafe_new_contract_state();
Ownable::assert_only_owner(@ownable);
let mut state = AccessControl::unsafe_new_contract_state();
AccessControl::disable_access_check(ref state);
}
}

///
/// Ownable
///

#[external(v0)]
impl OwnableImpl of IOwnable<ContractState> {
fn owner(self: @ContractState) -> ContractAddress {
let state = Ownable::unsafe_new_contract_state();
Ownable::OwnableImpl::owner(@state)
}

fn proposed_owner(self: @ContractState) -> ContractAddress {
let state = Ownable::unsafe_new_contract_state();
Ownable::OwnableImpl::proposed_owner(@state)
}

fn transfer_ownership(ref self: ContractState, new_owner: ContractAddress) {
let mut state = Ownable::unsafe_new_contract_state();
Ownable::OwnableImpl::transfer_ownership(ref state, new_owner)
}

fn accept_ownership(ref self: ContractState) {
let mut state = Ownable::unsafe_new_contract_state();
Ownable::OwnableImpl::accept_ownership(ref state)
}

fn renounce_ownership(ref self: ContractState) {
let mut state = Ownable::unsafe_new_contract_state();
Ownable::OwnableImpl::renounce_ownership(ref state)
}
}

///
/// Upgradeable
///

#[view]
fn type_and_version(self: @ContractState) -> felt252 {
'AccessController 1.0.0'
}

#[external(v0)]
impl UpgradeableImpl of IUpgradeable<ContractState> {
fn upgrade(ref self: ContractState, new_impl: ClassHash) {
let ownable = Ownable::unsafe_new_contract_state();
Ownable::assert_only_owner(@ownable);
self.ownable.assert_only_owner();
Upgradeable::upgrade(new_impl);
}
}
Expand Down
57 changes: 57 additions & 0 deletions contracts/src/account.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// copied from https://github.com/OpenZeppelin/cairo-contracts/blob/v0.8.1/src/presets/account.cairo

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.8.1 (presets/account.cairo)

/// # Account Preset
///
/// OpenZeppelin's basic account which can change its public key and declare, deploy, or call contracts.
#[starknet::contract(account)]
mod Account {
use openzeppelin::account::AccountComponent;
use openzeppelin::introspection::src5::SRC5Component;

component!(path: AccountComponent, storage: account, event: AccountEvent);
component!(path: SRC5Component, storage: src5, event: SRC5Event);

// Account
#[abi(embed_v0)]
impl SRC6Impl = AccountComponent::SRC6Impl<ContractState>;
#[abi(embed_v0)]
impl SRC6CamelOnlyImpl = AccountComponent::SRC6CamelOnlyImpl<ContractState>;
#[abi(embed_v0)]
impl PublicKeyImpl = AccountComponent::PublicKeyImpl<ContractState>;
#[abi(embed_v0)]
impl PublicKeyCamelImpl = AccountComponent::PublicKeyCamelImpl<ContractState>;
#[abi(embed_v0)]
impl DeclarerImpl = AccountComponent::DeclarerImpl<ContractState>;
#[abi(embed_v0)]
impl DeployableImpl = AccountComponent::DeployableImpl<ContractState>;
impl AccountInternalImpl = AccountComponent::InternalImpl<ContractState>;

// SRC5
#[abi(embed_v0)]
impl SRC5Impl = SRC5Component::SRC5Impl<ContractState>;

#[storage]
struct Storage {
#[substorage(v0)]
account: AccountComponent::Storage,
#[substorage(v0)]
src5: SRC5Component::Storage
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
AccountEvent: AccountComponent::Event,
#[flat]
SRC5Event: SRC5Component::Event
}

#[constructor]
fn constructor(ref self: ContractState, public_key: felt252) {
self.account.initializer(public_key);
}
}
Loading

0 comments on commit 6c48b26

Please sign in to comment.