def test_coin_transfer_signed_request_message_fields_are_stored_in_bytes(field_name, value): signed_change_request_msg = factories.CoinTransferSignedChangeRequestMessageFactory(**{field_name: value}) signed_change_request = factories.CoinTransferSignedChangeRequestFactory(message=signed_change_request_msg) block_msg = factories.CoinTransferBlockMessageFactory(signed_change_request=signed_change_request) block = factories.CoinTransferBlockFactory(message=block_msg) compact_dict = block.to_compact_dict(compact_keys=False)['message']['signed_change_request']['message'] assert compact_dict[field_name] == bytes.fromhex(value)
def test_non_ascii_memo_is_serialized_correctly(): # TODO(dmu) HIGH: This test must test transaction without using outer structures memo = 'Тестовое сообщение' # Test message in Russian transaction = factories.CoinTransferTransactionFactory(memo=memo) transaction.fee = False trm = factories.CoinTransferSignedChangeRequestMessageFactory( txs=[transaction]) tr = factories.CoinTransferSignedChangeRequestFactory(message=trm) block_message = factories.CoinTransferBlockMessageFactory( signed_change_request=tr) block = factories.CoinTransferBlockFactory(message=block_message) msg_pack = block.to_messagepack() restored_block = block.from_messagepack(msg_pack) assert restored_block == block
def test_transaction_optional_keys_are_not_serialized(key, value): # TODO(dmu) HIGH: This test must test transaction without using outer structures transaction = factories.CoinTransferTransactionFactory(**{key: value}) trm = factories.CoinTransferSignedChangeRequestMessageFactory( txs=[transaction]) tr = factories.CoinTransferSignedChangeRequestFactory(message=trm) block_message = factories.CoinTransferBlockMessageFactory( signed_change_request=tr) block = factories.CoinTransferBlockFactory(message=block_message) compact_dict = block.to_compact_dict(compact_values=False, compact_keys=False) transaction_dict = compact_dict['message']['signed_change_request'][ 'message']['txs'][0] assert key not in transaction_dict
initial_arf = factories.InitialAccountRootFileFactory(account_states={ USER_ACCOUNT_1: factories.AccountStateFactory(balance=100, balance_lock=USER_ACCOUNT_1) }, ) block_0 = factories.CoinTransferBlockFactory( message=factories.CoinTransferBlockMessageFactory( block_number=0, block_identifier=BLOCK_IDENTIFIER, signed_change_request=factories.CoinTransferSignedChangeRequestFactory( signer=USER_ACCOUNT_1, message=factories.CoinTransferSignedChangeRequestMessageFactory( balance_lock=USER_ACCOUNT_1, txs=[ factories.CoinTransferTransactionFactory( recipient=USER_ACCOUNT_2, amount=11, ) ])), updated_account_states={ USER_ACCOUNT_1: factories.AccountStateFactory(balance=89, balance_lock=MESSAGE_HASH), USER_ACCOUNT_2: factories.AccountStateFactory(balance=11, balance_lock=None), }), message_hash=MESSAGE_HASH, ) def test_validate_number_of_accounts_mismatch(blockchain_base):
def test_generate_blockchain_state(blockchain_base): blockchain_genesis_state = factories.InitialBlockchainStateFactory( account_states={USER_ACCOUNT_1: factories.AccountStateFactory( balance=1000, balance_lock=USER_ACCOUNT_1, )} ) block_0 = factories.CoinTransferBlockFactory( message=factories.CoinTransferBlockMessageFactory( block_number=0, block_identifier='fake-block-identifier-0', timestamp=datetime(2021, 1, 1), signed_change_request=factories.CoinTransferSignedChangeRequestFactory( signer=USER_ACCOUNT_1, message=factories.CoinTransferSignedChangeRequestMessageFactory( balance_lock=USER_ACCOUNT_1, txs=[ factories.CoinTransferTransactionFactory( recipient=USER_ACCOUNT_2, amount=99, ), ] ), ), updated_account_states={ USER_ACCOUNT_1: factories.AccountStateFactory( balance=901, balance_lock='user-account-1-lock', ), USER_ACCOUNT_2: factories.AccountStateFactory( balance=99, balance_lock=None, ) } ), hash='fake-message-hash', ) blockchain_state_patch = patch_blockchain_states(blockchain_base, [blockchain_genesis_state]) block_patch = patch_blocks(blockchain_base, [block_0]) with blockchain_state_patch, block_patch: blockchain_state = blockchain_base.generate_blockchain_state() assert blockchain_state == factories.BlockchainStateFactory( account_states={ USER_ACCOUNT_1: factories.AccountStateFactory( balance=901, balance_lock='user-account-1-lock', node=None, ), USER_ACCOUNT_2: factories.AccountStateFactory( balance=99, balance_lock=None, node=None, ) }, last_block_number=0, last_block_identifier=block_0.message.block_identifier, last_block_timestamp=block_0.message.timestamp, next_block_identifier=block_0.hash, )