def test_is_valid_minimalist(self): leaves = [ '02aae7e86eb50f61a62083a320475d9d60cbd52749dbf08fa942b1b97f50aee5' ] nodes = [] bitmap = "bf" depth = "0004" anchor = get_anchor_dict() self.assertTrue( Proof.isValid(Proof(leaves, nodes, depth, bitmap, anchor)), 'Proof should be valid.')
def test_is_valid_depth_too_short(self): leaves = [ '02aae7e86eb50f61a62083a320475d9d60cbd52749dbf08fa942b1b97f50aee5' ] nodes = [ "bb6986853646d083929d1d92638f3d4741a3b7149bd2b63c6bfedd32e3c684d3", "0616067c793ac533815ae2d48d785d339e0330ce5bb5345b5e6217dd9d1dbeab", "68b8f6b25cc700e64ed3e3d33f2f246e24801f93d29786589fbbab3b11f5bcee" ] bitmap = "bfdf7000" depth = "000400060006000" anchor = get_anchor_dict() self.assertFalse( Proof.isValid(Proof(leaves, nodes, depth, bitmap, anchor)), 'Proof should be valid.')
def test_verify_proof_okay(self, MockProofRepo): MockProofRepo.verifyProof.return_value = Record('root') proof = Proof( bitmap="bfdf7000", depth="000400060006000500030002000400060007000800090009", leaves=[ "02aae7e86eb50f61a62083a320475d9d60cbd52749dbf08fa942b1b97f50aee5", ], nodes=[ "bb6986853646d083929d1d92638f3d4741a3b7149bd2b63c6bfedd32e3c684d3", "0616067c793ac533815ae2d48d785d339e0330ce5bb5345b5e6217dd9d1dbeab", "68b8f6b25cc700e64ed3e3d33f2f246e24801f93d29786589fbbab3b11f5bcee" ], anchor={ "anchor_id": 387, "root": "c6372dab6a48637173a457e3ae0c54a500bb50346e847eccf2b818ade94d8ccf", "networks": [{ "name": "bloock_chain", "tx_hash": "0xc087797b9700245c8e3f678874e9c419297f2302cb822d798ca94cce8c27aea9", "state": "Confirmed", "created_at": 0 }, { "name": "ethereum_rinkeby", "tx_hash": "0xc087797b9700245c8e3f678874e9c419297f2302cb822d798ca94cce8c27aea9", "state": "Confirmed", "created_at": 1 }, { "name": "ethereum_mainnet", "tx_hash": "0xc087797b9700245c8e3f678874e9c419297f2302cb822d798ca94cce8c27aea9", "state": "Confirmed", "created_at": 1 }], "status": "Success" }) root = Record('root') calls = [ call(Network.BLOOCK_CHAIN, root), call(Network.ETHEREUM_RINKEBY, root), call(Network.ETHEREUM_MAINNET, root) ] MockProofRepo.validateRoot.has_calls(calls) MockProofRepo.validateRoot.side_effect = [0, 1, 2] service = ProofService(MockProofRepo) timestamp = service.verifyProof(proof) self.assertEqual(timestamp, 2, 'wrong timestamp recieved')
def test_verify_proof_failing_invalid_bitmap(self, MockHttpClient, MockBlockchainClient, MockConfig): leaves = [ '0000000000000000000000000000000000000000000000000000000000000000'] nodes = [ '0101010101010101010101010101010101010101010101010101010101010101' ] depth = '000000000' bitmap = '4' anchor = get_anchor_dict() proof_repo = ProofRepository( MockHttpClient, MockBlockchainClient, MockConfig) proof = Proof(leaves, nodes, depth, bitmap, anchor) with self.assertRaises(ProofVerificationException): proof_repo.verifyProof(proof)
def test_verify_proof_keccak_3(self, MockHttpClient, MockBlockchainClient, MockConfig): leaves = [ '0000000000000000000000000000000000000000000000000000000000000000'] nodes = [ 'f49d70da1c2c8989766908e06b8d2277a6954ec8533696b9a404b631b0b7735a' ] depth = '00010001' bitmap = '4000' root = '5c67902dc31624d9278c286ef4ce469451d8f1d04c1edb29a5941ca0e03ddc8d' anchor = get_anchor_dict() proof_repo = ProofRepository( MockHttpClient, MockBlockchainClient, MockConfig) proof = Proof(leaves, nodes, depth, bitmap, anchor) self.assertEqual(proof_repo.verifyProof(proof).getHash(), root, 'Proof not verifying correctly.')
def test_verify_proof_keccak_2(self, MockHttpClient, MockBlockchainClient, MockConfig): leaves = [ '0000000000000000000000000000000000000000000000000000000000000000'] nodes = [ '0101010101010101010101010101010101010101010101010101010101010101' ] depth = '00000000' bitmap = '40' root = 'd5f4f7e1d989848480236fb0a5f808d5877abf778364ae50845234dd6c1e80fc' anchor = get_anchor_dict() proof_repo = ProofRepository( MockHttpClient, MockBlockchainClient, MockConfig) proof = Proof(leaves, nodes, depth, bitmap, anchor) self.assertEqual(proof_repo.verifyProof(proof).getHash(), root, 'Proof not verifying correctly.')
def test_verify_proof_keccak(self, MockHttpClient, MockBlockchainClient, MockConfig): leaves = [ '0000000000000000000000000000000000000000000000000000000000000000'] nodes = [ '1111111111111111111111111111111111111111111111111111111111111111' ] depth = '00010001' bitmap = '40' root = '8e4b8e18156a1c7271055ce5b7ef53bb370294ebd631a3b95418a92da46e681f' anchor = get_anchor_dict() proof_repo = ProofRepository( MockHttpClient, MockBlockchainClient, MockConfig) proof = Proof(leaves, nodes, depth, bitmap, anchor) self.assertEqual(proof_repo.verifyProof(proof).getHash(), root, 'Proof not verifying correctly.')
def test_verify_proof_wrong_network_name(self, MockProofRepo): MockProofRepo.verifyProof.return_value = Record('root') proof = Proof( bitmap="bfdf7000", depth="000400060006000500030002000400060007000800090009", leaves=[ "02aae7e86eb50f61a62083a320475d9d60cbd52749dbf08fa942b1b97f50aee5", ], nodes=[ "bb6986853646d083929d1d92638f3d4741a3b7149bd2b63c6bfedd32e3c684d3", "0616067c793ac533815ae2d48d785d339e0330ce5bb5345b5e6217dd9d1dbeab", "68b8f6b25cc700e64ed3e3d33f2f246e24801f93d29786589fbbab3b11f5bcee" ], anchor={ "anchor_id": 387, "root": "c6372dab6a48637173a457e3ae0c54a500bb50346e847eccf2b818ade94d8ccf", "networks": [{ "name": "bloock_chain", "tx_hash": "0xc087797b9700245c8e3f678874e9c419297f2302cb822d798ca94cce8c27aea9", "state": "Confirmed", "created_at": 0 }, { "name": "ethereum_secret_master_network", "tx_hash": "0xc087797b9700245c8e3f678874e9c419297f2302cb822d798ca94cce8c27aea9", "state": "Confirmed", "created_at": 1 }, { "name": "ethereum_mainnet", "tx_hash": "0xc087797b9700245c8e3f678874e9c419297f2302cb822d798ca94cce8c27aea9", "state": "Confirmed", "created_at": 1 }], "status": "Success" }) service = ProofService(MockProofRepo) with self.assertRaises(Exception) as context: service.verifyProof(proof) self.assertTrue( "'ethereum_secret_master_network' is not a valid Network" in str( context.exception))