Skip to content

Commit

Permalink
chore: update workflow, run scarb fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Darlington02 committed Apr 2, 2024
1 parent 0bdd9f2 commit b102906
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
- uses: software-mansion/setup-scarb@v1
- uses: foundry-rs/setup-snfoundry@v3
with:
starknet-foundry-version: 0.19.0
starknet-foundry-version: 0.20.1
- name: Run cairo tests
run: snforge test
20 changes: 8 additions & 12 deletions src/account/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ mod AccountComponent {
account::Call, call_contract_syscall, replace_class_syscall, ClassHash, SyscallResultTrait
};
use token_bound_accounts::interfaces::IERC721::{IERC721DispatcherTrait, IERC721Dispatcher};
use token_bound_accounts::interfaces::IAccount::{IAccount, IAccountDispatcherTrait, IAccountDispatcher, TBA_INTERFACE_ID};
use token_bound_accounts::interfaces::IAccount::{
IAccount, IAccountDispatcherTrait, IAccountDispatcher, TBA_INTERFACE_ID
};

#[storage]
struct Storage {
Expand Down Expand Up @@ -84,8 +86,7 @@ mod AccountComponent {
) -> felt252 {
if self._is_valid_signer(signer) {
return starknet::VALIDATED;
}
else {
} else {
return 0;
}
}
Expand Down Expand Up @@ -136,9 +137,7 @@ mod AccountComponent {
/// @notice gets the NFT owner
/// @param token_contract the contract address of the NFT
/// @param token_id the token ID of the NFT
fn owner(
self: @ComponentState<TContractState>
) -> ContractAddress {
fn owner(self: @ComponentState<TContractState>) -> ContractAddress {
let token_contract = self.account_token_contract.read();
let token_id = self.account_token_id.read();
self._get_owner(token_contract, token_id)
Expand All @@ -157,7 +156,7 @@ mod AccountComponent {

let (lock_status, _) = self._is_locked();
assert(!lock_status, Errors::LOCKED_ACCOUNT);

let current_timestamp = get_block_timestamp();
let unlock_time = current_timestamp + duration;
self.account_unlock_timestamp.write(unlock_time);
Expand Down Expand Up @@ -265,13 +264,10 @@ mod AccountComponent {

let owner = self
._get_owner(self.account_token_contract.read(), self.account_token_id.read());
let account = IAccountDispatcher {
contract_address: owner
};
let account = IAccountDispatcher { contract_address: owner };
if (account.is_valid_signature(hash, signature) == starknet::VALIDATED) {
return starknet::VALIDATED;
}
else {
} else {
return 0;
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/interfaces/IAccount.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ trait IAccount<TContractState> {
fn is_valid_signature(
self: @TContractState, hash: felt252, signature: Span<felt252>
) -> felt252;
fn is_valid_signer(
self: @TContractState, signer: ContractAddress
) -> felt252;
fn is_valid_signer(self: @TContractState, signer: ContractAddress) -> felt252;
fn __validate__(ref self: TContractState, calls: Array<Call>) -> felt252;
fn __validate_declare__(self: @TContractState, class_hash: felt252) -> felt252;
fn __validate_deploy__(
self: @TContractState, class_hash: felt252, contract_address_salt: felt252
) -> felt252;
fn __execute__(ref self: TContractState, calls: Array<Call>) -> Array<Span<felt252>>;
fn token(self: @TContractState) -> (ContractAddress, u256);
fn owner(
self: @TContractState
) -> ContractAddress;
fn owner(self: @TContractState) -> ContractAddress;
fn lock(ref self: TContractState, duration: u64);
fn is_locked(self: @TContractState) -> (bool, u64);
fn supports_interface(self: @TContractState, interface_id: felt252) -> bool;
Expand Down
21 changes: 12 additions & 9 deletions src/test_helper/simple_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use starknet::{account::Call, ContractAddress, ClassHash};
trait ISimpleAccount<TContractState> {
fn get_public_key(self: @TContractState) -> felt252;
fn set_public_key(ref self: TContractState, new_public_key: felt252);
fn is_valid_signature(self: @TContractState, hash: felt252, signature: Span<felt252>) -> felt252;
fn is_valid_signature(
self: @TContractState, hash: felt252, signature: Span<felt252>
) -> felt252;
fn __validate__(ref self: TContractState, calls: Array<Call>) -> felt252;
fn __validate_declare__(self: @TContractState, class_hash: felt252) -> felt252;
fn __validate_deploy__(
Expand All @@ -31,10 +33,7 @@ mod SimpleAccount {
}

#[constructor]
fn constructor(
ref self: ContractState,
_public_key: felt252
) {
fn constructor(ref self: ContractState, _public_key: felt252) {
self._public_key.write(_public_key);
}

Expand All @@ -49,7 +48,9 @@ mod SimpleAccount {
self._public_key.write(new_public_key);
}

fn is_valid_signature(self: @ContractState, hash: felt252, signature: Span<felt252>) -> felt252 {
fn is_valid_signature(
self: @ContractState, hash: felt252, signature: Span<felt252>
) -> felt252 {
self._is_valid_signature(hash, signature)
}

Expand Down Expand Up @@ -93,7 +94,10 @@ mod SimpleAccount {
let tx_info = get_tx_info().unbox();
let tx_hash = tx_info.transaction_hash;
let signature = tx_info.signature;
assert(self._is_valid_signature(tx_hash, signature) == starknet::VALIDATED, 'Account: invalid signature');
assert(
self._is_valid_signature(tx_hash, signature) == starknet::VALIDATED,
'Account: invalid signature'
);
starknet::VALIDATED
}

Expand All @@ -110,8 +114,7 @@ mod SimpleAccount {
signature_s: *signature[1_u32],
) {
return starknet::VALIDATED;
}
else {
} else {
return 0;
}
}
Expand Down
14 changes: 11 additions & 3 deletions tests/test_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ use snforge_std::{
CheatTarget
};

use token_bound_accounts::interfaces::IAccount::{IAccountDispatcher, IAccountDispatcherTrait, IAccountSafeDispatcher, IAccountSafeDispatcherTrait};
use token_bound_accounts::interfaces::IAccount::{
IAccountDispatcher, IAccountDispatcherTrait, IAccountSafeDispatcher, IAccountSafeDispatcherTrait
};
use token_bound_accounts::presets::account::Account;
use token_bound_accounts::interfaces::IUpgradeable::{IUpgradeableDispatcher, IUpgradeableDispatcherTrait};
use token_bound_accounts::interfaces::IUpgradeable::{
IUpgradeableDispatcher, IUpgradeableDispatcherTrait
};

use token_bound_accounts::test_helper::{
hello_starknet::{IHelloStarknetDispatcher, IHelloStarknetDispatcherTrait, HelloStarknet},
Expand Down Expand Up @@ -47,7 +51,11 @@ fn __setup__() -> (ContractAddress, ContractAddress) {

// deploy recipient contract
let account_contract = declare("SimpleAccount");
let mut recipient = account_contract.deploy(@array![883045738439352841478194533192765345509759306772397516907181243450667673002]).unwrap();
let mut recipient = account_contract
.deploy(
@array![883045738439352841478194533192765345509759306772397516907181243450667673002]
)
.unwrap();

// mint a new token
let dispatcher = IERC721Dispatcher { contract_address: erc721_contract_address };
Expand Down
8 changes: 6 additions & 2 deletions tests/test_registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ use snforge_std::{declare, start_prank, stop_prank, ContractClassTrait, Contract
use token_bound_accounts::interfaces::IRegistry::{IRegistryDispatcherTrait, IRegistryDispatcher};
use token_bound_accounts::registry::registry::Registry;

use token_bound_accounts::interfaces::IUpgradeable::{IUpgradeableDispatcher, IUpgradeableDispatcherTrait};
use token_bound_accounts::interfaces::IUpgradeable::{
IUpgradeableDispatcher, IUpgradeableDispatcherTrait
};

use token_bound_accounts::interfaces::IAccount::{IAccountDispatcher, IAccountDispatcherTrait};
use token_bound_accounts::presets::account::Account;

use token_bound_accounts::test_helper::erc721_helper::{IERC721Dispatcher, IERC721DispatcherTrait, ERC721};
use token_bound_accounts::test_helper::erc721_helper::{
IERC721Dispatcher, IERC721DispatcherTrait, ERC721
};

const ACCOUNT: felt252 = 1234;

Expand Down

0 comments on commit b102906

Please sign in to comment.