Skip to content

Commit

Permalink
Added Decimal type for nonce purposes (#663)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
mariacarmina and calina-c authored Sep 7, 2023
1 parent 10e0f39 commit 7bee2d1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.1.2
current_version = 2.1.3
commit = True
tag = True

Expand Down
7 changes: 5 additions & 2 deletions ocean_provider/routes/consume.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
import json
import logging
from _decimal import Decimal

from flask import jsonify, request
from flask_sieve import validate
Expand Down Expand Up @@ -74,11 +75,13 @@ def nonce():
new_nonce = 1
update_nonce(address, new_nonce)
nonce = get_nonce(address)
assert int(nonce) == new_nonce, "New nonce could not be stored correctly."
assert Decimal(nonce) == Decimal(
new_nonce
), "New nonce could not be stored correctly."

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

response = jsonify(nonce=int(nonce)), 200
response = jsonify(nonce=Decimal(nonce)), 200
logger.info(f"nonce response = {response}")

return response
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
url="https://github.com/oceanprotocol/provider-py",
# fmt: off
# bumpversion needs single quotes
version='2.1.2',
version='2.1.3',
# fmt: on
zip_safe=False,
)
7 changes: 4 additions & 3 deletions tests/helpers/nonce.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import time
from _decimal import Decimal

from ocean_provider.user_nonce import get_nonce, update_nonce


def build_nonce(address) -> int:
def build_nonce(address) -> Decimal:
nonce = get_nonce(address)
if nonce:
nonce = int(float(nonce)) + 1
update_nonce(address, nonce)

return int(nonce)
return Decimal(nonce)

update_nonce(address, 1)
return 1
return Decimal(1)


def build_nonce_for_compute() -> int:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
import datetime
import json
from _decimal import Decimal

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

value = response.json if response.json else json.loads(response.data)
assert value["nonce"] == get_nonce(address)
assert Decimal(value["nonce"]) == Decimal(get_nonce(address))


def test_timestamp_format_nonce(client, ganache_wallet, consumer_wallet, web3):
Expand Down

0 comments on commit 7bee2d1

Please sign in to comment.