Beispiel #1
0
    def test_coin_part_revision_3(self):
        part1 = CoinPart()
        self.assertIsNotNone(part1)
        self.assertIs(CoinPartFlag.NONE, part1.flags)
        self.assertTrue(part1.balance == 0)

        part1.deposit(100)
        self.assertEqual(100, part1.balance)

        part1.withdraw(100)
        self.assertEqual(0, part1.balance)

        # wrong value
        self.assertRaises(InvalidParamsException, part1.deposit, -10)

        # 0 transfer is possible
        old = part1.balance
        part1.deposit(0)
        self.assertEqual(old, part1.balance)

        self.assertRaises(InvalidParamsException, part1.withdraw, -11234)
        self.assertRaises(OutOfBalanceException, part1.withdraw, 1)

        old = part1.balance
        part1.withdraw(0)
        self.assertEqual(old, part1.balance)
Beispiel #2
0
    def test_coin_part_equal(self):
        part1 = CoinPart()
        part2 = CoinPart()
        self.assertEqual(part1, part2)

        balance = 100
        part1.deposit(balance)
        part3 = CoinPart(balance=balance)
        self.assertEqual(part1, part3)
Beispiel #3
0
    def test_coin_part_withdraw(self):
        balance = 100
        part = CoinPart()

        self.assertFalse(part.is_dirty())
        part.deposit(balance)
        part.withdraw(balance)
        self.assertTrue(part.is_dirty())
        self.assertEqual(0, part.balance)
Beispiel #4
0
    def test_coin_part_from_bytes_to_bytes_old_db_load_revision_4(self):
        part1 = CoinPart()

        balance = 1024
        part1.type = CoinPartType.GENERAL
        part1.deposit(balance)

        part2 = CoinPart.from_bytes(part1.to_bytes(Revision.THREE.value))
        self.assertEqual(part1, part2)

        data: bytes = part1.to_bytes(Revision.FOUR.value)
        part3 = CoinPart.from_bytes(data)
        self.assertEqual(part1, part3)
Beispiel #5
0
    def test_coin_part_from_bytes_to_bytes_revision_4(self):
        part1 = CoinPart()

        data = part1.to_bytes(Revision.FOUR.value)
        self.assertTrue(isinstance(data, bytes))

        part2 = CoinPart.from_bytes(data)
        self.assertEqual(part1, part2)
        self.assertEqual(CoinPartType.GENERAL, part2.type)
        self.assertEqual(0, part2.balance)
        self.assertEqual(CoinPartFlag.NONE, part2.flags)

        part1.type = CoinPartType.GENESIS
        part1.deposit(1024)

        part3 = CoinPart.from_bytes(part1.to_bytes(Revision.FOUR.value))
        self.assertEqual(CoinPartType.GENESIS, part3.type)
        self.assertEqual(1024, part3.balance)
Beispiel #6
0
    def test_coin_part_from_bytes_to_bytes_revision_3(self):
        part1 = CoinPart()
        revision = 3

        data = part1.to_bytes(revision)
        self.assertTrue(isinstance(data, bytes))
        self.assertEqual(36, len(data))

        part2 = CoinPart.from_bytes(data)
        self.assertEqual(CoinPartType.GENERAL, part2.type)
        self.assertEqual(0, part2.balance)

        part1.type = CoinPartType.GENESIS
        part1.deposit(1024)

        part3 = CoinPart.from_bytes(part1.to_bytes(revision))
        self.assertEqual(CoinPartType.GENESIS, part3.type)
        self.assertEqual(1024, part3.balance)