Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2023-05-24 09:18:25 +02:00
parent a1803a8041
commit 2a14c707d2
No known key found for this signature in database
18 changed files with 33 additions and 34 deletions

View File

@ -1,3 +1,4 @@
---
# Copyright © 2020 Interplanetary Database Association e.V.,
# Planetmint and IPDB software contributors.
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)

View File

@ -120,11 +120,8 @@ def test_env_config(monkeypatch):
assert result == expected
@pytest.mark.skip
def test_autoconfigure_read_both_from_file_and_env(
monkeypatch, request
): # TODO Disabled until we create a better config format
return
@pytest.mark.skip(reason="Disabled until we create a better config format")
def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request):
# constants
DATABASE_HOST = "test-host"
DATABASE_NAME = "test-dbname"

View File

@ -1,3 +1,4 @@
---
# Copyright © 2020 Interplanetary Database Association e.V.,
# Planetmint and IPDB software contributors.
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
@ -35,6 +36,3 @@ services:
- ./integration/scripts:/scripts
- ./integration/cli:/tests
- shared:/shared
volumes:
shared:

View File

@ -1,3 +1,4 @@
---
# Copyright © 2020 Interplanetary Database Association e.V.,
# Planetmint and IPDB software contributors.
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)

View File

@ -189,7 +189,6 @@ def main():
ctx["public_keys_transfer"] = tx_transfer.outputs[0].public_keys[0]
ctx["tx_transfer_id"] = tx_transfer.id
# privkey_transfer_last = 'sG3jWDtdTXUidBJK53ucSTrosktG616U3tQHBk81eQe'
pubkey_transfer_last = "3Af3fhhjU6d9WecEM9Uw5hfom9kNEwE7YuDWdqAUssqm"
cid = 0

View File

@ -198,7 +198,6 @@ todo_include_todos = False
# a list of builtin themes.
#
html_theme = "press"
# html_theme = 'sphinx_documatt_theme'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the

View File

@ -1,3 +1,4 @@
---
# Copyright © 2020 Interplanetary Database Association e.V.,
# Planetmint and IPDB software contributors.
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)

View File

@ -1,3 +1,4 @@
---
# Copyright © 2020 Interplanetary Database Association e.V.,
# Planetmint and IPDB software contributors.
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)

View File

@ -1,3 +1,4 @@
---
# Copyright © 2020 Interplanetary Database Association e.V.,
# Planetmint and IPDB software contributors.
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)

View File

@ -1,3 +1,4 @@
---
# Copyright © 2020 Interplanetary Database Association e.V.,
# Planetmint and IPDB software contributors.
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)

View File

@ -82,7 +82,7 @@ class ApplicationLogic(BaseApplication):
if known_chain["is_synced"]:
msg = (
f"Got invalid InitChain ABCI request ({genesis}) - " f"the chain {chain_id} is already synced."
f"Got invalid InitChain ABCI request ({genesis}) - the chain {chain_id} is already synced."
)
logger.error(msg)
sys.exit(1)
@ -238,7 +238,7 @@ class ApplicationLogic(BaseApplication):
block_txn_hash = calculate_hash(self.block_txn_ids)
block = self.validator.models.get_latest_block()
logger.debug("BLOCK: ", block)
logger.debug(f"BLOCK: {block}")
if self.block_txn_ids:
self.block_txn_hash = calculate_hash([block["app_hash"], block_txn_hash])
else:
@ -279,7 +279,7 @@ class ApplicationLogic(BaseApplication):
sys.exit(1)
logger.debug(
"Commit-ing new block with hash: apphash=%s ," "height=%s, txn ids=%s",
"Commit-ing new block with hash: apphash=%s, height=%s, txn ids=%s",
data,
self.new_height,
self.block_txn_ids,

View File

@ -79,7 +79,6 @@ def new_validator_set(validators, updates):
def get_public_key_decoder(pk):
encoding = pk["type"]
decoder = base64.b64decode
if encoding == "ed25519-base16":
decoder = base64.b16decode

View File

@ -62,7 +62,7 @@ class Validator:
asset_id = tx.get_asset_id(input_txs)
if asset_id != Transaction.read_out_asset_id(tx):
raise AssetIdMismatch(
("The asset id of the input does not" " match the asset id of the" " transaction")
("The asset id of the input does not match the asset id of the transaction")
)
else:
asset_ids = Transaction.get_asset_ids(input_txs)
@ -105,9 +105,7 @@ class Validator:
if output_amount != input_amount:
raise AmountError(
(
"The amount used in the inputs `{}`" " needs to be same as the amount used" " in the outputs `{}`"
).format(input_amount, output_amount)
"The amount used in the inputs `{}` needs to be same as the amount used in the outputs `{}`".format(input_amount, output_amount)
)
return True
@ -202,15 +200,16 @@ class Validator:
raise InvalidProposer("Public key is not a part of the validator set")
# NOTE: Check if all validators have been assigned votes equal to their voting power
if not self.is_same_topology(current_validators, transaction.outputs):
if not Validator.is_same_topology(current_validators, transaction.outputs):
raise UnequalValidatorSet("Validator set much be exactly same to the outputs of election")
if transaction.operation == VALIDATOR_ELECTION:
self.validate_validator_election(transaction)
return transaction
def is_same_topology(cls, current_topology, election_topology):
@staticmethod
def is_same_topology(current_topology, election_topology):
voters = {}
for voter in election_topology:
if len(voter.public_keys) > 1:

View File

@ -73,7 +73,7 @@ class LocalMongoDBConnection(DBConnection):
try:
return query.run(self.connect())
except pymongo.errors.AutoReconnect:
logger.warning("Lost connection to the database, " "retrying query.")
logger.warning("Lost connection to the database, retrying query.")
return query.run(self.connect())
except pymongo.errors.AutoReconnect as exc:
raise ConnectionError from exc

View File

@ -117,7 +117,7 @@ class Config(metaclass=Singleton):
def set(self, config):
self._private_real_config = config
def get_db_key_map(sefl, db):
def get_db_key_map(self, db):
return sefl.__private_database_keys_map[db]
def get_db_map(sefl, db):
@ -132,14 +132,14 @@ DEFAULT_LOGGING_CONFIG = {
"console": {
"class": "logging.Formatter",
"format": (
"[%(asctime)s] [%(levelname)s] (%(name)s) " "%(message)s (%(processName)-10s - pid: %(process)d)"
"[%(asctime)s] [%(levelname)s] (%(name)s) %(message)s (%(processName)-10s - pid: %(process)d)"
),
"datefmt": "%Y-%m-%d %H:%M:%S",
},
"file": {
"class": "logging.Formatter",
"format": (
"[%(asctime)s] [%(levelname)s] (%(name)s) " "%(message)s (%(processName)-10s - pid: %(process)d)"
"[%(asctime)s] [%(levelname)s] (%(name)s) %(message)s (%(processName)-10s - pid: %(process)d)"
),
"datefmt": "%Y-%m-%d %H:%M:%S",
},

View File

@ -337,7 +337,6 @@ class DataAccessor(metaclass=Singleton):
str: Merkle root in hexadecimal form.
"""
utxoset = backend.query.get_unspent_outputs(self.connection)
# TODO Once ready, use the already pre-computed utxo_hash field.
# See common/transactions.py for details.
hashes = [
@ -346,5 +345,4 @@ class DataAccessor(metaclass=Singleton):
print(sorted(hashes))
# TODO Notice the sorted call!
return merkleroot(sorted(hashes))

View File

@ -3,6 +3,7 @@
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
# Code is Apache-2.0 and docs are CC-BY-4.0
import sys
import logging
import setproctitle
@ -94,4 +95,4 @@ def start(args):
if __name__ == "__main__":
start()
start(sys.argv)

View File

@ -26,6 +26,9 @@ from planetmint.backend.connection import Connection
from tests.utils import generate_election, generate_validators
rpc_write_transaction_string = "planetmint.abci.rpc.ABCI_RPC.write_transaction"
def mock_get_validators(self, height):
return [
{
@ -57,7 +60,7 @@ def test_chain_migration_election_show_shows_inconclusive(b_flushed, test_abci_r
b = b_flushed
validators = generate_validators([1] * 4)
output = b.models.store_validator_set(1, [v["storage"] for v in validators])
_ = b.models.store_validator_set(1, [v["storage"] for v in validators])
public_key = validators[0]["public_key"]
private_key = validators[0]["private_key"]
@ -465,7 +468,7 @@ def test_election_new_upsert_validator_without_tendermint(
from planetmint.model.dataaccessor import DataAccessor
m.setattr(DataAccessor, "get_validators", mock_get_validators)
m.setattr("planetmint.abci.rpc.ABCI_RPC.write_transaction", mock_write)
m.setattr(rpc_write_transaction_string, mock_write)
args = Namespace(
action="new",
@ -505,7 +508,7 @@ def test_election_new_chain_migration_without_tendermint(
from planetmint.model.dataaccessor import DataAccessor
m.setattr(DataAccessor, "get_validators", mock_get_validators)
m.setattr("planetmint.abci.rpc.ABCI_RPC.write_transaction", mock_write)
m.setattr(rpc_write_transaction_string, mock_write)
args = Namespace(action="new", election_type="migration", sk=priv_validator_path, config={})
@ -546,7 +549,7 @@ def test_election_new_upsert_validator_invalid_power(
from planetmint.model.dataaccessor import DataAccessor
m.setattr(DataAccessor, "get_validators", mock_get_validators)
m.setattr("planetmint.abci.rpc.ABCI_RPC.write_transaction", mock_write)
m.setattr(rpc_write_transaction_string, mock_write)
args = Namespace(
action="new",
@ -600,7 +603,7 @@ def test_election_approve_without_tendermint(
from planetmint.model.dataaccessor import DataAccessor
m.setattr(DataAccessor, "get_validators", mock_get_validators)
m.setattr("planetmint.abci.rpc.ABCI_RPC.write_transaction", mock_write)
m.setattr(rpc_write_transaction_string, mock_write)
b, election_id = call_election_internal(b, new_validator, node_key)
@ -674,7 +677,7 @@ def call_election(monkeypatch, b, new_validator, node_key, abci_rpc):
from planetmint.model.dataaccessor import DataAccessor
m.setattr(DataAccessor, "get_validators", mock_get_validators)
m.setattr("planetmint.abci.rpc.ABCI_RPC.write_transaction", mock_write)
m.setattr(rpc_write_transaction_string, mock_write)
b, election_id = call_election_internal(b, new_validator, node_key)
m.undo()
return b, election_id