func TestEthBlockCopy(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	defer func() {
		r := recover()
		if r == nil {
			t.Fatal("Expected panic")
		}
		if r != "dont use this yet" {
			t.Fatal("Expected panic message 'dont use this yet'")
		}
	}()
	_ = ethBlock.Copy()
}
/*
These functions below should go away
We are working on test coverage anyways...
package ipldeth
import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"runtime"
	"strconv"
	"testing"
	block "github.com/ipfs/go-block-format"
	node "github.com/ipfs/go-ipld-format"
	"github.com/ethereum/go-ethereum/core/types"
)
func TestBlockBodyRlpParsing(t *testing.T) {
	fi, err := os.Open("test_data/eth-block-body-rlp-999999")
	checkError(err, t)
	output, _, _, err := FromBlockRLP(fi)
	checkError(err, t)
	testEthBlockFields(output, t)
}
func TestBlockHeaderRlpParsing(t *testing.T) {
	fi, err := os.Open("test_data/eth-block-header-rlp-999999")
	checkError(err, t)
	output, _, _, err := FromBlockRLP(fi)
	checkError(err, t)
	testEthBlockFields(output, t)
}
func TestBlockBodyJsonParsing(t *testing.T) {
	fi, err := os.Open("test_data/eth-block-body-json-999999")
	checkError(err, t)
	output, _, _, err := FromBlockJSON(fi)
	checkError(err, t)
	testEthBlockFields(output, t)
}
func TestEthBlockProcessTransactionsError(t *testing.T) {
	fi, err := os.Open("test_data/error-tx-eth-block-body-json-999999")
	checkError(err, t)
	_, _, _, err = FromBlockJSON(fi)
	if err == nil {
		t.Fatal("Expected an error")
	}
}
func TestDecodeBlockHeader(t *testing.T) {
	storedEthBlock := prepareStoredEthBlock("test_data/eth-block-header-rlp-999999", t)
	ethBlock, err := DecodeEthBlock(storedEthBlock.Cid(), storedEthBlock.RawData())
	checkError(err, t)
	testEthBlockFields(ethBlock, t)
}
func TestEthBlockString(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	if ethBlock.String() != "<EthBlock z43AaGF4uHSY4waU68L3DLUKHZP7yfZoo6QbLmid5HomZ4WtbWw>" {
		t.Fatalf("Wrong String()")
	}
}
func TestEthBlockLoggable(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	l := ethBlock.Loggable()
	if _, ok := l["type"]; !ok {
		t.Fatal("Loggable map expected the field 'type'")
	}
	if l["type"] != "eth-block" {
		t.Fatal("Wrong Loggable 'type' value")
	}
}
func TestEthBlockJSONMarshal(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	jsonOutput, err := ethBlock.MarshalJSON()
	checkError(err, t)
	var data map[string]interface{}
	err = json.Unmarshal(jsonOutput, &data)
	checkError(err, t)
	if data["bloom"].(string)[:10] != "0x00000000" {
		t.Fatal("Wrong Bloom")
	}
	if data["coinbase"] != "0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5" {
		t.Fatal("Wrong Coinbase")
	}
	if parseFloat(data["difficulty"]) != "12555463106190" {
		t.Fatal("Wrong Difficulty")
	}
	if data["extra"] != "0xd783010303844765746887676f312e342e32856c696e7578" {
		t.Fatal("Wrong Extra")
	}
	if parseFloat(data["gaslimit"]) != "3141592" {
		t.Fatal("Wrong Gas limit")
	}
	if parseFloat(data["gasused"]) != "231000" {
		t.Fatal("Wrong Gas used")
	}
	if data["mixdigest"] != "0x5b10f4a08a6c209d426f6158bd24b574f4f7b7aa0099c67c14a1f693b4dd04d0" {
		t.Fatal("Wrong Mix digest")
	}
	if data["nonce"] != "0xf491f46b60fe04b3" {
		t.Fatal("Wrong nonce")
	}
	if parseFloat(data["number"]) != "999999" {
		t.Fatal("Wrong block number")
	}
	if parseMapElement(data["parent"]) != "z43AaGF6wP6uoLFEauru5oLK5JS5MGfNuGDK1xWEpQK4BqkJkL3" {
		t.Fatal("Wrong Parent cid")
	}
	if parseMapElement(data["receipts"]) != "z44vkPhhDSTXPAswvC1rdDunzkgZ7FgAAnhGQtNDNDk9m9N2BZA" {
		t.Fatal("Wrong Receipt root cid")
	}
	if parseMapElement(data["root"]) != "z45oqTSAZvPiiPV8hMZDH5fi4NkaAkMYTJC6PmaeWBmYUpbMpoh" {
		t.Fatal("Wrong root hash cid")
	}
	if parseFloat(data["time"]) != "1455404037" {
		t.Fatal("Wrong Time")
	}
	if parseMapElement(data["tx"]) != "z443fKyHHMwVy13VXtD4fdRcUXSqkr79Q5E8hcmEravVBq3Dc51" {
		t.Fatal("Wrong Tx root cid")
	}
	if parseMapElement(data["uncles"]) != "z43c7o74hjCAqnyneWetkyXU2i5KuGQLbYfVWZMvJMG4VTYABtz" {
		t.Fatal("Wrong Uncle hash cid")
	}
}
func TestEthBlockLinks(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	links := ethBlock.Links()
	if links[0].Cid.String() != "z43AaGF6wP6uoLFEauru5oLK5JS5MGfNuGDK1xWEpQK4BqkJkL3" {
		t.Fatal("Wrong cid for parent link")
	}
	if links[1].Cid.String() != "z44vkPhhDSTXPAswvC1rdDunzkgZ7FgAAnhGQtNDNDk9m9N2BZA" {
		t.Fatal("Wrong cid for receipt root link")
	}
	if links[2].Cid.String() != "z45oqTSAZvPiiPV8hMZDH5fi4NkaAkMYTJC6PmaeWBmYUpbMpoh" {
		t.Fatal("Wrong cid for state root link")
	}
	if links[3].Cid.String() != "z443fKyHHMwVy13VXtD4fdRcUXSqkr79Q5E8hcmEravVBq3Dc51" {
		t.Fatal("Wrong cid for transaction root link")
	}
	if links[4].Cid.String() != "z43c7o74hjCAqnyneWetkyXU2i5KuGQLbYfVWZMvJMG4VTYABtz" {
		t.Fatal("Wrong cid for uncle root link")
	}
}
func TestEthBlockResolveEmptyPath(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	obj, rest, err := ethBlock.Resolve([]string{})
	checkError(err, t)
	if ethBlock != obj.(*EthBlock) {
		t.Fatal("Should have returned the same eth-block object")
	}
	if len(rest) != 0 {
		t.Fatal("Wrong rest of the path returned")
	}
}
func TestEthBlockResolveNoSuchLink(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	_, _, err := ethBlock.Resolve([]string{"wewonthavethisfieldever"})
	if err == nil {
		t.Fatal("Should have failed with unknown field")
	}
	if err.Error() != "no such link" {
		t.Fatal("Wrong error message")
	}
}
func TestEthBlockResolveBloom(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	obj, rest, err := ethBlock.Resolve([]string{"bloom"})
	checkError(err, t)
	bloomInText := fmt.Sprintf("%x", obj.(types.Bloom))
	if bloomInText[:10] != "0000000000" {
		t.Fatal("Wrong Bloom")
	}
	if len(rest) != 0 {
		t.Fatal("Wrong rest of the path returned")
	}
}
func TestEthBlockResolveBloomExtraPathElements(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	obj, rest, err := ethBlock.Resolve([]string{"bloom", "unexpected", "extra", "elements"})
	if obj != nil {
		t.Fatal("Returned obj should be nil")
	}
	if rest != nil {
		t.Fatal("Returned rest should be nil")
	}
	if err.Error() != "unexpected path elements past bloom" {
		t.Fatal("Wrong error")
	}
}
func TestEthBlockResolveNonLinkFields(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	testCases := map[string][]string{
		"coinbase":   []string{"%x", "52bc44d5378309ee2abf1539bf71de1b7d7be3b5"},
		"difficulty": []string{"%s", "12555463106190"},
		"extra":      []string{"%s", "0xd783010303844765746887676f312e342e32856c696e7578"},
		"gaslimit":   []string{"%s", "3141592"},
		"gasused":    []string{"%s", "231000"},
		"mixdigest":  []string{"%x", "5b10f4a08a6c209d426f6158bd24b574f4f7b7aa0099c67c14a1f693b4dd04d0"},
		"nonce":      []string{"%x", "f491f46b60fe04b3"},
		"number":     []string{"%s", "999999"},
		"time":       []string{"%s", "1455404037"},
	}
	for field, value := range testCases {
		obj, rest, err := ethBlock.Resolve([]string{field})
		checkError(err, t)
		format := value[0]
		result := value[1]
		if fmt.Sprintf(format, obj) != result {
			t.Fatalf("Wrong %v", field)
		}
		if len(rest) != 0 {
			t.Fatal("Wrong rest of the path returned")
		}
	}
}
func TestEthBlockResolveNonLinkFieldsExtraPathElements(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	testCases := []string{
		"coinbase",
		"difficulty",
		"extra",
		"gaslimit",
		"gasused",
		"mixdigest",
		"nonce",
		"number",
		"time",
	}
	for _, field := range testCases {
		obj, rest, err := ethBlock.Resolve([]string{field, "unexpected", "extra", "elements"})
		if obj != nil {
			t.Fatal("Returned obj should be nil")
		}
		if rest != nil {
			t.Fatal("Returned rest should be nil")
		}
		if err.Error() != "unexpected path elements past "+field {
			t.Fatal("Wrong error")
		}
	}
}
func TestEthBlockResolveLinkFields(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	testCases := map[string]string{
		"parent":   "z43AaGF6wP6uoLFEauru5oLK5JS5MGfNuGDK1xWEpQK4BqkJkL3",
		"receipts": "z44vkPhhDSTXPAswvC1rdDunzkgZ7FgAAnhGQtNDNDk9m9N2BZA",
		"root":     "z45oqTSAZvPiiPV8hMZDH5fi4NkaAkMYTJC6PmaeWBmYUpbMpoh",
		"tx":       "z443fKyHHMwVy13VXtD4fdRcUXSqkr79Q5E8hcmEravVBq3Dc51",
		"uncles":   "z43c7o74hjCAqnyneWetkyXU2i5KuGQLbYfVWZMvJMG4VTYABtz",
	}
	for field, result := range testCases {
		obj, rest, err := ethBlock.Resolve([]string{field, "anything", "goes", "here"})
		checkError(err, t)
		lnk, ok := obj.(*node.Link)
		if !ok {
			t.Fatal("Returned object is not a link")
		}
		if lnk.Cid.String() != result {
			t.Fatalf("Wrong %s", field)
		}
		for i, p := range []string{"anything", "goes", "here"} {
			if rest[i] != p {
				t.Fatal("Wrong rest of the path returned")
			}
		}
	}
}
func TestEthBlockTreeBadParams(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	tree := ethBlock.Tree("non-empty-string", 0)
	if tree != nil {
		t.Fatal("Expected nil to be returned")
	}
	tree = ethBlock.Tree("non-empty-string", 1)
	if tree != nil {
		t.Fatal("Expected nil to be returned")
	}
	tree = ethBlock.Tree("", 0)
	if tree != nil {
		t.Fatal("Expected nil to be returned")
	}
}
func TestEThBlockTree(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	tree := ethBlock.Tree("", 1)
	lookupElements := map[string]interface{}{
		"bloom":      nil,
		"coinbase":   nil,
		"difficulty": nil,
		"extra":      nil,
		"gaslimit":   nil,
		"gasused":    nil,
		"mixdigest":  nil,
		"nonce":      nil,
		"number":     nil,
		"parent":     nil,
		"receipts":   nil,
		"root":       nil,
		"time":       nil,
		"tx":         nil,
		"uncles":     nil,
	}
	if len(tree) != len(lookupElements) {
		t.Fatalf("Wrong number of elements. Got %d. Expecting %d", len(tree), len(lookupElements))
	}
	for _, te := range tree {
		if _, ok := lookupElements[te]; !ok {
			t.Fatalf("Unexpected Element: %v", te)
		}
	}
}
func TestEthBlockResolveLinksBadLink(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	obj, rest, err := ethBlock.ResolveLink([]string{"supercalifragilist"})
	if obj != nil {
		t.Fatalf("Expected obj to be nil")
	}
	if rest != nil {
		t.Fatal("Expected rest to be nil")
	}
	if err.Error() != "no such link" {
		t.Fatal("Expected error")
	}
}
func TestEthBlockResolveLinksGoodLink(t *testing.T) {
	ethBlock := prepareDecodedEthBlock("test_data/eth-block-header-rlp-999999", t)
	obj, rest, err := ethBlock.ResolveLink([]string{"tx", "0", "0", "0"})
	if obj == nil {
		t.Fatalf("Expected valid *node.Link obj to be returned")
	}
	if rest == nil {
		t.Fatal("Expected rest to be returned")
	}
	for i, p := range []string{"0", "0", "0"} {
		if rest[i] != p {
			t.Fatal("Wrong rest of the path returned")
		}
	}
	if err != nil {
		t.Fatal("Non error expected")
	}
}