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,
|
||||
)
|
||||
|
||||
from planetmint.utils import Singleton
|
||||
from planetmint.abci.tendermint_utils import encode_transaction
|
||||
from planetmint.application.validator import logger
|
||||
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)
|
||||
|
||||
|
||||
class ABCI_RPC:
|
||||
class ABCI_RPC(metaclass=Singleton):
|
||||
def __init__(self):
|
||||
autoconfigure()
|
||||
self.tendermint_host = Config().get()["tendermint"]["host"]
|
||||
|
@ -70,9 +70,9 @@ class Output:
|
||||
def outputs_dict(output: dict, transaction_id: str = "") -> Output:
|
||||
out_dict: Output
|
||||
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:
|
||||
out_dict = output_with_sub_conditions(output, transaction_id)
|
||||
out_dict = Output.output_with_sub_conditions(output, transaction_id)
|
||||
return out_dict
|
||||
|
||||
@staticmethod
|
||||
@ -111,8 +111,8 @@ class Output:
|
||||
def list_to_dict(output_list: list[Output]) -> list[dict]:
|
||||
return [output.to_dict() for output in output_list or []]
|
||||
|
||||
|
||||
def output_with_public_key(output, transaction_id) -> Output:
|
||||
@staticmethod
|
||||
def output_with_public_key(output, transaction_id) -> Output:
|
||||
return Output(
|
||||
transaction_id=transaction_id,
|
||||
public_keys=output["public_keys"],
|
||||
@ -122,8 +122,8 @@ def output_with_public_key(output, transaction_id) -> Output:
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def output_with_sub_conditions(output, transaction_id) -> Output:
|
||||
@staticmethod
|
||||
def output_with_sub_conditions(output, transaction_id) -> Output:
|
||||
return Output(
|
||||
transaction_id=transaction_id,
|
||||
public_keys=output["public_keys"],
|
||||
|
@ -1,19 +1,10 @@
|
||||
import copy
|
||||
import logging
|
||||
import os
|
||||
|
||||
# from planetmint.log import DEFAULT_LOGGING_CONFIG as log_config
|
||||
from planetmint.version import __version__ # noqa
|
||||
from decouple import config
|
||||
|
||||
|
||||
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]
|
||||
from planetmint.utils import Singleton
|
||||
from planetmint.version import __version__
|
||||
|
||||
|
||||
class Config(metaclass=Singleton):
|
||||
|
@ -10,6 +10,15 @@ import multiprocessing
|
||||
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):
|
||||
"""Wrapper around multiprocessing.Process that uses
|
||||
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.skip(reason="mock_write overwrite doesn't work")
|
||||
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
|
||||
|
||||
@ -355,7 +354,7 @@ def test_election_new_upsert_validator_without_tendermint(caplog, b, priv_valida
|
||||
|
||||
with caplog.at_level(logging.INFO):
|
||||
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)
|
||||
|
||||
|
||||
@ -369,10 +368,9 @@ def test_election_new_chain_migration_with_tendermint(b, priv_validator_path, us
|
||||
|
||||
|
||||
@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 mock_write(tx, mode):
|
||||
b.models.store_bulk_transactions([tx])
|
||||
def mock_write(modelist, endpoint, mode_commit, transaction, mode):
|
||||
b.models.store_bulk_transactions([transaction])
|
||||
return (202, "")
|
||||
|
||||
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 transactions.common.exceptions import InvalidPowerChange
|
||||
|
||||
def mock_write(tx, mode):
|
||||
b.models.store_bulk_transactions([tx])
|
||||
def mock_write(modelist, endpoint, mode_commit, transaction, mode):
|
||||
b.models.store_bulk_transactions([transaction])
|
||||
return (400, "")
|
||||
|
||||
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):
|
||||
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
|
||||
@ -456,7 +454,6 @@ def test_election_approve_with_tendermint(b, priv_validator_path, user_sk, valid
|
||||
|
||||
|
||||
@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):
|
||||
from planetmint.commands.planetmint import run_election_approve
|
||||
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.skip(reason="mock_write overwrite doesn't work")
|
||||
def test_election_approve_failure(caplog, b, priv_validator_path, new_validator, node_key):
|
||||
from planetmint.commands.planetmint import run_election_approve
|
||||
from argparse import Namespace
|
||||
|
||||
b, election_id = call_election(b, new_validator, node_key)
|
||||
|
||||
def mock_write(tx, mode):
|
||||
b.models.store_bulk_transactions([tx])
|
||||
def mock_write(modelist, endpoint, mode_commit, transaction, mode):
|
||||
b.models.store_bulk_transactions([transaction])
|
||||
return (400, "")
|
||||
|
||||
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):
|
||||
assert not run_election_approve(args, b)
|
||||
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."
|
||||
)
|
||||
|
||||
@ -604,8 +600,8 @@ def mock_get_validators(height):
|
||||
|
||||
|
||||
def call_election(b, new_validator, node_key):
|
||||
def mock_write(tx, mode):
|
||||
b.models.store_bulk_transactions([tx])
|
||||
def mock_write(modelist, endpoint, mode_commit, transaction, mode):
|
||||
b.models.store_bulk_transactions([transaction])
|
||||
return (202, "")
|
||||
|
||||
# patch the validator set. We now have one validator with power 10
|
||||
|
Loading…
x
Reference in New Issue
Block a user