Improve interface test error messages.

This commit changes the interface test errors to all report the block
height and hash prior to the failure.  Test failures that transactions
also now report the transaction number and hash.  The makes it much
easier to track down where a test failure occurs.
This commit is contained in:
Dave Collins 2013-10-14 18:27:12 -05:00
parent c99416c121
commit 9ec86518ac

View file

@ -29,8 +29,8 @@ func testInsertBlock(tc *testContext) bool {
// The block must insert without any errors. // The block must insert without any errors.
newHeight, err := tc.db.InsertBlock(tc.block) newHeight, err := tc.db.InsertBlock(tc.block)
if err != nil { if err != nil {
tc.t.Errorf("InsertBlock (%s): failed to insert block %v "+ tc.t.Errorf("InsertBlock (%s): failed to insert block #%d (%s) "+
"err %v", tc.dbType, tc.blockHeight, err) "err %v", tc.dbType, tc.blockHeight, tc.blockHash, err)
return false return false
} }
@ -48,8 +48,8 @@ func testInsertBlock(tc *testContext) bool {
func testExistsSha(tc *testContext) bool { func testExistsSha(tc *testContext) bool {
// The block must exist in the database. // The block must exist in the database.
if exists := tc.db.ExistsSha(tc.blockHash); !exists { if exists := tc.db.ExistsSha(tc.blockHash); !exists {
tc.t.Errorf("ExistsSha (%s): block %v does not exist", tc.t.Errorf("ExistsSha (%s): block #%d (%s) does not exist",
tc.dbType, tc.blockHash) tc.dbType, tc.blockHeight, tc.blockHash)
return false return false
} }
@ -62,16 +62,17 @@ func testFetchBlockBySha(tc *testContext) bool {
// The block must be fetchable by its hash without any errors. // The block must be fetchable by its hash without any errors.
blockFromDb, err := tc.db.FetchBlockBySha(tc.blockHash) blockFromDb, err := tc.db.FetchBlockBySha(tc.blockHash)
if err != nil { if err != nil {
tc.t.Errorf("FetchBlockBySha (%s): %v", tc.dbType, err) tc.t.Errorf("FetchBlockBySha (%s): block #%d (%s) err: %v",
tc.dbType, tc.blockHeight, tc.blockHash, err)
return false return false
} }
// The block fetched from the database must give back the same MsgBlock // The block fetched from the database must give back the same MsgBlock
// and raw bytes that were stored. // and raw bytes that were stored.
if !reflect.DeepEqual(tc.block.MsgBlock(), blockFromDb.MsgBlock()) { if !reflect.DeepEqual(tc.block.MsgBlock(), blockFromDb.MsgBlock()) {
tc.t.Errorf("FetchBlockBySha (%s): block from database "+ tc.t.Errorf("FetchBlockBySha (%s): block #%d (%s) does not "+
"does not match stored block\ngot: %v\n"+ "match stored block\ngot: %v\nwant: %v", tc.dbType,
"want: %v", tc.dbType, tc.blockHeight, tc.blockHash,
spew.Sdump(blockFromDb.MsgBlock()), spew.Sdump(blockFromDb.MsgBlock()),
spew.Sdump(tc.block.MsgBlock())) spew.Sdump(tc.block.MsgBlock()))
return false return false
@ -87,9 +88,9 @@ func testFetchBlockBySha(tc *testContext) bool {
return false return false
} }
if !reflect.DeepEqual(blockBytes, blockFromDbBytes) { if !reflect.DeepEqual(blockBytes, blockFromDbBytes) {
tc.t.Errorf("FetchBlockBySha (%s): block bytes from "+ tc.t.Errorf("FetchBlockBySha (%s): block #%d (%s) bytes do "+
"database do not match stored block bytes\n"+ "not match stored bytes\ngot: %v\nwant: %v", tc.dbType,
"got: %v\nwant: %v", tc.dbType, tc.blockHeight, tc.blockHash,
spew.Sdump(blockFromDbBytes), spew.Sdump(blockBytes)) spew.Sdump(blockFromDbBytes), spew.Sdump(blockBytes))
return false return false
} }
@ -104,13 +105,14 @@ func testFetchBlockShaByHeight(tc *testContext) bool {
// value. // value.
hashFromDb, err := tc.db.FetchBlockShaByHeight(tc.blockHeight) hashFromDb, err := tc.db.FetchBlockShaByHeight(tc.blockHeight)
if err != nil { if err != nil {
tc.t.Errorf("FetchBlockShaByHeight (%s): %v", tc.dbType, err) tc.t.Errorf("FetchBlockShaByHeight (%s): block #%d (%s) err: %v",
tc.dbType, tc.blockHeight, tc.blockHash, err)
return false return false
} }
if !hashFromDb.IsEqual(tc.blockHash) { if !hashFromDb.IsEqual(tc.blockHash) {
tc.t.Errorf("FetchBlockShaByHeight (%s): returned hash "+ tc.t.Errorf("FetchBlockShaByHeight (%s): block #%d (%s) hash "+
"does not match expected value - got: %v, "+ "does not match expected value - got: %v", tc.dbType,
"want: %v", tc.dbType, hashFromDb, tc.blockHash) tc.blockHeight, tc.blockHash, hashFromDb)
return false return false
} }
@ -147,8 +149,9 @@ func testExistsTxSha(tc *testContext) bool {
// The transaction must exist in the database. // The transaction must exist in the database.
txHash := txHashes[i] txHash := txHashes[i]
if exists := tc.db.ExistsTxSha(txHash); !exists { if exists := tc.db.ExistsTxSha(txHash); !exists {
tc.t.Errorf("ExistsTxSha (%s): tx %v does not exist", tc.t.Errorf("ExistsTxSha (%s): block #%d (%s) "+
tc.dbType, txHash) "tx #%d (%s) does not exist", tc.dbType,
tc.blockHeight, tc.blockHash, i, txHash)
return false return false
} }
} }
@ -168,20 +171,25 @@ func testFetchTxBySha(tc *testContext) bool {
txHash := txHashes[i] txHash := txHashes[i]
txReplyList, err := tc.db.FetchTxBySha(txHash) txReplyList, err := tc.db.FetchTxBySha(txHash)
if err != nil { if err != nil {
tc.t.Errorf("FetchTxBySha (%s): %v", tc.dbType, err) tc.t.Errorf("FetchTxBySha (%s): block #%d (%s) "+
"tx #%d (%s) err: %v", tc.dbType, tc.blockHeight,
tc.blockHash, i, txHash, err)
return false return false
} }
if len(txReplyList) == 0 { if len(txReplyList) == 0 {
tc.t.Errorf("FetchTxBySha (%s): tx %v did not "+ tc.t.Errorf("FetchTxBySha (%s): block #%d (%s) "+
"return reply data", tc.dbType, txHash) "tx #%d (%s) did not return reply data",
tc.dbType, tc.blockHeight, tc.blockHash, i,
txHash)
return false return false
} }
txFromDb := txReplyList[len(txReplyList)-1].Tx txFromDb := txReplyList[len(txReplyList)-1].Tx
if !reflect.DeepEqual(tx, txFromDb) { if !reflect.DeepEqual(tx, txFromDb) {
tc.t.Errorf("FetchTxBySha (%s): tx %v from "+ tc.t.Errorf("FetchTxBySha (%s): block #%d (%s) "+
"database does not match stored tx\n"+ "tx #%d (%s) does not match stored tx\n"+
"got: %v\nwant: %v", tc.dbType, txHash, "got: %v\nwant: %v", tc.dbType, tc.blockHeight,
spew.Sdump(txFromDb), spew.Sdump(tx)) tc.blockHash, i, txHash, spew.Sdump(txFromDb),
spew.Sdump(tx))
return false return false
} }
} }
@ -200,8 +208,8 @@ func testFetchTxByShaList(tc *testContext) bool {
txReplyList := tc.db.FetchTxByShaList(txHashes) txReplyList := tc.db.FetchTxByShaList(txHashes)
if len(txReplyList) != len(txHashes) { if len(txReplyList) != len(txHashes) {
tc.t.Errorf("FetchTxByShaList (%s): tx reply list for "+ tc.t.Errorf("FetchTxByShaList (%s): block #%d (%s) "+
"block #%d (%v) does not match expected length "+ "tx reply list does not match expected length "+
"- got: %v, want: %v", tc.dbType, tc.blockHeight, "- got: %v, want: %v", tc.dbType, tc.blockHeight,
tc.blockHash, len(txReplyList), len(txHashes)) tc.blockHash, len(txReplyList), len(txHashes))
return false return false
@ -212,52 +220,56 @@ func testFetchTxByShaList(tc *testContext) bool {
// The transaction hash in the reply must be the expected value. // The transaction hash in the reply must be the expected value.
if !txD.Sha.IsEqual(txHash) { if !txD.Sha.IsEqual(txHash) {
tc.t.Errorf("FetchTxByShaList (%s): tx #%d hash "+ tc.t.Errorf("FetchTxByShaList (%s): block #%d (%s) "+
"does not match expected - got %v, "+ "tx #%d (%s) hash does not match expected "+
"want %v", tc.dbType, i, txD.Sha, txHashes[i]) "value - got %v", tc.dbType, tc.blockHeight,
tc.blockHash, i, txHash, txD.Sha)
return false return false
} }
// The reply must not indicate any errors. // The reply must not indicate any errors.
if txD.Err != nil { if txD.Err != nil {
tc.t.Errorf("FetchTxByShaList (%s): tx #%d (%v) "+ tc.t.Errorf("FetchTxByShaList (%s): block #%d (%s) "+
"returned unexpected error - got %v, "+ "tx #%d (%s) returned unexpected error - "+
"want nil", tc.dbType, i, txD.Sha, txD.Err) "got %v, want nil", tc.dbType, tc.blockHeight,
tc.blockHash, i, txHash, txD.Err)
return false return false
} }
// The transaction in the reply fetched from the database must // The transaction in the reply fetched from the database must
// be the same MsgTx that was stored. // be the same MsgTx that was stored.
if !reflect.DeepEqual(tx, txD.Tx) { if !reflect.DeepEqual(tx, txD.Tx) {
tc.t.Errorf("FetchTxByShaList (%s): tx #%d (%v) from "+ tc.t.Errorf("FetchTxByShaList (%s): block #%d (%s) "+
"database does not match stored tx\n"+ "tx #%d (%s) does not match stored tx\n"+
"got: %v\nwant: %v", tc.dbType, i, txHash, "got: %v\nwant: %v", tc.dbType, tc.blockHeight,
spew.Sdump(txD.Tx), spew.Sdump(tx)) tc.blockHash, i, txHash, spew.Sdump(txD.Tx),
spew.Sdump(tx))
return false return false
} }
// The block hash in the reply from the database must be the // The block hash in the reply from the database must be the
// expected value. // expected value.
if txD.BlkSha == nil { if txD.BlkSha == nil {
tc.t.Errorf("FetchTxByShaList (%s): tx #%d (%v) "+ tc.t.Errorf("FetchTxByShaList (%s): block #%d (%s) "+
"returned nil block hash", tc.dbType, i, txD.Sha) "tx #%d (%s) returned nil block hash", tc.dbType,
tc.blockHeight, tc.blockHash, i, txHash)
return false return false
} }
if !txD.BlkSha.IsEqual(tc.blockHash) { if !txD.BlkSha.IsEqual(tc.blockHash) {
tc.t.Errorf("FetchTxByShaList (%s): tx #%d (%v) "+ tc.t.Errorf("FetchTxByShaList (%s): block #%d (%s) "+
"returned unexpected block hash - got %v, "+ "tx #%d (%s) returned unexpected block hash - "+
"want %v", tc.dbType, i, txD.Sha, txD.BlkSha, "got %v", tc.dbType, tc.blockHeight,
tc.blockHash) tc.blockHash, i, txHash, txD.BlkSha)
return false return false
} }
// The block height in the reply from the database must be the // The block height in the reply from the database must be the
// expected value. // expected value.
if txD.Height != tc.blockHeight { if txD.Height != tc.blockHeight {
tc.t.Errorf("FetchTxByShaList (%s): tx #%d (%v) "+ tc.t.Errorf("FetchTxByShaList (%s): block #%d (%s) "+
"returned unexpected block height - got %v, "+ "tx #%d (%s) returned unexpected block height "+
"want %v", tc.dbType, i, txD.Sha, txD.Height, "- got %v", tc.dbType, tc.blockHeight,
tc.blockHeight) tc.blockHash, i, txHash, txD.Height)
return false return false
} }
@ -265,16 +277,17 @@ func testFetchTxByShaList(tc *testContext) bool {
// indicate any of the transactions that were just inserted are // indicate any of the transactions that were just inserted are
// spent. // spent.
if txD.TxSpent == nil { if txD.TxSpent == nil {
tc.t.Errorf("FetchTxByShaList (%s): tx #%d (%v) "+ tc.t.Errorf("FetchTxByShaList (%s): block #%d (%s) "+
"returned nil spend data", tc.dbType, i, txD.Sha) "tx #%d (%s) returned nil spend data", tc.dbType,
tc.blockHeight, tc.blockHash, i, txHash)
return false return false
} }
noSpends := make([]bool, len(tx.TxOut)) noSpends := make([]bool, len(tx.TxOut))
if !reflect.DeepEqual(txD.TxSpent, noSpends) { if !reflect.DeepEqual(txD.TxSpent, noSpends) {
tc.t.Errorf("FetchTxByShaList (%s): tx #%d (%v) "+ tc.t.Errorf("FetchTxByShaList (%s): block #%d (%s) "+
"returned unexpected spend data - got %v, "+ "tx #%d (%s) returned unexpected spend data - "+
"want %v", tc.dbType, i, txD.Sha, txD.TxSpent, "got %v, want %v", tc.dbType, tc.blockHeight,
noSpends) tc.blockHash, i, txHash, txD.TxSpent, noSpends)
return false return false
} }
} }
@ -293,8 +306,8 @@ func testFetchUnSpentTxByShaList(tc *testContext) bool {
txReplyList := tc.db.FetchUnSpentTxByShaList(txHashes) txReplyList := tc.db.FetchUnSpentTxByShaList(txHashes)
if len(txReplyList) != len(txHashes) { if len(txReplyList) != len(txHashes) {
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx reply list for "+ tc.t.Errorf("FetchUnSpentTxByShaList (%s): block #%d (%s) "+
"block #%d (%v) does not match expected length "+ "tx reply list does not match expected length "+
"- got: %v, want: %v", tc.dbType, tc.blockHeight, "- got: %v, want: %v", tc.dbType, tc.blockHeight,
tc.blockHash, len(txReplyList), len(txHashes)) tc.blockHash, len(txReplyList), len(txHashes))
return false return false
@ -305,52 +318,56 @@ func testFetchUnSpentTxByShaList(tc *testContext) bool {
// The transaction hash in the reply must be the expected value. // The transaction hash in the reply must be the expected value.
if !txD.Sha.IsEqual(txHash) { if !txD.Sha.IsEqual(txHash) {
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d hash "+ tc.t.Errorf("FetchUnSpentTxByShaList (%s): block #%d (%s) "+
"does not match expected - got %v, "+ "tx #%d (%s) hash does not match expected "+
"want %v", tc.dbType, i, txD.Sha, txHashes[i]) "value - got %v", tc.dbType, tc.blockHeight,
tc.blockHash, i, txHash, txD.Sha)
return false return false
} }
// The reply must not indicate any errors. // The reply must not indicate any errors.
if txD.Err != nil { if txD.Err != nil {
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d (%v) "+ tc.t.Errorf("FetchUnSpentTxByShaList (%s): block #%d (%s) "+
"returned unexpected error - got %v, "+ "tx #%d (%s) returned unexpected error - "+
"want nil", tc.dbType, i, txD.Sha, txD.Err) "got %v, want nil", tc.dbType, tc.blockHeight,
tc.blockHash, i, txHash, txD.Err)
return false return false
} }
// The transaction in the reply fetched from the database must // The transaction in the reply fetched from the database must
// be the same MsgTx that was stored. // be the same MsgTx that was stored.
if !reflect.DeepEqual(tx, txD.Tx) { if !reflect.DeepEqual(tx, txD.Tx) {
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d (%v) "+ tc.t.Errorf("FetchUnSpentTxByShaList (%s): block #%d (%s) "+
"from database does not match stored tx\n"+ "tx #%d (%s) does not match stored tx\n"+
"got: %v\nwant: %v", tc.dbType, i, txHash, "got: %v\nwant: %v", tc.dbType, tc.blockHeight,
spew.Sdump(txD.Tx), spew.Sdump(tx)) tc.blockHash, i, txHash, spew.Sdump(txD.Tx),
spew.Sdump(tx))
return false return false
} }
// The block hash in the reply from the database must be the // The block hash in the reply from the database must be the
// expected value. // expected value.
if txD.BlkSha == nil { if txD.BlkSha == nil {
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d (%v) "+ tc.t.Errorf("FetchUnSpentTxByShaList (%s): block #%d (%s) "+
"returned nil block hash", tc.dbType, i, txD.Sha) "tx #%d (%s) returned nil block hash", tc.dbType,
tc.blockHeight, tc.blockHash, i, txHash)
return false return false
} }
if !txD.BlkSha.IsEqual(tc.blockHash) { if !txD.BlkSha.IsEqual(tc.blockHash) {
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d (%v) "+ tc.t.Errorf("FetchUnSpentTxByShaList (%s): block #%d (%s) "+
"returned unexpected block hash - got %v, "+ "tx #%d (%s) returned unexpected block hash - "+
"want %v", tc.dbType, i, txD.Sha, txD.BlkSha, "got %v", tc.dbType, tc.blockHeight,
tc.blockHash) tc.blockHash, i, txHash, txD.BlkSha)
return false return false
} }
// The block height in the reply from the database must be the // The block height in the reply from the database must be the
// expected value. // expected value.
if txD.Height != tc.blockHeight { if txD.Height != tc.blockHeight {
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d (%v) "+ tc.t.Errorf("FetchUnSpentTxByShaList (%s): block #%d (%s) "+
"returned unexpected block height - got %v, "+ "tx #%d (%s) returned unexpected block height "+
"want %v", tc.dbType, i, txD.Sha, txD.Height, "- got %v", tc.dbType, tc.blockHeight,
tc.blockHeight) tc.blockHash, i, txHash, txD.Height)
return false return false
} }
@ -358,16 +375,17 @@ func testFetchUnSpentTxByShaList(tc *testContext) bool {
// indicate any of the transactions that were just inserted are // indicate any of the transactions that were just inserted are
// spent. // spent.
if txD.TxSpent == nil { if txD.TxSpent == nil {
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d (%v) "+ tc.t.Errorf("FetchUnSpentTxByShaList (%s): block #%d (%s) "+
"returned nil spend data", tc.dbType, i, txD.Sha) "tx #%d (%s) returned nil spend data", tc.dbType,
tc.blockHeight, tc.blockHash, i, txHash)
return false return false
} }
noSpends := make([]bool, len(tx.TxOut)) noSpends := make([]bool, len(tx.TxOut))
if !reflect.DeepEqual(txD.TxSpent, noSpends) { if !reflect.DeepEqual(txD.TxSpent, noSpends) {
tc.t.Errorf("FetchUnSpentTxByShaList (%s): tx #%d (%v) "+ tc.t.Errorf("FetchUnSpentTxByShaList (%s): block #%d (%s) "+
"returned unexpected spend data - got %v, "+ "tx #%d (%s) returned unexpected spend data - "+
"want %v", tc.dbType, i, txD.Sha, txD.TxSpent, "got %v, want %v", tc.dbType, tc.blockHeight,
noSpends) tc.blockHash, i, txHash, txD.TxSpent, noSpends)
return false return false
} }
} }