Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into augustus.BCI-1224.…
Browse files Browse the repository at this point in the history
…rewrite-example-contracts
  • Loading branch information
archseer committed Aug 10, 2023
2 parents cfc12c8 + 93dbe83 commit d4ce9a7
Show file tree
Hide file tree
Showing 155 changed files with 5,751 additions and 4,006 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: "v1.0.0"
default: "v2.1.0"
required: false
scarb_version:
description: Scarb release version
default: "v0.2.1"
default: "v0.6.0"
required: false

runs:
Expand Down
33 changes: 26 additions & 7 deletions .github/workflows/integration-tests-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ jobs:
permissions:
id-token: write
contents: read
strategy:
matrix:
image:
- name: ""
dockerfile: core/chainlink.Dockerfile
tag-suffix: ""
- name: (plugins)
dockerfile: plugins/chainlink.Dockerfile
tag-suffix: -plugins
steps:
- name: Collect Metrics
if: always()
Expand All @@ -44,26 +53,27 @@ jobs:
uses: smartcontractkit/chainlink-github-actions/docker/image-exists@2c9f401149f6c25fb632067b7e6626aebeee5d69 # v2.1.6
with:
repository: chainlink
tag: starknet.${{ github.sha }}
tag: starknet.${{ github.sha }}${{ matrix.image.tag-suffix }}
AWS_REGION: ${{ secrets.QA_AWS_REGION }}
AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
- name: Build Image
- name: Build Image ${{ matrix.image.name }}
if: steps.check-image.outputs.exists == 'false'
# note using a temporary commit for build-image that works around the go get issues, replace when go get issues are fixed please
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/build-image@2c9f401149f6c25fb632067b7e6626aebeee5d69
with:
cl_repo: smartcontractkit/chainlink
cl_ref: ${{ github.event.inputs.cl_branch_ref }}
cl_dockerfile: ${{ matrix.image.dockerfile }}
# commit of the caller branch
dep_starknet_sha: ${{ github.event.pull_request.head.sha || github.sha }}
push_tag: ${{ env.CL_ECR }}:starknet.${{ github.sha }}
push_tag: ${{ env.CL_ECR }}:starknet.${{ github.sha }}${{ matrix.image.tag-suffix }}
QA_AWS_REGION: ${{ secrets.QA_AWS_REGION }}
QA_AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
QA_PRIVATE_GHA_PULL: ${{ secrets.QA_PRIVATE_GHA_PULL }}
- name: Print Chainlink Image Built
run: |
echo "### chainlink image tag used for this test run :link:" >> $GITHUB_STEP_SUMMARY
echo "\`starknet.${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "\`starknet.${{ github.sha }}${{ matrix.image.tag-suffix }}\`" >> $GITHUB_STEP_SUMMARY
build_test_image:
environment: integration
Expand Down Expand Up @@ -97,6 +107,14 @@ jobs:
runs-on: ubuntu20.04-16cores-64GB
needs: [ build_custom_chainlink_image, build_test_image ]
environment: integration
# these values need to match those used to build the chainlink image
strategy:
matrix:
image:
- name: ""
tag-suffix: ""
- name: (plugins)
tag-suffix: -plugins
env:
TEST_SUITE: smoke
TEST_ARGS: -test.timeout 1h
Expand All @@ -105,6 +123,7 @@ 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
permissions:
checks: write
pull-requests: write
Expand All @@ -118,21 +137,21 @@ jobs:
with:
basic-auth: ${{ secrets.GRAFANA_CLOUD_BASIC_AUTH }}
hostname: ${{ secrets.GRAFANA_CLOUD_HOST }}
this-job-name: Run Smoke Tests
this-job-name: Run Smoke Tests ${{ matrix.image.name }}
continue-on-error: true
- name: Checkout the repo
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: Install Nix
uses: cachix/install-nix-action@29bd9290ef037a3ecbdafe83cbd2185e9dd0fa0a # v20
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Run Tests
- name: Run Tests ${{ matrix.image.name }}
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@2c9f401149f6c25fb632067b7e6626aebeee5d69
with:
test_command_to_run: nix develop -c 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 }}
cl_image_tag: starknet.${{ github.sha }}${{ matrix.image.tag-suffix }}
token: ${{ secrets.GITHUB_TOKEN }}
go_mod_path: ./integration-tests/go.mod
QA_AWS_REGION: ${{ secrets.QA_AWS_REGION }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/integration-tests-soak.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ jobs:
TEST_SUITE: soak
TEST_ARGS: -test.timeout ${{ github.event.inputs.ttl }}
TEST_LOG_LEVEL: debug
INTERNAL_DOCKER_REPO: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com
permissions:
checks: write
pull-requests: write
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/monitoring-build-push-ecr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- develop
paths:
- monitoring/**
- relayer/**

jobs:
build-and-publish-monitoring:
Expand Down Expand Up @@ -46,7 +47,7 @@ jobs:
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 # v3.2.0
with:
push: true
context: monitoring
context: ./
file: monitoring/ops/Dockerfile
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
14 changes: 5 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,13 @@ format-go-mod-tidy:

.PHONY: format-cairo
format-cairo:
find ./contracts/src -name "*.cairo" -type f \
-exec cairo-format -i {} +
find ./examples -name "*.cairo" -type f \
-exec cairo-format -i {} +
cairo-format -i ./contracts/src/**/*.cairo
cairo-format -i ./examples/**/*.cairo

.PHONY: format-cairo-check
format-cairo-check:
find ./contracts/src -name "*.cairo" -type f \
-exec cairo-format -c {} +
find ./examples -name "*.cairo" -type f \
-exec cairo-format -c {} +
cairo-format -c ./contracts/src/**/*.cairo
cairo-format -c ./examples/**/*.cairo

.PHONY: format-ts
format-ts:
Expand Down Expand Up @@ -267,7 +263,7 @@ build-cairo-contracts:

.PHONY: test-cairo-contracts
test-cairo-contracts:
cd contracts && scarb run test
cd contracts && scarb test

# TODO: this script needs to be replaced with a predefined K8s enviroment
.PHONY: env-devnet-hardhat
Expand Down
14 changes: 8 additions & 6 deletions contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ homepage = "https://github.com/smartcontractkit/chainlink-starknet"

[scripts]
sierra = "cairo-compile . -r"
test = "cairo-test --starknet ."
# 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]
# quaireaux = { git = "https://github.com/keep-starknet-strange/quaireaux.git" }
starknet = ">=1.0.0"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "495ed8a" } # latest cairo-2 branch

[lib]

[[target.starknet-contract]]
sierra = true
Expand All @@ -21,7 +23,7 @@ casm = true
# Unsupported compiled class format. Cairo 1.0 compiled class must contain the attribute `pythonic_hints`.
casm-add-pythonic-hints = true

# Necessary to be used as a library by other scarb projects
[lib]
sierra = true # Enable Sierra codegen.
casm = true # Enable CASM codegen.
# this elevates the severity of disallowed libfuncs to compilation errors
# https://docs.swmansion.com/scarb/docs/starknet/contract-target#allowed-libfuncs-validation
allowed-libfuncs-deny = true
allowed-libfuncs-list.name = "audited"
4 changes: 2 additions & 2 deletions contracts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ecdsa
fastecdsa
sympy
cairo-lang>=0.11.1.1
starknet-devnet>=0.5.2
cairo-lang>=0.12.1a0
starknet-devnet>=0.6.0a0
145 changes: 76 additions & 69 deletions contracts/src/access_control/access_controller.cairo
Original file line number Diff line number Diff line change
@@ -1,99 +1,106 @@
use starknet::ContractAddress;

#[abi]
trait IAccessController {
fn has_access(user: ContractAddress, data: Array<felt252>) -> bool;
fn add_access(user: ContractAddress);
fn remove_access(user: ContractAddress);
fn enable_access_check();
fn disable_access_check();
}

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

use chainlink::libraries::access_control::AccessControl;
use chainlink::libraries::ownable::Ownable;
use chainlink::libraries::access_control::{AccessControl, IAccessController};
use chainlink::libraries::ownable::{Ownable, IOwnable};
use chainlink::libraries::upgradeable::Upgradeable;

#[constructor]
fn constructor(owner_address: ContractAddress) {
Ownable::initializer(owner_address);
AccessControl::initializer();
}

#[view]
fn has_access(user: ContractAddress, data: Array<felt252>) -> bool {
AccessControl::has_access(user, data)
}

#[external]
fn add_access(user: ContractAddress) {
Ownable::assert_only_owner();
AccessControl::add_access(user);
}

#[external]
fn remove_access(user: ContractAddress) {
Ownable::assert_only_owner();
AccessControl::remove_access(user);
}
#[storage]
struct Storage {}

#[external]
fn enable_access_check() {
Ownable::assert_only_owner();
AccessControl::enable_access_check();
#[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);
}

#[external]
fn disable_access_check() {
Ownable::assert_only_owner();
AccessControl::disable_access_check();
#[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);
}

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
///

#[view]
fn owner() -> ContractAddress {
Ownable::owner()
}

#[view]
fn proposed_owner() -> ContractAddress {
Ownable::proposed_owner()
}

#[external]
fn transfer_ownership(new_owner: ContractAddress) {
Ownable::transfer_ownership(new_owner);
}

#[external]
fn accept_ownership() {
Ownable::accept_ownership();
}

#[external]
fn renounce_ownership() {
Ownable::renounce_ownership();
#[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() -> felt252 {
fn type_and_version(self: @ContractState) -> felt252 {
'AccessController 1.0.0'
}

#[external]
fn upgrade(new_impl: ClassHash) {
Ownable::assert_only_owner();
#[external(v0)]
fn upgrade(ref self: ContractState, new_impl: ClassHash) {
let ownable = Ownable::unsafe_new_contract_state();
Ownable::assert_only_owner(@ownable);
Upgradeable::upgrade(new_impl);
}
}
2 changes: 0 additions & 2 deletions contracts/src/account.cairo

This file was deleted.

Loading

0 comments on commit d4ce9a7

Please sign in to comment.