Skip to content

Commit 7bee2d1

Browse files
Added Decimal type for nonce purposes (#663)
* Added Decimal type for comparison. * Black. * Modified tests. Bump version to v2.1.3. * Adds conversion to string for nonce saving through sql. * Fix test helps. --------- Co-authored-by: Calina Cenan <calina@cenan.net>
1 parent 10e0f39 commit 7bee2d1

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.1.2
2+
current_version = 2.1.3
33
commit = True
44
tag = True
55

ocean_provider/routes/consume.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
import json
66
import logging
7+
from _decimal import Decimal
78

89
from flask import jsonify, request
910
from flask_sieve import validate
@@ -74,11 +75,13 @@ def nonce():
7475
new_nonce = 1
7576
update_nonce(address, new_nonce)
7677
nonce = get_nonce(address)
77-
assert int(nonce) == new_nonce, "New nonce could not be stored correctly."
78+
assert Decimal(nonce) == Decimal(
79+
new_nonce
80+
), "New nonce could not be stored correctly."
7881

7982
logger.info(f"nonce for user {address} is {nonce}")
8083

81-
response = jsonify(nonce=int(nonce)), 200
84+
response = jsonify(nonce=Decimal(nonce)), 200
8285
logger.info(f"nonce response = {response}")
8386

8487
return response

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
url="https://github.com/oceanprotocol/provider-py",
101101
# fmt: off
102102
# bumpversion needs single quotes
103-
version='2.1.2',
103+
version='2.1.3',
104104
# fmt: on
105105
zip_safe=False,
106106
)

tests/helpers/nonce.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import time
2+
from _decimal import Decimal
23

34
from ocean_provider.user_nonce import get_nonce, update_nonce
45

56

6-
def build_nonce(address) -> int:
7+
def build_nonce(address) -> Decimal:
78
nonce = get_nonce(address)
89
if nonce:
910
nonce = int(float(nonce)) + 1
1011
update_nonce(address, nonce)
1112

12-
return int(nonce)
13+
return Decimal(nonce)
1314

1415
update_nonce(address, 1)
15-
return 1
16+
return Decimal(1)
1617

1718

1819
def build_nonce_for_compute() -> int:

tests/test_routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
import datetime
66
import json
7+
from _decimal import Decimal
78

89
import pytest
910
from ocean_provider.constants import BaseURLs
@@ -99,7 +100,7 @@ def test_get_nonce(client, publisher_wallet):
99100
), f"get nonce endpoint failed: response status {response.status}, data {response.data}"
100101

101102
value = response.json if response.json else json.loads(response.data)
102-
assert value["nonce"] == get_nonce(address)
103+
assert Decimal(value["nonce"]) == Decimal(get_nonce(address))
103104

104105

105106
def test_timestamp_format_nonce(client, ganache_wallet, consumer_wallet, web3):

0 commit comments

Comments
 (0)