Skip to content

Commit

Permalink
Merge pull request #25 from ermvrs/main
Browse files Browse the repository at this point in the history
Removed deprecated contracts & Initial integration tests for Rosettanet
  • Loading branch information
ermvrs authored Dec 4, 2024
2 parents ce33417 + 040f8dd commit a7fabb2
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 240 deletions.
100 changes: 0 additions & 100 deletions src/factory.cairo

This file was deleted.

1 change: 0 additions & 1 deletion src/lens.cairo

This file was deleted.

104 changes: 0 additions & 104 deletions src/lens/lens_dev.cairo

This file was deleted.

15 changes: 14 additions & 1 deletion src/rosettanet.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ pub trait IRosettanet<TState> {
// Write methods
fn register_contract(ref self: TState, address: ContractAddress); // Registers existing starknet contract to registry
fn deploy_account(ref self: TState, eth_address: EthAddress) -> ContractAddress; // Deploys starknet account and returns address
fn set_account_class(ref self: TState, class: ClassHash); // Sets account class, this function will be removed after stable account
// Read methods
fn get_starknet_address(self: @TState, eth_address: EthAddress) -> ContractAddress;
fn get_ethereum_address(self: @TState, sn_address: ContractAddress) -> EthAddress;
fn precalculate_starknet_account(self: @TState, eth_address: EthAddress) -> ContractAddress;
fn account_class(self: @TState) -> ClassHash;
fn developer(self: @TState) -> ContractAddress;
}
#[starknet::contract]
pub mod Rosettanet {
use core::num::traits::Zero;
use starknet::storage::{Map};
use core::poseidon::{poseidon_hash_span};
use starknet::syscalls::{deploy_syscall};
use starknet::{ContractAddress, EthAddress, ClassHash, get_contract_address};
use starknet::{ContractAddress, EthAddress, ClassHash, get_contract_address, get_caller_address};
use openzeppelin::utils::deployments::{calculate_contract_address_from_deploy_syscall};

#[storage]
Expand Down Expand Up @@ -51,6 +53,13 @@ pub mod Rosettanet {

account
}

fn set_account_class(ref self: ContractState, class: ClassHash) {
assert(get_caller_address() == self.dev.read(), 'only dev');

self.account_class.write(class);
}

// View methods
fn get_starknet_address(self: @ContractState, eth_address: EthAddress) -> ContractAddress {
self.eth_to_sn.read(eth_address)
Expand All @@ -73,6 +82,10 @@ pub mod Rosettanet {
fn account_class(self: @ContractState) -> ClassHash {
self.account_class.read()
}

fn developer(self: @ContractState) -> ContractAddress {
self.dev.read()
}
}

#[generate_trait]
Expand Down
1 change: 0 additions & 1 deletion src/verifier.cairo

This file was deleted.

28 changes: 0 additions & 28 deletions src/verifier/utils.cairo

This file was deleted.

75 changes: 75 additions & 0 deletions tests/rosettanet_tests.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use snforge_std::{declare, ContractClassTrait, DeclareResultTrait, start_cheat_caller_address, stop_cheat_caller_address};

use rosettacontracts::rosettanet::{
IRosettanetDispatcher, IRosettanetDispatcherTrait
};
use starknet::{ContractAddress, ClassHash, EthAddress};

fn developer() -> ContractAddress {
starknet::contract_address_const::<1>()
}

fn eth_account() -> EthAddress {
0x12345678.try_into().unwrap()
}

fn declare_accounts() -> ClassHash {
let class = declare("RosettaAccount").unwrap().contract_class();
*class.class_hash
}

fn deploy_rosettanet() -> IRosettanetDispatcher {
let contract = declare("Rosettanet").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@array![developer().into()]).unwrap();
IRosettanetDispatcher { contract_address }
}

fn deploy_and_set_account() -> IRosettanetDispatcher {
let contract = declare("Rosettanet").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@array![developer().into()]).unwrap();
let dispatcher = IRosettanetDispatcher { contract_address };
let account_class = declare_accounts();

start_cheat_caller_address(dispatcher.contract_address, developer());
dispatcher.set_account_class(account_class);
stop_cheat_caller_address(dispatcher.contract_address);

dispatcher
}

#[test]
fn rosettanet_deploy_initial_dev() {
let rosettanet = deploy_rosettanet();

assert_eq!(rosettanet.developer(), starknet::contract_address_const::<1>());
}

#[test]
#[should_panic(expected: 'only dev')]
fn rosettanet_non_dev_set_class() {
let rosettanet = deploy_rosettanet();

rosettanet.set_account_class(1.try_into().unwrap());
}

#[test]
fn rosettanet_set_class() {
let rosettanet = deploy_rosettanet();

start_cheat_caller_address(rosettanet.contract_address, developer());
rosettanet.set_account_class(1.try_into().unwrap());
stop_cheat_caller_address(rosettanet.contract_address);

assert_eq!(rosettanet.account_class(), 1.try_into().unwrap());
}

#[test]
fn rosettanet_check_precalculate_address() {
let rosettanet = deploy_and_set_account();

let precalculated_address = rosettanet.precalculate_starknet_account(eth_account());

let deployed_account = rosettanet.deploy_account(eth_account());

assert_eq!(precalculated_address, deployed_account)
}
5 changes: 0 additions & 5 deletions tests/test_data.md

This file was deleted.

0 comments on commit a7fabb2

Please sign in to comment.