Skip to content
Permalink
Browse files
Change DFI ticker to XFI (#169, DFI-599)
* Change DFI ticker to XFI

* Update access vector tests.
  • Loading branch information
RIg410 committed Aug 12, 2020
1 parent ae9b402 commit a2f608494f828eb414d418fad1634057f346a403
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 21 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -13,9 +13,9 @@ const GAS_AMOUNT_MAX_VALUE: u64 = u64::MAX / 1000;
#[derive(Debug)]
pub struct ExecutionMeta {
/// Max gas units to be used in transaction execution.
max_gas_amount: u64,
/// Price in `DFI` coins per unit of gas.
gas_unit_price: u64,
pub max_gas_amount: u64,
/// Price in `XFI` coins per unit of gas.
pub gas_unit_price: u64,
/// Sender address of the transaction owner.
sender: AccountAddress,
}
@@ -4,8 +4,8 @@ use serde_derive::{Deserialize, Serialize};
const COIN_MODULE: &str = "Coins";
const PRICE_STRUCT: &str = "Price";

const DFI_MODULE: &str = "DFI";
const DFI_RESOURCE: &str = "T";
const XFI_MODULE: &str = "XFI";
const XFI_RESOURCE: &str = "T";

const BLOCK_RESOURCE: &str = "BlockMetadata";

@@ -42,11 +42,11 @@ pub fn oracle_metadata(first: &str, second: &str) -> StructTag {

fn currency_type(curr: &str) -> TypeTag {
let curr = curr.to_uppercase();
if curr == DFI_MODULE {
if curr == XFI_MODULE {
TypeTag::Struct(StructTag {
address: CORE_CODE_ADDRESS,
name: Identifier::new(DFI_RESOURCE).expect("Valid module name."),
module: Identifier::new(DFI_MODULE).expect("Valid currency name."),
name: Identifier::new(XFI_RESOURCE).expect("Valid module name."),
module: Identifier::new(XFI_MODULE).expect("Valid currency name."),
type_params: vec![],
})
} else {
@@ -81,14 +81,21 @@ pub fn time_metadata() -> StructTag {

#[cfg(test)]
mod tests {
use crate::resources::{time_metadata, block_metadata, oracle_metadata};
use crate::resources::*;
use libra::prelude::CORE_CODE_ADDRESS;

const ACCOUNT_MODULE: &str = "Account";
const BALANCE_STRUCT: &str = "Balance";

const DFINANCE_MODULE: &str = "Dfinance";
const INFO_STRUCT: &str = "Info";

#[test]
pub fn test_oracle_metadata() {
let vector = oracle_metadata("DFI", "BTC").access_vector();
let vector = oracle_metadata("XFI", "BTC").access_vector();
assert_eq!(
vector,
hex::decode("01b1a724361d17c9866b12e199ecdb17eb5cb16630b647bbc997fe65362920e3bb")
hex::decode("018c2f213d25358a39f9370a494dbe4bd80f84734137a01ec8f468c3b2ef16360a")
.unwrap()
);

@@ -100,6 +107,58 @@ mod tests {
);
}

#[test]
pub fn test_balance_vector() {
fn balance_vector(curr: &str) -> StructTag {
StructTag {
address: CORE_CODE_ADDRESS,
name: Identifier::new(BALANCE_STRUCT).expect("Valid struct name."),
module: Identifier::new(ACCOUNT_MODULE).expect("Valid module name."),
type_params: vec![currency_type(curr)],
}
}

let vector = balance_vector("eth").access_vector();
assert_eq!(
vector,
hex::decode("0138f4f2895881c804de0e57ced1d44f02e976f9c6561c889f7b7eef8e660d2c9a")
.unwrap()
);

let vector = balance_vector("xfi").access_vector();
assert_eq!(
vector,
hex::decode("01226844e85ad6e3867f4ff1a4300e71ed6057538631a5a5330512772b7104b585")
.unwrap()
);
}

#[test]
pub fn test_currency_info_vector() {
fn currency_info_vector(curr: &str) -> StructTag {
StructTag {
address: CORE_CODE_ADDRESS,
name: Identifier::new(INFO_STRUCT).expect("Valid struct name."),
module: Identifier::new(DFINANCE_MODULE).expect("Valid module name."),
type_params: vec![currency_type(curr)],
}
}

let vector = currency_info_vector("eth").access_vector();
assert_eq!(
vector,
hex::decode("012a00668b5325f832c28a24eb83dffa8295170c80345fbfbf99a5263f962c76f4")
.unwrap()
);

let vector = currency_info_vector("xfi").access_vector();
assert_eq!(
vector,
hex::decode("01b9ed21c23abf8c7a53fb868a36e106d45394c30127fb722f8dd2d45aae719585")
.unwrap()
);
}

#[test]
pub fn test_time_metadata() {
let vector = time_metadata().access_vector();
@@ -1,10 +1,10 @@
address 0x1 {

/// DFI Coin. The one and only.
/// XFI Coin. The one and only.
/// Put into separate module to highlight its importance and role in Dfinance
/// ecosystem. Also moved not to be mistaken for peg-zone coin. Same-naming
/// attack from peg-zone is impossible when DFI coin moved outside of Coins module
module DFI {
/// attack from peg-zone is impossible when XFI coin moved outside of Coins module
module XFI {
struct T {}
}
}
@@ -9,25 +9,25 @@ script {
}

//#eth_btc:4078
//#btc_dfi:20
//#btc_xfi:20
script {
use 0x01::Coins;
use 0x01::DFI;
use 0x01::XFI;

fun test_get_price() {
assert(Coins::get_price<Coins::ETH, Coins::BTC>() == 4078, 1);
assert(Coins::get_price<Coins::BTC, DFI::T>() == 20, 2);
assert(Coins::get_price<Coins::BTC, XFI::T>() == 20, 2);
}
}

//#eth_btc:4078
//#status:4008 MISSING_DATA
script {
use 0x01::Coins;
use 0x01::DFI;
use 0x01::XFI;

fun test_price_not_found() {
assert(Coins::get_price<Coins::ETH, Coins::BTC>() == 4078, 1);
assert(Coins::get_price<Coins::BTC, DFI::T>() == 20, 2);
assert(Coins::get_price<Coins::BTC, XFI::T>() == 20, 2);
}
}

0 comments on commit a2f6084

Please sign in to comment.