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

refactor: fix warnings post cairo bump #599

Merged
merged 2 commits into from
Nov 29, 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
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scarb nightly-2023-11-22
scarb nightly-2023-11-25
6 changes: 3 additions & 3 deletions crates/alexandria_storage/src/list.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ trait ListTrait<T> {
/// The storage is not actually cleared, only the length is set to 0.
/// The values can still be accessible using low-level syscalls, but cannot
/// be accessed through the list interface.
fn clean(ref self: List<T>);
fn clean(ref self: List<T>) -> SyscallResult<()>;

/// Removes and returns the first element of the List.
///
Expand Down Expand Up @@ -226,9 +226,9 @@ impl ListImpl<T, +Copy<T>, +Drop<T>, +Store<T>> of ListTrait<T> {
}

#[inline(always)]
fn clean(ref self: List<T>) {
fn clean(ref self: List<T>) -> SyscallResult<()> {
self.len = 0;
Store::write(self.address_domain, self.base, self.len);
Store::write(self.address_domain, self.base, self.len)
}

fn pop_front(ref self: List<T>) -> SyscallResult<Option<T>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/contracts/src/components/upgradeable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod upgradeable_component {
fn upgrade_contract(
ref self: ComponentState<TContractState>, new_class_hash: starknet::ClassHash
) {
starknet::replace_class_syscall(new_class_hash);
starknet::replace_class_syscall(new_class_hash).expect('replace class failed');
self.emit(ContractUpgraded { new_class_hash: new_class_hash });
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/contracts/src/contract_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ mod ContractAccount {
)
.expect(BYTECODE_WRITE_ERROR);
let mut stored_list: List<bytes31> = ListTrait::new(0, data_address);
stored_list.append_span(packed_bytecode.data.span());
stored_list.append_span(packed_bytecode.data.span()).expect('failed to store bytecode');
}

fn storage_at(self: @ContractState, key: u256) -> u256 {
Expand Down
4 changes: 2 additions & 2 deletions crates/contracts/src/eoa.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ mod ExternallyOwnedAccount {
let call = calls.at(0);
let calldata = call.calldata.span().try_into_bytes().expect('conversion failed');

let EthereumTransaction{nonce,
let EthereumTransaction{nonce: _nonce,
gas_price,
gas_limit,
destination,
amount,
calldata,
chain_id } =
chain_id: _chain_id } =
EthTransactionTrait::decode(
calldata.span()
)
Expand Down
4 changes: 2 additions & 2 deletions crates/contracts/src/kakarot_core/kakarot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ mod KakarotCore {
// part of the Kakarot system and thus deployed by the main Kakarot contract
// itself.

let (caller_account_type, caller_starknet_address) = self
let (caller_account_type, _) = self
.address_registry(origin.evm)
.expect('Fetching EOA failed');
assert(caller_account_type == AccountType::EOA, 'Caller is not an EOA');
Expand All @@ -298,7 +298,7 @@ mod KakarotCore {
.handle_call(:origin, :to, :gas_limit, :gas_price, :value, :calldata);
match maybe_exec_result {
Result::Ok(mut result) => {
result.state.commit_state();
result.state.commit_state().expect('Committing state failed');
if to.is_none() {
// Overwrite return_data with deployed address
return result.address.evm.to_bytes().span();
Expand Down
8 changes: 4 additions & 4 deletions crates/contracts/src/tests/test_contract_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use evm::tests::test_utils::{ca_address, native_token};

#[test]
fn test_ca_deploy() {
let (native_token, kakarot_core) = setup_contracts_for_testing();
let (_, kakarot_core) = setup_contracts_for_testing();
let ca_address = deploy_contract_account(ca_address(), Default::default().span());
let contract_account = IContractAccountDispatcher { contract_address: ca_address.starknet };

Expand All @@ -19,7 +19,7 @@ fn test_ca_deploy() {

#[test]
fn test_ca_bytecode() {
let (native_token, kakarot_core) = setup_contracts_for_testing();
setup_contracts_for_testing();
let bytecode = counter_evm_bytecode();
let ca_address = deploy_contract_account(ca_address(), bytecode);
let contract_account = IContractAccountDispatcher { contract_address: ca_address.starknet };
Expand All @@ -31,7 +31,7 @@ fn test_ca_bytecode() {

#[test]
fn test_ca_nonce() {
let (native_token, kakarot_core) = setup_contracts_for_testing();
setup_contracts_for_testing();
let ca_address = deploy_contract_account(ca_address(), Default::default().span());
let contract_account = IContractAccountDispatcher { contract_address: ca_address.starknet };

Expand All @@ -49,7 +49,7 @@ fn test_ca_nonce() {

#[test]
fn test_ca_storage() {
let (native_token, kakarot_core) = setup_contracts_for_testing();
setup_contracts_for_testing();
let ca_address = deploy_contract_account(ca_address(), Default::default().span());
let contract_account = IContractAccountDispatcher { contract_address: ca_address.starknet };

Expand Down
17 changes: 6 additions & 11 deletions crates/contracts/src/tests/test_eoa.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ mod test_external_owned_account {
#[test]
#[available_gas(2000000000)]
fn test_evm_address() {
let owner = contract_address_const::<1>();
let expected_address: EthAddress = eoa_address();
let (_, kakarot) = setup_contracts_for_testing();
let kakarot_address = kakarot.contract_address;
setup_contracts_for_testing();

let eoa_contract = deploy_eoa(eoa_address());

Expand All @@ -69,8 +67,7 @@ mod test_external_owned_account {
#[test]
#[available_gas(2000000000)]
fn test_eoa_upgrade() {
let (_, kakarot) = setup_contracts_for_testing();
let kakarot_address = kakarot.contract_address;
setup_contracts_for_testing();
let eoa_contract = deploy_eoa(eoa_address());

let new_class_hash: ClassHash = MockContractUpgradeableV1::TEST_CLASS_HASH
Expand All @@ -92,8 +89,7 @@ mod test_external_owned_account {
#[available_gas(2000000000)]
#[should_panic(expected: ('Caller not self', 'ENTRYPOINT_FAILED'))]
fn test_eoa_upgrade_from_noncontractaddress() {
let (_, kakarot) = setup_contracts_for_testing();
let kakarot_address = kakarot.contract_address;
setup_contracts_for_testing();
let eoa_contract = deploy_eoa(eoa_address());
let new_class_hash: ClassHash = MockContractUpgradeableV1::TEST_CLASS_HASH
.try_into()
Expand All @@ -112,7 +108,7 @@ mod test_external_owned_account {

let kakarot_address = kakarot_core.contract_address;

let account = deploy_contract_account(other_evm_address(), counter_evm_bytecode());
deploy_contract_account(other_evm_address(), counter_evm_bytecode());

set_contract_address(eoa);
let eoa_contract = AccountContractDispatcher { contract_address: eoa };
Expand Down Expand Up @@ -143,7 +139,7 @@ mod test_external_owned_account {
calldata: encoded_tx.to_felt252_array()
};

let result = eoa_contract.__execute__(array![call]);
eoa_contract.__execute__(array![call]);

// check counter value has increased
let return_data = kakarot_core
Expand All @@ -163,8 +159,7 @@ mod test_external_owned_account {
#[available_gas(2000000000)]
#[should_panic(expected: ('calls length is not 1', 'ENTRYPOINT_FAILED'))]
fn test___execute___should_fail_with_zero_calls() {
let (_, kakarot) = setup_contracts_for_testing();
let kakarot_address = kakarot.contract_address;
setup_contracts_for_testing();

let eoa_contract = deploy_eoa(eoa_address());
let eoa_contract = AccountContractDispatcher {
Expand Down
30 changes: 14 additions & 16 deletions crates/contracts/src/tests/test_kakarot_core.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn test_kakarot_core_set_native_token() {

#[test]
fn test_kakarot_core_deploy_eoa() {
let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing();
let (_, kakarot_core) = contract_utils::setup_contracts_for_testing();
let eoa_starknet_address = kakarot_core.deploy_eoa(test_utils::evm_address());
// We drop the first event of Kakarot Core, as it is the initializer from Ownable,
// triggered in the constructor
Expand All @@ -105,7 +105,7 @@ fn test_kakarot_core_deploy_eoa() {
#[test]
fn test_kakarot_core_eoa_mapping() {
// Given
let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing();
let (_, kakarot_core) = contract_utils::setup_contracts_for_testing();
assert(
kakarot_core.address_registry(test_utils::evm_address()).is_none(),
'should be uninitialized'
Expand Down Expand Up @@ -165,7 +165,7 @@ fn test_kakarot_core_upgrade_contract() {
#[test]
fn test_kakarot_contract_account_nonce() {
// Given
let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing();
let (_, kakarot_core) = contract_utils::setup_contracts_for_testing();
let address = contract_utils::deploy_contract_account(
test_utils::other_evm_address(), Default::default().span()
);
Expand All @@ -180,7 +180,7 @@ fn test_kakarot_contract_account_nonce() {
#[test]
fn test_kakarot_contract_account_storage_at() {
// Given
let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing();
let (_, kakarot_core) = contract_utils::setup_contracts_for_testing();
let address = contract_utils::deploy_contract_account(
test_utils::other_evm_address(), Default::default().span()
);
Expand All @@ -199,7 +199,7 @@ fn test_kakarot_contract_account_storage_at() {
#[test]
fn test_kakarot_contract_account_bytecode() {
// Given
let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing();
let (_, kakarot_core) = contract_utils::setup_contracts_for_testing();
let address = contract_utils::deploy_contract_account(
test_utils::other_evm_address(), counter_evm_bytecode()
);
Expand All @@ -215,7 +215,7 @@ fn test_kakarot_contract_account_bytecode() {
#[should_panic(expected: ('unimplemented', 'ENTRYPOINT_FAILED'))]
fn test_kakarot_contract_account_false_positive_jumpdest() {
// Given
let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing();
let (_, kakarot_core) = contract_utils::setup_contracts_for_testing();
let address = contract_utils::deploy_contract_account(
test_utils::other_evm_address(), Default::default().span()
);
Expand All @@ -234,7 +234,7 @@ fn test_kakarot_contract_account_false_positive_jumpdest() {
#[test]
fn test_eth_send_transaction() {
// Given
let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing();
let (_, kakarot_core) = contract_utils::setup_contracts_for_testing();

let evm_address = test_utils::evm_address();
let eoa = kakarot_core.deploy_eoa(evm_address);
Expand Down Expand Up @@ -288,10 +288,10 @@ fn test_eth_send_transaction() {
#[test]
fn test_eth_call() {
// Given
let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing();
let (_, kakarot_core) = contract_utils::setup_contracts_for_testing();

let evm_address = test_utils::evm_address();
let eoa = kakarot_core.deploy_eoa(evm_address);
kakarot_core.deploy_eoa(evm_address);

let account = contract_utils::deploy_contract_account(
test_utils::other_evm_address(), counter_evm_bytecode()
Expand All @@ -317,12 +317,12 @@ fn test_eth_call() {
#[test]
fn test_handle_call() {
// Given
let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing();
let mut kakarot_core = KakarotCore::unsafe_new_contract_state();
let (_, kakarot_core) = contract_utils::setup_contracts_for_testing();

let evm_address = test_utils::evm_address();
let eoa = kakarot_core.deploy_eoa(evm_address);
let account = contract_utils::deploy_contract_account(

let _account = contract_utils::deploy_contract_account(
test_utils::other_evm_address(), counter_evm_bytecode()
);

Expand Down Expand Up @@ -356,7 +356,7 @@ fn test_handle_call() {
#[test]
fn test_eth_send_transaction_deploy_tx() {
// Given
let (native_token, kakarot_core) = contract_utils::setup_contracts_for_testing();
let (_, kakarot_core) = contract_utils::setup_contracts_for_testing();

let evm_address = test_utils::evm_address();
let eoa = kakarot_core.deploy_eoa(evm_address);
Expand Down Expand Up @@ -385,9 +385,7 @@ fn test_eth_send_transaction_deploy_tx() {
testing::set_contract_address(kakarot_core.contract_address);
let kakarot_state = KakarotCore::unsafe_new_contract_state();
let computed_sn_addr = kakarot_state.compute_starknet_address(expected_address);
let CA = IContractAccountDispatcher {
contract_address: kakarot_state.compute_starknet_address(expected_address)
};
let CA = IContractAccountDispatcher { contract_address: computed_sn_addr };
let bytecode = CA.bytecode();
assert(bytecode == counter_evm_bytecode(), 'wrong bytecode');

Expand Down
4 changes: 2 additions & 2 deletions crates/contracts/src/tests/test_ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn test_assert_only_owner_not_owner() {
let mut ownable: TestingState = TestingStateTrait::new_with(OWNER());
testing::set_caller_address(OTHER());

let result = ownable.assert_only_owner();
ownable.assert_only_owner();
}

#[test]
Expand All @@ -84,7 +84,7 @@ fn test_assert_only_owner_zero() {
let mut ownable: TestingState = TestingStateTrait::new_with(OWNER());
testing::set_caller_address(ZERO());

let result = ownable.assert_only_owner();
ownable.assert_only_owner();
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn test_account_initialize() {
#[test]
#[should_panic(expected: ('Caller not Kakarot Core address', 'ENTRYPOINT_FAILED'))]
fn test_eoa_upgrade_from_nonkakarot() {
let (native_token, kakarot_core) = setup_contracts_for_testing();
let (_, kakarot_core) = setup_contracts_for_testing();
let account = deploy_account(kakarot_core.contract_address);
set_contract_address(kakarot_address());
let new_class_hash: ClassHash = MockContractUpgradeableV1::TEST_CLASS_HASH.try_into().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/contracts/src/tests/test_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn pop_log<T, impl TDrop: Drop<T>, impl TEvent: starknet::Event<T>>(
let (mut keys, mut data) = testing::pop_log_raw(address)?;

// Remove the event ID from the keys
keys.pop_front();
keys.pop_front().expect('pop_log popfront failed');

let ret = starknet::Event::deserialize(ref keys, ref data);
assert(data.is_empty(), 'Event has extra data');
Expand All @@ -40,7 +40,7 @@ fn pop_log<T, impl TDrop: Drop<T>, impl TEvent: starknet::Event<T>>(

/// Author: Openzeppelin https://github.com/OpenZeppelin/cairo-contracts
fn drop_event(address: ContractAddress) {
testing::pop_log_raw(address);
testing::pop_log_raw(address).unwrap();
}

/// Author: Openzeppelin https://github.com/OpenZeppelin/cairo-contracts
Expand Down
5 changes: 2 additions & 3 deletions crates/evm/src/create_helpers.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ impl MachineCreateHelpersImpl of MachineCreateHelpers {
// Success
Status::Stopped => {
let mut return_data = self.return_data();
let mut i = 0;

let mut account = self.state.get_account(account_address);
account.set_code(return_data);
Expand All @@ -159,12 +158,12 @@ impl MachineCreateHelpersImpl of MachineCreateHelpers {
'type should be CA in finalize'
);
self.state.set_account(account);
self.return_to_parent_ctx();
self.return_to_parent_ctx()?;
self.stack.push(account_address.into())
},
// Failure
Status::Reverted => {
self.return_to_parent_ctx();
self.return_to_parent_ctx()?;
self.stack.push(0)
},
}
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/src/execution.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn execute(

let transfer = Transfer { sender: origin, recipient: target, amount: value };
match machine.state.add_transfer(transfer) {
Result::Ok(x) => {},
Result::Ok(_) => {},
Result::Err(err) => { return reverted_with_err(machine, err); }
}

Expand Down Expand Up @@ -102,7 +102,7 @@ fn reverted_with_err(mut machine: Machine, error: EVMError) -> ExecutionResult {
ExecutionResult {
address: machine.address(),
status: Status::Reverted,
return_data: Default::default().span(),
return_data: return_data,
state: machine.state,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl EnvironmentInformationImpl of EnvironmentInformationTrait {
return Result::Err(EVMError::ReturnDataError(RETURNDATA_OUT_OF_BOUNDS_ERROR));
}
},
Result::Err(x) => {
Result::Err(_) => {
return Result::Err(EVMError::ReturnDataError(RETURNDATA_OUT_OF_BOUNDS_ERROR));
}
}
Expand Down
Loading
Loading