diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-17 06:10:26 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-17 06:10:26 +0800 |
commit | 843db4978e876674ca111706880a58c84202880d (patch) | |
tree | 6d565f14ae8ed2524c73e478e301891c4d86436e /tests/blocktest.go | |
parent | 4e181c5764b78193705f91d3220710bb63b8962f (diff) | |
download | dexon-843db4978e876674ca111706880a58c84202880d.tar dexon-843db4978e876674ca111706880a58c84202880d.tar.gz dexon-843db4978e876674ca111706880a58c84202880d.tar.bz2 dexon-843db4978e876674ca111706880a58c84202880d.tar.lz dexon-843db4978e876674ca111706880a58c84202880d.tar.xz dexon-843db4978e876674ca111706880a58c84202880d.tar.zst dexon-843db4978e876674ca111706880a58c84202880d.zip |
updated blockpool
Diffstat (limited to 'tests/blocktest.go')
-rw-r--r-- | tests/blocktest.go | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/tests/blocktest.go b/tests/blocktest.go index 0b923f08b..e4d001089 100644 --- a/tests/blocktest.go +++ b/tests/blocktest.go @@ -12,8 +12,9 @@ import ( "strconv" "strings" - "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/state" ) @@ -101,12 +102,12 @@ func (t *BlockTest) InsertPreState(db common.Database) error { statedb := state.New(nil, db) for addrString, acct := range t.preAccounts { // XXX: is is worth it checking for errors here? - addr, _ := hex.DecodeString(addrString) + //addr, _ := hex.DecodeString(addrString) code, _ := hex.DecodeString(strings.TrimPrefix(acct.Code, "0x")) balance, _ := new(big.Int).SetString(acct.Balance, 0) nonce, _ := strconv.ParseUint(acct.Nonce, 16, 64) - obj := statedb.NewStateObject(addr) + obj := statedb.NewStateObject(common.HexToAddress(addrString)) obj.SetCode(code) obj.SetBalance(balance) obj.SetNonce(nonce) @@ -119,7 +120,7 @@ func (t *BlockTest) InsertPreState(db common.Database) error { // sync trie to disk statedb.Sync() - if !bytes.Equal(t.Genesis.Root(), statedb.Root()) { + if !bytes.Equal(t.Genesis.Root().Bytes(), statedb.Root()) { return errors.New("computed state root does not match genesis block") } return nil @@ -153,23 +154,25 @@ func mustConvertGenesis(testGenesis btHeader) *types.Block { func mustConvertHeader(in btHeader) *types.Header { // hex decode these fields - return &types.Header{ + header := &types.Header{ //SeedHash: mustConvertBytes(in.SeedHash), - MixDigest: mustConvertBytes(in.MixHash), - Bloom: mustConvertBytes(in.Bloom), - ReceiptHash: mustConvertBytes(in.ReceiptTrie), - TxHash: mustConvertBytes(in.TransactionsTrie), - Root: mustConvertBytes(in.StateRoot), - Coinbase: mustConvertBytes(in.Coinbase), - UncleHash: mustConvertBytes(in.UncleHash), - ParentHash: mustConvertBytes(in.ParentHash), - Nonce: mustConvertBytes(in.Nonce), + MixDigest: mustConvertHash(in.MixHash), + Bloom: mustConvertBloom(in.Bloom), + ReceiptHash: mustConvertHash(in.ReceiptTrie), + TxHash: mustConvertHash(in.TransactionsTrie), + Root: mustConvertHash(in.StateRoot), + Coinbase: mustConvertAddress(in.Coinbase), + UncleHash: mustConvertHash(in.UncleHash), + ParentHash: mustConvertHash(in.ParentHash), Extra: string(mustConvertBytes(in.ExtraData)), GasUsed: mustConvertBigInt10(in.GasUsed), GasLimit: mustConvertBigInt10(in.GasLimit), Difficulty: mustConvertBigInt10(in.Difficulty), Time: mustConvertUint(in.Timestamp), } + // XXX cheats? :-) + header.SetNonce(common.BytesToHash(mustConvertBytes(in.Nonce)).Big().Uint64()) + return header } func mustConvertBlocks(testBlocks []btBlock) []*types.Block { @@ -193,6 +196,30 @@ func mustConvertBytes(in string) []byte { return out } +func mustConvertHash(in string) common.Hash { + out, err := hex.DecodeString(strings.TrimPrefix(in, "0x")) + if err != nil { + panic(fmt.Errorf("invalid hex: %q", in)) + } + return common.BytesToHash(out) +} + +func mustConvertAddress(in string) common.Address { + out, err := hex.DecodeString(strings.TrimPrefix(in, "0x")) + if err != nil { + panic(fmt.Errorf("invalid hex: %q", in)) + } + return common.BytesToAddress(out) +} + +func mustConvertBloom(in string) core.Bloom { + out, err := hex.DecodeString(strings.TrimPrefix(in, "0x")) + if err != nil { + panic(fmt.Errorf("invalid hex: %q", in)) + } + return core.BytesToBloom(out) +} + func mustConvertBigInt10(in string) *big.Int { out, ok := new(big.Int).SetString(in, 10) if !ok { |