Skip to content

Commit a2f6084

Browse files
authored
Change DFI ticker to XFI (#169, DFI-599)
* Change DFI ticker to XFI * Update access vector tests.
1 parent ae9b402 commit a2f6084

5 files changed

Lines changed: 80 additions & 21 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/src/move_vm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ const GAS_AMOUNT_MAX_VALUE: u64 = u64::MAX / 1000;
1313
#[derive(Debug)]
1414
pub struct ExecutionMeta {
1515
/// Max gas units to be used in transaction execution.
16-
max_gas_amount: u64,
17-
/// Price in `DFI` coins per unit of gas.
18-
gas_unit_price: u64,
16+
pub max_gas_amount: u64,
17+
/// Price in `XFI` coins per unit of gas.
18+
pub gas_unit_price: u64,
1919
/// Sender address of the transaction owner.
2020
sender: AccountAddress,
2121
}

runtime/src/resources.rs

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use serde_derive::{Deserialize, Serialize};
44
const COIN_MODULE: &str = "Coins";
55
const PRICE_STRUCT: &str = "Price";
66

7-
const DFI_MODULE: &str = "DFI";
8-
const DFI_RESOURCE: &str = "T";
7+
const XFI_MODULE: &str = "XFI";
8+
const XFI_RESOURCE: &str = "T";
99

1010
const BLOCK_RESOURCE: &str = "BlockMetadata";
1111

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

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

8282
#[cfg(test)]
8383
mod tests {
84-
use crate::resources::{time_metadata, block_metadata, oracle_metadata};
84+
use crate::resources::*;
85+
use libra::prelude::CORE_CODE_ADDRESS;
86+
87+
const ACCOUNT_MODULE: &str = "Account";
88+
const BALANCE_STRUCT: &str = "Balance";
89+
90+
const DFINANCE_MODULE: &str = "Dfinance";
91+
const INFO_STRUCT: &str = "Info";
8592

8693
#[test]
8794
pub fn test_oracle_metadata() {
88-
let vector = oracle_metadata("DFI", "BTC").access_vector();
95+
let vector = oracle_metadata("XFI", "BTC").access_vector();
8996
assert_eq!(
9097
vector,
91-
hex::decode("01b1a724361d17c9866b12e199ecdb17eb5cb16630b647bbc997fe65362920e3bb")
98+
hex::decode("018c2f213d25358a39f9370a494dbe4bd80f84734137a01ec8f468c3b2ef16360a")
9299
.unwrap()
93100
);
94101

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

110+
#[test]
111+
pub fn test_balance_vector() {
112+
fn balance_vector(curr: &str) -> StructTag {
113+
StructTag {
114+
address: CORE_CODE_ADDRESS,
115+
name: Identifier::new(BALANCE_STRUCT).expect("Valid struct name."),
116+
module: Identifier::new(ACCOUNT_MODULE).expect("Valid module name."),
117+
type_params: vec![currency_type(curr)],
118+
}
119+
}
120+
121+
let vector = balance_vector("eth").access_vector();
122+
assert_eq!(
123+
vector,
124+
hex::decode("0138f4f2895881c804de0e57ced1d44f02e976f9c6561c889f7b7eef8e660d2c9a")
125+
.unwrap()
126+
);
127+
128+
let vector = balance_vector("xfi").access_vector();
129+
assert_eq!(
130+
vector,
131+
hex::decode("01226844e85ad6e3867f4ff1a4300e71ed6057538631a5a5330512772b7104b585")
132+
.unwrap()
133+
);
134+
}
135+
136+
#[test]
137+
pub fn test_currency_info_vector() {
138+
fn currency_info_vector(curr: &str) -> StructTag {
139+
StructTag {
140+
address: CORE_CODE_ADDRESS,
141+
name: Identifier::new(INFO_STRUCT).expect("Valid struct name."),
142+
module: Identifier::new(DFINANCE_MODULE).expect("Valid module name."),
143+
type_params: vec![currency_type(curr)],
144+
}
145+
}
146+
147+
let vector = currency_info_vector("eth").access_vector();
148+
assert_eq!(
149+
vector,
150+
hex::decode("012a00668b5325f832c28a24eb83dffa8295170c80345fbfbf99a5263f962c76f4")
151+
.unwrap()
152+
);
153+
154+
let vector = currency_info_vector("xfi").access_vector();
155+
assert_eq!(
156+
vector,
157+
hex::decode("01b9ed21c23abf8c7a53fb868a36e106d45394c30127fb722f8dd2d45aae719585")
158+
.unwrap()
159+
);
160+
}
161+
103162
#[test]
104163
pub fn test_time_metadata() {
105164
let vector = time_metadata().access_vector();
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
address 0x1 {
22

3-
/// DFI Coin. The one and only.
3+
/// XFI Coin. The one and only.
44
/// Put into separate module to highlight its importance and role in Dfinance
55
/// ecosystem. Also moved not to be mistaken for peg-zone coin. Same-naming
6-
/// attack from peg-zone is impossible when DFI coin moved outside of Coins module
7-
module DFI {
6+
/// attack from peg-zone is impossible when XFI coin moved outside of Coins module
7+
module XFI {
88
struct T {}
99
}
1010
}

stdlib/tests/stdlib/coins.move

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ script {
99
}
1010

1111
//#eth_btc:4078
12-
//#btc_dfi:20
12+
//#btc_xfi:20
1313
script {
1414
use 0x01::Coins;
15-
use 0x01::DFI;
15+
use 0x01::XFI;
1616

1717
fun test_get_price() {
1818
assert(Coins::get_price<Coins::ETH, Coins::BTC>() == 4078, 1);
19-
assert(Coins::get_price<Coins::BTC, DFI::T>() == 20, 2);
19+
assert(Coins::get_price<Coins::BTC, XFI::T>() == 20, 2);
2020
}
2121
}
2222

2323
//#eth_btc:4078
2424
//#status:4008 MISSING_DATA
2525
script {
2626
use 0x01::Coins;
27-
use 0x01::DFI;
27+
use 0x01::XFI;
2828

2929
fun test_price_not_found() {
3030
assert(Coins::get_price<Coins::ETH, Coins::BTC>() == 4078, 1);
31-
assert(Coins::get_price<Coins::BTC, DFI::T>() == 20, 2);
31+
assert(Coins::get_price<Coins::BTC, XFI::T>() == 20, 2);
3232
}
3333
}

0 commit comments

Comments
 (0)