Skip to content

Commit

Permalink
fix: conflicts with branch master
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Nov 3, 2023
2 parents 8e7109d + 5232af6 commit 0f665e4
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI Tests
on: [push, pull_request, pull_request_target]

env:
SCARB_VERSION: 2.3.0
SCARB_VERSION: 2.3.1

jobs:
scarb-tests:
Expand Down
3 changes: 2 additions & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ version = "0.1.0"
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest

[dependencies]
starknet = "2.3.0"
starknet = "2.3.1"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.8.0-beta.0" }
identity = { git = "https://github.com/starknet-id/identity.git", rev = "2e8fecab0d9a971710e8efb21abc25fb7825ee09" }
storage_read = { git = "https://github.com/starknet-id/storage_read_component", rev = "c6c69e15d34abfc39ac51dc21b96724e2e19ff31" }

[[target.starknet-contract]]
# Enable Sierra codegen.
Expand Down
4 changes: 2 additions & 2 deletions src/naming/internal.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ impl InternalImpl of InternalTrait {
fn resolve_util(
self: @Naming::ContractState, domain: Span<felt252>, field: felt252, hint: Span<felt252>
) -> (felt252, felt252) {
let (resolver, parent_start) = self.domain_to_resolver(domain, 0);
let (resolver, parent_start) = self.domain_to_resolver(domain, 1);
if (resolver != ContractAddressZeroable::zero()) {
(
0,
IResolverDispatcher { contract_address: resolver }
.resolve(domain.slice(parent_start, domain.len() - parent_start), field, hint)
.resolve(domain.slice(0, parent_start), field, hint)
)
} else {
let hashed_domain = self.hash_domain(domain);
Expand Down
9 changes: 8 additions & 1 deletion src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod Naming {
use openzeppelin::token::erc20::interface::{
IERC20Camel, IERC20CamelDispatcher, IERC20CamelDispatcherTrait
};
use debug::PrintTrait;
use storage_read::{main::storage_read_component, interface::IStorageRead};

#[event]
#[derive(Drop, starknet::Event)]
Expand All @@ -37,6 +37,7 @@ mod Naming {
DomainTransfer: DomainTransfer,
SubdomainsReset: SubdomainsReset,
SaleMetadata: SaleMetadata,
StorageReadEvent: storage_read_component::Event
}

#[derive(Drop, starknet::Event)]
Expand Down Expand Up @@ -116,6 +117,8 @@ mod Naming {
_domain_data: LegacyMap<felt252, DomainData>,
_hash_to_domain: LegacyMap<(felt252, usize), felt252>,
_address_to_domain: LegacyMap<(ContractAddress, usize), felt252>,
#[substorage(v0)]
storage_read: storage_read_component::Storage,
}

#[constructor]
Expand All @@ -132,6 +135,10 @@ mod Naming {
self._admin_address.write(admin);
}

component!(path: storage_read_component, storage: storage_read, event: StorageReadEvent);

#[abi(embed_v0)]
impl StorageReadComponent = storage_read_component::StorageRead<ContractState>;

#[external(v0)]
impl NamingImpl of INaming<ContractState> {
Expand Down
1 change: 1 addition & 0 deletions src/tests/naming.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod common;
mod test_abuses;
mod test_custom_resolver;
mod test_usecases;
mod test_features;
99 changes: 99 additions & 0 deletions src/tests/naming/test_custom_resolver.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use array::ArrayTrait;
use array::SpanTrait;
use debug::PrintTrait;
use option::OptionTrait;
use zeroable::Zeroable;
use traits::Into;
use starknet::testing;
use starknet::ContractAddress;
use starknet::contract_address::ContractAddressZeroable;
use starknet::contract_address_const;
use starknet::testing::set_contract_address;
use super::super::utils;
use openzeppelin::token::erc20::{
erc20::ERC20, interface::{IERC20Camel, IERC20CamelDispatcher, IERC20CamelDispatcherTrait}
};
use identity::{
identity::main::Identity, interface::identity::{IIdentityDispatcher, IIdentityDispatcherTrait}
};
use naming::interface::naming::{INamingDispatcher, INamingDispatcherTrait};
use naming::interface::pricing::{IPricingDispatcher, IPricingDispatcherTrait};
use naming::naming::main::Naming;
use naming::pricing::Pricing;
use super::common::deploy;
use naming::naming::main::Naming::Discount;
use naming::interface::resolver::IResolver;

#[starknet::contract]
mod CustomResolver {
use core::array::SpanTrait;
use naming::interface::resolver::IResolver;
use debug::PrintTrait;

#[storage]
struct Storage {}


#[external(v0)]
impl AdditionResolveImpl of IResolver<ContractState> {
fn resolve(self: @ContractState, mut domain: Span<felt252>, field: felt252) -> felt252 {
let mut output = 0;
loop {
match domain.pop_front() {
Option::Some(domain_part) => { output += *domain_part; },
Option::None => { break; }
}
};
output.print();
output
}
}
}


#[test]
#[available_gas(2000000000)]
fn test_custom_resolver() {
// setup
let (eth, pricing, identity, naming) = deploy();
let custom_resolver = IERC20CamelDispatcher {
contract_address: utils::deploy(CustomResolver::TEST_CLASS_HASH, ArrayTrait::new())
};

let caller = contract_address_const::<0x123>();
set_contract_address(caller);
let id: u128 = 1;
let th0rgal: felt252 = 33133781693;

//we mint an id
identity.mint(id);

// we check how much a domain costs
let (_, price) = pricing.compute_buy_price(7, 365);

// we allow the naming to take our money
eth.approve(naming.contract_address, price);

// we buy with no resolver, no sponsor, no discount and empty metadata
naming
.buy(
id,
th0rgal,
365,
custom_resolver.contract_address,
ContractAddressZeroable::zero(),
0,
0
);

let domain = array![th0rgal].span();
// by default we should have nothing written
assert(naming.resolve(domain, 'starknet') == 0, 'non empty starknet field');
// so it should resolve to the starknetid owner
assert(naming.domain_to_address(domain) == caller, 'wrong domain target');

let domain = array![1, 2, 3, th0rgal].span();

// let's try the resolving
assert(naming.resolve(domain, 'starknet') == 1 + 2 + 3, 'wrong target');
}

0 comments on commit 0f665e4

Please sign in to comment.