コード例 #1
0
 def test_create_merkle_proof(self):
     leaves = {0: dummy_val, 2: dummy_val, 3: dummy_val_2}
     tree = SparseMerkleTree(depth=2, leaves=leaves)
     mid_left_val = keccak(dummy_val + default_hash)
     mid_right_val = keccak(dummy_val + dummy_val_2)
     assert (
         tree.create_merkle_proof(0) == (2).to_bytes(8, byteorder='big') +
         mid_right_val)
     assert (
         tree.create_merkle_proof(1) == (3).to_bytes(8, byteorder='big') +
         dummy_val + mid_right_val)
     assert (
         tree.create_merkle_proof(2) == (3).to_bytes(8, byteorder='big') +
         dummy_val_2 + mid_left_val)
     assert (
         tree.create_merkle_proof(3) == (3).to_bytes(8, byteorder='big') +
         dummy_val + mid_left_val)
コード例 #2
0
 def test_real_slot_proofs(self):
     slot = 14414645988802088183
     txHash = HexBytes(
         '0x510a183d5457e0d22951440a273f0d8e28e01d15f750d79fd1b27442299f7220'
     )
     tree = SparseMerkleTree(64, {slot: txHash})
     proof = tree.create_merkle_proof(slot)
     inc = tree.verify(slot, proof)
     assert inc
コード例 #3
0
 def test_old(self):
     slot = 2
     txHash = HexBytes(
         '0xcf04ea8bb4ff94066eb84dd932f9e66d1c9f40d84d5491f5a7735200de010d84'
     )
     slot2 = 600
     txHash2 = HexBytes(
         '0xabcabcabacbc94566eb84dd932f9e66d1c9f40d84d5491f5a7735200de010d84'
     )
     slot3 = 30000
     txHash3 = HexBytes(
         '0xabcaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c9f40d84d5491f5a7735200de010d84'
     )
     tx = {slot: txHash, slot2: txHash2, slot3: txHash3}
     tree = SparseMerkleTree(64, tx)
     for s in tx.keys():
         proof = tree.create_merkle_proof(s)
         inc = tree.verify(s, proof)
         assert inc