Skip to content

Commit dfbeb70

Browse files
committed
micro -> nano
1 parent a4f4fd5 commit dfbeb70

2 files changed

Lines changed: 27 additions & 27 deletions

File tree

CodaClient.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010

1111
class CurrencyFormat(Enum):
1212
WHOLE = 1
13-
MICRO = 2
13+
NANO = 2
1414

1515
class CurrencyUnderflow(Exception):
1616
pass
1717

1818
class Currency():
1919
@classmethod
20-
def __microcodas_from_int(_cls, n):
20+
def __nanocodas_from_int(_cls, n):
2121
return n * 1000000000
2222

2323
@classmethod
24-
def __microcodas_from_string(_cls, s):
24+
def __nanocodas_from_string(_cls, s):
2525
segments = s.split('.')
2626
if len(segments) == 1:
2727
return int(segments[0])
@@ -35,30 +35,30 @@ def __microcodas_from_string(_cls, s):
3535
def __init__(self, value, format=CurrencyFormat.WHOLE):
3636
if format == CurrencyFormat.WHOLE:
3737
if isinstance(value, int):
38-
self.__microcodas = Currency.__microcodas_from_int(value)
38+
self.__nanocodas = Currency.__nanocodas_from_int(value)
3939
elif isinstance(value, float):
40-
self.__microcodas = Currency.__microcodas_from_string(str(value))
40+
self.__nanocodas = Currency.__nanocodas_from_string(str(value))
4141
elif isinstance(value, str):
42-
self.__microcodas = Currency.__microcodas_from_string(value)
42+
self.__nanocodas = Currency.__nanocodas_from_string(value)
4343
else:
4444
raise Exception('cannot construct whole Currency from %s' % type(value))
45-
elif format == CurrencyFormat.MICRO:
45+
elif format == CurrencyFormat.NANO:
4646
if isinstance(value, int):
47-
self.__microcodas = value
47+
self.__nanocodas = value
4848
else:
49-
raise Exception('cannot construct micro Currency from %s' % type(value))
49+
raise Exception('cannot construct nano Currency from %s' % type(value))
5050
else:
5151
raise Exception('invalid Currency format %s' % format)
5252

5353
def decimal_format(self):
54-
s = str(self.__microcodas)
54+
s = str(self.__nanocodas)
5555
if len(s) > 9:
5656
return s[:-9] + '.' + s[-9:]
5757
else:
5858
return '0.' + ('0' * (9 - len(s))) + s
5959

60-
def microcodas(self):
61-
return self.__microcodas
60+
def nanocodas(self):
61+
return self.__nanocodas
6262

6363
def __str__(self):
6464
return self.decimal_format()
@@ -68,25 +68,25 @@ def __repr__(self):
6868

6969
def __add__(self, other):
7070
if isinstance(other, Currency):
71-
return Currency(self.microcodas() + other.microcodas(), format=CurrencyFormat.MICRO)
71+
return Currency(self.nanocodas() + other.nanocodas(), format=CurrencyFormat.NANO)
7272
else:
7373
raise Exception('cannot add Currency and %s' % type(other))
7474

7575
def __sub__(self, other):
7676
if isinstance(other, Currency):
77-
new_value = self.microcodas() - other.microcodas()
77+
new_value = self.nanocodas() - other.nanocodas()
7878
if new_value >= 0:
79-
return Currency(new_value, format=CurrencyFormat.MICRO)
79+
return Currency(new_value, format=CurrencyFormat.NANO)
8080
else:
8181
raise CurrencyUnderflow()
8282
else:
8383
raise Exception('cannot subtract Currency and %s' % type(other))
8484

8585
def __mul__(self, other):
8686
if isinstance(other, int):
87-
return Currency(self.microcodas() * other, format=CurrencyFormat.MICRO)
87+
return Currency(self.nanocodas() * other, format=CurrencyFormat.NANO)
8888
elif isinstance(other, Currency):
89-
return Currency(self.microcodas() * other.microcodas(), format=CurrencyFormat.MICRO)
89+
return Currency(self.nanocodas() * other.nanocodas(), format=CurrencyFormat.NANO)
9090
else:
9191
raise Exception('cannot multiply Currency and %s' % type(other))
9292

@@ -507,8 +507,8 @@ def send_payment(self, to_pk: str, from_pk: str, amount: Currency, fee: Currency
507507
variables = {
508508
"from": from_pk,
509509
"to": to_pk,
510-
"amount": amount.microcodas(),
511-
"fee": fee.microcodas(),
510+
"amount": amount.nanocodas(),
511+
"fee": fee.nanocodas(),
512512
"memo": memo
513513
}
514514
res = self._send_mutation(query, variables)

tests/test_currency.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44

55
def test_constructor_whole_int():
66
n = 500
7-
assert Currency(n).microcodas() == n * precision
7+
assert Currency(n).nanocodas() == n * precision
88

99
def test_constructor_whole_float():
1010
n = 5.5
11-
assert Currency(n).microcodas() == n * precision
11+
assert Currency(n).nanocodas() == n * precision
1212

1313
def test_constructor_whole_string():
1414
n = "5.5"
15-
assert Currency(n).microcodas() == float(n) * precision
15+
assert Currency(n).nanocodas() == float(n) * precision
1616

17-
def test_constructor_micro_int():
17+
def test_constructor_nano_int():
1818
n = 500
1919
assert Currency(n, format=CurrencyFormat.MICRO)
2020

2121
def test_add():
22-
assert (Currency(5) + Currency(2)).microcodas() == 7 * precision
22+
assert (Currency(5) + Currency(2)).nanocodas() == 7 * precision
2323

2424
def test_sub():
25-
assert (Currency(5) - Currency(2)).microcodas() == 3 * precision
25+
assert (Currency(5) - Currency(2)).nanocodas() == 3 * precision
2626

2727
def test_sub_underflow():
2828
try:
@@ -34,7 +34,7 @@ def test_sub_underflow():
3434
raise
3535

3636
def test_mul_int():
37-
assert (Currency(5) * 2).microcodas() == 10 * precision
37+
assert (Currency(5) * 2).nanocodas() == 10 * precision
3838

3939
def test_mul_currency():
40-
assert (Currency(5) * Currency(2, format=CurrencyFormat.MICRO)).microcodas() == 10 * precision
40+
assert (Currency(5) * Currency(2, format=CurrencyFormat.MICRO)).nanocodas() == 10 * precision

0 commit comments

Comments
 (0)