コード例 #1
0
ファイル: utils.py プロジェクト: BlockScience/TheGraph
def convertFromLongStrToEth(d, field):
    for events in d.values():
        for event in events:
            # sometimes it comes in as a number, sometimes as a string
            event[field] = str(event[field])

            # put in a decimal place 18 chars from the right then convert to Decimal to avoid overflow error.
            try:
                if event[field] == 'nan':
                    event[field] = Decimal(0)
                else:
                    floatValue = float(event[field])
                    intValue = int(floatValue)
                    event[field] = from_wei(intValue, 'ether')
            except:
                print("Unexpected error:", traceback.format_exc())
                sys.exit()
                event[field] = Decimal(0)
コード例 #2
0
ファイル: token.py プロジェクト: zaxayn/nucypher
 def to_tokens(self) -> Decimal:
     """Returns an decimal value of NU"""
     return currency.from_wei(self.__value, unit='ether')
コード例 #3
0
def test_from_wei(value, expected):
    assert from_wei(*value) == decimal.Decimal(expected)
コード例 #4
0
def test_conversion_revers_round_trip_trip(amount_in_ether):
    intermediate_amount = to_wei(amount_in_ether, 'ether')
    result_amount = from_wei(intermediate_amount, 'ether')
    assert decimal.Decimal(result_amount) == decimal.Decimal(
        str(amount_in_ether))
コード例 #5
0
def test_conversion_round_trip(amount_in_wei, intermediate_unit):
    intermediate_amount = from_wei(amount_in_wei, intermediate_unit)
    result_amount = to_wei(intermediate_amount, intermediate_unit)
    assert result_amount == amount_in_wei
コード例 #6
0
def test_invalid_to_wei_values(value, unit):
    with pytest.raises(ValueError):
        to_wei(value, unit)

    with pytest.raises(ValueError):
        from_wei(value, unit)