github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/test/util/gtest_currency.cpp (about)

     1  // Copyright (C) 2018 go-nebulas authors
     2  //
     3  // This file is part of the go-nebulas library.
     4  //
     5  // the go-nebulas library is free software: you can redistribute it and/or
     6  // modify
     7  // it under the terms of the GNU General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // (at your option) any later version.
    10  //
    11  // the go-nebulas library is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU General Public License
    17  // along with the go-nebulas library.  If not, see
    18  // <http://www.gnu.org/licenses/>.
    19  //
    20  #include "common/nebulas_currency.h"
    21  #include <gtest/gtest.h>
    22  
    23  TEST(test_currency, simple) {
    24    neb::nas v3(1089238_nas);
    25    neb::nas_storage_t vs = neb::nas_to_storage(v3);
    26    neb::nas v4 = neb::storage_to_nas<neb::nas>(vs);
    27    EXPECT_EQ(v3, v4);
    28  }
    29  
    30  TEST(test_currency, neg) {
    31    neb::nas v0;
    32    neb::nas v1(1089238_nas);
    33    neb::nas v3 = v0 - v1;
    34    neb::nas_storage_t vs = neb::nas_to_storage(v3);
    35    neb::nas v4 = neb::storage_to_nas<neb::nas>(vs);
    36    EXPECT_EQ(v3, v4);
    37  }
    38  
    39  TEST(test_currency, to_storage_and_from_storage) {
    40    neb::nas v0 = 1_nas;
    41    std::cout << v0 << std::endl;
    42    auto tmp = neb::wei_to_storage(v0.wei_value());
    43    neb::wei v1 = neb::storage_to_wei(tmp);
    44    std::cout << v1 << std::endl;
    45  }