Update tests for btcutil Block.Sha API change.

This commit is contained in:
Dave Collins 2015-04-17 00:58:45 -05:00
parent 750d657666
commit 88fd338420
5 changed files with 13 additions and 42 deletions

View file

@ -549,13 +549,8 @@ func testInterface(t *testing.T, dbType string) {
// Get the appropriate block and hash and update the test // Get the appropriate block and hash and update the test
// context accordingly. // context accordingly.
block := blocks[height] block := blocks[height]
blockHash, err := block.Sha()
if err != nil {
t.Errorf("block.Sha: %v", err)
return
}
context.blockHeight = height context.blockHeight = height
context.blockHash = blockHash context.blockHash = block.Sha()
context.block = block context.block = block
// The block must insert without any errors and return the // The block must insert without any errors and return the
@ -590,13 +585,8 @@ func testInterface(t *testing.T, dbType string) {
// Get the appropriate block and hash and update the // Get the appropriate block and hash and update the
// test context accordingly. // test context accordingly.
block := blocks[height] block := blocks[height]
blockHash, err := block.Sha()
if err != nil {
t.Errorf("block.Sha: %v", err)
return
}
context.blockHeight = height context.blockHeight = height
context.blockHash = blockHash context.blockHash = block.Sha()
context.block = block context.block = block
testIntegrity(&context) testIntegrity(&context)

View file

@ -103,7 +103,7 @@ out:
t.Errorf("height doe not match latest block height %v %v %v", blkid, height, err) t.Errorf("height doe not match latest block height %v %v %v", blkid, height, err)
} }
blkSha, _ := block.Sha() blkSha := block.Sha()
if *newSha != *blkSha { if *newSha != *blkSha {
t.Errorf("Newest block sha does not match freshly inserted one %v %v %v ", newSha, blkSha, err) t.Errorf("Newest block sha does not match freshly inserted one %v %v %v ", newSha, blkSha, err)
} }

View file

@ -150,9 +150,8 @@ endtest:
continue continue
} }
dropblock := blocks[height-1] dropblock := blocks[height-1]
dropsha, _ := dropblock.Sha()
err = db.DropAfterBlockBySha(dropsha) err = db.DropAfterBlockBySha(dropblock.Sha())
if err != nil { if err != nil {
t.Errorf("failed to drop block %v err %v", height, err) t.Errorf("failed to drop block %v err %v", height, err)
break endtest break endtest

View file

@ -268,7 +268,7 @@ out:
t.Errorf("height does not match latest block height %v %v %v", blkid, height, err) t.Errorf("height does not match latest block height %v %v %v", blkid, height, err)
} }
blkSha, _ := block.Sha() blkSha := block.Sha()
if *newSha != *blkSha { if *newSha != *blkSha {
t.Errorf("Newest block sha does not match freshly inserted one %v %v %v ", newSha, blkSha, err) t.Errorf("Newest block sha does not match freshly inserted one %v %v %v ", newSha, blkSha, err)
} }
@ -345,11 +345,7 @@ func testBackout(t *testing.T) {
} }
}() }()
sha, err := testDb.blocks[99].Sha() sha := testDb.blocks[99].Sha()
if err != nil {
t.Errorf("failed to get block 99 sha err %v", err)
return
}
if _, err := testDb.db.ExistsSha(sha); err != nil { if _, err := testDb.db.ExistsSha(sha); err != nil {
t.Errorf("ExistsSha: unexpected error: %v", err) t.Errorf("ExistsSha: unexpected error: %v", err)
} }
@ -359,11 +355,7 @@ func testBackout(t *testing.T) {
return return
} }
sha, err = testDb.blocks[119].Sha() sha = testDb.blocks[119].Sha()
if err != nil {
t.Errorf("failed to get block 110 sha err %v", err)
return
}
if _, err := testDb.db.ExistsSha(sha); err != nil { if _, err := testDb.db.ExistsSha(sha); err != nil {
t.Errorf("ExistsSha: unexpected error: %v", err) t.Errorf("ExistsSha: unexpected error: %v", err)
} }
@ -472,11 +464,7 @@ func testFetchHeightRange(t *testing.T, db database.Db, blocks []*btcutil.Block)
nBlocks := int64(len(blocks)) nBlocks := int64(len(blocks))
for i := range blocks { for i := range blocks {
blockSha, err := blocks[i].Sha() shanames[i] = blocks[i].Sha()
if err != nil {
t.Errorf("FetchHeightRange: unexpected failure computing block sah %v", err)
}
shanames[i] = blockSha
} }
for startheight := int64(0); startheight < nBlocks; startheight += testincrement { for startheight := int64(0); startheight < nBlocks; startheight += testincrement {
@ -557,7 +545,7 @@ func TestLimitAndSkipFetchTxsForAddr(t *testing.T) {
copy(hash160[:], scriptAddr[:]) copy(hash160[:], scriptAddr[:])
index[hash160] = append(index[hash160], &txLoc[i]) index[hash160] = append(index[hash160], &txLoc[i])
} }
blkSha, _ := testBlock.Sha() blkSha := testBlock.Sha()
err = testDb.db.UpdateAddrIndexForBlock(blkSha, newheight, index) err = testDb.db.UpdateAddrIndexForBlock(blkSha, newheight, index)
if err != nil { if err != nil {
t.Fatalf("UpdateAddrIndexForBlock: failed to index"+ t.Fatalf("UpdateAddrIndexForBlock: failed to index"+

View file

@ -34,13 +34,10 @@ func testReorganization(t *testing.T, dbType string) {
} }
for i := int64(0); i <= 2; i++ { for i := int64(0); i <= 2; i++ {
blkHash, err := blocks[i].Sha()
if err != nil {
t.Fatalf("Error getting SHA for block %d: %v", i, err)
}
_, err = db.InsertBlock(blocks[i]) _, err = db.InsertBlock(blocks[i])
if err != nil { if err != nil {
t.Fatalf("Error inserting block %d (%v): %v", i, blkHash, err) t.Fatalf("Error inserting block %d (%v): %v", i,
blocks[i].Sha(), err)
} }
var txIDs []string var txIDs []string
for _, tx := range blocks[i].Transactions() { for _, tx := range blocks[i].Transactions() {
@ -49,10 +46,7 @@ func testReorganization(t *testing.T, dbType string) {
} }
for i := int64(1); i >= 0; i-- { for i := int64(1); i >= 0; i-- {
blkHash, err := blocks[i].Sha() blkHash := blocks[i].Sha()
if err != nil {
t.Fatalf("Error getting SHA for block %d: %v", i, err)
}
err = db.DropAfterBlockBySha(blkHash) err = db.DropAfterBlockBySha(blkHash)
if err != nil { if err != nil {
t.Fatalf("Error removing block %d for reorganization: %v", i, err) t.Fatalf("Error removing block %d for reorganization: %v", i, err)
@ -70,7 +64,7 @@ func testReorganization(t *testing.T, dbType string) {
} }
for i := int64(3); i < int64(len(blocks)); i++ { for i := int64(3); i < int64(len(blocks)); i++ {
blkHash, err := blocks[i].Sha() blkHash := blocks[i].Sha()
if err != nil { if err != nil {
t.Fatalf("Error getting SHA for block %dA: %v", i-2, err) t.Fatalf("Error getting SHA for block %dA: %v", i-2, err)
} }