Skip to content

Commit

Permalink
Merge pull request #239 from anikitinDSR/public/fix_get_fees
Browse files Browse the repository at this point in the history
[FIX_GET_FEES] fix result of GET_FEES when fees doesn't exist in the …
  • Loading branch information
anikitinDSR committed May 23, 2019
2 parents 785e6ff + 545dfb3 commit 1326d91
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion devops/Makefile
Expand Up @@ -53,7 +53,7 @@ ifeq ($(SRC_DIR_NAME),sovtoken)
# pypi: indy-plenum
# apt: indy-plenum (stable component)

FPM_P_DEPENDS := indy-node(=1.8.0~dev935)
FPM_P_DEPENDS := indy-node(=1.8.0~dev943)
FPM_ARGS := --no-python-dependencies $(FPM_ARGS)
endif

Expand Down
5 changes: 5 additions & 0 deletions sovtoken/sovtoken/test/helpers/helper_node.py
Expand Up @@ -14,6 +14,11 @@ class HelperNode():
def __init__(self, nodes):
self._nodes = nodes

def get_primary_node(self):
for n in self._nodes:
if n.master_replica.isPrimary:
return n

def get_last_ledger_transaction_on_nodes(self, ledger_id):
""" Return last transaction stored on ledger from each node. """
transactions = []
Expand Down
5 changes: 3 additions & 2 deletions sovtokenfees/sovtokenfees/static_fee_req_handler.py
Expand Up @@ -177,7 +177,8 @@ def updateState(self, txns, isCommitted=False):
def get_fees(self, request: Request):
fees, proof = self._get_fees(is_committed=True, with_proof=True)
result = {f.IDENTIFIER.nm: request.identifier,
f.REQ_ID.nm: request.reqId, FEES: fees}
f.REQ_ID.nm: request.reqId,
FEES: fees}
if proof:
result[STATE_PROOF] = proof
result.update(request.operation)
Expand Down Expand Up @@ -248,7 +249,7 @@ def _get_fees(self, is_committed=False, with_proof=False):
with_proof=with_proof)
if with_proof:
fees, proof = result
return fees, proof if fees is not None else ({}, None)
return (fees, proof) if fees is not None else ({}, proof)
else:
return result if result is not None else {}

Expand Down
40 changes: 40 additions & 0 deletions sovtokenfees/sovtokenfees/test/test_get_fees_from_empty_state.py
@@ -0,0 +1,40 @@
from indy_common.constants import CONFIG_LEDGER_ID

from plenum.common.constants import AUDIT_LEDGER_ID
from sovtokenfees.constants import FEES
from sovtokenfees.domain import build_path_for_set_fees
from sovtokenfees.fees_authorizer import FeesAuthorizer
from sovtokenfees.static_fee_req_handler import StaticFeesReqHandler

from stp_core.loop.eventually import eventually

from plenum.test.txn_author_agreement.helper import check_state_proof

from state.pruning_state import PruningState

from storage.kv_in_memory import KeyValueStorageInMemory


def test_get_fees_when_no_fees_set(helpers, looper):
def _freshness_done():
assert audit_ledger.size == length_after + 1

for n in helpers.node._nodes:
curr_state = n.states[CONFIG_LEDGER_ID]
curr_state.remove(build_path_for_set_fees().encode())
"""
Update config state
"""
primary = helpers.node.get_primary_node()
audit_ledger = primary.getLedger(AUDIT_LEDGER_ID)
length_after = audit_ledger.size
primary.master_replica._do_send_3pc_batch(ledger_id=CONFIG_LEDGER_ID)
looper.run(eventually(_freshness_done))
"""
GET_FEES
"""
response = helpers.general.do_get_fees()
ledger_fees = response[FEES]
assert ledger_fees == {}
check_state_proof(response, build_path_for_set_fees(), None)
helpers.node.assert_set_fees_in_memory({})
10 changes: 5 additions & 5 deletions sovtokenfees/sovtokenfees/test/test_set_get_fees.py
Expand Up @@ -3,7 +3,7 @@
import pytest

from common.serializers.serialization import state_roots_serializer
from plenum.common.constants import NYM, PROOF_NODES, ROOT_HASH, STATE_PROOF
from plenum.common.constants import NYM, PROOF_NODES, ROOT_HASH, STATE_PROOF, AUDIT_LEDGER_ID
from plenum.common.exceptions import (RequestNackedException,
RequestRejectedException, PoolLedgerTimeoutException)
from plenum.common.txn_util import get_seq_no
Expand All @@ -19,11 +19,11 @@
from state.trie.pruning_trie import Trie, rlp_encode
from storage.kv_in_memory import KeyValueStorageInMemory

from indy_common.constants import CONFIG_LEDGER_ID

def test_get_fees_when_no_fees_set(helpers):
ledger_fees = helpers.general.do_get_fees()[FEES]
assert ledger_fees == {}
helpers.node.assert_set_fees_in_memory({})
from stp_core.loop.eventually import eventually

from plenum.test.txn_author_agreement.helper import check_state_proof


def test_set_fees_invalid_numeric(helpers):
Expand Down

0 comments on commit 1326d91

Please sign in to comment.