-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1461 from multiversx/feat/managed-decimal
Feature: ManagedDecimal
- Loading branch information
Showing
31 changed files
with
5,248 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
contracts/feature-tests/basic-features/scenarios/managed_decimal.scen.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
{ | ||
"steps": [ | ||
{ | ||
"step": "setState", | ||
"accounts": { | ||
"sc:basic-features": { | ||
"nonce": "0", | ||
"balance": "0", | ||
"code": "mxsc:../output/basic-features.mxsc.json" | ||
}, | ||
"address:an_account": { | ||
"nonce": "0", | ||
"balance": "0" | ||
} | ||
} | ||
}, | ||
{ | ||
"step": "scCall", | ||
"id": "1", | ||
"tx": { | ||
"from": "address:an_account", | ||
"to": "sc:basic-features", | ||
"function": "managed_decimal_addition", | ||
"arguments": [ | ||
"4", | ||
"5" | ||
], | ||
"gasLimit": "1,000,000,000,000", | ||
"gasPrice": "0" | ||
}, | ||
"expect": { | ||
"out": [ | ||
"9" | ||
] | ||
} | ||
}, | ||
{ | ||
"step": "scCall", | ||
"id": "1", | ||
"tx": { | ||
"from": "address:an_account", | ||
"to": "sc:basic-features", | ||
"function": "managed_decimal_subtraction", | ||
"arguments": [ | ||
"9", | ||
"4" | ||
], | ||
"gasLimit": "1,000,000,000,000", | ||
"gasPrice": "0" | ||
}, | ||
"expect": { | ||
"out": [ | ||
"5" | ||
] | ||
} | ||
}, | ||
{ | ||
"step": "scCall", | ||
"id": "2", | ||
"tx": { | ||
"from": "address:an_account", | ||
"to": "sc:basic-features", | ||
"function": "managed_decimal_subtraction", | ||
"arguments": [ | ||
"2", | ||
"8" | ||
], | ||
"gasLimit": "1,000,000,000,000", | ||
"gasPrice": "0" | ||
}, | ||
"expect": { | ||
"out": [], | ||
"status": "4", | ||
"message": "str:cannot subtract because result would be negative", | ||
"gas": "*", | ||
"refund": "*" | ||
} | ||
}, | ||
{ | ||
"step": "scCall", | ||
"id": "3", | ||
"tx": { | ||
"from": "address:an_account", | ||
"to": "sc:basic-features", | ||
"function": "managed_decimal_eq", | ||
"arguments": [ | ||
"13", | ||
"13" | ||
], | ||
"gasLimit": "1,000,000,000,000", | ||
"gasPrice": "0" | ||
}, | ||
"expect": { | ||
"out": [ | ||
"0x01" | ||
], | ||
"status": "", | ||
"message": "*", | ||
"gas": "*", | ||
"refund": "*" | ||
} | ||
}, | ||
{ | ||
"step": "scCall", | ||
"id": "4", | ||
"tx": { | ||
"from": "address:an_account", | ||
"to": "sc:basic-features", | ||
"function": "managed_decimal_trunc", | ||
"arguments": [], | ||
"gasLimit": "1,000,000,000,000", | ||
"gasPrice": "0" | ||
}, | ||
"expect": { | ||
"out": [ | ||
"313" | ||
], | ||
"status": "", | ||
"message": "*", | ||
"gas": "*", | ||
"refund": "*" | ||
} | ||
}, | ||
{ | ||
"step": "scCall", | ||
"id": "5", | ||
"tx": { | ||
"from": "address:an_account", | ||
"to": "sc:basic-features", | ||
"function": "managed_decimal_into_raw_units", | ||
"arguments": [], | ||
"gasLimit": "1,000,000,000,000", | ||
"gasPrice": "0" | ||
}, | ||
"expect": { | ||
"out": [ | ||
"12345" | ||
], | ||
"status": "", | ||
"message": "*", | ||
"gas": "*", | ||
"refund": "*" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
contracts/feature-tests/basic-features/src/egld_decimal.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
multiversx_sc::imports!(); | ||
|
||
/// Used for testing the egld_decimal function return type | ||
#[multiversx_sc::module] | ||
pub trait EgldDecimal { | ||
#[payable("EGLD")] | ||
#[endpoint] | ||
fn returns_egld_decimal(&self) -> ManagedDecimal<Self::Api, ConstDecimals<18>> { | ||
self.call_value().egld_decimal() | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
contracts/feature-tests/basic-features/src/managed_decimal_features.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
multiversx_sc::imports!(); | ||
|
||
#[multiversx_sc::module] | ||
pub trait ManagedDecimalFeatures { | ||
#[endpoint] | ||
fn managed_decimal_addition( | ||
&self, | ||
first: ManagedDecimal<Self::Api, ConstDecimals<2>>, | ||
second: ManagedDecimal<Self::Api, ConstDecimals<2>>, | ||
) -> ManagedDecimal<Self::Api, ConstDecimals<2>> { | ||
first + second | ||
} | ||
|
||
#[endpoint] | ||
fn managed_decimal_subtraction( | ||
&self, | ||
first: ManagedDecimal<Self::Api, ConstDecimals<2>>, | ||
second: ManagedDecimal<Self::Api, ConstDecimals<2>>, | ||
) -> ManagedDecimal<Self::Api, ConstDecimals<2>> { | ||
first - second | ||
} | ||
|
||
#[endpoint] | ||
fn managed_decimal_eq( | ||
&self, | ||
first: ManagedDecimal<Self::Api, ConstDecimals<2>>, | ||
second: ManagedDecimal<Self::Api, ConstDecimals<2>>, | ||
) -> bool { | ||
first.eq(&second) | ||
} | ||
|
||
#[endpoint] | ||
fn managed_decimal_trunc(&self) -> BigUint { | ||
let dec = ManagedDecimal::from_raw_units(BigUint::from(31332u64), 2usize); | ||
dec.trunc() | ||
} | ||
|
||
#[endpoint] | ||
fn managed_decimal_into_raw_units(&self) -> BigUint { | ||
let dec = ManagedDecimal::from_raw_units(BigUint::from(12345u64), 2usize); | ||
dec.into_raw_units().clone() | ||
} | ||
} |
Oops, something went wrong.