def test_block_skip_verify(): """ Deserialize a Block by skipping the verification of signature and PoW """ block_data = BLOCKS["receive"]["data"].copy() block_data["work"] = "a" * 16 # The work is invalid, but it's OK Block.from_dict(block_data, verify=False) Block.from_json(json.dumps(block_data), verify=False) block_data["signature"] = "A" * 128 # The signature is invalid, but that's OK as well now Block.from_dict(block_data, verify=False) Block.from_json(json.dumps(block_data), verify=False)
def test_block_json(name, block): """ Deserialize every block from JSON and ensure they can be serialized back into identical JSON """ test_block = block["data"] block = Block.from_json(json.dumps(test_block)) assert json.loads(block.json()) == test_block
def test_block_complete(name, block): """ Deserialize every block from JSON and check that they have valid PoW and signatures """ test_block = block["data"] block = Block.from_json(json.dumps(test_block)) assert block.has_valid_work if block.account: assert block.has_valid_signature assert block.complete else: # Nano reference wallet's RPC API doesn't return some legacy blocks # with 'account' fields set even if they're required to verify the # signature. try: assert not block.account block.verify_signature() except ValueError as e: assert "'account' not included" in str(e) assert not block.complete