示例#1
0
    def get_account(self, address: 'Address') -> 'Account':
        """Read the account from statedb

        :param address:
        :return:
        """
        value: bytes = self._db.get(address.to_bytes())
        if value is None:
            return None

        account = Account.from_bytes(value)
        account.address = address

        return account
示例#2
0
    def test_account_from_bytes_to_bytes(self):
        account = Account()

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

        account2 = Account.from_bytes(data)
        self.assertFalse(account2.locked)
        self.assertFalse(account2.c_rep)
        self.assertEqual(AccountType.GENERAL, account2.type)
        self.assertEqual(0, account2.icx)

        account.type = AccountType.GENESIS
        account.locked = True
        account.c_rep = True
        account.deposit(1024)

        account3 = Account.from_bytes(account.to_bytes())
        self.assertTrue(account3.locked)
        self.assertTrue(account3.c_rep)
        self.assertEqual(AccountType.GENESIS, account3.type)
        self.assertEqual(1024, account3.icx)