2021-08-27 18:31:53 -07:00
|
|
|
# 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.
|
2020-12-26 04:56:46 -08:00
|
|
|
import mock
|
2020-12-28 23:52:32 -08:00
|
|
|
import pytest
|
2020-12-25 20:17:54 -08:00
|
|
|
|
2022-03-26 20:42:42 -07:00
|
|
|
from squeaknode.client.network_controller import NetworkController
|
2021-01-05 23:39:04 -08:00
|
|
|
from squeaknode.config.config import SqueaknodeConfig
|
2020-12-25 20:17:54 -08:00
|
|
|
from squeaknode.core.lightning_address import LightningAddressHostPort
|
2021-10-10 21:00:56 -07:00
|
|
|
from squeaknode.core.peer_address import Network
|
2021-02-21 15:29:00 -08:00
|
|
|
from squeaknode.core.peer_address import PeerAddress
|
2021-12-23 08:33:40 -08:00
|
|
|
from squeaknode.node.node_settings import NodeSettings
|
2021-02-12 00:14:45 -08:00
|
|
|
from squeaknode.node.payment_processor import PaymentProcessor
|
2021-02-13 07:46:00 -08:00
|
|
|
from squeaknode.node.squeak_controller import SqueakController
|
2021-12-25 09:47:55 -08:00
|
|
|
from squeaknode.node.squeak_store import SqueakStore
|
2022-03-26 20:42:42 -07:00
|
|
|
from squeaknode.twitter.twitter_forwarder import TwitterForwarder
|
2021-01-03 22:02:55 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def config():
|
2021-01-05 23:39:04 -08:00
|
|
|
squeaknode_config = SqueaknodeConfig()
|
|
|
|
|
squeaknode_config.read()
|
|
|
|
|
return squeaknode_config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def regtest_config():
|
|
|
|
|
squeaknode_config = SqueaknodeConfig(
|
2021-08-24 01:13:24 -07:00
|
|
|
dict_config={'node': {'network': 'regtest'}}
|
2021-01-05 23:39:04 -08:00
|
|
|
)
|
|
|
|
|
squeaknode_config.read()
|
|
|
|
|
return squeaknode_config
|
2020-12-25 20:17:54 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2021-12-25 09:47:55 -08:00
|
|
|
def squeak_store():
|
|
|
|
|
return mock.Mock(spec=SqueakStore)
|
2020-12-25 20:17:54 -08:00
|
|
|
|
|
|
|
|
|
2021-12-23 08:33:40 -08:00
|
|
|
@pytest.fixture
|
|
|
|
|
def node_settings():
|
|
|
|
|
return mock.Mock(spec=NodeSettings)
|
|
|
|
|
|
|
|
|
|
|
2020-12-25 20:17:54 -08:00
|
|
|
@pytest.fixture
|
|
|
|
|
def lightning_host_port():
|
2020-12-26 02:01:22 -08:00
|
|
|
return LightningAddressHostPort(host="my_lightning_host", port=8765)
|
2020-12-25 20:17:54 -08:00
|
|
|
|
|
|
|
|
|
2021-08-21 00:54:48 -07:00
|
|
|
@pytest.fixture
|
|
|
|
|
def peer_address():
|
2021-10-10 21:00:56 -07:00
|
|
|
return PeerAddress(
|
|
|
|
|
network=Network.IPV4,
|
|
|
|
|
host="fake_host",
|
|
|
|
|
port=5678,
|
|
|
|
|
)
|
2021-08-21 00:54:48 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def peer_address_with_zero():
|
2021-10-10 21:00:56 -07:00
|
|
|
return PeerAddress(
|
|
|
|
|
network=Network.IPV4,
|
|
|
|
|
host="fake_host",
|
|
|
|
|
port=0,
|
|
|
|
|
)
|
2021-08-21 00:54:48 -07:00
|
|
|
|
|
|
|
|
|
2020-12-25 20:17:54 -08:00
|
|
|
@pytest.fixture
|
|
|
|
|
def price_msat():
|
|
|
|
|
return 777
|
|
|
|
|
|
|
|
|
|
|
2021-02-12 00:14:45 -08:00
|
|
|
@pytest.fixture
|
|
|
|
|
def payment_processor():
|
|
|
|
|
return mock.Mock(spec=PaymentProcessor)
|
|
|
|
|
|
|
|
|
|
|
2022-03-26 20:42:42 -07:00
|
|
|
@pytest.fixture
|
|
|
|
|
def twitter_forwarder():
|
|
|
|
|
return mock.Mock(spec=TwitterForwarder)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def network_controller():
|
|
|
|
|
return mock.Mock(spec=NetworkController)
|
|
|
|
|
|
|
|
|
|
|
2020-12-25 20:17:54 -08:00
|
|
|
@pytest.fixture
|
2020-12-26 02:01:22 -08:00
|
|
|
def squeak_controller(
|
2021-12-25 09:47:55 -08:00
|
|
|
squeak_store,
|
2021-02-12 00:14:45 -08:00
|
|
|
payment_processor,
|
2022-03-26 20:42:42 -07:00
|
|
|
twitter_forwarder,
|
|
|
|
|
network_controller,
|
2021-12-23 08:33:40 -08:00
|
|
|
node_settings,
|
2021-01-03 22:02:55 -08:00
|
|
|
config,
|
2020-12-26 02:01:22 -08:00
|
|
|
):
|
2020-12-25 20:17:54 -08:00
|
|
|
return SqueakController(
|
2021-12-25 09:47:55 -08:00
|
|
|
squeak_store,
|
2021-02-12 00:14:45 -08:00
|
|
|
payment_processor,
|
2022-03-26 20:42:42 -07:00
|
|
|
twitter_forwarder,
|
|
|
|
|
network_controller,
|
2021-12-23 08:33:40 -08:00
|
|
|
node_settings,
|
2021-01-03 22:02:55 -08:00
|
|
|
config,
|
2020-12-25 20:17:54 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2021-01-05 23:39:04 -08:00
|
|
|
@pytest.fixture
|
|
|
|
|
def regtest_squeak_controller(
|
2021-12-25 09:47:55 -08:00
|
|
|
squeak_store,
|
2021-02-12 00:14:45 -08:00
|
|
|
payment_processor,
|
2022-03-26 20:42:42 -07:00
|
|
|
twitter_forwarder,
|
|
|
|
|
network_controller,
|
2021-12-23 08:33:40 -08:00
|
|
|
node_settings,
|
2021-01-05 23:39:04 -08:00
|
|
|
regtest_config,
|
|
|
|
|
):
|
|
|
|
|
return SqueakController(
|
2021-12-25 09:47:55 -08:00
|
|
|
squeak_store,
|
2021-02-12 00:14:45 -08:00
|
|
|
payment_processor,
|
2022-03-26 20:42:42 -07:00
|
|
|
twitter_forwarder,
|
|
|
|
|
network_controller,
|
2021-12-23 08:33:40 -08:00
|
|
|
node_settings,
|
2021-01-05 23:39:04 -08:00
|
|
|
regtest_config,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2021-01-04 01:28:08 -08:00
|
|
|
def test_get_network_default(squeak_controller):
|
2021-01-03 22:02:55 -08:00
|
|
|
assert squeak_controller.get_network() == "testnet"
|
2021-01-04 01:28:08 -08:00
|
|
|
|
|
|
|
|
|
2021-01-05 23:39:04 -08:00
|
|
|
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)
|
2021-01-04 01:28:08 -08:00
|
|
|
|
2021-01-05 23:39:04 -08:00
|
|
|
# assert squeak_controller.get_network() == "regtest"
|
2021-01-06 23:47:03 -08:00
|
|
|
|
|
|
|
|
|
2021-12-25 09:47:55 -08:00
|
|
|
def test_create_peer(squeak_store, squeak_controller, peer_address):
|
2021-01-06 23:47:03 -08:00
|
|
|
squeak_controller.create_peer(
|
|
|
|
|
"fake_peer_name",
|
2021-08-21 00:54:48 -07:00
|
|
|
peer_address,
|
2021-01-06 23:47:03 -08:00
|
|
|
)
|
|
|
|
|
|
2021-12-25 09:47:55 -08:00
|
|
|
squeak_store.create_peer.assert_called_with(
|
|
|
|
|
"fake_peer_name",
|
|
|
|
|
peer_address,
|
2022-06-17 19:04:31 -07:00
|
|
|
0,
|
2021-01-06 23:47:03 -08:00
|
|
|
)
|