squeaknode/tests/node/test_squeak_controller.py
Jonathan Zernik b5801097b8
Implement squeak store v3 (#1886)
* Add test for insert squeak in squeak store

* Add test for delete squeak in squeak store

* Add test for save and get sent offer

* Add test for get received offer in squeak store

* Add subscription methods for squeak store

* Use squeak store in squeak controller

* Use squeak store for save squeak method in controller

* Use squeak store for unlock squeak method in controller

* Add comment to make squeak method

* Use squeak_store for more methods in controller

* Use squeak_store for price policy in controller

* Use squeak_store for create signing profile in controller

* Use squeak_store for more profile methods in controller

* Use squeak_store for more profile methods in controller

* Use squeak_store for create peer method in controller

* Use squeak_store for more peer methods in controller

* Use squeak_store for pay offer method in controller

* Use squeak_store for get sent payments and received payments method in controller

* Use squeak_store for get received offers method in controller

* Use squeak store for delete expired offers method

* Use squeak store for get squeak entries methods

* Use squeak store for save received offer method of controller

* Use squeak store for get followed public keys method of controller

* Use squeak store for reprocess received payments method of controller

* Use squeak store for delete old squeaks method of controller

* Use squeak store for like and unlike squeak method of controller

* Use squeak store for get connected peers method of controller

* Use squeak store for add and remove twitter account methods of controller

* Remove squeak_db param from controller constructor

* Use squeak core in squeak store for save squeak andunlock squeak

* Use squeak core in squeak store for make and get sent offer

* Remove old comments

* Remove more old comments

* Use squeak core in squeak store for save received offer

* Use squeak core in squeak store for pay received offer

* Use squeak core in squeak store for get interested struct

* Update twitter forwarder to use squeak store instead of squeak controller

* Update squeak deletion worker to use squeak store instead of squeak controller

* Delete old comments with lines about squeak controller

* Update squeak forwarder worker to use squeak store instead of squeak controller

* Update squeak secret key forwarder worker to use squeak store instead of squeak controller

* Update delete expired offers worker to use squeak store instead of squeak controller

* Update peer subscription workers to use squeak store instead of squeak controller

* Update peer autoconnect worker to use squeak store instead of squeak controller

* Remove usage of squeak controller in download manager start method.

* Add network handler class

* Remove unused constructor params from network handler

* Remove old comments
2021-12-25 09:47:55 -08:00

190 lines
4.8 KiB
Python

# MIT License
#
# Copyright (c) 2020 Jonathan Zernik
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import mock
import pytest
from squeaknode.config.config import SqueaknodeConfig
from squeaknode.core.lightning_address import LightningAddressHostPort
from squeaknode.core.peer_address import Network
from squeaknode.core.peer_address import PeerAddress
from squeaknode.core.squeak_core import SqueakCore
from squeaknode.network.network_manager import NetworkManager
from squeaknode.node.active_download_manager import ActiveDownloadManager
from squeaknode.node.node_settings import NodeSettings
from squeaknode.node.payment_processor import PaymentProcessor
from squeaknode.node.squeak_controller import SqueakController
from squeaknode.node.squeak_store import SqueakStore
from squeaknode.twitter.twitter_forwarder import TwitterForwarder
@pytest.fixture
def config():
squeaknode_config = SqueaknodeConfig()
squeaknode_config.read()
return squeaknode_config
@pytest.fixture
def regtest_config():
squeaknode_config = SqueaknodeConfig(
dict_config={'node': {'network': 'regtest'}}
)
squeaknode_config.read()
return squeaknode_config
@pytest.fixture
def squeak_store():
return mock.Mock(spec=SqueakStore)
@pytest.fixture
def node_settings():
return mock.Mock(spec=NodeSettings)
@pytest.fixture
def network_manager():
return mock.Mock(spec=NetworkManager)
@pytest.fixture
def squeak_core():
return mock.Mock(spec=SqueakCore)
@pytest.fixture
def lightning_host_port():
return LightningAddressHostPort(host="my_lightning_host", port=8765)
@pytest.fixture
def peer_address():
return PeerAddress(
network=Network.IPV4,
host="fake_host",
port=5678,
)
@pytest.fixture
def peer_address_with_zero():
return PeerAddress(
network=Network.IPV4,
host="fake_host",
port=0,
)
@pytest.fixture
def price_msat():
return 777
@pytest.fixture
def payment_processor():
return mock.Mock(spec=PaymentProcessor)
@pytest.fixture
def download_manager():
return mock.Mock(spec=ActiveDownloadManager)
@pytest.fixture
def twitter_forwarder():
return mock.Mock(spec=TwitterForwarder)
@pytest.fixture
def squeak_controller(
squeak_store,
squeak_core,
payment_processor,
network_manager,
download_manager,
twitter_forwarder,
node_settings,
config,
):
return SqueakController(
squeak_store,
squeak_core,
payment_processor,
network_manager,
download_manager,
twitter_forwarder,
node_settings,
config,
)
@pytest.fixture
def regtest_squeak_controller(
squeak_store,
squeak_core,
payment_processor,
network_manager,
download_manager,
twitter_forwarder,
node_settings,
regtest_config,
):
return SqueakController(
squeak_store,
squeak_core,
payment_processor,
network_manager,
download_manager,
twitter_forwarder,
node_settings,
regtest_config,
)
def test_get_network_default(squeak_controller):
assert squeak_controller.get_network() == "testnet"
def test_get_network_regtest(regtest_squeak_controller):
assert regtest_squeak_controller.get_network() == "regtest"
# def test_get_network_regtest(config, squeak_controller):
# # with mock.patch.object(Config, 'squeaknode_network', new_callable=mock.PropertyMock) as mock_config:
# # mock_config.return_value = 'regtest'
# config.squeaknode_network = "regtest"
# print(config.squeaknode_network)
# assert squeak_controller.get_network() == "regtest"
def test_create_peer(squeak_store, squeak_controller, peer_address):
squeak_controller.create_peer(
"fake_peer_name",
peer_address,
)
squeak_store.create_peer.assert_called_with(
"fake_peer_name",
peer_address,
)