Commit 1a68a4ba authored by George Hotz's avatar George Hotz

trie test is working

parent d7ffc3e7
......@@ -5,14 +5,22 @@ import (
"fmt"
"sort"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/trie"
)
type PreimageKeyValueWriter struct{}
var preimages = make(map[common.Hash][]byte)
// TODO: this is copied from the oracle
func (kw PreimageKeyValueWriter) Put(key []byte, value []byte) error {
//fmt.Println("preimage", key, value)
// cache this
hash := crypto.Keccak256Hash(value)
if hash != common.BytesToHash(key) {
panic("bad preimage value write")
}
preimages[hash] = common.CopyBytes(value)
return nil
}
......@@ -43,4 +51,6 @@ func RamToTrie(ram map[uint32](uint32)) {
mt.Update(tk, tv)
}
fmt.Println("ram hash", mt.Hash())
fmt.Println("hash count", len(preimages))
fmt.Println("root node", preimages[mt.Hash()])
}
......@@ -9,7 +9,14 @@ import (
func TestTrie(t *testing.T) {
fn := "../mipigo/minigeth.bin"
ram := make(map[uint32](uint32))
// TODO: copied from compare_test.go
LoadMappedFile(fn, ram, 0)
/*inputFile := fmt.Sprintf("/tmp/eth/%d", 13284469)
LoadMappedFile(inputFile, ram, 0xB0000000)*/
for i := uint32(0xC0000000); i < 0xC0000000+36*4; i += 4 {
WriteRam(ram, i, 0)
}
RamToTrie(ram)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment