core/types: make blocks immutable

This commit is contained in:
Felix Lange
2015-06-16 12:41:50 +02:00
committed by Jeffrey Wilcke
parent 654564e164
commit 1d42888d30
17 changed files with 457 additions and 587 deletions

View File

@ -117,7 +117,7 @@ func testChain(chainB types.Blocks, bman *BlockProcessor) (*big.Int, error) {
}
func loadChain(fn string, t *testing.T) (types.Blocks, error) {
fh, err := os.OpenFile(filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "_data", fn), os.O_RDONLY, os.ModePerm)
fh, err := os.OpenFile(filepath.Join("..", "_data", fn), os.O_RDONLY, os.ModePerm)
if err != nil {
return nil, err
}
@ -265,7 +265,7 @@ func TestBrokenChain(t *testing.T) {
}
func TestChainInsertions(t *testing.T) {
t.Skip() // travil fails.
t.Skip("Skipped: outdated test files")
db, _ := ethdb.NewMemDatabase()
@ -303,7 +303,7 @@ func TestChainInsertions(t *testing.T) {
}
func TestChainMultipleInsertions(t *testing.T) {
t.Skip() // travil fails.
t.Skip("Skipped: outdated test files")
db, _ := ethdb.NewMemDatabase()
@ -346,8 +346,8 @@ func TestChainMultipleInsertions(t *testing.T) {
}
}
func TestGetAncestors(t *testing.T) {
t.Skip() // travil fails.
func TestGetBlocksFromHash(t *testing.T) {
t.Skip("Skipped: outdated test files")
db, _ := ethdb.NewMemDatabase()
chainMan := theChainManager(db, t)
@ -361,8 +361,8 @@ func TestGetAncestors(t *testing.T) {
chainMan.write(block)
}
ancestors := chainMan.GetAncestors(chain[len(chain)-1], 4)
fmt.Println(ancestors)
blocks := chainMan.GetBlocksFromHash(chain[len(chain)-1].Hash(), 4)
fmt.Println(blocks)
}
type bproc struct{}
@ -372,15 +372,17 @@ func (bproc) Process(*types.Block) (state.Logs, error) { return nil, nil }
func makeChainWithDiff(genesis *types.Block, d []int, seed byte) []*types.Block {
var chain []*types.Block
for i, difficulty := range d {
header := &types.Header{Number: big.NewInt(int64(i + 1)), Difficulty: big.NewInt(int64(difficulty))}
block := types.NewBlockWithHeader(header)
copy(block.HeaderHash[:2], []byte{byte(i + 1), seed})
if i == 0 {
block.ParentHeaderHash = genesis.Hash()
} else {
copy(block.ParentHeaderHash[:2], []byte{byte(i), seed})
header := &types.Header{
Coinbase: common.Address{seed},
Number: big.NewInt(int64(i + 1)),
Difficulty: big.NewInt(int64(difficulty)),
}
if i == 0 {
header.ParentHash = genesis.Hash()
} else {
header.ParentHash = chain[i-1].Hash()
}
block := types.NewBlockWithHeader(header)
chain = append(chain, block)
}
return chain
@ -399,7 +401,6 @@ func chm(genesis *types.Block, db common.Database) *ChainManager {
}
func TestReorgLongest(t *testing.T) {
t.Skip("skipped while cache is removed")
db, _ := ethdb.NewMemDatabase()
genesis := GenesisBlock(0, db)
bc := chm(genesis, db)
@ -419,7 +420,6 @@ func TestReorgLongest(t *testing.T) {
}
func TestReorgShortest(t *testing.T) {
t.Skip("skipped while cache is removed")
db, _ := ethdb.NewMemDatabase()
genesis := GenesisBlock(0, db)
bc := chm(genesis, db)