From 817f908adcd8ac00f4a6ea7c3b25ad5c7871de50 Mon Sep 17 00:00:00 2001 From: Djerfy Date: Mon, 4 Jul 2022 23:27:30 +0200 Subject: [PATCH] Add test before/after (chia v1.4.0) for wallet_added_coin --- .../test_wallet_added_coin_handler.py | 19 +++++++++++-------- .../wallet_added_coin/nominal-after-1.4.0.txt | 6 ++++++ .../{nominal.txt => nominal-before-1.4.0.txt} | 0 .../parsers/test_wallet_added_coin_parser.py | 19 +++++++++++-------- 4 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 tests/chia_log/logs/wallet_added_coin/nominal-after-1.4.0.txt rename tests/chia_log/logs/wallet_added_coin/{nominal.txt => nominal-before-1.4.0.txt} (100%) diff --git a/tests/chia_log/handlers/test_wallet_added_coin_handler.py b/tests/chia_log/handlers/test_wallet_added_coin_handler.py index cff18db..6d33479 100644 --- a/tests/chia_log/handlers/test_wallet_added_coin_handler.py +++ b/tests/chia_log/handlers/test_wallet_added_coin_handler.py @@ -23,15 +23,18 @@ def testConfig(self): self.assertEqual(self.handler_config["min_mojos_amount"], 5) def testNominal(self): - with open(self.example_logs_path / "nominal.txt", encoding="UTF-8") as f: - logs = f.readlines() + with open(self.example_logs_path / "nominal-before-1.4.0.txt", encoding="UTF-8") as f: + logs_before = f.readlines() + with open(self.example_logs_path / "nominal-after-1.4.0.txt", encoding="UTF-8") as f: + logs_after = f.readlines() - events = self.handler.handle("".join(logs)) - self.assertEqual(1, len(events)) - self.assertEqual(events[0].type, EventType.USER, "Unexpected event type") - self.assertEqual(events[0].priority, EventPriority.LOW, "Unexpected priority") - self.assertEqual(events[0].service, EventService.WALLET, "Unexpected service") - self.assertEqual(events[0].message, "Cha-ching! Just received 2 XCH ☘️") + for logs in [logs_before, logs_after]: + events = self.handler.handle("".join(logs)) + self.assertEqual(1, len(events)) + self.assertEqual(events[0].type, EventType.USER, "Unexpected event type") + self.assertEqual(events[0].priority, EventPriority.LOW, "Unexpected priority") + self.assertEqual(events[0].service, EventService.WALLET, "Unexpected service") + self.assertEqual(events[0].message, "Cha-ching! Just received 2 XCH ☘️") def testFloatPrecision(self): with open(self.example_logs_path / "small_values.txt", encoding="UTF-8") as f: diff --git a/tests/chia_log/logs/wallet_added_coin/nominal-after-1.4.0.txt b/tests/chia_log/logs/wallet_added_coin/nominal-after-1.4.0.txt new file mode 100644 index 0000000..9eab095 --- /dev/null +++ b/tests/chia_log/logs/wallet_added_coin/nominal-after-1.4.0.txt @@ -0,0 +1,6 @@ +22:50:45.215 wallet chia.wallet.wallet_state_manager: INFO Adding record to state manager coin: {'amount': 250000000000, + 'parent_coin_info': '0x3333333333333333333333333333333333333333333333333333333333333333', + 'puzzle_hash': '0x1111111111111111111111111111111111111111111111111111111111111111'} at 424242 +22:50:47.227 wallet chia.wallet.wallet_state_manager: INFO Adding record to state manager coin: {'amount': 1750000000000, + 'parent_coin_info': '0xcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', + 'puzzle_hash': '0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'} at 424242 diff --git a/tests/chia_log/logs/wallet_added_coin/nominal.txt b/tests/chia_log/logs/wallet_added_coin/nominal-before-1.4.0.txt similarity index 100% rename from tests/chia_log/logs/wallet_added_coin/nominal.txt rename to tests/chia_log/logs/wallet_added_coin/nominal-before-1.4.0.txt diff --git a/tests/chia_log/parsers/test_wallet_added_coin_parser.py b/tests/chia_log/parsers/test_wallet_added_coin_parser.py index 8639fc9..a6c3ef8 100644 --- a/tests/chia_log/parsers/test_wallet_added_coin_parser.py +++ b/tests/chia_log/parsers/test_wallet_added_coin_parser.py @@ -10,17 +10,20 @@ class TestWalletAddedCoinParser(unittest.TestCase): def setUp(self) -> None: self.parser = WalletAddedCoinParser() self.example_logs_path = Path(__file__).resolve().parents[1] / "logs/wallet_added_coin" - with open(self.example_logs_path / "nominal.txt", encoding="UTF-8") as f: - self.nominal_logs = f.read() + with open(self.example_logs_path / "nominal-before-1.4.0.txt", encoding="UTF-8") as f: + self.nominal_logs_before = f.read() + with open(self.example_logs_path / "nominal-after-1.4.0.txt", encoding="UTF-8") as f: + self.nominal_logs_after = f.read() def testBasicParsing(self): - added_coins = self.parser.parse(self.nominal_logs) - total_mojos = 0 - for coin in added_coins: - total_mojos += coin.amount_mojos + for nominal_logs in [self.nominal_logs_before, self.nominal_logs_after]: + added_coins = self.parser.parse(nominal_logs) + total_mojos = 0 + for coin in added_coins: + total_mojos += coin.amount_mojos - chia = total_mojos / 1e12 - self.assertEqual(2, chia) + chia = total_mojos / 1e12 + self.assertEqual(2, chia) if __name__ == "__main__":