From 06cb2ec817f8dfd375e228386ba17ec224c3f5a7 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Mon, 14 Oct 2013 00:42:58 -0500 Subject: [PATCH] Add interface test for FetchTxBySha. This commit adds an interface test for FetchTxBySha to ensure it returns the same MsgTx that was part of an inserted block. --- interface_test.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/interface_test.go b/interface_test.go index 355abf95..6a6d78ac 100644 --- a/interface_test.go +++ b/interface_test.go @@ -145,6 +145,27 @@ func testInterface(t *testing.T, dbType string) { dbType, txHash) return } + + // Ensure loading the transaction back from the database + // gives back the same MsgTx. + txReplyList, err := db.FetchTxBySha(txHash) + if err != nil { + t.Errorf("FetchTxBySha (%s): %v", dbType, err) + return + } + if len(txReplyList) == 0 { + t.Errorf("FetchTxBySha (%s): tx %v did not "+ + "return reply data", dbType, txHash) + return + } + txFromDb := txReplyList[len(txReplyList)-1].Tx + if !reflect.DeepEqual(tx, txFromDb) { + t.Errorf("FetchTxBySha (%s): tx %v from "+ + "database does not match stored tx\n"+ + "got: %v\nwant: %v", dbType, txHash, + spew.Sdump(txFromDb), spew.Sdump(tx)) + return + } } } @@ -166,7 +187,7 @@ func testInterface(t *testing.T, dbType string) { - FetchBlockShaByHeight(height int64) (sha *btcwire.ShaHash, err error) FetchHeightRange(startHeight, endHeight int64) (rshalist []btcwire.ShaHash, err error) - ExistsTxSha(sha *btcwire.ShaHash) (exists bool) - FetchTxBySha(txsha *btcwire.ShaHash) ([]*TxListReply, error) + - FetchTxBySha(txsha *btcwire.ShaHash) ([]*TxListReply, error) FetchTxByShaList(txShaList []*btcwire.ShaHash) []*TxListReply FetchUnSpentTxByShaList(txShaList []*btcwire.ShaHash) []*TxListReply - InsertBlock(block *btcutil.Block) (height int64, err error)