Exemplo n.º 1
0
 def test_decoding(self):
     tdata = utils.load_test_data("hexencodetest.txt")
     for expected, sample in tdata:
         actual = trie.bin_to_hexarraykey(sample.decode('hex'))
         assert expected == actual, (
             "HexDecode mismatch for sample '%s'; expected='%s' - "
             "actual='%s'" % (sample, expected, actual))
Exemplo n.º 2
0
    sys.exit()

rlpdata = json.loads(open(os.path.join(testdir,'rlptest.txt')).read())
for x,y in rlpdata:
    yprime = rlp.encode(x).encode('hex')
    if yprime != y: print ("RLPEncode Mismatch: ",x,y,yprime)
    xprime = rlp.decode(y.decode('hex'))
    jx, jxprime = json.dumps(x), json.dumps(xprime)
    if jx != jxprime: print ("RLPDecode Mismatch: ",jx,jxprime,y)

hexencodedata = json.loads(open(os.path.join(testdir,'hexencodetest.txt')).read())

for x,y in hexencodedata:
    yprime = trie.hexarraykey_to_bin(x).encode('hex')
    if yprime != y: print ("HexEncode Mismatch: ",x,y,yprime)
    xprime = trie.bin_to_hexarraykey(y.decode('hex'))
    jx,jxprime = json.dumps(x), json.dumps(xprime)
    if jx != jxprime: print ("HexDecode Mismatch: ",jx,jxprime,y)

triedata = json.loads(open(os.path.join(testdir,'trietest.txt')).read())


for td in triedata:
    x = td["inputs"]
    y = td["expectation"]
    t0 = trie.Trie('/tmp/trietest-'+str(random.randrange(1000000000000)))
    for k, v in x.items():
        t0.update(k,v)
    er = t0.root.encode('hex')
    if er != y:
        print ("Mismatch with adds only (\"%s\" -> \"%s\")" % (x, er))
Exemplo n.º 3
0
for x, y in rlpdata:
    yprime = rlp.encode(x).encode("hex")
    if yprime != y:
        print "RLPEncode Mismatch: ", x, y, yprime
    xprime = rlp.decode(y.decode("hex"))
    jx, jxprime = json.dumps(x), json.dumps(xprime)
    if jx != jxprime:
        print "RLPDecode Mismatch: ", jx, jxprime, y

hexencodedata = json.loads(open(os.path.join(testdir, "hexencodetest.txt")).read())

for x, y in hexencodedata:
    yprime = trie.hexarraykey_to_bin(x).encode("hex")
    if yprime != y:
        print "HexEncode Mismatch: ", x, y, yprime
    xprime = trie.bin_to_hexarraykey(y.decode("hex"))
    jx, jxprime = json.dumps(x), json.dumps(xprime)
    if jx != jxprime:
        print "HexDecode Mismatch: ", jx, jxprime, y

triedata = json.loads(open(os.path.join(testdir, "trietest.txt")).read())

for x, y in triedata:
    t0 = trie.Trie("/tmp/trietest-" + str(random.randrange(1000000000000)))
    for k in x:
        t0.update(k, x[k])
    if t0.root.encode("hex") != y:
        print "Mismatch with adds only"
        continue
    t = trie.Trie("/tmp/trietest-" + str(random.randrange(1000000000000)))
    dummies, reals = [], []