mirror of
https://github.com/planetmint/planetmint.git
synced 2025-07-01 10:22:30 +00:00
reintegrated disabled tests
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
6aa37cf6a6
commit
c6b22a8e8c
@ -7,6 +7,7 @@ from transactions.common.transaction_mode_types import (
|
|||||||
BROADCAST_TX_SYNC,
|
BROADCAST_TX_SYNC,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from planetmint.utils import Singleton
|
||||||
from planetmint.abci.tendermint_utils import encode_transaction
|
from planetmint.abci.tendermint_utils import encode_transaction
|
||||||
from planetmint.application.validator import logger
|
from planetmint.application.validator import logger
|
||||||
from planetmint.config_utils import autoconfigure
|
from planetmint.config_utils import autoconfigure
|
||||||
@ -16,7 +17,7 @@ MODE_COMMIT = BROADCAST_TX_COMMIT
|
|||||||
MODE_LIST = (BROADCAST_TX_ASYNC, BROADCAST_TX_SYNC, MODE_COMMIT)
|
MODE_LIST = (BROADCAST_TX_ASYNC, BROADCAST_TX_SYNC, MODE_COMMIT)
|
||||||
|
|
||||||
|
|
||||||
class ABCI_RPC:
|
class ABCI_RPC(metaclass=Singleton):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
autoconfigure()
|
autoconfigure()
|
||||||
self.tendermint_host = Config().get()["tendermint"]["host"]
|
self.tendermint_host = Config().get()["tendermint"]["host"]
|
||||||
|
@ -70,9 +70,9 @@ class Output:
|
|||||||
def outputs_dict(output: dict, transaction_id: str = "") -> Output:
|
def outputs_dict(output: dict, transaction_id: str = "") -> Output:
|
||||||
out_dict: Output
|
out_dict: Output
|
||||||
if output["condition"]["details"].get("subconditions") is None:
|
if output["condition"]["details"].get("subconditions") is None:
|
||||||
out_dict = output_with_public_key(output, transaction_id)
|
out_dict = Output.output_with_public_key(output, transaction_id)
|
||||||
else:
|
else:
|
||||||
out_dict = output_with_sub_conditions(output, transaction_id)
|
out_dict = Output.output_with_sub_conditions(output, transaction_id)
|
||||||
return out_dict
|
return out_dict
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -111,24 +111,24 @@ class Output:
|
|||||||
def list_to_dict(output_list: list[Output]) -> list[dict]:
|
def list_to_dict(output_list: list[Output]) -> list[dict]:
|
||||||
return [output.to_dict() for output in output_list or []]
|
return [output.to_dict() for output in output_list or []]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def output_with_public_key(output, transaction_id) -> Output:
|
||||||
|
return Output(
|
||||||
|
transaction_id=transaction_id,
|
||||||
|
public_keys=output["public_keys"],
|
||||||
|
amount=output["amount"],
|
||||||
|
condition=Condition(
|
||||||
|
uri=output["condition"]["uri"], details=ConditionDetails.from_dict(output["condition"]["details"])
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
def output_with_public_key(output, transaction_id) -> Output:
|
@staticmethod
|
||||||
return Output(
|
def output_with_sub_conditions(output, transaction_id) -> Output:
|
||||||
transaction_id=transaction_id,
|
return Output(
|
||||||
public_keys=output["public_keys"],
|
transaction_id=transaction_id,
|
||||||
amount=output["amount"],
|
public_keys=output["public_keys"],
|
||||||
condition=Condition(
|
amount=output["amount"],
|
||||||
uri=output["condition"]["uri"], details=ConditionDetails.from_dict(output["condition"]["details"])
|
condition=Condition(
|
||||||
),
|
uri=output["condition"]["uri"], details=ConditionDetails.from_dict(output["condition"]["details"])
|
||||||
)
|
),
|
||||||
|
)
|
||||||
|
|
||||||
def output_with_sub_conditions(output, transaction_id) -> Output:
|
|
||||||
return Output(
|
|
||||||
transaction_id=transaction_id,
|
|
||||||
public_keys=output["public_keys"],
|
|
||||||
amount=output["amount"],
|
|
||||||
condition=Condition(
|
|
||||||
uri=output["condition"]["uri"], details=ConditionDetails.from_dict(output["condition"]["details"])
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
@ -1,19 +1,10 @@
|
|||||||
import copy
|
import copy
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# from planetmint.log import DEFAULT_LOGGING_CONFIG as log_config
|
|
||||||
from planetmint.version import __version__ # noqa
|
|
||||||
from decouple import config
|
from decouple import config
|
||||||
|
|
||||||
|
from planetmint.utils import Singleton
|
||||||
class Singleton(type):
|
from planetmint.version import __version__
|
||||||
_instances = {}
|
|
||||||
|
|
||||||
def __call__(cls, *args, **kwargs):
|
|
||||||
if cls not in cls._instances:
|
|
||||||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
|
||||||
return cls._instances[cls]
|
|
||||||
|
|
||||||
|
|
||||||
class Config(metaclass=Singleton):
|
class Config(metaclass=Singleton):
|
||||||
|
@ -10,6 +10,15 @@ import multiprocessing
|
|||||||
import setproctitle
|
import setproctitle
|
||||||
|
|
||||||
|
|
||||||
|
class Singleton(type):
|
||||||
|
_instances = {}
|
||||||
|
|
||||||
|
def __call__(cls, *args, **kwargs):
|
||||||
|
if cls not in cls._instances:
|
||||||
|
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
|
||||||
|
return cls._instances[cls]
|
||||||
|
|
||||||
|
|
||||||
class Process(multiprocessing.Process):
|
class Process(multiprocessing.Process):
|
||||||
"""Wrapper around multiprocessing.Process that uses
|
"""Wrapper around multiprocessing.Process that uses
|
||||||
setproctitle to set the name of the process when running
|
setproctitle to set the name of the process when running
|
||||||
|
@ -330,7 +330,6 @@ def test_election_new_upsert_validator_with_tendermint(b, priv_validator_path, u
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.bdb
|
@pytest.mark.bdb
|
||||||
@pytest.mark.skip(reason="mock_write overwrite doesn't work")
|
|
||||||
def test_election_new_upsert_validator_without_tendermint(caplog, b, priv_validator_path, user_sk):
|
def test_election_new_upsert_validator_without_tendermint(caplog, b, priv_validator_path, user_sk):
|
||||||
from planetmint.commands.planetmint import run_election_new_upsert_validator
|
from planetmint.commands.planetmint import run_election_new_upsert_validator
|
||||||
|
|
||||||
@ -355,7 +354,7 @@ def test_election_new_upsert_validator_without_tendermint(caplog, b, priv_valida
|
|||||||
|
|
||||||
with caplog.at_level(logging.INFO):
|
with caplog.at_level(logging.INFO):
|
||||||
election_id = run_election_new_upsert_validator(args, b)
|
election_id = run_election_new_upsert_validator(args, b)
|
||||||
assert caplog.records[0].msg == "[SUCCESS] Submitted proposal with id: " + election_id
|
assert caplog.records[1].msg == "[SUCCESS] Submitted proposal with id: " + election_id
|
||||||
assert b.models.get_transaction(election_id)
|
assert b.models.get_transaction(election_id)
|
||||||
|
|
||||||
|
|
||||||
@ -369,10 +368,9 @@ def test_election_new_chain_migration_with_tendermint(b, priv_validator_path, us
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.bdb
|
@pytest.mark.bdb
|
||||||
@pytest.mark.skip(reason="mock_write overwrite doesn't work")
|
|
||||||
def test_election_new_chain_migration_without_tendermint(caplog, b, priv_validator_path, user_sk):
|
def test_election_new_chain_migration_without_tendermint(caplog, b, priv_validator_path, user_sk):
|
||||||
def mock_write(tx, mode):
|
def mock_write(modelist, endpoint, mode_commit, transaction, mode):
|
||||||
b.models.store_bulk_transactions([tx])
|
b.models.store_bulk_transactions([transaction])
|
||||||
return (202, "")
|
return (202, "")
|
||||||
|
|
||||||
b.models.get_validators = mock_get_validators
|
b.models.get_validators = mock_get_validators
|
||||||
@ -410,8 +408,8 @@ def test_election_new_upsert_validator_invalid_power(caplog, b, priv_validator_p
|
|||||||
from planetmint.commands.planetmint import run_election_new_upsert_validator
|
from planetmint.commands.planetmint import run_election_new_upsert_validator
|
||||||
from transactions.common.exceptions import InvalidPowerChange
|
from transactions.common.exceptions import InvalidPowerChange
|
||||||
|
|
||||||
def mock_write(tx, mode):
|
def mock_write(modelist, endpoint, mode_commit, transaction, mode):
|
||||||
b.models.store_bulk_transactions([tx])
|
b.models.store_bulk_transactions([transaction])
|
||||||
return (400, "")
|
return (400, "")
|
||||||
|
|
||||||
ABCI_RPC().write_transaction = mock_write
|
ABCI_RPC().write_transaction = mock_write
|
||||||
@ -428,7 +426,7 @@ def test_election_new_upsert_validator_invalid_power(caplog, b, priv_validator_p
|
|||||||
|
|
||||||
with caplog.at_level(logging.ERROR):
|
with caplog.at_level(logging.ERROR):
|
||||||
assert not run_election_new_upsert_validator(args, b)
|
assert not run_election_new_upsert_validator(args, b)
|
||||||
assert caplog.records[1].msg.__class__ == InvalidPowerChange
|
assert caplog.records[0].msg.__class__ == InvalidPowerChange
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.abci
|
@pytest.mark.abci
|
||||||
@ -456,7 +454,6 @@ def test_election_approve_with_tendermint(b, priv_validator_path, user_sk, valid
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.bdb
|
@pytest.mark.bdb
|
||||||
@pytest.mark.skip(reason="mock_write overwrite doesn't work")
|
|
||||||
def test_election_approve_without_tendermint(caplog, b, priv_validator_path, new_validator, node_key):
|
def test_election_approve_without_tendermint(caplog, b, priv_validator_path, new_validator, node_key):
|
||||||
from planetmint.commands.planetmint import run_election_approve
|
from planetmint.commands.planetmint import run_election_approve
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
@ -474,15 +471,14 @@ def test_election_approve_without_tendermint(caplog, b, priv_validator_path, new
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.bdb
|
@pytest.mark.bdb
|
||||||
@pytest.mark.skip(reason="mock_write overwrite doesn't work")
|
|
||||||
def test_election_approve_failure(caplog, b, priv_validator_path, new_validator, node_key):
|
def test_election_approve_failure(caplog, b, priv_validator_path, new_validator, node_key):
|
||||||
from planetmint.commands.planetmint import run_election_approve
|
from planetmint.commands.planetmint import run_election_approve
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
|
|
||||||
b, election_id = call_election(b, new_validator, node_key)
|
b, election_id = call_election(b, new_validator, node_key)
|
||||||
|
|
||||||
def mock_write(tx, mode):
|
def mock_write(modelist, endpoint, mode_commit, transaction, mode):
|
||||||
b.models.store_bulk_transactions([tx])
|
b.models.store_bulk_transactions([transaction])
|
||||||
return (400, "")
|
return (400, "")
|
||||||
|
|
||||||
ABCI_RPC().write_transaction = mock_write
|
ABCI_RPC().write_transaction = mock_write
|
||||||
@ -508,7 +504,7 @@ def test_election_approve_called_with_bad_key(caplog, b, bad_validator_path, new
|
|||||||
with caplog.at_level(logging.ERROR):
|
with caplog.at_level(logging.ERROR):
|
||||||
assert not run_election_approve(args, b)
|
assert not run_election_approve(args, b)
|
||||||
assert (
|
assert (
|
||||||
caplog.records[1].msg == "The key you provided does not match any of "
|
caplog.records[0].msg == "The key you provided does not match any of "
|
||||||
"the eligible voters in this election."
|
"the eligible voters in this election."
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -604,8 +600,8 @@ def mock_get_validators(height):
|
|||||||
|
|
||||||
|
|
||||||
def call_election(b, new_validator, node_key):
|
def call_election(b, new_validator, node_key):
|
||||||
def mock_write(tx, mode):
|
def mock_write(modelist, endpoint, mode_commit, transaction, mode):
|
||||||
b.models.store_bulk_transactions([tx])
|
b.models.store_bulk_transactions([transaction])
|
||||||
return (202, "")
|
return (202, "")
|
||||||
|
|
||||||
# patch the validator set. We now have one validator with power 10
|
# patch the validator set. We now have one validator with power 10
|
||||||
|
Loading…
x
Reference in New Issue
Block a user