Skip to content

Commit

Permalink
fix: quote typing
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Mar 5, 2024
1 parent 3f7a65d commit 2e27f08
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/interface/naming.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use starknet::{ContractAddress, ClassHash};
use naming::naming::main::Naming::{Discount, DomainData};
use wadray::Wad;

#[starknet::interface]
trait INaming<TContractState> {
Expand Down Expand Up @@ -43,7 +42,7 @@ trait INaming<TContractState> {
discount_id: felt252,
metadata: felt252,
altcoin_addr: ContractAddress,
quote: Wad,
quote: u128,
max_validity: u64,
sig: (felt252, felt252),
);
Expand All @@ -65,7 +64,7 @@ trait INaming<TContractState> {
discount_id: felt252,
metadata: felt252,
altcoin_addr: ContractAddress,
quote: Wad,
quote: u128,
max_validity: u64,
sig: (felt252, felt252),
);
Expand Down
10 changes: 6 additions & 4 deletions src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ mod Naming {
discount_id: felt252,
metadata: felt252,
altcoin_addr: ContractAddress,
quote: Wad,
quote: u128,
max_validity: u64,
sig: (felt252, felt252),
) {
Expand Down Expand Up @@ -316,7 +316,8 @@ mod Naming {
}
.compute_buy_price(domain_len, days);
// compute domain cost in altcoin
let price_in_altcoin = self.get_altcoin_price(quote, price_in_eth.try_into().unwrap());
let price_in_altcoin = self
.get_altcoin_price(quote.into(), price_in_eth.try_into().unwrap());
self
.pay_domain(
domain_len,
Expand Down Expand Up @@ -383,7 +384,7 @@ mod Naming {
discount_id: felt252,
metadata: felt252,
altcoin_addr: ContractAddress,
quote: Wad,
quote: u128,
max_validity: u64,
sig: (felt252, felt252),
) {
Expand Down Expand Up @@ -414,7 +415,8 @@ mod Naming {
}
.compute_renew_price(domain_len, days);
// compute domain cost in altcoin
let price_in_altcoin = self.get_altcoin_price(quote, price_in_eth.try_into().unwrap());
let price_in_altcoin = self
.get_altcoin_price(quote.into(), price_in_eth.try_into().unwrap());
self
.pay_domain(
domain_len,
Expand Down
22 changes: 11 additions & 11 deletions src/tests/naming/test_altcoin.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ fn test_buy_domain_with_strk() {
identity.mint(id1);

// we check how much a domain costs
let quote = Wad { val: 5221805004292776 };
let quote = 5221805004292776_u128;
let (_, price_in_eth) = pricing.compute_buy_price(7, 365);
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote;
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote.into();

// we allow the naming to take our money
strk.approve(naming.contract_address, price_in_strk.into());
Expand Down Expand Up @@ -120,9 +120,9 @@ fn test_buy_domain_altcoin_quote_expired() {
identity.mint(id1);

// we check how much a domain costs
let quote = Wad { val: 5221805004292776 };
let quote = 5221805004292776_u128;
let (_, price_in_eth) = pricing.compute_buy_price(7, 365);
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote;
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote.into();

// we allow the naming to take our money
strk.approve(naming.contract_address, price_in_strk.into());
Expand Down Expand Up @@ -174,9 +174,9 @@ fn test_buy_domain_altcoin_wrong_quote() {
identity.mint(id1);

// we check how much a domain costs
let quote = Wad { val: 5221805004292776 };
let quote = 5221805004292776_u128;
let (_, price_in_eth) = pricing.compute_buy_price(7, 365);
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote;
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote.into();

// we allow the naming to take our money
strk.approve(naming.contract_address, price_in_strk.into());
Expand All @@ -198,7 +198,7 @@ fn test_buy_domain_altcoin_wrong_quote() {
0,
0,
strk.contract_address,
Wad { val: 1 },
1,
max_validity,
sig
);
Expand All @@ -224,9 +224,9 @@ fn test_renew_domain_with_strk() {
identity.mint(id1);

// we check how much a domain costs
let quote = Wad { val: 5221805004292776 };
let quote = 5221805004292776_u128;
let (_, price_in_eth) = pricing.compute_buy_price(7, 365);
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote;
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote.into();

// we allow the naming to take our money
strk.approve(naming.contract_address, price_in_strk.into());
Expand Down Expand Up @@ -259,9 +259,9 @@ fn test_renew_domain_with_strk() {
);

// we check how much a domain costs to renew
let quote = Wad { val: 1221805004292776 };
let quote = 1221805004292776_u128;
let (_, price_in_eth) = pricing.compute_buy_price(7, 365);
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote;
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote.into();

// we allow the naming to take our money
strk.approve(naming.contract_address, price_in_strk.into());
Expand Down

0 comments on commit 2e27f08

Please sign in to comment.