mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9230 from ethereum/issue-8716
Add unit denomination ``gwei``
This commit is contained in:
@@ -48,6 +48,7 @@ using Address = util::h160;
|
||||
// The various denominations; here for ease of use where needed within code.
|
||||
static const u256 wei = 1;
|
||||
static const u256 shannon = u256("1000000000");
|
||||
static const u256 gwei = shannon;
|
||||
static const u256 szabo = shannon * 1000;
|
||||
static const u256 finney = szabo * 1000;
|
||||
static const u256 ether = finney * 1000;
|
||||
|
||||
@@ -221,6 +221,21 @@ BOOST_AUTO_TEST_CASE(int_with_wei_ether_subdenomination)
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(int_with_gwei_ether_subdenomination)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function test () {
|
||||
uint x = 1 gwei;
|
||||
}
|
||||
}
|
||||
)";
|
||||
bytes code = compileFirstExpression(sourceCode);
|
||||
|
||||
bytes expectation({uint8_t(Instruction::PUSH4), 0x3b, 0x9a, 0xca, 0x00});
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(int_with_szabo_ether_subdenomination)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
|
||||
@@ -428,8 +428,9 @@ BOOST_AUTO_TEST_CASE(comments_mixed_in_sequence)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ether_subdenominations)
|
||||
{
|
||||
Scanner scanner(CharStream("wei szabo finney ether", ""));
|
||||
Scanner scanner(CharStream("wei gwei szabo finney ether", ""));
|
||||
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::SubWei);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::SubSzabo);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::SubFinney);
|
||||
BOOST_CHECK_EQUAL(scanner.next(), Token::SubEther);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
contract C {
|
||||
uint constant gwei = 1 gwei;
|
||||
|
||||
function f() public view returns(uint) { return gwei; }
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 1000000000
|
||||
|
||||
@@ -2,5 +2,6 @@ contract C {
|
||||
uint constant a = 1 wei + 2 szabo + 3 finney + 4 ether;
|
||||
uint constant b = 1 seconds + 2 minutes + 3 hours + 4 days + 5 weeks;
|
||||
uint constant c = 2 szabo / 1 seconds + 3 finney * 3 hours;
|
||||
uint constant d = 2 gwei / 1 seconds + 3 finney * 3 hours;
|
||||
}
|
||||
// ----
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
contract C {
|
||||
uint constant gwei = 1 gwei;
|
||||
}
|
||||
+4
-3
@@ -1,15 +1,16 @@
|
||||
contract c {
|
||||
contract C {
|
||||
function f() public
|
||||
{
|
||||
a = 1 wei;
|
||||
b = 2 szabo;
|
||||
c = 3 finney;
|
||||
b = 4 ether;
|
||||
d = 4 ether;
|
||||
e = 5 gwei;
|
||||
}
|
||||
uint256 a;
|
||||
uint256 b;
|
||||
uint256 c;
|
||||
uint256 d;
|
||||
uint256 e;
|
||||
}
|
||||
// ----
|
||||
// Warning 2519: (170-179): This declaration shadows an existing declaration.
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
" ether "
|
||||
" finney "
|
||||
" gasleft() "
|
||||
" gwei "
|
||||
" hours "
|
||||
" minutes "
|
||||
" msg.data "
|
||||
|
||||
Reference in New Issue
Block a user