Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hathor/cli/events_simulator/events_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def execute(args: Namespace) -> None:

storage = EventMemoryStorage()

for event in args.scenario.get_events():
for event in args.scenario.value:
storage.save_event(event)

factory = EventWebsocketFactory(reactor, storage)
Expand Down
71 changes: 14 additions & 57 deletions hathor/cli/events_simulator/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,20 @@

from enum import Enum

from hathor.event.model.base_event import BaseEvent
from hathor.event.model.event_data import TxData, TxMetadata
from hathor.event.model.event_type import EventType


class Scenario(Enum):
SINGLE_CHAIN = 'SINGLE_CHAIN'
BEST_CHAIN_WITH_SIDE_CHAINS = 'BEST_CHAIN_WITH_SIDE_CHAINS'
MULTIPLE_FORKS = 'MULTIPLE_FORKS'

def get_events(self):
return _SCENARIO_EVENTS[self]


_TRANSACTION_DATA_1 = TxData(
hash='123',
nonce=456,
timestamp=0,
version=1,
weight=2,
inputs=[],
outputs=[],
parents=[],
tokens=[],
metadata=TxMetadata(
hash='123',
spent_outputs=[],
conflict_with=[],
voided_by=[],
received_by=[],
children=[],
twins=[],
accumulated_weight=2,
score=2,
height=0,
validation=''
)
)

_TRANSACTION_1 = BaseEvent(
peer_id='123',
id=0,
timestamp=0,
type=EventType.NEW_VERTEX_ACCEPTED,
data=_TRANSACTION_DATA_1
from hathor.cli.events_simulator.scenarios.only_load_events import ONLY_LOAD_EVENTS
from hathor.cli.events_simulator.scenarios.reorg_events import REORG_EVENTS
from hathor.cli.events_simulator.scenarios.single_chain_blocks_and_transactions_events import (
SINGLE_CHAIN_BLOCKS_AND_TRANSACTIONS_EVENTS,
)
from hathor.cli.events_simulator.scenarios.single_chain_one_block_events import SINGLE_CHAIN_ONE_BLOCK_EVENTS


# TODO: We still have to actually populate the list of events for each scenario. Pending on design discussions.
_SCENARIO_EVENTS = {
Scenario.SINGLE_CHAIN: [
_TRANSACTION_1
],
Scenario.BEST_CHAIN_WITH_SIDE_CHAINS: [
_TRANSACTION_1
],
Scenario.MULTIPLE_FORKS: [
_TRANSACTION_1
],
}
class Scenario(Enum):
"""
NOTE: The lists of events used in each scenario's enum value below were obtained from the tests in
tests.event.test_simulation.TestEventSimulation
"""
ONLY_LOAD = ONLY_LOAD_EVENTS
SINGLE_CHAIN_ONE_BLOCK = SINGLE_CHAIN_ONE_BLOCK_EVENTS
SINGLE_CHAIN_BLOCKS_AND_TRANSACTIONS = SINGLE_CHAIN_BLOCKS_AND_TRANSACTIONS_EVENTS
REORG = REORG_EVENTS
Empty file.
24 changes: 24 additions & 0 deletions hathor/cli/events_simulator/scenarios/only_load_events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 Hathor Labs
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from hathor.event.model.base_event import BaseEvent, EventType
from hathor.event.model.event_data import EmptyData, TxData, TxMetadata, TxOutput

ONLY_LOAD_EVENTS = [
BaseEvent(peer_id='97c14daade28cfe68d5854361bf6d5754b2a1f81e38fb44fe51367f1eb254d11', id=0, timestamp=1572653259.0, type=EventType.LOAD_STARTED, data=EmptyData(), group_id=None), # noqa E501
BaseEvent(peer_id='97c14daade28cfe68d5854361bf6d5754b2a1f81e38fb44fe51367f1eb254d11', id=1, timestamp=1572653259.0, type=EventType.NEW_VERTEX_ACCEPTED, data=TxData(hash='339f47da87435842b0b1b528ecd9eac2495ce983b3e9c923a37e1befbe12c792', nonce=0, timestamp=1572636343, version=0, weight=2.0, inputs=[], outputs=[TxOutput(value=100000000000, script='dqkU/QUFm2AGJJVDuC82h2oXxz/SJnuIrA==', token_data=0)], parents=[], tokens=[], token_name=None, token_symbol=None, metadata=TxMetadata(hash='339f47da87435842b0b1b528ecd9eac2495ce983b3e9c923a37e1befbe12c792', spent_outputs=[], conflict_with=[], voided_by=[], received_by=[], children=[], twins=[], accumulated_weight=2.0, score=2.0, first_block=None, height=0, validation='full')), group_id=None), # noqa E501
BaseEvent(peer_id='97c14daade28cfe68d5854361bf6d5754b2a1f81e38fb44fe51367f1eb254d11', id=2, timestamp=1572653259.0, type=EventType.NEW_VERTEX_ACCEPTED, data=TxData(hash='16ba3dbe424c443e571b00840ca54b9ff4cff467e10b6a15536e718e2008f952', nonce=6, timestamp=1572636344, version=1, weight=2.0, inputs=[], outputs=[], parents=[], tokens=[], token_name=None, token_symbol=None, metadata=TxMetadata(hash='16ba3dbe424c443e571b00840ca54b9ff4cff467e10b6a15536e718e2008f952', spent_outputs=[], conflict_with=[], voided_by=[], received_by=[], children=[], twins=[], accumulated_weight=2.0, score=2.0, first_block=None, height=0, validation='full')), group_id=None), # noqa E501
BaseEvent(peer_id='97c14daade28cfe68d5854361bf6d5754b2a1f81e38fb44fe51367f1eb254d11', id=3, timestamp=1572653259.0, type=EventType.NEW_VERTEX_ACCEPTED, data=TxData(hash='33e14cb555a96967841dcbe0f95e9eab5810481d01de8f4f73afb8cce365e869', nonce=2, timestamp=1572636345, version=1, weight=2.0, inputs=[], outputs=[], parents=[], tokens=[], token_name=None, token_symbol=None, metadata=TxMetadata(hash='33e14cb555a96967841dcbe0f95e9eab5810481d01de8f4f73afb8cce365e869', spent_outputs=[], conflict_with=[], voided_by=[], received_by=[], children=[], twins=[], accumulated_weight=2.0, score=2.0, first_block=None, height=0, validation='full')), group_id=None), # noqa E501
BaseEvent(peer_id='97c14daade28cfe68d5854361bf6d5754b2a1f81e38fb44fe51367f1eb254d11', id=4, timestamp=1572653259.0, type=EventType.LOAD_FINISHED, data=EmptyData(), group_id=None) # noqa E501
]
Loading