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

Update starknet-hardhat-plugin to fix broken tests, latest cairo/scarb, OZ preview #321

Merged
merged 6 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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.1.0"
default: "v2.2.0"
required: false
scarb_version:
description: Scarb release version
default: "v0.6.0"
default: "v0.7.0"
required: false

runs:
Expand Down
2 changes: 1 addition & 1 deletion contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sierra = "cairo-compile . -r"
# Note: currently testing doesn't work with dependencies
[dependencies]
starknet = ">=1.0.0"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", rev = "495ed8a" } # latest cairo-2 branch
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.7.0-rc.0" }

[lib]

Expand Down
4 changes: 2 additions & 2 deletions contracts/src/libraries/token/erc677.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod ERC677 {
#[event]
#[derive(Drop, starknet::Event)]
enum Event {
Transfer: Transfer,
Transfer: Transfer,
}

#[derive(Drop, starknet::Event)]
Expand All @@ -51,7 +51,7 @@ mod ERC677 {
self
.emit(
Event::Transfer(
Transfer { from: sender, to: to, value: value, data: data.clone(), }
Transfer { from: sender, to: to, value: value, data: data.clone(), }
)
);

Expand Down
13 changes: 7 additions & 6 deletions contracts/src/multisig.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use starknet::ContractAddress;
use starknet::class_hash::ClassHash;

fn assert_unique_values<
T, impl TCopy: Copy<T>, impl TDrop: Drop<T>, impl TPartialEq: PartialEq<T>,
T, impl TCopy: Copy<T>, impl TDrop: Drop<T>, impl TPartialEq: PartialEq<T>,
>(
a: @Array::<T>
) {
Expand All @@ -13,7 +13,7 @@ fn assert_unique_values<
}

fn _assert_unique_values_loop<
T, impl TCopy: Copy<T>, impl TDrop: Drop<T>, impl TPartialEq: PartialEq<T>,
T, impl TCopy: Copy<T>, impl TDrop: Drop<T>, impl TPartialEq: PartialEq<T>,
>(
a: @Array::<T>, len: usize, j: usize, k: usize
) {
Expand Down Expand Up @@ -84,6 +84,7 @@ mod Multisig {
use starknet::Felt252TryIntoContractAddress;
use starknet::StorageBaseAddress;
use starknet::SyscallResult;
use starknet::SyscallResultTrait;
use starknet::call_contract_syscall;
use starknet::get_caller_address;
use starknet::get_contract_address;
Expand Down Expand Up @@ -169,7 +170,7 @@ mod Multisig {
self._is_signer.read(address)
}

fn get_signers_len(self: @ContractState, ) -> usize {
fn get_signers_len(self: @ContractState,) -> usize {
self._signers_len.read()
}

Expand All @@ -180,11 +181,11 @@ mod Multisig {
signers
}

fn get_threshold(self: @ContractState, ) -> usize {
fn get_threshold(self: @ContractState,) -> usize {
self._threshold.read()
}

fn get_transactions_len(self: @ContractState, ) -> u128 {
fn get_transactions_len(self: @ContractState,) -> u128 {
self._next_nonce.read()
}

Expand All @@ -207,7 +208,7 @@ mod Multisig {
(transaction, calldata)
}

fn type_and_version(self: @ContractState, ) -> felt252 {
fn type_and_version(self: @ContractState,) -> felt252 {
'Multisig 1.0.0'
}

Expand Down
5 changes: 4 additions & 1 deletion contracts/src/ocr2/mocks/mock_aggregator.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ mod MockAggregator {
use traits::Into;

use chainlink::ocr2::aggregator::IAggregator;
use chainlink::ocr2::aggregator::Aggregator::{Transmission, NewTransmission, Event};
use chainlink::ocr2::aggregator::Aggregator::{Transmission, NewTransmission};
use chainlink::ocr2::aggregator::Round;

#[event]
use chainlink::ocr2::aggregator::Aggregator::Event;

#[storage]
struct Storage {
_transmissions: LegacyMap<u128, Transmission>,
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/tests/test_access_controller.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn setup() -> ContractAddress {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Ownable: caller is not owner', ))]
#[should_panic(expected: ('Ownable: caller is not owner',))]
fn test_upgrade_not_owner() {
let sender = setup();
let mut state = STATE();
Expand All @@ -43,7 +43,7 @@ fn test_access_control() {
let owner = setup();
// Deploy access controller
let calldata = array![owner.into(), // owner
];
];
let (accessControllerAddr, _) = deploy_syscall(
AccessController::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false
)
Expand Down
39 changes: 18 additions & 21 deletions contracts/src/tests/test_aggregator.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn setup() -> (

// deploy billing access controller
let calldata = array![acc1.into(), // owner = acc1;
];
];
let (billingAccessControllerAddr, _) = deploy_syscall(
AccessController::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false
)
Expand All @@ -93,7 +93,7 @@ fn setup() -> (
// deploy link token contract
let calldata = array![acc1.into(), // minter = acc1;
acc1.into(), // owner = acc1;
];
];
let (linkTokenAddr, _) = deploy_syscall(
LinkToken::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false
)
Expand Down Expand Up @@ -151,7 +151,7 @@ fn test_access_control() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Ownable: caller is not owner', ))]
#[should_panic(expected: ('Ownable: caller is not owner',))]
fn test_upgrade_non_owner() {
let sender = setup();
let mut state = STATE();
Expand All @@ -162,7 +162,7 @@ fn test_upgrade_non_owner() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Ownable: caller is not owner', ))]
#[should_panic(expected: ('Ownable: caller is not owner',))]
fn test_set_billing_access_controller_not_owner() {
let (owner, acc2, billingAccessController, _) = setup();
let mut state = STATE();
Expand All @@ -177,7 +177,7 @@ fn test_set_billing_access_controller_not_owner() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('caller does not have access', ))]
#[should_panic(expected: ('caller does not have access',))]
fn test_set_billing_config_no_access() {
let (owner, acc2, billingAccessController, _) = setup();
let mut state = STATE();
Expand Down Expand Up @@ -278,15 +278,15 @@ fn test_set_billing_config_as_acc_with_access() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Ownable: caller is not owner', ))]
#[should_panic(expected: ('Ownable: caller is not owner',))]
fn test_set_payees_caller_not_owner() {
let (owner, acc2, _, _) = setup();
let mut state = STATE();
Aggregator::constructor(
ref state, owner, contract_address_const::<777>(), 0, 100, acc2, 8, 123
);

let payees = array![PayeeConfig { transmitter: acc2, payee: acc2, }, ];
let payees = array![PayeeConfig { transmitter: acc2, payee: acc2, },];

// set payee should revert if caller is not owner
set_caller_address(acc2);
Expand All @@ -302,7 +302,7 @@ fn test_set_single_payee() {
ref state, owner, contract_address_const::<777>(), 0, 100, acc2, 8, 123
);

let payees = array![PayeeConfig { transmitter: acc2, payee: acc2, }, ];
let payees = array![PayeeConfig { transmitter: acc2, payee: acc2, },];

set_caller_address(owner);
PayeeManagementImpl::set_payees(ref state, payees);
Expand All @@ -318,11 +318,8 @@ fn test_set_multiple_payees() {
);

let payees = array![
PayeeConfig {
transmitter: acc2, payee: acc2,
}, PayeeConfig {
transmitter: owner, payee: owner,
},
PayeeConfig { transmitter: acc2, payee: acc2, },
PayeeConfig { transmitter: owner, payee: owner, },
];

set_caller_address(owner);
Expand All @@ -331,7 +328,7 @@ fn test_set_multiple_payees() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('only current payee can update', ))]
#[should_panic(expected: ('only current payee can update',))]
fn test_transfer_payeeship_caller_not_payee() {
let (owner, acc2, _, _) = setup();
let mut state = STATE();
Expand All @@ -340,7 +337,7 @@ fn test_transfer_payeeship_caller_not_payee() {
);

let transmitter = contract_address_const::<123>();
let payees = array![PayeeConfig { transmitter: transmitter, payee: acc2, }, ];
let payees = array![PayeeConfig { transmitter: transmitter, payee: acc2, },];

set_caller_address(owner);
PayeeManagementImpl::set_payees(ref state, payees);
Expand All @@ -349,7 +346,7 @@ fn test_transfer_payeeship_caller_not_payee() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('cannot transfer to self', ))]
#[should_panic(expected: ('cannot transfer to self',))]
fn test_transfer_payeeship_to_self() {
let (owner, acc2, _, _) = setup();
let mut state = STATE();
Expand All @@ -358,7 +355,7 @@ fn test_transfer_payeeship_to_self() {
);

let transmitter = contract_address_const::<123>();
let payees = array![PayeeConfig { transmitter: transmitter, payee: acc2, }, ];
let payees = array![PayeeConfig { transmitter: transmitter, payee: acc2, },];

set_caller_address(owner);
PayeeManagementImpl::set_payees(ref state, payees);
Expand All @@ -368,7 +365,7 @@ fn test_transfer_payeeship_to_self() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('only proposed payee can accept', ))]
#[should_panic(expected: ('only proposed payee can accept',))]
fn test_accept_payeeship_caller_not_proposed_payee() {
let (owner, acc2, _, _) = setup();
let mut state = STATE();
Expand All @@ -377,7 +374,7 @@ fn test_accept_payeeship_caller_not_proposed_payee() {
);

let transmitter = contract_address_const::<123>();
let payees = array![PayeeConfig { transmitter: transmitter, payee: acc2, }, ];
let payees = array![PayeeConfig { transmitter: transmitter, payee: acc2, },];

set_caller_address(owner);
PayeeManagementImpl::set_payees(ref state, payees);
Expand All @@ -396,7 +393,7 @@ fn test_transfer_and_accept_payeeship() {
);

let transmitter = contract_address_const::<123>();
let payees = array![PayeeConfig { transmitter: transmitter, payee: acc2, }, ];
let payees = array![PayeeConfig { transmitter: transmitter, payee: acc2, },];

set_caller_address(owner);
PayeeManagementImpl::set_payees(ref state, payees);
Expand All @@ -422,7 +419,7 @@ fn test_owed_payment_no_rounds() {
);

let transmitter = contract_address_const::<123>();
let mut payees = array![PayeeConfig { transmitter: transmitter, payee: acc2, }, ];
let mut payees = array![PayeeConfig { transmitter: transmitter, payee: acc2, },];

set_caller_address(owner);
PayeeManagementImpl::set_payees(ref state, payees);
Expand Down
8 changes: 4 additions & 4 deletions contracts/src/tests/test_aggregator_proxy.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn test_ownable() {
let (account, mockAggregatorAddr, _, _, _) = setup();
// Deploy aggregator proxy
let calldata = array![account.into(), // owner = account
mockAggregatorAddr.into(), ];
mockAggregatorAddr.into(),];
let (aggregatorProxyAddr, _) = deploy_syscall(
AggregatorProxy::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false
)
Expand All @@ -80,7 +80,7 @@ fn test_access_control() {
let (account, mockAggregatorAddr, _, _, _) = setup();
// Deploy aggregator proxy
let calldata = array![account.into(), // owner = account
mockAggregatorAddr.into(), ];
mockAggregatorAddr.into(),];
let (aggregatorProxyAddr, _) = deploy_syscall(
AggregatorProxy::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false
)
Expand All @@ -91,7 +91,7 @@ fn test_access_control() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Ownable: caller is not owner', ))]
#[should_panic(expected: ('Ownable: caller is not owner',))]
fn test_upgrade_non_owner() {
let (_, _, _, _, _) = setup();
let mut state = STATE();
Expand Down Expand Up @@ -119,7 +119,7 @@ fn test_query_latest_round_data() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('user does not have read access', ))]
#[should_panic(expected: ('user does not have read access',))]
fn test_query_latest_round_data_without_access() {
let (owner, mockAggregatorAddr, mockAggregator, _, _) = setup();
let mut state = STATE();
Expand Down
6 changes: 3 additions & 3 deletions contracts/src/tests/test_erc677.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn transfer_and_call(receiver: ContractAddress) {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('ERC20: transfer to 0', ))]
#[should_panic(expected: ('ERC20: transfer to 0',))]
fn test_to_zero_address() {
setup();
transfer_and_call(Zeroable::zero());
Expand All @@ -82,7 +82,7 @@ fn test_valid_transfer_and_call() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', ))]
#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND',))]
fn test_invalid_receiver_supports_interface_true() {
setup();
let (receiver_address, receiver) = setup_invalid_receiver();
Expand All @@ -104,7 +104,7 @@ fn test_invalid_receiver_supports_interface_false() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', ))]
#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED',))]
fn test_nonexistent_receiver() {
setup();

Expand Down
10 changes: 5 additions & 5 deletions contracts/src/tests/test_link_token.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn test_ownable() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('minter is 0', ))]
#[should_panic(expected: ('minter is 0',))]
fn test_constructor_zero_address() {
let sender = setup();
let mut state = STATE();
Expand Down Expand Up @@ -89,7 +89,7 @@ fn test_permissioned_mint_from_minter() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('only minter', ))]
#[should_panic(expected: ('only minter',))]
fn test_permissioned_mint_from_nonminter() {
let sender = setup();
let mut state = STATE();
Expand All @@ -103,7 +103,7 @@ fn test_permissioned_mint_from_nonminter() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('u256_sub Overflow', ))]
#[should_panic(expected: ('u256_sub Overflow',))]
fn test_permissioned_burn_from_minter() {
let zero = 0;
let sender = setup();
Expand Down Expand Up @@ -132,7 +132,7 @@ fn test_permissioned_burn_from_minter() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('only minter', ))]
#[should_panic(expected: ('only minter',))]
fn test_permissioned_burn_from_nonminter() {
let sender = setup();
let mut state = STATE();
Expand All @@ -146,7 +146,7 @@ fn test_permissioned_burn_from_nonminter() {

#[test]
#[available_gas(2000000)]
#[should_panic(expected: ('Ownable: caller is not owner', ))]
#[should_panic(expected: ('Ownable: caller is not owner',))]
fn test_upgrade_non_owner() {
let sender = setup();
let mut state = STATE();
Expand Down
Loading
Loading