Skip to content

Commit

Permalink
Add test before/after (chia v1.4.0) for wallet_added_coin
Browse files Browse the repository at this point in the history
  • Loading branch information
djerfy authored and martomi committed Jul 4, 2022
1 parent 5576c29 commit 817f908
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
19 changes: 11 additions & 8 deletions tests/chia_log/handlers/test_wallet_added_coin_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions tests/chia_log/logs/wallet_added_coin/nominal-after-1.4.0.txt
Original file line number Diff line number Diff line change
@@ -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
19 changes: 11 additions & 8 deletions tests/chia_log/parsers/test_wallet_added_coin_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit 817f908

Please sign in to comment.