From c5d34da03a4e6b8fefe1559c2647ee89e9bc426c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=B6ckli?= Date: Thu, 14 Dec 2023 10:35:00 +0100 Subject: [PATCH] Add integration test --- .../store/sql/get_transaction_blocks_test.go | 44 +++++++++++++++++++ blocktx/store/sql/sql.go | 3 +- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/blocktx/store/sql/get_transaction_blocks_test.go b/blocktx/store/sql/get_transaction_blocks_test.go index 1604033d5..d1f8d6a1a 100644 --- a/blocktx/store/sql/get_transaction_blocks_test.go +++ b/blocktx/store/sql/get_transaction_blocks_test.go @@ -7,10 +7,54 @@ import ( "github.com/DATA-DOG/go-sqlmock" "github.com/bitcoin-sv/arc/blocktx/blocktx_api" + "github.com/bitcoin-sv/arc/blocktx/store" + . "github.com/bitcoin-sv/arc/database_testing" "github.com/libsv/go-p2p/chaincfg/chainhash" "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" ) +type GetTransactionBlocksSuite struct { + DatabaseTestSuite +} + +func (s *GetTransactionBlocksSuite) Test() { + block := GetTestBlock() + tx := GetTestTransaction() + s.InsertBlock(block) + + s.InsertTransaction(tx) + + s.InsertBlockTransactionMap(&store.BlockTransactionMap{ + BlockID: block.ID, + TransactionID: tx.ID, + Pos: 2, + }) + + store, err := NewPostgresStore(DefaultParams) + require.NoError(s.T(), err) + + b, err := store.GetTransactionBlocks(context.Background(), &blocktx_api.Transactions{ + Transactions: []*blocktx_api.Transaction{ + { + Hash: []byte(tx.Hash), + }, + }, + }) + require.NoError(s.T(), err) + + require.NoError(s.T(), err) + require.Equal(s.T(), block.Hash, string(b.TransactionBlocks[0].BlockHash)) + + require.NoError(s.T(), err) + require.Equal(s.T(), tx.Hash, string(b.TransactionBlocks[0].TransactionHash)) +} + +func TestGetTransactionBlocksIntegration(t *testing.T) { + s := new(GetTransactionBlocksSuite) + suite.Run(t, s) +} + func TestGetTransactionBlocks(t *testing.T) { txHash1, err := chainhash.NewHashFromStr("181fcd0be5a1742aabd594a5bfd5a1e7863a4583290da72fb2a896dfa824645c") require.NoError(t, err) diff --git a/blocktx/store/sql/sql.go b/blocktx/store/sql/sql.go index 108f26149..51d6c2f7d 100644 --- a/blocktx/store/sql/sql.go +++ b/blocktx/store/sql/sql.go @@ -40,7 +40,8 @@ func NewPostgresStore(params dbconn.DBConnectionParams) (store.Interface, error) } return &SQL{ - db: db, + db: db, + engine: postgresEngine, }, nil }