Skip to content

Commit

Permalink
wip: add naming contract
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Aug 7, 2023
1 parent 2ca26ca commit 7925238
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 67 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: 0.6.0-alpha.4
SCARB_VERSION: 0.6.0

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

[dependencies]
starknet = "2.1.0-rc4"
starknet = "2.1.0"
# openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", branch = "cairo-2" }

[[target.starknet-contract]]
# Enable Sierra codegen.
Expand All @@ -15,4 +16,4 @@ sierra = true
casm = true

# Emit Python-powered hints in order to run compiled CASM class with legacy Cairo VM.
casm-add-pythonic-hints = true
casm-add-pythonic-hints = true
3 changes: 2 additions & 1 deletion src/interface.cairo
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mod pricing;
mod pricing;
mod naming;
6 changes: 6 additions & 0 deletions src/interface/naming.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use starknet::ContractAddress;

#[starknet::interface]
trait INaming<TContractState> {
fn resolve(self: @TContractState, domain: felt252, field: felt252) -> felt252;
}
4 changes: 2 additions & 2 deletions src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod upgrades;
mod interface;
mod pricing;
mod tests;
mod naming;
mod tests;
1 change: 1 addition & 0 deletions src/naming.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod main;
38 changes: 38 additions & 0 deletions src/naming/main.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#[starknet::contract]
mod Naming {
use starknet::ContractAddress;
use starknet::{get_caller_address, get_contract_address};
use traits::Into;
use array::{ArrayTrait};
use zeroable::Zeroable;
use starknet::class_hash::ClassHash;
use naming::interface::naming::{INaming, INamingDispatcher, INamingDispatcherTrait};
use integer::{u256_safe_divmod, u256_as_non_zero};

#[storage]
struct Storage {
starknetid_contract: ContractAddress,
_pricing_contract: ContractAddress,
_admin_address: ContractAddress,
}

#[constructor]
fn constructor(
ref self: ContractState,
starknetid: ContractAddress,
pricing: ContractAddress,
admin: ContractAddress
) {
self.starknetid_contract.write(starknetid);
self._pricing_contract.write(pricing);
self._admin_address.write(admin);
}


#[external(v0)]
impl PricingImpl of INaming<ContractState> {
fn resolve(self: @ContractState, domain: felt252, field: felt252) -> felt252 {
1
}
}
}
2 changes: 1 addition & 1 deletion src/pricing.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mod Pricing {
}

fn get_price_per_day(self: @ContractState, domain: felt252) -> u128 {
let number_of_character = self.get_price_per_day(domain.into());
let number_of_character = self.get_amount_of_chars(domain.into());

if number_of_character == 1 {
return 1068493150684932;
Expand Down
1 change: 1 addition & 0 deletions src/tests.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod utils;
mod test_pricing;
mod test_naming;
43 changes: 43 additions & 0 deletions src/tests/test_naming.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use array::ArrayTrait;
use debug::PrintTrait;
use zeroable::Zeroable;
use traits::Into;

use starknet::ContractAddress;
use starknet::testing;
use super::utils;
use naming::interface::naming::{INamingDispatcher, INamingDispatcherTrait};
use naming::naming::main::Naming;
use naming::pricing::Pricing;

#[cfg(test)]
fn deploy() -> INamingDispatcher {

//erc20
let mut calldata = ArrayTrait::<felt252>::new();
calldata.append(0x789);
let pricing = utils::deploy(Pricing::TEST_CLASS_HASH, calldata);

// pricing
let mut calldata = ArrayTrait::<felt252>::new();
calldata.append(0x789);
let pricing = utils::deploy(Pricing::TEST_CLASS_HASH, calldata);

// naming
let mut calldata = ArrayTrait::<felt252>::new();
let starknetid = 0x456;
let admin = 0x123;
calldata.append(starknetid);
calldata.append(pricing.into());
calldata.append(admin);
let address = utils::deploy(Naming::TEST_CLASS_HASH, calldata);
INamingDispatcher { contract_address: address }
}

#[cfg(test)]
#[test]
#[available_gas(20000000000)]
fn test_buy_price() {
deploy();
}

2 changes: 1 addition & 1 deletion src/tests/test_pricing.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ fn test_get_amount_of_chars() {
) == 30,
'Should return 30'
);
}
}
2 changes: 1 addition & 1 deletion src/tests/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ fn deploy(contract_class_hash: felt252, calldata: Array<felt252>) -> ContractAdd
)
.unwrap();
address
}
}
58 changes: 0 additions & 58 deletions src/upgrades/upgradeable.cairo

This file was deleted.

0 comments on commit 7925238

Please sign in to comment.