Skip to content

Commit

Permalink
Fix PFSDatabase.delete_channel(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
palango committed Jan 9, 2020
1 parent e1deb47 commit 49380d6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/pathfinding_service/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,11 @@ def get_channels(self) -> Iterator[Channel]:
def delete_channel(
self, token_network_address: TokenNetworkAddress, channel_id: ChannelID
) -> None:
self.conn.execute(
cursor = self.conn.execute(
"DELETE FROM channel WHERE token_network_address = ? AND channel_id = ?",
[token_network_address, channel_id],
[to_checksum_address(token_network_address), hex256(channel_id)],
)
assert cursor.rowcount == 1, "Deleted more than one channel."

def get_token_networks(self) -> Iterator[TokenNetwork]:
for row in self.conn.execute("SELECT address FROM token_network"):
Expand Down
40 changes: 40 additions & 0 deletions tests/pathfinding/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from uuid import uuid4

from pathfinding_service.database import PFSDatabase
from pathfinding_service.model.channel import Channel
from pathfinding_service.model.feedback import FeedbackToken
from raiden.constants import EMPTY_SIGNATURE
from raiden.messages.path_finding_service import PFSCapacityUpdate, PFSFeeUpdate
Expand Down Expand Up @@ -202,3 +203,42 @@ def test_waiting_messages(pathfinding_service_mock):
)
)
assert len(recovered_messages2) == 0


def test_channels(pathfinding_service_mock):
# Participants need to be ordered
parts = [make_address(), make_address(), make_address()]
parts.sort()

token_network_address = TokenNetworkAddress(b"1" * 20)

# register token network internally
database = pathfinding_service_mock.database
database.upsert_token_network(token_network_address)

channel1 = Channel(
token_network_address=token_network_address,
channel_id=ChannelID(1),
participant1=parts[0],
participant2=parts[1],
settle_timeout=BlockTimeout(100),
)
channel2 = Channel(
token_network_address=token_network_address,
channel_id=ChannelID(2),
participant1=parts[1],
participant2=parts[2],
settle_timeout=BlockTimeout(100),
)

database.upsert_channel(channel1)
assert [chan.channel_id for chan in database.get_channels()] == [channel1.channel_id]

database.upsert_channel(channel2)
assert [chan.channel_id for chan in database.get_channels()] == [
channel1.channel_id,
channel2.channel_id,
]

database.delete_channel(channel1.token_network_address, channel1.channel_id)
assert [chan.channel_id for chan in database.get_channels()] == [channel2.channel_id]

0 comments on commit 49380d6

Please sign in to comment.