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

trie test is working

parent d7ffc3e7
...@@ -5,14 +5,22 @@ import ( ...@@ -5,14 +5,22 @@ import (
"fmt" "fmt"
"sort" "sort"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/trie"
) )
type PreimageKeyValueWriter struct{} 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 { func (kw PreimageKeyValueWriter) Put(key []byte, value []byte) error {
//fmt.Println("preimage", key, value) hash := crypto.Keccak256Hash(value)
// cache this if hash != common.BytesToHash(key) {
panic("bad preimage value write")
}
preimages[hash] = common.CopyBytes(value)
return nil return nil
} }
...@@ -43,4 +51,6 @@ func RamToTrie(ram map[uint32](uint32)) { ...@@ -43,4 +51,6 @@ func RamToTrie(ram map[uint32](uint32)) {
mt.Update(tk, tv) mt.Update(tk, tv)
} }
fmt.Println("ram hash", mt.Hash()) fmt.Println("ram hash", mt.Hash())
fmt.Println("hash count", len(preimages))
fmt.Println("root node", preimages[mt.Hash()])
} }
...@@ -9,7 +9,14 @@ import ( ...@@ -9,7 +9,14 @@ import (
func TestTrie(t *testing.T) { func TestTrie(t *testing.T) {
fn := "../mipigo/minigeth.bin" fn := "../mipigo/minigeth.bin"
ram := make(map[uint32](uint32)) ram := make(map[uint32](uint32))
// TODO: copied from compare_test.go
LoadMappedFile(fn, ram, 0) 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) 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