Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cairo 2.4.3 + components + starknet.go (RPC v0.6, tx v3) #343

Merged
merged 57 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
154c016
nix: Update flake dependencies
archseer Jan 9, 2024
65859b4
Upgrade scarb and cairo to 2.4.3
archseer Jan 9, 2024
402abd9
Pass tests apart from erc677
archseer Jan 9, 2024
b79b6bb
Rewrite ERC677 as a component
archseer Jan 9, 2024
d95e565
Refactor Ownable as a component
archseer Jan 9, 2024
385ccc4
Upgradeaable: remove broken test
archseer Jan 9, 2024
468eb8c
Refactor AccessControl into a component
archseer Jan 9, 2024
0530156
Use latest upstream sdk: starknet.go
archseer Jul 11, 2023
10edfb8
Remove venv
archseer Jan 10, 2024
d72c069
Switch to new starknet-devnet
archseer Jan 10, 2024
8d0feb7
fix a couple go tests
archseer Jan 10, 2024
5ed6cb7
Fix nonce manager so it passes tests
archseer Jan 11, 2024
a644512
txm: Fix integration tests
archseer Jan 12, 2024
b63a621
Fix devnet startup wait
archseer Jan 16, 2024
56e5a38
Switch to v3 transactions for future compat
archseer Jan 16, 2024
3e320e1
scarb fmt
archseer Jan 10, 2024
2f61b87
node-gyp requires python
archseer Jan 15, 2024
c49eca4
Update starknet.js
archseer Jan 15, 2024
c5c3f5f
Use the external devnet over startNetwork()
archseer Jan 16, 2024
0f8be32
Stop relying on venv during e2e test prep
archseer Jan 16, 2024
d7693b1
Spin up devnet before test-integration-go
archseer Jan 16, 2024
31a8467
test: fix devnet seed 0 account information
archseer Jan 16, 2024
0cc29bd
test: fix multisig signer constants
archseer Jan 16, 2024
5ffb88b
Update to starkgate 2.0 interface
archseer Jan 16, 2024
8d40514
Fix compiled artifact suffixes for latest scarb
archseer Jan 22, 2024
6544e20
Disable starknet-hardhat-plugin tests so they don't waste CI time
archseer Jan 22, 2024
0d99566
ts: token test: Reuse devnet constants in test
archseer Jan 22, 2024
b69db46
test: Remove unused file
archseer Jan 22, 2024
bf07476
fix e2e linter + standardize gomodtidy (#352)
aalu1418 Feb 6, 2024
717f9b7
Fixing E2E
smickovskid Jan 31, 2024
f39ea79
Removed improper escape chars
smickovskid Feb 5, 2024
d23946a
Trying devnet max fee fix
smickovskid Feb 5, 2024
89e7ff0
Changed min gas fee
smickovskid Feb 5, 2024
b51240f
devnet: Set gas-price to 1
archseer Feb 7, 2024
ff5c6c4
devnet: Set gas-price to 1 in helm chart too
archseer Feb 7, 2024
c5a4481
txm: Revert back to V1 transactions
archseer Feb 7, 2024
bcdfd83
Bumping deps
smickovskid Feb 8, 2024
a9bd40d
Fixed missing go file reference
smickovskid Feb 8, 2024
841faf5
Reverted CI job
smickovskid Feb 8, 2024
d68066e
Fixing CI
smickovskid Feb 8, 2024
b780c8e
Adding logging
smickovskid Feb 8, 2024
89cea5b
Added formatting to CI
smickovskid Feb 8, 2024
9a6f211
Fixing pipeline
smickovskid Feb 8, 2024
ff9f60d
Fixing pipeline
smickovskid Feb 8, 2024
0bc77e4
Added logging
smickovskid Feb 8, 2024
e6f7597
Import OZ 0.8.1 Account preset, remove reliance on an old package
archseer Feb 8, 2024
58d9847
Fix account deployment test
archseer Feb 9, 2024
49f4177
devnet: Pin to commit, manually downloading cairo not needed anymore
archseer Feb 9, 2024
660cfc5
tests: Rewrite to drop k3d, use same setup as chainlink-cosmos
archseer Feb 9, 2024
4d112f9
tests: Slight cleanup
archseer Feb 9, 2024
3bbc56c
update relayer
augustbleeds Feb 14, 2024
168491a
adds recursive multisig cairo tests
chris-de-leon-cll Feb 14, 2024
c20ef0f
bump chainlink version
augustbleeds Feb 15, 2024
9d6d994
working local soaktests (#357)
augustbleeds Feb 15, 2024
f9153e4
dropping packages-ts/integration-multisig
chris-de-leon-cll Feb 15, 2024
00cac1d
Merge pull request #359 from smartcontractkit/feat/BCI-2027-multisig-…
archseer Feb 19, 2024
e1051e3
BCI-2625: add TypeAndVersion interface and usage (#353)
augustbleeds Feb 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the future, we can create a scarb nix package and have CI use the nix shell

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also get rid of the cairo and scarb git submodules if we nixify. (scarb comes with cairo so i think we can also avoid the need to install cairo seperately from scarb).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, we should add the new scarb version in .tool-versions file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi! maybe this could help:
https://github.com/cairo-nix/cairo-nix

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
Loading