|
| 1 | +from func_tests import BaseTest, execute, ADDR |
| 2 | +import unittest |
| 3 | +import re |
| 4 | + |
| 5 | + |
| 6 | +class TestChannels(BaseTest): |
| 7 | + def setUp(self): |
| 8 | + super().setUp() |
| 9 | + self.org_id = "SNet" |
| 10 | + self.org_2_id = "singularitynet" |
| 11 | + self.amount = "0.001" |
| 12 | + self.password = "12345" |
| 13 | + self.group = "default_group" |
| 14 | + data = execute(["channel", "print-filter-sender"], self.parser, self.conf) |
| 15 | + lines = data.split("\n") |
| 16 | + self.max_id = "" |
| 17 | + for line in lines: |
| 18 | + parts = line.split() |
| 19 | + if len(parts) >= 6 and parts[0].isdigit() and parts[-1].isdigit(): |
| 20 | + self.max_id = parts[0] |
| 21 | + |
| 22 | + def test_channel_1_extend(self): |
| 23 | + execute(["account", "deposit", self.amount, "-y", "-q"], self.parser, self.conf) |
| 24 | + if self.max_id: |
| 25 | + result1 = execute(["channel", "extend-add", self.max_id, "--amount", self.amount, "-y"], self.parser, self.conf) |
| 26 | + else: |
| 27 | + block_number = int(execute(["channel", "block-number"], self.parser, self.conf)) |
| 28 | + channel_open_output = execute(["channel", "open", self.org_id, self.group, self.amount, f"{block_number+10000}", "-y", "--open-new-anyway"], self.parser, self.conf) |
| 29 | + match = re.search(r"#channel_id\s+(\d+)", channel_open_output) |
| 30 | + self.max_id = match.group(1) |
| 31 | + execute(["channel", "extend-add", self.max_id, "--amount", self.amount, "-y"], self.parser, self.conf) |
| 32 | + result1 = execute(["channel", "extend-add", self.max_id, "--amount", self.amount, "-y"], self.parser, |
| 33 | + self.conf) |
| 34 | + # result2 = execute(["channel", "extend-add-for-org", self.org_id, "default_group", "--channel-id", f"{self.max_id}", "-y"], self.parser, self.conf) |
| 35 | + print(result1) |
| 36 | + assert "event: ChannelAddFunds" in result1 |
| 37 | + |
| 38 | + def test_channel_2_print_filter_sender(self): |
| 39 | + result = execute(["channel", "print-filter-sender"], self.parser, self.conf) |
| 40 | + print(result) |
| 41 | + assert "Channels for sender: ", ADDR in result |
| 42 | + |
| 43 | + def test_channel_3_print_filter_group_sender(self): |
| 44 | + result = execute(["channel", "print-filter-group-sender", self.org_id, self.group], self.parser, self.conf) |
| 45 | + assert "Channels for sender: ", ADDR in result |
| 46 | + |
| 47 | + def test_channel_4_print_filter_group(self): |
| 48 | + result = execute(["channel", "print-filter-group", self.org_id, self.group], self.parser, self.conf) |
| 49 | + assert self.max_id in result |
| 50 | + |
| 51 | + def test_channel_5_print_filter_recipient(self): |
| 52 | + result = execute(["channel", "print-filter-recipient"], self.parser, self.conf) |
| 53 | + assert "Channels for recipient:", ADDR in result |
| 54 | + |
| 55 | + def test_channel_5_claim(self): |
| 56 | + execute(["account", "deposit", self.amount, "-y", "-q"], self.parser, self.conf) |
| 57 | + if self.max_id: |
| 58 | + execute(["channel", "extend-add", self.max_id, "--amount", self.amount, "-y"], self.parser, self.conf) |
| 59 | + result1 = execute(["channel", "claim-timeout", f"{self.max_id}", "-y"], self.parser, self.conf) |
| 60 | + execute(["account", "deposit", self.amount, "-y", "-q"], self.parser, self.conf) |
| 61 | + execute(["channel", "extend-add", self.max_id, "--amount", self.amount, "-y"], self.parser, self.conf) |
| 62 | + result2 = execute(["channel", "claim-timeout-all", "-y"], self.parser, self.conf) |
| 63 | + else: |
| 64 | + block_number = int(execute(["channel", "block-number"], self.parser, self.conf)) |
| 65 | + execute(["channel", "open", self.org_id, self.group, self.amount, f"{block_number-1}", "-y"], self.parser, self.conf) |
| 66 | + execute(["channel", "extend-add", self.max_id, "--amount", self.amount, "-y"], self.parser, self.conf) |
| 67 | + result1 = execute(["channel", "claim-timeout", f"{self.max_id}", "-y"], self.parser, self.conf) |
| 68 | + execute(["account", "deposit", self.amount, "-y", "-q"], self.parser, self.conf) |
| 69 | + execute(["channel", "extend-add", self.max_id, "--amount", self.amount, "-y"], self.parser, self.conf) |
| 70 | + result2 = execute(["channel", "claim-timeout-all", "-y"], self.parser, self.conf) |
| 71 | + print(result1) |
| 72 | + assert ("event: ChannelSenderClaim" in result1) and ("event: ChannelSenderClaim" in result2) |
| 73 | + |
| 74 | + def test_channel_6_print_all(self): |
| 75 | + result = execute(["channel", "print-all", "-ds"], self.parser, self.conf) |
| 76 | + assert self.max_id in result |
| 77 | + |
| 78 | +if __name__ == "__main__": |
| 79 | + unittest.main() |
0 commit comments