def crypto_block(crypto_transaction, crypto_transaction_2): # TODO: Block is not from testnet and it has wrong data and signature # Change it once we're able to forge blocks with our code block = Block( height=2243161, id="10977713934532967004", id_hex=b"9858aca939b17a5c", number_of_transactions=2, payload_hash=( "3784b953afcf936bdffd43fdf005b5732b49c1fc6b11e195c364c20b2eb06282" ), payload_length=224, previous_block="3112633353705641986", previous_block_hex=b"2b324b8b33a85802", reward=200000000, timestamp=24760440, total_amount=3890300, total_fee=70000000, version=0, generator_public_key=( "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" ), block_signature=( "3045022100eee6c37b5e592e99811d588532726353592923f347c701d52912e6d583443e40022" "0277ffe38ad31e216ba0907c4738fed19b2071246b150c72c0a52bae4477ebe29" ), ) crypto_transaction.block_id = "7176646138626297930" crypto_transaction_2.block_id = "7176646138626297930" block.transactions = [crypto_transaction, crypto_transaction_2] return block
def test_apply_block_updates_vote_balance_of_voted_delegate(redis, mocker): manager = WalletManager() apply_transaction_mock = mocker.patch( "chain.plugins.database.wallet_manager.WalletManager.apply_transaction" ) transaction_1 = TransferTransaction() transaction_2 = TransferTransaction() block = Block() block.height = 1337 block.reward = 2 block.transactions = [transaction_1, transaction_2] block.generator_public_key = ( "0316510c1409d3307d9f205cac58f1a871499c3ffea3878ddbbb48c821cfbc079a" ) redis.set( "wallets:address:AWoysqF1xm1LXYLQvmRDpfVNKzzaLVwPVM", json.dumps( { "address": "AWoysqF1xm1LXYLQvmRDpfVNKzzaLVwPVM", "public_key": ( "0316b3dc139c1a35927ecbdcb8d8b628ad06bd4f1869fe3ad0e23c8106678a460f" ), "vote_balance": 2000000, } ), ) redis.set( "wallets:address:ASt5oBHKDW8AeJe2Ybc1RucMLS7mRCiuRe", Wallet( { "address": "ASt5oBHKDW8AeJe2Ybc1RucMLS7mRCiuRe", "public_key": ( "0316510c1409d3307d9f205cac58f1a871499c3ffea3878ddbbb48c821cfbc079a" ), "balance": 0, "vote": ( "0316b3dc139c1a35927ecbdcb8d8b628ad06bd4f1869fe3ad0e23c8106678a460f" ), } ).to_json(), ) manager.apply_block(block) assert apply_transaction_mock.call_count == 2 delegate = Wallet( json.loads(redis.get("wallets:address:ASt5oBHKDW8AeJe2Ybc1RucMLS7mRCiuRe")) ) assert delegate.balance == 2 vote_wallet = Wallet( json.loads(redis.get("wallets:address:AWoysqF1xm1LXYLQvmRDpfVNKzzaLVwPVM")) ) assert vote_wallet.vote_balance == 2000002
def test_apply_block_raises_if_not_genesis_and_no_delegate(redis): manager = WalletManager() transaction_1 = TransferTransaction() transaction_2 = TransferTransaction() block = Block() block.height = 1337 block.reward = 2 block.transactions = [transaction_1, transaction_2] block.generator_public_key = ( "0316510c1409d3307d9f205cac58f1a871499c3ffea3878ddbbb48c821cfbc079a" ) with pytest.raises(Exception) as excinfo: manager.apply_block(block) assert str(excinfo.value) == ( "Could not find a delegate with public key: " "0316510c1409d3307d9f205cac58f1a871499c3ffea3878ddbbb48c821cfbc079a" )
def test_apply_block_correctly_handles_genesis_block(redis, mocker): manager = WalletManager() apply_transaction_mock = mocker.patch( "chain.plugins.database.wallet_manager.WalletManager.apply_transaction" ) transaction_1 = TransferTransaction() transaction_2 = TransferTransaction() block = Block() block.height = 1 block.reward = 2 block.transactions = [transaction_1, transaction_2] block.generator_public_key = ( "0316510c1409d3307d9f205cac58f1a871499c3ffea3878ddbbb48c821cfbc079a" ) manager.apply_block(block) assert apply_transaction_mock.call_count == 2 delegate = Wallet( json.loads(redis.get("wallets:address:ASt5oBHKDW8AeJe2Ybc1RucMLS7mRCiuRe")) ) assert delegate.balance == 2