Пример #1
0
 def test_encoding(self):
     tdata = utils.load_test_data("hexencodetest.txt")
     for sample, expected in tdata:
         actual = trie.hexarraykey_to_bin(sample).encode('hex')
         assert expected == actual, (
             "HexEncode mismatch for sample '%s'; expected='%s' - "
             "actual='%s'" % (sample, expected, actual))
Пример #2
0
except:
    print 'You need to clone the "tests" which can be found here: https://github.com/ethereum/tests'
    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')
Пример #3
0
testdir = sys.argv[1] if len(sys.argv) >= 2 else "../tests"

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 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"