mirror of
https://github.com/planetmint/planetmint.git
synced 2025-06-07 22:56:37 +00:00
added fixes for the most important issues
This commit is contained in:
parent
d79f92c8c9
commit
b9c96f4029
@ -50,10 +50,6 @@ from planetmint.events import EventTypes, Event
|
|||||||
CodeTypeError = 1
|
CodeTypeError = 1
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class TmVersion(enum.Enum):
|
|
||||||
"""Supported Tendermint versions enum"""
|
|
||||||
v0_34_11 = 'v0.34.11'
|
|
||||||
|
|
||||||
|
|
||||||
class App(BaseApplication):
|
class App(BaseApplication):
|
||||||
"""Bridge between Planetmint and Tendermint.
|
"""Bridge between Planetmint and Tendermint.
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from planetmint import App, Planetmint
|
from planetmint import App
|
||||||
|
from planetmint.lib import Planetmint
|
||||||
from planetmint.tendermint_utils import decode_transaction
|
from planetmint.tendermint_utils import decode_transaction
|
||||||
from abci.application import OkCode
|
from abci.application import OkCode
|
||||||
from tendermint.abci.types_pb2 import (
|
from tendermint.abci.types_pb2 import (
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import setproctitle
|
import setproctitle
|
||||||
|
|
||||||
#from abci import TmVersion, ABCI
|
|
||||||
|
|
||||||
import planetmint
|
import planetmint
|
||||||
from planetmint.lib import Planetmint
|
from planetmint.lib import Planetmint
|
||||||
from planetmint.core import App
|
from planetmint.core import App
|
||||||
|
@ -4,29 +4,15 @@ import codecs
|
|||||||
import enum
|
import enum
|
||||||
|
|
||||||
import planetmint
|
import planetmint
|
||||||
from tendermint.abci import types_pb2 as types_v0_34_11
|
from tendermint.abci import types_pb2
|
||||||
from tendermint.crypto import keys_pb2
|
from tendermint.crypto import keys_pb2
|
||||||
from planetmint.common.exceptions import InvalidPublicKey, BigchainDBError
|
from planetmint.common.exceptions import InvalidPublicKey, BigchainDBError
|
||||||
|
|
||||||
class TmVersion(enum.Enum):
|
|
||||||
"""Supported Tendermint versions enum"""
|
|
||||||
v0_34_11 = 'v0.34.11'
|
|
||||||
|
|
||||||
def encode_validator(v):
|
def encode_validator(v):
|
||||||
ed25519_public_key = v['public_key']['value']
|
ed25519_public_key = v['public_key']['value']
|
||||||
# NOTE: tendermint expects public to be encoded in go-amino format
|
pub_key = keys_pb2.PublicKey(ed25519=bytes.fromhex(ed25519_public_key))
|
||||||
try:
|
|
||||||
version = TmVersion(planetmint.config["tendermint"]["version"])
|
|
||||||
except ValueError:
|
|
||||||
raise BigchainDBError('Invalid tendermint version, '
|
|
||||||
'check Planetmint configuration file')
|
|
||||||
|
|
||||||
validator_update_t, pubkey_t = {
|
return types_pb2.ValidatorUpdate(pub_key=pub_key, power=v['power'])
|
||||||
TmVersion.v0_34_11: (types_v0_34_11.ValidatorUpdate, keys_pb2.PublicKey)
|
|
||||||
}[version]
|
|
||||||
pub_key = pubkey_t(ed25519=bytes.fromhex(ed25519_public_key))
|
|
||||||
|
|
||||||
return validator_update_t(pub_key=pub_key, power=v['power'])
|
|
||||||
|
|
||||||
|
|
||||||
def decode_validator(v):
|
def decode_validator(v):
|
||||||
|
@ -16,7 +16,8 @@ from flask_cors import CORS
|
|||||||
import gunicorn.app.base
|
import gunicorn.app.base
|
||||||
|
|
||||||
from planetmint import utils
|
from planetmint import utils
|
||||||
from planetmint import Planetmint
|
#from planetmint import Planetmint
|
||||||
|
from planetmint.lib import Planetmint
|
||||||
from planetmint.web.routes import add_routes
|
from planetmint.web.routes import add_routes
|
||||||
from planetmint.web.strip_content_type_middleware import StripContentTypeMiddleware
|
from planetmint.web.strip_content_type_middleware import StripContentTypeMiddleware
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ from planetmint.lib import Block
|
|||||||
from planetmint.elections.election import Election
|
from planetmint.elections.election import Election
|
||||||
from planetmint.migrations.chain_migration_election import ChainMigrationElection
|
from planetmint.migrations.chain_migration_election import ChainMigrationElection
|
||||||
from planetmint.upsert_validator.validator_election import ValidatorElection
|
from planetmint.upsert_validator.validator_election import ValidatorElection
|
||||||
from planetmint.core import TmVersion
|
|
||||||
|
|
||||||
@pytest.mark.bdb
|
@pytest.mark.bdb
|
||||||
def test_process_block_concludes_all_elections(b):
|
def test_process_block_concludes_all_elections(b):
|
||||||
|
@ -53,7 +53,7 @@ def generate_init_chain_request(chain_id, vals=None):
|
|||||||
|
|
||||||
def test_init_chain_successfully_registers_chain(a, b):
|
def test_init_chain_successfully_registers_chain(a, b):
|
||||||
request = generate_init_chain_request('chain-XYZ')
|
request = generate_init_chain_request('chain-XYZ')
|
||||||
res = App(a, b).init_chain(request)
|
res = App(b, a).init_chain(request)
|
||||||
assert res == types.ResponseInitChain()
|
assert res == types.ResponseInitChain()
|
||||||
chain = query.get_latest_abci_chain(b.connection)
|
chain = query.get_latest_abci_chain(b.connection)
|
||||||
assert chain == {'height': 0, 'chain_id': 'chain-XYZ', 'is_synced': True}
|
assert chain == {'height': 0, 'chain_id': 'chain-XYZ', 'is_synced': True}
|
||||||
@ -67,7 +67,7 @@ def test_init_chain_successfully_registers_chain(a, b):
|
|||||||
def test_init_chain_ignores_invalid_init_chain_requests(a, b):
|
def test_init_chain_ignores_invalid_init_chain_requests(a, b):
|
||||||
validators = [generate_validator()]
|
validators = [generate_validator()]
|
||||||
request = generate_init_chain_request('chain-XYZ', validators)
|
request = generate_init_chain_request('chain-XYZ', validators)
|
||||||
res = App(a, b).init_chain(request)
|
res = App(b, a).init_chain(request)
|
||||||
assert res == types.ResponseInitChain()
|
assert res == types.ResponseInitChain()
|
||||||
|
|
||||||
validator_set = query.get_validator_set(b.connection)
|
validator_set = query.get_validator_set(b.connection)
|
||||||
@ -81,7 +81,7 @@ def test_init_chain_ignores_invalid_init_chain_requests(a, b):
|
|||||||
]
|
]
|
||||||
for r in invalid_requests:
|
for r in invalid_requests:
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).init_chain(r)
|
App(b, a).init_chain(r)
|
||||||
# assert nothing changed - neither validator set, nor chain ID
|
# assert nothing changed - neither validator set, nor chain ID
|
||||||
new_validator_set = query.get_validator_set(b.connection)
|
new_validator_set = query.get_validator_set(b.connection)
|
||||||
assert new_validator_set == validator_set
|
assert new_validator_set == validator_set
|
||||||
@ -97,7 +97,7 @@ def test_init_chain_ignores_invalid_init_chain_requests(a, b):
|
|||||||
def test_init_chain_recognizes_new_chain_after_migration(a, b):
|
def test_init_chain_recognizes_new_chain_after_migration(a, b):
|
||||||
validators = [generate_validator()]
|
validators = [generate_validator()]
|
||||||
request = generate_init_chain_request('chain-XYZ', validators)
|
request = generate_init_chain_request('chain-XYZ', validators)
|
||||||
res = App(a, b).init_chain(request)
|
res = App(b, a).init_chain(request)
|
||||||
assert res == types.ResponseInitChain()
|
assert res == types.ResponseInitChain()
|
||||||
|
|
||||||
validator_set = query.get_validator_set(b.connection)['validators']
|
validator_set = query.get_validator_set(b.connection)['validators']
|
||||||
@ -116,7 +116,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b):
|
|||||||
]
|
]
|
||||||
for r in invalid_requests:
|
for r in invalid_requests:
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).init_chain(r)
|
App(b, a).init_chain(r)
|
||||||
assert query.get_latest_abci_chain(b.connection) == {
|
assert query.get_latest_abci_chain(b.connection) == {
|
||||||
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
||||||
'is_synced': False,
|
'is_synced': False,
|
||||||
@ -129,7 +129,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b):
|
|||||||
# completes the migration
|
# completes the migration
|
||||||
request = generate_init_chain_request('chain-XYZ-migrated-at-height-1',
|
request = generate_init_chain_request('chain-XYZ-migrated-at-height-1',
|
||||||
validators)
|
validators)
|
||||||
res = App(a, b).init_chain(request)
|
res = App(b, a).init_chain(request)
|
||||||
assert res == types.ResponseInitChain()
|
assert res == types.ResponseInitChain()
|
||||||
assert query.get_latest_abci_chain(b.connection) == {
|
assert query.get_latest_abci_chain(b.connection) == {
|
||||||
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
||||||
@ -150,7 +150,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b):
|
|||||||
]
|
]
|
||||||
for r in invalid_requests:
|
for r in invalid_requests:
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).init_chain(r)
|
App(b, a).init_chain(r)
|
||||||
assert query.get_latest_abci_chain(b.connection) == {
|
assert query.get_latest_abci_chain(b.connection) == {
|
||||||
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
||||||
'is_synced': True,
|
'is_synced': True,
|
||||||
@ -167,7 +167,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b):
|
|||||||
|
|
||||||
def test_info(a, b):
|
def test_info(a, b):
|
||||||
r = types.RequestInfo(version=__tm_supported_versions__[0])
|
r = types.RequestInfo(version=__tm_supported_versions__[0])
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
|
|
||||||
res = app.info(r)
|
res = app.info(r)
|
||||||
assert res.last_block_height == 0
|
assert res.last_block_height == 0
|
||||||
@ -180,7 +180,7 @@ def test_info(a, b):
|
|||||||
|
|
||||||
# simulate a migration and assert the height is shifted
|
# simulate a migration and assert the height is shifted
|
||||||
b.store_abci_chain(2, 'chain-XYZ')
|
b.store_abci_chain(2, 'chain-XYZ')
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
b.store_block(Block(app_hash='2', height=2, transactions=[])._asdict())
|
b.store_block(Block(app_hash='2', height=2, transactions=[])._asdict())
|
||||||
res = app.info(r)
|
res = app.info(r)
|
||||||
assert res.last_block_height == 0
|
assert res.last_block_height == 0
|
||||||
@ -193,7 +193,7 @@ def test_info(a, b):
|
|||||||
|
|
||||||
# it's always the latest migration that is taken into account
|
# it's always the latest migration that is taken into account
|
||||||
b.store_abci_chain(4, 'chain-XYZ-new')
|
b.store_abci_chain(4, 'chain-XYZ-new')
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
b.store_block(Block(app_hash='4', height=4, transactions=[])._asdict())
|
b.store_block(Block(app_hash='4', height=4, transactions=[])._asdict())
|
||||||
res = app.info(r)
|
res = app.info(r)
|
||||||
assert res.last_block_height == 0
|
assert res.last_block_height == 0
|
||||||
@ -212,7 +212,7 @@ def test_check_tx__signed_create_is_ok(a, b):
|
|||||||
[([bob.public_key], 1)])\
|
[([bob.public_key], 1)])\
|
||||||
.sign([alice.private_key])
|
.sign([alice.private_key])
|
||||||
|
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
result = app.check_tx(encode_tx_to_bytes(tx))
|
result = app.check_tx(encode_tx_to_bytes(tx))
|
||||||
assert result.code == OkCode
|
assert result.code == OkCode
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ def test_check_tx__unsigned_create_is_error(a, b):
|
|||||||
tx = Transaction.create([alice.public_key],
|
tx = Transaction.create([alice.public_key],
|
||||||
[([bob.public_key], 1)])
|
[([bob.public_key], 1)])
|
||||||
|
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
result = app.check_tx(encode_tx_to_bytes(tx))
|
result = app.check_tx(encode_tx_to_bytes(tx))
|
||||||
assert result.code == CodeTypeError
|
assert result.code == CodeTypeError
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ def test_deliver_tx__double_spend_fails(a, b, init_chain_request):
|
|||||||
[([bob.public_key], 1)])\
|
[([bob.public_key], 1)])\
|
||||||
.sign([alice.private_key])
|
.sign([alice.private_key])
|
||||||
|
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
app.init_chain(init_chain_request)
|
app.init_chain(init_chain_request)
|
||||||
|
|
||||||
begin_block = types.RequestBeginBlock()
|
begin_block = types.RequestBeginBlock()
|
||||||
@ -305,7 +305,7 @@ def test_deliver_transfer_tx__double_spend_fails(a, b, init_chain_request):
|
|||||||
from planetmint.models import Transaction
|
from planetmint.models import Transaction
|
||||||
from planetmint.common.crypto import generate_key_pair
|
from planetmint.common.crypto import generate_key_pair
|
||||||
|
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
app.init_chain(init_chain_request)
|
app.init_chain(init_chain_request)
|
||||||
|
|
||||||
begin_block = types.RequestBeginBlock()
|
begin_block = types.RequestBeginBlock()
|
||||||
@ -345,7 +345,7 @@ def test_deliver_transfer_tx__double_spend_fails(a, b, init_chain_request):
|
|||||||
|
|
||||||
|
|
||||||
def test_end_block_return_validator_updates(a, b, init_chain_request):
|
def test_end_block_return_validator_updates(a, b, init_chain_request):
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
app.init_chain(init_chain_request)
|
app.init_chain(init_chain_request)
|
||||||
|
|
||||||
begin_block = types.RequestBeginBlock()
|
begin_block = types.RequestBeginBlock()
|
||||||
@ -389,7 +389,7 @@ def test_store_pre_commit_state_in_end_block(a, b, alice, init_chain_request):
|
|||||||
asset={'msg': 'live long and prosper'})\
|
asset={'msg': 'live long and prosper'})\
|
||||||
.sign([alice.private_key])
|
.sign([alice.private_key])
|
||||||
|
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
app.init_chain(init_chain_request)
|
app.init_chain(init_chain_request)
|
||||||
|
|
||||||
begin_block = types.RequestBeginBlock()
|
begin_block = types.RequestBeginBlock()
|
||||||
@ -410,7 +410,7 @@ def test_store_pre_commit_state_in_end_block(a, b, alice, init_chain_request):
|
|||||||
|
|
||||||
# simulate a chain migration and assert the height is shifted
|
# simulate a chain migration and assert the height is shifted
|
||||||
b.store_abci_chain(100, 'new-chain')
|
b.store_abci_chain(100, 'new-chain')
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
app.begin_block(begin_block)
|
app.begin_block(begin_block)
|
||||||
app.deliver_tx(encode_tx_to_bytes(tx))
|
app.deliver_tx(encode_tx_to_bytes(tx))
|
||||||
app.end_block(types.RequestEndBlock(height=1))
|
app.end_block(types.RequestEndBlock(height=1))
|
||||||
@ -507,39 +507,39 @@ def test_info_aborts_if_chain_is_not_synced(a, b):
|
|||||||
b.store_abci_chain(0, 'chain-XYZ', False)
|
b.store_abci_chain(0, 'chain-XYZ', False)
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).info(types.RequestInfo())
|
App(b, a).info(types.RequestInfo())
|
||||||
|
|
||||||
|
|
||||||
def test_check_tx_aborts_if_chain_is_not_synced(a, b):
|
def test_check_tx_aborts_if_chain_is_not_synced(a, b):
|
||||||
b.store_abci_chain(0, 'chain-XYZ', False)
|
b.store_abci_chain(0, 'chain-XYZ', False)
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).check_tx('some bytes')
|
App(b, a).check_tx('some bytes')
|
||||||
|
|
||||||
|
|
||||||
def test_begin_aborts_if_chain_is_not_synced(a, b):
|
def test_begin_aborts_if_chain_is_not_synced(a, b):
|
||||||
b.store_abci_chain(0, 'chain-XYZ', False)
|
b.store_abci_chain(0, 'chain-XYZ', False)
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).info(types.RequestBeginBlock())
|
App(b, a).info(types.RequestBeginBlock())
|
||||||
|
|
||||||
|
|
||||||
def test_deliver_tx_aborts_if_chain_is_not_synced(a, b):
|
def test_deliver_tx_aborts_if_chain_is_not_synced(a, b):
|
||||||
b.store_abci_chain(0, 'chain-XYZ', False)
|
b.store_abci_chain(0, 'chain-XYZ', False)
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).deliver_tx('some bytes')
|
App(b, a).deliver_tx('some bytes')
|
||||||
|
|
||||||
|
|
||||||
def test_end_block_aborts_if_chain_is_not_synced(a, b):
|
def test_end_block_aborts_if_chain_is_not_synced(a, b):
|
||||||
b.store_abci_chain(0, 'chain-XYZ', False)
|
b.store_abci_chain(0, 'chain-XYZ', False)
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).info(types.RequestEndBlock())
|
App(b, a).info(types.RequestEndBlock())
|
||||||
|
|
||||||
|
|
||||||
def test_commit_aborts_if_chain_is_not_synced(a, b):
|
def test_commit_aborts_if_chain_is_not_synced(a, b):
|
||||||
b.store_abci_chain(0, 'chain-XYZ', False)
|
b.store_abci_chain(0, 'chain-XYZ', False)
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).commit()
|
App(b, a).commit()
|
||||||
|
@ -25,7 +25,7 @@ def test_app(a, b, init_chain_request):
|
|||||||
from planetmint.common.crypto import generate_key_pair
|
from planetmint.common.crypto import generate_key_pair
|
||||||
from planetmint.models import Transaction
|
from planetmint.models import Transaction
|
||||||
|
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
p = ProtocolHandler(app)
|
p = ProtocolHandler(app)
|
||||||
|
|
||||||
data = p.process('info',
|
data = p.process('info',
|
||||||
@ -150,7 +150,7 @@ def test_post_transaction_responses(tendermint_ws_url, b):
|
|||||||
def test_exit_when_tm_ver_not_supported(a, b):
|
def test_exit_when_tm_ver_not_supported(a, b):
|
||||||
from planetmint import App
|
from planetmint import App
|
||||||
|
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
p = ProtocolHandler(app)
|
p = ProtocolHandler(app)
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
|
@ -53,7 +53,7 @@ def generate_init_chain_request(chain_id, vals=None):
|
|||||||
|
|
||||||
def test_init_chain_successfully_registers_chain(a, b):
|
def test_init_chain_successfully_registers_chain(a, b):
|
||||||
request = generate_init_chain_request('chain-XYZ')
|
request = generate_init_chain_request('chain-XYZ')
|
||||||
res = App(a, b).init_chain(request)
|
res = App(b, a).init_chain(request)
|
||||||
assert res == types.ResponseInitChain()
|
assert res == types.ResponseInitChain()
|
||||||
chain = query.get_latest_abci_chain(b.connection)
|
chain = query.get_latest_abci_chain(b.connection)
|
||||||
assert chain == {'height': 0, 'chain_id': 'chain-XYZ', 'is_synced': True}
|
assert chain == {'height': 0, 'chain_id': 'chain-XYZ', 'is_synced': True}
|
||||||
@ -67,7 +67,7 @@ def test_init_chain_successfully_registers_chain(a, b):
|
|||||||
def test_init_chain_ignores_invalid_init_chain_requests(a, b):
|
def test_init_chain_ignores_invalid_init_chain_requests(a, b):
|
||||||
validators = [generate_validator()]
|
validators = [generate_validator()]
|
||||||
request = generate_init_chain_request('chain-XYZ', validators)
|
request = generate_init_chain_request('chain-XYZ', validators)
|
||||||
res = App(a, b).init_chain(request)
|
res = App(b, a).init_chain(request)
|
||||||
assert res == types.ResponseInitChain()
|
assert res == types.ResponseInitChain()
|
||||||
|
|
||||||
validator_set = query.get_validator_set(b.connection)
|
validator_set = query.get_validator_set(b.connection)
|
||||||
@ -81,7 +81,7 @@ def test_init_chain_ignores_invalid_init_chain_requests(a, b):
|
|||||||
]
|
]
|
||||||
for r in invalid_requests:
|
for r in invalid_requests:
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).init_chain(r)
|
App(b, a).init_chain(r)
|
||||||
# assert nothing changed - neither validator set, nor chain ID
|
# assert nothing changed - neither validator set, nor chain ID
|
||||||
new_validator_set = query.get_validator_set(b.connection)
|
new_validator_set = query.get_validator_set(b.connection)
|
||||||
assert new_validator_set == validator_set
|
assert new_validator_set == validator_set
|
||||||
@ -97,7 +97,7 @@ def test_init_chain_ignores_invalid_init_chain_requests(a, b):
|
|||||||
def test_init_chain_recognizes_new_chain_after_migration(a, b):
|
def test_init_chain_recognizes_new_chain_after_migration(a, b):
|
||||||
validators = [generate_validator()]
|
validators = [generate_validator()]
|
||||||
request = generate_init_chain_request('chain-XYZ', validators)
|
request = generate_init_chain_request('chain-XYZ', validators)
|
||||||
res = App(a, b).init_chain(request)
|
res = App(b, a).init_chain(request)
|
||||||
assert res == types.ResponseInitChain()
|
assert res == types.ResponseInitChain()
|
||||||
|
|
||||||
validator_set = query.get_validator_set(b.connection)['validators']
|
validator_set = query.get_validator_set(b.connection)['validators']
|
||||||
@ -116,7 +116,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b):
|
|||||||
]
|
]
|
||||||
for r in invalid_requests:
|
for r in invalid_requests:
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).init_chain(r)
|
App(b, a).init_chain(r)
|
||||||
assert query.get_latest_abci_chain(b.connection) == {
|
assert query.get_latest_abci_chain(b.connection) == {
|
||||||
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
||||||
'is_synced': False,
|
'is_synced': False,
|
||||||
@ -129,7 +129,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b):
|
|||||||
# completes the migration
|
# completes the migration
|
||||||
request = generate_init_chain_request('chain-XYZ-migrated-at-height-1',
|
request = generate_init_chain_request('chain-XYZ-migrated-at-height-1',
|
||||||
validators)
|
validators)
|
||||||
res = App(a, b).init_chain(request)
|
res = App(b, a).init_chain(request)
|
||||||
assert res == types.ResponseInitChain()
|
assert res == types.ResponseInitChain()
|
||||||
assert query.get_latest_abci_chain(b.connection) == {
|
assert query.get_latest_abci_chain(b.connection) == {
|
||||||
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
||||||
@ -150,7 +150,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b):
|
|||||||
]
|
]
|
||||||
for r in invalid_requests:
|
for r in invalid_requests:
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).init_chain(r)
|
App(b, a).init_chain(r)
|
||||||
assert query.get_latest_abci_chain(b.connection) == {
|
assert query.get_latest_abci_chain(b.connection) == {
|
||||||
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
||||||
'is_synced': True,
|
'is_synced': True,
|
||||||
@ -167,7 +167,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b):
|
|||||||
|
|
||||||
def test_info(a, b):
|
def test_info(a, b):
|
||||||
r = types.RequestInfo(version=__tm_supported_versions__[0])
|
r = types.RequestInfo(version=__tm_supported_versions__[0])
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
|
|
||||||
res = app.info(r)
|
res = app.info(r)
|
||||||
assert res.last_block_height == 0
|
assert res.last_block_height == 0
|
||||||
@ -180,7 +180,7 @@ def test_info(a, b):
|
|||||||
|
|
||||||
# simulate a migration and assert the height is shifted
|
# simulate a migration and assert the height is shifted
|
||||||
b.store_abci_chain(2, 'chain-XYZ')
|
b.store_abci_chain(2, 'chain-XYZ')
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
b.store_block(Block(app_hash='2', height=2, transactions=[])._asdict())
|
b.store_block(Block(app_hash='2', height=2, transactions=[])._asdict())
|
||||||
res = app.info(r)
|
res = app.info(r)
|
||||||
assert res.last_block_height == 0
|
assert res.last_block_height == 0
|
||||||
@ -193,7 +193,7 @@ def test_info(a, b):
|
|||||||
|
|
||||||
# it's always the latest migration that is taken into account
|
# it's always the latest migration that is taken into account
|
||||||
b.store_abci_chain(4, 'chain-XYZ-new')
|
b.store_abci_chain(4, 'chain-XYZ-new')
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
b.store_block(Block(app_hash='4', height=4, transactions=[])._asdict())
|
b.store_block(Block(app_hash='4', height=4, transactions=[])._asdict())
|
||||||
res = app.info(r)
|
res = app.info(r)
|
||||||
assert res.last_block_height == 0
|
assert res.last_block_height == 0
|
||||||
@ -212,7 +212,7 @@ def test_check_tx__signed_create_is_ok(a, b):
|
|||||||
[([bob.public_key], 1)])\
|
[([bob.public_key], 1)])\
|
||||||
.sign([alice.private_key])
|
.sign([alice.private_key])
|
||||||
|
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
result = app.check_tx(encode_tx_to_bytes(tx))
|
result = app.check_tx(encode_tx_to_bytes(tx))
|
||||||
assert result.code == CodeTypeOk
|
assert result.code == CodeTypeOk
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ def test_check_tx__unsigned_create_is_error(a, b):
|
|||||||
tx = Transaction.create([alice.public_key],
|
tx = Transaction.create([alice.public_key],
|
||||||
[([bob.public_key], 1)])
|
[([bob.public_key], 1)])
|
||||||
|
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
result = app.check_tx(encode_tx_to_bytes(tx))
|
result = app.check_tx(encode_tx_to_bytes(tx))
|
||||||
assert result.code == CodeTypeError
|
assert result.code == CodeTypeError
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ def test_deliver_tx__double_spend_fails(a, b, init_chain_request):
|
|||||||
[([bob.public_key], 1)])\
|
[([bob.public_key], 1)])\
|
||||||
.sign([alice.private_key])
|
.sign([alice.private_key])
|
||||||
|
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
app.init_chain(init_chain_request)
|
app.init_chain(init_chain_request)
|
||||||
|
|
||||||
begin_block = types.RequestBeginBlock()
|
begin_block = types.RequestBeginBlock()
|
||||||
@ -305,7 +305,7 @@ def test_deliver_transfer_tx__double_spend_fails(a, b, init_chain_request):
|
|||||||
from planetmint.models import Transaction
|
from planetmint.models import Transaction
|
||||||
from planetmint.common.crypto import generate_key_pair
|
from planetmint.common.crypto import generate_key_pair
|
||||||
|
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
app.init_chain(init_chain_request)
|
app.init_chain(init_chain_request)
|
||||||
|
|
||||||
begin_block = types.RequestBeginBlock()
|
begin_block = types.RequestBeginBlock()
|
||||||
@ -345,7 +345,7 @@ def test_deliver_transfer_tx__double_spend_fails(a, b, init_chain_request):
|
|||||||
|
|
||||||
|
|
||||||
def test_end_block_return_validator_updates(a, b, init_chain_request):
|
def test_end_block_return_validator_updates(a, b, init_chain_request):
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
app.init_chain(init_chain_request)
|
app.init_chain(init_chain_request)
|
||||||
|
|
||||||
begin_block = types.RequestBeginBlock()
|
begin_block = types.RequestBeginBlock()
|
||||||
@ -389,7 +389,7 @@ def test_store_pre_commit_state_in_end_block(a, b, alice, init_chain_request):
|
|||||||
asset={'msg': 'live long and prosper'})\
|
asset={'msg': 'live long and prosper'})\
|
||||||
.sign([alice.private_key])
|
.sign([alice.private_key])
|
||||||
|
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
app.init_chain(init_chain_request)
|
app.init_chain(init_chain_request)
|
||||||
|
|
||||||
begin_block = types.RequestBeginBlock()
|
begin_block = types.RequestBeginBlock()
|
||||||
@ -410,7 +410,7 @@ def test_store_pre_commit_state_in_end_block(a, b, alice, init_chain_request):
|
|||||||
|
|
||||||
# simulate a chain migration and assert the height is shifted
|
# simulate a chain migration and assert the height is shifted
|
||||||
b.store_abci_chain(100, 'new-chain')
|
b.store_abci_chain(100, 'new-chain')
|
||||||
app = App(a, b)
|
app = App(b, a)
|
||||||
app.begin_block(begin_block)
|
app.begin_block(begin_block)
|
||||||
app.deliver_tx(encode_tx_to_bytes(tx))
|
app.deliver_tx(encode_tx_to_bytes(tx))
|
||||||
app.end_block(types.RequestEndBlock(height=1))
|
app.end_block(types.RequestEndBlock(height=1))
|
||||||
@ -507,39 +507,39 @@ def test_info_aborts_if_chain_is_not_synced(a, b):
|
|||||||
b.store_abci_chain(0, 'chain-XYZ', False)
|
b.store_abci_chain(0, 'chain-XYZ', False)
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).info(types.RequestInfo())
|
App(b, a).info(types.RequestInfo())
|
||||||
|
|
||||||
|
|
||||||
def test_check_tx_aborts_if_chain_is_not_synced(a, b):
|
def test_check_tx_aborts_if_chain_is_not_synced(a, b):
|
||||||
b.store_abci_chain(0, 'chain-XYZ', False)
|
b.store_abci_chain(0, 'chain-XYZ', False)
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).check_tx('some bytes')
|
App(b, a).check_tx('some bytes')
|
||||||
|
|
||||||
|
|
||||||
def test_begin_aborts_if_chain_is_not_synced(a, b):
|
def test_begin_aborts_if_chain_is_not_synced(a, b):
|
||||||
b.store_abci_chain(0, 'chain-XYZ', False)
|
b.store_abci_chain(0, 'chain-XYZ', False)
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).info(types.RequestBeginBlock())
|
App(b, a).info(types.RequestBeginBlock())
|
||||||
|
|
||||||
|
|
||||||
def test_deliver_tx_aborts_if_chain_is_not_synced(a, b):
|
def test_deliver_tx_aborts_if_chain_is_not_synced(a, b):
|
||||||
b.store_abci_chain(0, 'chain-XYZ', False)
|
b.store_abci_chain(0, 'chain-XYZ', False)
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).deliver_tx('some bytes')
|
App(b, a).deliver_tx('some bytes')
|
||||||
|
|
||||||
|
|
||||||
def test_end_block_aborts_if_chain_is_not_synced(a, b):
|
def test_end_block_aborts_if_chain_is_not_synced(a, b):
|
||||||
b.store_abci_chain(0, 'chain-XYZ', False)
|
b.store_abci_chain(0, 'chain-XYZ', False)
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).info(types.RequestEndBlock())
|
App(b, a).info(types.RequestEndBlock())
|
||||||
|
|
||||||
|
|
||||||
def test_commit_aborts_if_chain_is_not_synced(a, b):
|
def test_commit_aborts_if_chain_is_not_synced(a, b):
|
||||||
b.store_abci_chain(0, 'chain-XYZ', False)
|
b.store_abci_chain(0, 'chain-XYZ', False)
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(a, b).commit()
|
App(b, a).commit()
|
Loading…
x
Reference in New Issue
Block a user