Пример #1
0
func TestSaveLoadABlockHead(t *testing.T) {
	b1 := CreateTestAdminBlock(nil)

	dbo := NewOverlay(new(mapdb.MapDB))
	defer dbo.Close()

	err := dbo.SaveABlockHead(b1)
	if err != nil {
		t.Error(err)
	}

	head, err := dbo.FetchABlockHead()
	if err != nil {
		t.Error(err)
	}
	if head == nil {
		t.Error("DBlock head is nil")
	}

	m1, err := b1.MarshalBinary()
	if err != nil {
		t.Error(err)
	}
	m2, err := head.MarshalBinary()
	if err != nil {
		t.Error(err)
	}

	if primitives.AreBytesEqual(m1, m2) == false {
		t.Error("Blocks are not equal")
	}

	b2 := CreateTestAdminBlock(b1)

	err = dbo.SaveABlockHead(b2)
	if err != nil {
		t.Error(err)
	}

	head, err = dbo.FetchABlockHead()
	if err != nil {
		t.Error(err)
	}
	if head == nil {
		t.Error("DBlock head is nil")
	}

	m1, err = b2.MarshalBinary()
	if err != nil {
		t.Error(err)
	}
	m2, err = head.MarshalBinary()
	if err != nil {
		t.Error(err)
	}

	if primitives.AreBytesEqual(m1, m2) == false {
		t.Error("Blocks are not equal")
	}
}
Пример #2
0
func TestECBlockHashingConsistency(t *testing.T) {
	ecb := createECBlock()
	h1, err := ecb.Hash()
	if err != nil {
		t.Error(err)
	}
	k1, err := ecb.HeaderHash()
	if err != nil {
		t.Error(err)
	}
	h2, err := ecb.Hash()
	if err != nil {
		t.Error(err)
	}
	k2, err := ecb.HeaderHash()
	if err != nil {
		t.Error(err)
	}
	if primitives.AreBytesEqual(h1.Bytes(), h2.Bytes()) == false {
		t.Error("ecb.Hash()es are not equal")
	}
	if primitives.AreBytesEqual(k1.Bytes(), k2.Bytes()) == false {
		t.Error("ecb.HeaderHash()es are not equal")
	}
}
Пример #3
0
func TestInsertFetch(t *testing.T) {
	dbo := createOverlay()
	defer dbo.Close()
	b := NewDBTestObject()
	b.Data = []byte{0x00, 0x01, 0x02, 0x03}

	err := dbo.Insert(TestBucket, b)
	if err != nil {
		t.Error(err)
	}

	index := b.DatabasePrimaryIndex()

	b2 := NewDBTestObject()
	resp, err := dbo.FetchBlock(TestBucket, index, b2)
	if err != nil {
		t.Error(err)
	}

	if resp == nil {
		t.Error("Response is nil while it shouldn't be.")
	}

	bResp := resp.(*DBTestObject)

	bytes1 := b.Data
	bytes2 := bResp.Data

	if primitives.AreBytesEqual(bytes1, bytes2) == false {
		t.Errorf("Bytes are not equal - %x vs %x", bytes1, bytes2)
	}
}
Пример #4
0
func TestSignature(t *testing.T) {
	pub, priv, err := ed25519.GenerateKey(rand.Reader)
	if err != nil {
		t.Error(err)
	}
	t.Logf("priv, pub - %x, %x", *priv, *pub)

	testData := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}

	sig := ed25519.Sign(priv, testData)

	ok := ed25519.Verify(pub, testData, sig)

	if ok == false {
		t.Error("Signature could not be verified")
	}

	pub2, err := primitives.PrivateKeyToPublicKey(priv[:])
	if err != nil {
		t.Error(err)
	}

	t.Logf("pub1 - %x", pub)
	t.Logf("pub2 - %x", pub2)

	if primitives.AreBytesEqual(pub[:], pub2[:]) == false {
		t.Error("Public keys are not equal")
	}
}
Пример #5
0
func TestAppendExtIDs(t *testing.T) {
	ids := [][]byte{
		[]byte{0x01, 0x02},
		[]byte{0x03, 0x04},
		[]byte{0x05, 0x06},
		[]byte{0x07, 0x08},
		[]byte{0x09, 0x0a},
	}

	appended := []byte{
		0x03, 0x04,
		0x05, 0x06,
		0x07, 0x08,
		0x09, 0x0a,
	}

	resp, err := AppendExtIDs(ids, 1, 4)
	if err != nil {
		t.Errorf("%v", err)
	}
	if primitives.AreBytesEqual(resp, appended) == false {
		t.Errorf("AppendExtIDs are not equal - %x vs %x", resp, appended)
	}

	resp, err = AppendExtIDs(ids, 1, 5)
	if err == nil {
		t.Error("Err is not when it should not be")
	}
	if resp != nil {
		t.Error("Resp is not nil when it should be")
	}
}
Пример #6
0
func TestFetchECTransactionByHash(t *testing.T) {
	blocks := CreateFullTestBlockSet()
	dbo := CreateAndPopulateTestDatabaseOverlay()

	for _, block := range blocks {
		for _, tx := range block.ECBlock.GetEntries() {
			if tx.ECID() != entryCreditBlock.ECIDChainCommit && tx.ECID() != entryCreditBlock.ECIDEntryCommit || tx.ECID() == entryCreditBlock.ECIDBalanceIncrease {
				continue
			}

			dTx, err := dbo.FetchECTransaction(tx.Hash())
			if err != nil {
				t.Errorf("%v", err)
			}
			if dTx == nil {
				t.Errorf("Tx %v not found!", tx.Hash().String())
				continue
			}

			h1, err := tx.MarshalBinary()
			if err != nil {
				t.Errorf("%v", err)
			}

			h2, err := dTx.MarshalBinary()
			if err != nil {
				t.Errorf("%v", err)
			}

			if primitives.AreBytesEqual(h1, h2) == false {
				t.Error("Returned transactions are not equal")
			}
		}
	}
}
Пример #7
0
func TestMarshalUnmarshalAnchorRecordV2(t *testing.T) {
	record := `{"AnchorRecordVer":1,"DBHeight":5,"KeyMR":"980ab6d50d9fad574ad4df6dba06a8c02b1c67288ee5beab3fbfde2723f73ef6","RecordHeight":6,"Bitcoin":{"Address":"1K2SXgApmo9uZoyahvsbSanpVWbzZWVVMF","TXID":"e2ac71c9c0fd8edc0be8c0ba7098b77fb7d90dcca755d5b9348116f3f9d9f951","BlockHeight":372576,"BlockHash":"000000000000000003059382ed4dd82b2086e99ec78d1b6e811ebb9d53d8656d","Offset":1144}}`
	ar, err := UnmarshalAnchorRecord([]byte(record))
	if err != nil {
		t.Error(err)
	}

	priv := "ec9f1cefa00406b80d46135a53504f1f4182d4c0f3fed6cca9281bc020eff973"
	pk1, err := primitives.NewPrivateKeyFromHex(priv)
	if err != nil {
		t.Error(err)
	}

	data, sig, err := ar.MarshalAndSignV2(pk1)
	if err != nil {
		t.Error(err)
	}

	if primitives.AreBytesEqual([]byte(record), data) == false {
		t.Errorf("Anchors are not equal\n%s\nvs\n%s", record, string(data))
	}

	ar, valid, err := UnmarshalAndValidateAnchorRecordV2(data, [][]byte{sig}, pk1.Pub)
	if err != nil {
		t.Error(err)
	}
	if valid != true {
		t.Errorf("Anchor record is not valid")
	}
	if ar == nil {
		t.Errorf("No anchor record returned!")
	}
}
Пример #8
0
func TestFetchFactoidTransactionByHash(t *testing.T) {
	blocks := CreateFullTestBlockSet()
	dbo := CreateAndPopulateTestDatabaseOverlay()

	for _, block := range blocks {
		for _, tx := range block.FBlock.GetTransactions() {
			dTx, err := dbo.FetchFactoidTransaction(tx.GetHash())
			if err != nil {
				t.Errorf("%v", err)
			}
			if dTx == nil {
				t.Errorf("Tx %v not found!", tx.GetHash().String())
				continue
			}

			h1, err := tx.MarshalBinary()
			if err != nil {
				t.Errorf("%v", err)
			}

			h2, err := dTx.MarshalBinary()
			if err != nil {
				t.Errorf("%v", err)
			}

			if primitives.AreBytesEqual(h1, h2) == false {
				t.Error("Returned transactions are not equal")
			}
		}
	}
}
Пример #9
0
func TestRCDAddress(t *testing.T) {
	priv := NewPrivKey(0)
	rcd := NewFactoidRCDAddress(0)
	pub := rcd.(*factoid.RCD_1).GetPublicKey()
	//pub2 := [32]byte{}
	//copy(pub2[:], pub)
	pub3 := PrivateKeyToEDPub(priv)

	if primitives.AreBytesEqual(pub, pub3) == false {
		t.Error("RCD public keys are not equal")
	}
}
Пример #10
0
func TestCommitMarshalUnmarshal(t *testing.T) {
	blocks := testHelper.CreateFullTestBlockSet()
	for _, block := range blocks {
		for _, tx := range block.ECBlock.GetEntries() {
			h1, err := tx.MarshalBinary()
			if err != nil {
				t.Errorf("Error marshalling - %v", err)
			}
			var h2 []byte
			var e interfaces.BinaryMarshallable
			switch tx.ECID() {
			case ECIDChainCommit:
				e = new(CommitChain)
				break
			case ECIDEntryCommit:
				e = new(CommitEntry)
				break
			case ECIDBalanceIncrease:
				e = new(IncreaseBalance)
				break
			case ECIDMinuteNumber:
				e = new(MinuteNumber)
				break
			case ECIDServerIndexNumber:
				e = new(ServerIndexNumber)
				break
			default:
				t.Error("Wrong ECID")
				break
			}

			h2, err = e.UnmarshalBinaryData(h1)
			if err != nil {
				t.Logf("Tried to unmarshal %x", h1)
				t.Errorf("Error unmarshalling - %v", err)
				continue
			}
			if len(h2) > 0 {
				t.Errorf("Leftovers from unmarshalling - %x", h2)
			}
			h2, err = e.MarshalBinary()
			if err != nil {
				t.Errorf("Error marshalling2 - %v", err)
				continue
			}

			if primitives.AreBytesEqual(h1, h2) == false {
				t.Error("ECEntries are not identical - %x vs %x", h1, h2)
			}
		}
	}
}
Пример #11
0
func (d1 *DBTestObject) IsEqual(d2 *DBTestObject) bool {
	if d1.DatabaseHeight != d2.DatabaseHeight {
		return false
	}

	if primitives.AreBytesEqual(d1.Data, d2.Data) == false {
		return false
	}

	if primitives.AreBytesEqual(d1.PrimaryIndex.Bytes(), d2.PrimaryIndex.Bytes()) == false {
		return false
	}

	if primitives.AreBytesEqual(d1.SecondaryIndex.Bytes(), d2.SecondaryIndex.Bytes()) == false {
		return false
	}

	if primitives.AreBytesEqual(d1.ChainID.Bytes(), d2.ChainID.Bytes()) == false {
		return false
	}

	return true
}
Пример #12
0
func (a *CommitChain) IsSameAs(b *CommitChain) bool {
	if b == nil {
		return false
	}
	bin1, err := a.MarshalBinary()
	if err != nil {
		return false
	}
	bin2, err := b.MarshalBinary()
	if err != nil {
		return false
	}
	return primitives.AreBytesEqual(bin1, bin2)
}
Пример #13
0
func TestMarshalUnmarshalAnchorRecord(t *testing.T) {
	record := `{"AnchorRecordVer":1,"DBHeight":5,"KeyMR":"980ab6d50d9fad574ad4df6dba06a8c02b1c67288ee5beab3fbfde2723f73ef6","RecordHeight":6,"Bitcoin":{"Address":"1K2SXgApmo9uZoyahvsbSanpVWbzZWVVMF","TXID":"e2ac71c9c0fd8edc0be8c0ba7098b77fb7d90dcca755d5b9348116f3f9d9f951","BlockHeight":372576,"BlockHash":"000000000000000003059382ed4dd82b2086e99ec78d1b6e811ebb9d53d8656d","Offset":1144}}`
	ar, err := UnmarshalAnchorRecord([]byte(record))
	if err != nil {
		t.Error(err)
	}
	data, err := ar.Marshal()
	if err != nil {
		t.Error(err)
	}

	if primitives.AreBytesEqual([]byte(record), data) == false {
		t.Errorf("Anchors are not equal\n%s\nvs\n%s", record, string(data))
	}
}
Пример #14
0
func TestMarshalUnmarshal(t *testing.T) {
	rawStr := "000000000000000000000000000000000000000000000000000000000000000f16a82932aa64e6ad45b2749f2abb871fcf3353ab9d4e163c9bd90e5bbd745b59a164ccbb77a21904edc4f2bb753aa60635fb2b60279c06ae01aa211f375417362fb170f73c3961d4218ff806dd75e6e348ca1798a5fc7a99d443fbe2ff939d9900000000000a2be8000000010000000002000000c702014f8a7fcd1b00000002014f8a851657010001e397a1607d4f56c528ab09da5bbf7b37b0b453f43db303730e28e9ebe02657dff431d4f7dfaf840017ef7a21d1a616d65e6b73f3c6a7ad5c49340a6c2592872020ec60767ff00d7d01a5be79b6ada79c0af4d6b7f91234ff321f3b647ed01e02ccbbc0fe9dcc63293482f22455b9756ee4b4db411a5d00e31b689c1bd1abe1d1e887cf4c52e67fc51fe4d9594c24643a91009c6ea91701b5b6df240248c2f39453162b61d71b98270100000000000000000000"
	raw, err := hex.DecodeString(rawStr)
	if err != nil {
		t.Errorf("%v", err)
	}

	f := new(FBlock)
	rest, err := f.UnmarshalBinaryData(raw)
	if err != nil {
		t.Errorf("%v", err)
	}
	if len(rest) > 0 {
		t.Errorf("Returned too much data - %x", rest)
	}

	b, err := f.MarshalBinary()
	if err != nil {
		t.Errorf("%v", err)
	}

	if primitives.AreBytesEqual(raw, b) == false {
		t.Errorf("Marshalled bytes are not equal - %x vs %x", raw, b)
	}

	//f.CalculateHashes()

	if f.DatabasePrimaryIndex().String() != "aa100f203f159e4369081bb366f6816b302387ec19a4f8b9c98495d97fbe3527" {
		t.Errorf("Wrong PrimaryIndex - %v vs %v", f.DatabasePrimaryIndex().String(), "aa100f203f159e4369081bb366f6816b302387ec19a4f8b9c98495d97fbe3527")
	}
	if f.DatabaseSecondaryIndex().String() != "5810ed83155dfb7b6039323b8a5572cd03166a37d1c3e86d4538c99907a81757" {
		t.Errorf("Wrong SecondaryIndex - %v vs %v", f.DatabaseSecondaryIndex().String(), "5810ed83155dfb7b6039323b8a5572cd03166a37d1c3e86d4538c99907a81757")
	}

	err = f.Validate()
	if err != nil {
		t.Errorf("%v", err)
	}
}
Пример #15
0
func (a *DataResponse) IsSameAs(b *DataResponse) bool {
	if b == nil {
		return false
	}
	if a.Timestamp.GetTimeMilli() != b.Timestamp.GetTimeMilli() {
		return false
	}
	if a.DataType != b.DataType {
		return false
	}

	if a.DataHash == nil && b.DataHash != nil {
		return false
	}
	if a.DataHash != nil {
		if a.DataHash.IsSameAs(b.DataHash) == false {
			return false
		}
	}

	if a.DataObject == nil && b.DataObject != nil {
		return false
	}
	if a.DataObject != nil {
		hex1, err := a.DataObject.MarshalBinary()
		if err != nil {
			return false
		}
		hex2, err := b.DataObject.MarshalBinary()
		if err != nil {
			return false
		}
		if primitives.AreBytesEqual(hex1, hex2) == false {
			return false
		}
	}
	return true
}
Пример #16
0
func TestMultiBatch(t *testing.T) {
	dbo := NewOverlay(new(mapdb.MapDB))

	var prev *testHelper.BlockSet = nil

	var err error

	for i := 0; i < 10; i++ {
		dbo.StartMultiBatch()
		prev = testHelper.CreateTestBlockSet(prev)

		err = dbo.ProcessABlockMultiBatch(prev.ABlock)
		if err != nil {
			t.Error(err)
		}

		err = dbo.ProcessEBlockMultiBatch(prev.EBlock, true)
		if err != nil {
			t.Error(err)
		}

		err = dbo.ProcessEBlockMultiBatch(prev.AnchorEBlock, true)
		if err != nil {
			t.Error(err)
		}

		err = dbo.ProcessECBlockMultiBatch(prev.ECBlock, false)
		if err != nil {
			t.Error(err)
		}

		err = dbo.ProcessFBlockMultiBatch(prev.FBlock)
		if err != nil {
			t.Error(err)
		}

		err = dbo.ProcessDBlockMultiBatch(prev.DBlock)
		if err != nil {
			t.Error(err)
		}

		for _, entry := range prev.Entries {
			err = dbo.InsertEntryMultiBatch(entry)
			if err != nil {
				t.Error(err)
			}
		}

		if err := dbo.ExecuteMultiBatch(); err != nil {
			t.Error(err)
		}
	}

	ahead, err := dbo.FetchABlockHead()
	if err != nil {
		t.Error(err)
	}
	if ahead == nil {
		t.Error("DBlock head is nil")
	}

	m1, err := prev.ABlock.MarshalBinary()
	if err != nil {
		t.Error(err)
	}
	m2, err := ahead.MarshalBinary()
	if err != nil {
		t.Error(err)
	}

	if primitives.AreBytesEqual(m1, m2) == false {
		t.Error("ABlocks are not equal")
	}

	fhead, err := dbo.FetchFBlockHead()
	if err != nil {
		t.Error(err)
	}
	if fhead == nil {
		t.Error("DBlock head is nil")
	}

	m1, err = prev.FBlock.MarshalBinary()
	if err != nil {
		t.Error(err)
	}
	m2, err = fhead.MarshalBinary()
	if err != nil {
		t.Error(err)
	}

	if primitives.AreBytesEqual(m1, m2) == false {
		t.Error("FBlocks are not equal")
	}

	echead, err := dbo.FetchECBlockHead()
	if err != nil {
		t.Error(err)
	}
	if echead == nil {
		t.Error("DBlock head is nil")
	}

	m1, err = prev.ECBlock.MarshalBinary()
	if err != nil {
		t.Error(err)
	}
	m2, err = echead.MarshalBinary()
	if err != nil {
		t.Error(err)
	}

	if primitives.AreBytesEqual(m1, m2) == false {
		t.Error("ECBlocks are not equal")
	}

	dhead, err := dbo.FetchDBlockHead()
	if err != nil {
		t.Error(err)
	}
	if dhead == nil {
		t.Error("DBlock head is nil")
	}

	m1, err = prev.DBlock.MarshalBinary()
	if err != nil {
		t.Error(err)
	}
	m2, err = dhead.MarshalBinary()
	if err != nil {
		t.Error(err)
	}

	if primitives.AreBytesEqual(m1, m2) == false {
		t.Error("DBlocks are not equal")
	}
}
Пример #17
0
func TestSaveLoadEBlockHead(t *testing.T) {
	b1, _ := CreateTestEntryBlock(nil)

	chain, err := primitives.NewShaHash(b1.GetChainID().Bytes())
	if err != nil {
		t.Error(err)
	}

	dbo := NewOverlay(new(mapdb.MapDB))
	defer dbo.Close()

	err = dbo.SaveEBlockHead(b1, false)
	if err != nil {
		t.Error(err)
	}

	head, err := dbo.FetchEBlockHead(chain)
	if err != nil {
		t.Error(err)
	}
	if head == nil {
		t.Error("DBlock head is nil")
	}

	m1, err := b1.MarshalBinary()
	if err != nil {
		t.Error(err)
	}
	m2, err := head.MarshalBinary()
	if err != nil {
		t.Error(err)
	}

	if primitives.AreBytesEqual(m1, m2) == false {
		t.Error("Blocks are not equal")
	}

	b2, _ := CreateTestEntryBlock(b1)

	err = dbo.SaveEBlockHead(b2, false)
	if err != nil {
		t.Error(err)
	}

	head, err = dbo.FetchEBlockHead(chain)
	if err != nil {
		t.Error(err)
	}
	if head == nil {
		t.Error("DBlock head is nil")
	}

	m1, err = b2.MarshalBinary()
	if err != nil {
		t.Error(err)
	}
	m2, err = head.MarshalBinary()
	if err != nil {
		t.Error(err)
	}
	if primitives.AreBytesEqual(m1, m2) == false {
		t.Error("Blocks are not equal")
	}
}
Пример #18
0
func TestSaveLoadEntries(t *testing.T) {
	dbo := NewOverlay(new(mapdb.MapDB))
	defer dbo.Close()

	entries := []*entryBlock.Entry{}

	firstEntry := CreateFirstTestEntry()
	err := dbo.InsertEntry(firstEntry)
	if err != nil {
		t.Error(err)
	}
	entries = append(entries, firstEntry)

	max := 10
	for i := 0; i < max; i++ {
		entry := CreateTestEntry(uint32(i))
		err = dbo.InsertEntry(entry)
		if err != nil {
			t.Error(err)
		}
		entries = append(entries, entry)
	}

	for _, entry := range entries {
		loaded, err := dbo.FetchEntry(entry.GetHash())
		if err != nil {
			t.Error(err)
		}

		m1, err := entry.MarshalBinary()
		if err != nil {
			t.Error(err)
		}
		m2, err := loaded.MarshalBinary()
		if err != nil {
			t.Error(err)
		}
		if primitives.AreBytesEqual(m1, m2) == false {
			t.Error("Entries are not equal")
		}
	}

	all, err := dbo.FetchAllEntriesByChainID(firstEntry.GetChainIDHash())
	if err != nil {
		t.Error(err)
	}

	if len(entries) != len(all) {
		t.Errorf("Loaded %v out of %v entries", len(all), len(entries))
	}

	foundCount := 0
	for _, entry := range entries {
		found := false
		for _, loaded := range all {
			if entry.GetHash().IsSameAs(loaded.GetHash()) {
				found = true

				m1, err := entry.MarshalBinary()
				if err != nil {
					t.Error(err)
				}
				m2, err := loaded.MarshalBinary()
				if err != nil {
					t.Error(err)
				}
				if primitives.AreBytesEqual(m1, m2) == false {
					t.Error("Entries are not equal")
				}
				break
			}
		}
		if found == false {
			t.Error("Entry %v not found", entry)
		} else {
			foundCount++
		}
	}
	if foundCount != len(entries) {
		t.Errorf("Found %v out of %v entries", foundCount, len(entries))
	}
}
Пример #19
0
func TestFetchBy(t *testing.T) {
	dbo := createOverlay()
	defer dbo.Close()

	blocks := []*DBTestObject{}

	max := 10
	for i := 0; i < max; i++ {
		b := NewDBTestObject()
		b.ChainID = primitives.NewHash(CopyZeroHash())
		b.Data = []byte{byte(i), byte(i + 1), byte(i + 2), byte(i + 3)}

		primaryIndex := CopyZeroHash()
		primaryIndex[len(primaryIndex)-1] = byte(i)

		secondaryIndex := CopyZeroHash()
		secondaryIndex[0] = byte(i)

		b.PrimaryIndex = primitives.NewHash(primaryIndex)
		b.SecondaryIndex = primitives.NewHash(secondaryIndex)
		b.DatabaseHeight = uint32(i)
		blocks = append(blocks, b)

		err := dbo.ProcessBlockBatch(TestBucket, TestNumberBucket, TestSecondaryIndexBucket, b)
		if err != nil {
			t.Error(err)
		}
	}
	headIndex, err := dbo.FetchHeadIndexByChainID(primitives.NewHash(CopyZeroHash()))
	if err != nil {
		t.Error(err)
	}
	if headIndex.IsSameAs(blocks[max-1].PrimaryIndex) == false {
		t.Error("Wrong chain head")
	}

	head, err := dbo.FetchChainHeadByChainID(TestBucket, primitives.NewHash(CopyZeroHash()), new(DBTestObject))
	if err != nil {
		t.Error(err)
	}
	if blocks[max-1].IsEqual(head.(*DBTestObject)) == false {
		t.Error("Heads are not equal")
	}

	for i := 0; i < max; i++ {
		primaryIndex := CopyZeroHash()
		primaryIndex[len(primaryIndex)-1] = byte(i)

		secondaryIndex := CopyZeroHash()
		secondaryIndex[0] = byte(i)

		dbHeight := uint32(i)

		block, err := dbo.FetchBlockByHeight(TestNumberBucket, TestBucket, dbHeight, new(DBTestObject))
		if err != nil {
			t.Error(err)
		}
		if blocks[i].IsEqual(block.(*DBTestObject)) == false {
			t.Error("Blocks are not equal")
		}

		index, err := dbo.FetchBlockIndexByHeight(TestNumberBucket, dbHeight)
		if err != nil {
			t.Error(err)
		}
		if primitives.AreBytesEqual(index.Bytes(), primaryIndex) == false {
			t.Error("Wrong primary index returned")
		}

		index, err = dbo.FetchPrimaryIndexBySecondaryIndex(TestSecondaryIndexBucket, primitives.NewHash(secondaryIndex))
		if err != nil {
			t.Error(err)
		}
		if primitives.AreBytesEqual(index.Bytes(), primaryIndex) == false {
			t.Error("Wrong primary index returned")
		}

		block, err = dbo.FetchBlockBySecondaryIndex(TestSecondaryIndexBucket, TestBucket, primitives.NewHash(secondaryIndex), new(DBTestObject))
		if err != nil {
			t.Error(err)
		}
		if blocks[i].IsEqual(block.(*DBTestObject)) == false {
			t.Error("Blocks are not equal")
		}
	}

	fetchedBlocks, err := dbo.FetchAllBlocksFromBucket(TestBucket, new(DBTestObject))
	if err != nil {
		t.Error(err)
	}
	if len(fetchedBlocks) != len(blocks) {
		t.Error("Invalid amount of blocks returned")
	}
	for i := 0; i < max; i++ {
		if blocks[i].IsEqual(fetchedBlocks[i].(*DBTestObject)) == false {
			t.Error("Block from batch is not equal")
		}
	}

	startIndex := 3
	indexCount := 4
	fetchedIndexes, err := dbo.FetchBlockIndexesInHeightRange(TestNumberBucket, int64(startIndex), int64(startIndex+indexCount))
	if len(fetchedIndexes) != indexCount {
		t.Error("Invalid amount of indexes returned")
	}
	for i := 0; i < indexCount; i++ {
		primaryIndex := CopyZeroHash()
		primaryIndex[len(primaryIndex)-1] = byte(i + startIndex)

		if primitives.AreBytesEqual(primaryIndex, fetchedIndexes[i].Bytes()) == false {
			t.Error("Index from batch is not equal")
		}
	}
}