diff --git a/Makefile b/Makefile index f8af4f502..e99324e04 100644 --- a/Makefile +++ b/Makefile @@ -86,6 +86,14 @@ gen: --go-grpc_opt=paths=source_relative \ internal/callbacker/callbacker_api/callbacker_api.proto + protoc \ + --proto_path=. \ + --go_out=. \ + --go_opt=paths=source_relative \ + --go-grpc_out=. \ + --go-grpc_opt=paths=source_relative \ + pkg/message_queue/nats/client/test_api/test_api.proto + .PHONY: clean_gen clean_gen: rm -f ./internal/metamorph/metamorph_api/*.pb.go diff --git a/cmd/arc/services/api.go b/cmd/arc/services/api.go index df36d52db..57f0fecc1 100644 --- a/cmd/arc/services/api.go +++ b/cmd/arc/services/api.go @@ -24,15 +24,15 @@ import ( "github.com/bitcoin-sv/arc/internal/blocktx" "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" arc_logger "github.com/bitcoin-sv/arc/internal/logger" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_core" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_jetstream" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/nats_connection" "github.com/bitcoin-sv/arc/internal/metamorph" "github.com/bitcoin-sv/arc/internal/metamorph/metamorph_api" "github.com/bitcoin-sv/arc/internal/node_client" - "github.com/bitcoin-sv/arc/internal/tracing" tx_finder "github.com/bitcoin-sv/arc/internal/tx_finder" "github.com/bitcoin-sv/arc/pkg/api" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_core" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_jetstream" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/nats_connection" + "github.com/bitcoin-sv/arc/pkg/tracing" "github.com/bitcoin-sv/arc/pkg/woc_client" ) @@ -66,7 +66,7 @@ func StartAPIServer(logger *slog.Logger, arcConfig *config.ArcConfig) (func(), e shutdownFns := make([]func(), 0) if arcConfig.IsTracingEnabled() { - cleanup, err := tracing.Enable(logger, "api", arcConfig.Tracing) + cleanup, err := tracing.Enable(logger, "api", arcConfig.Tracing.DialAddr, arcConfig.Tracing.Sample) if err != nil { logger.Error("failed to enable tracing", slog.String("err", err.Error())) } else { diff --git a/cmd/arc/services/blocktx.go b/cmd/arc/services/blocktx.go index 568426e76..e14ef3aec 100644 --- a/cmd/arc/services/blocktx.go +++ b/cmd/arc/services/blocktx.go @@ -15,11 +15,11 @@ import ( "github.com/bitcoin-sv/arc/internal/blocktx/store" "github.com/bitcoin-sv/arc/internal/blocktx/store/postgresql" "github.com/bitcoin-sv/arc/internal/grpc_opts" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_core" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_jetstream" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/nats_connection" - "github.com/bitcoin-sv/arc/internal/tracing" "github.com/bitcoin-sv/arc/internal/version" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_core" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_jetstream" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/nats_connection" + "github.com/bitcoin-sv/arc/pkg/tracing" ) const ( @@ -49,7 +49,7 @@ func StartBlockTx(logger *slog.Logger, arcConfig *config.ArcConfig) (func(), err processorOpts := make([]func(handler *blocktx.Processor), 0) if arcConfig.IsTracingEnabled() { - cleanup, err := tracing.Enable(logger, "blocktx", arcConfig.Tracing) + cleanup, err := tracing.Enable(logger, "blocktx", arcConfig.Tracing.DialAddr, arcConfig.Tracing.Sample) if err != nil { logger.Error("failed to enable tracing", slog.String("err", err.Error())) } else { diff --git a/cmd/arc/services/callbacker.go b/cmd/arc/services/callbacker.go index 214a557da..6566dae74 100644 --- a/cmd/arc/services/callbacker.go +++ b/cmd/arc/services/callbacker.go @@ -34,8 +34,8 @@ import ( "github.com/bitcoin-sv/arc/internal/callbacker/store" "github.com/bitcoin-sv/arc/internal/callbacker/store/postgresql" "github.com/bitcoin-sv/arc/internal/grpc_opts" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_jetstream" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/nats_connection" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_jetstream" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/nats_connection" ) func StartCallbacker(logger *slog.Logger, arcConfig *config.ArcConfig) (func(), error) { diff --git a/cmd/arc/services/metamorph.go b/cmd/arc/services/metamorph.go index 3df64f51d..e72771c9f 100644 --- a/cmd/arc/services/metamorph.go +++ b/cmd/arc/services/metamorph.go @@ -13,16 +13,16 @@ import ( "google.golang.org/grpc" "github.com/bitcoin-sv/arc/internal/cache" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_core" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_jetstream" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/nats_connection" + "github.com/bitcoin-sv/arc/pkg/tracing" "github.com/bitcoin-sv/arc/config" "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" "github.com/bitcoin-sv/arc/internal/callbacker" "github.com/bitcoin-sv/arc/internal/callbacker/callbacker_api" "github.com/bitcoin-sv/arc/internal/grpc_opts" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_core" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_jetstream" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/nats_connection" "github.com/bitcoin-sv/arc/internal/metamorph" "github.com/bitcoin-sv/arc/internal/metamorph/metamorph_api" "github.com/bitcoin-sv/arc/internal/metamorph/store" @@ -61,7 +61,7 @@ func StartMetamorph(logger *slog.Logger, arcConfig *config.ArcConfig, cacheStore callbackerOpts := make([]callbacker.Option, 0) if arcConfig.IsTracingEnabled() { - cleanup, err := tracing.Enable(logger, "metamorph", arcConfig.Tracing) + cleanup, err := tracing.Enable(logger, "metamorph", arcConfig.Tracing.DialAddr, arcConfig.Tracing.Sample) if err != nil { logger.Error("failed to enable tracing", slog.String("err", err.Error())) } else { diff --git a/internal/api/handler/default.go b/internal/api/handler/default.go index f3a967b5f..41942deb5 100644 --- a/internal/api/handler/default.go +++ b/internal/api/handler/default.go @@ -13,6 +13,7 @@ import ( "github.com/bitcoin-sv/arc/internal/api/handler/internal/merkle_verifier" "github.com/bitcoin-sv/arc/internal/metamorph" + "github.com/bitcoin-sv/arc/pkg/tracing" sdkTx "github.com/bitcoin-sv/go-sdk/transaction" "github.com/labstack/echo/v4" @@ -22,7 +23,6 @@ import ( "github.com/bitcoin-sv/arc/internal/beef" "github.com/bitcoin-sv/arc/internal/blocktx" "github.com/bitcoin-sv/arc/internal/metamorph/metamorph_api" - "github.com/bitcoin-sv/arc/internal/tracing" "github.com/bitcoin-sv/arc/internal/validator" beefValidator "github.com/bitcoin-sv/arc/internal/validator/beef" defaultValidator "github.com/bitcoin-sv/arc/internal/validator/default" diff --git a/internal/blocktx/blocktx_api/blocktx_api.pb.go b/internal/blocktx/blocktx_api/blocktx_api.pb.go index 37f2000f2..03dcd4f63 100644 --- a/internal/blocktx/blocktx_api/blocktx_api.pb.go +++ b/internal/blocktx/blocktx_api/blocktx_api.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.29.3 +// protoc v5.29.1 // source: internal/blocktx/blocktx_api/blocktx_api.proto package blocktx_api diff --git a/internal/blocktx/blocktx_api/blocktx_api_grpc.pb.go b/internal/blocktx/blocktx_api/blocktx_api_grpc.pb.go index 5bb4fea12..47c1381d3 100644 --- a/internal/blocktx/blocktx_api/blocktx_api_grpc.pb.go +++ b/internal/blocktx/blocktx_api/blocktx_api_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.5.1 -// - protoc v5.29.3 +// - protoc v5.29.1 // source: internal/blocktx/blocktx_api/blocktx_api.proto package blocktx_api diff --git a/internal/blocktx/integration_test/helpers.go b/internal/blocktx/integration_test/helpers.go index 5e1d8540c..0a0a23865 100644 --- a/internal/blocktx/integration_test/helpers.go +++ b/internal/blocktx/integration_test/helpers.go @@ -14,9 +14,9 @@ import ( "github.com/bitcoin-sv/arc/internal/blocktx" "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" "github.com/bitcoin-sv/arc/internal/blocktx/store/postgresql" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_core" - nats_mock "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_core/mocks" - testutils "github.com/bitcoin-sv/arc/internal/test_utils" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_core" + nats_mock "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_core/mocks" + "github.com/bitcoin-sv/arc/pkg/test_utils" ) func setupSut(t *testing.T, dbInfo string) (*blocktx.Processor, *blocktx.PeerHandler, *postgresql.PostgreSQL, chan []byte, chan *blocktx_api.TransactionBlock) { diff --git a/internal/blocktx/integration_test/merkle_paths_test.go b/internal/blocktx/integration_test/merkle_paths_test.go index 778920279..377a8d752 100644 --- a/internal/blocktx/integration_test/merkle_paths_test.go +++ b/internal/blocktx/integration_test/merkle_paths_test.go @@ -4,8 +4,9 @@ import ( "testing" "time" - testutils "github.com/bitcoin-sv/arc/internal/test_utils" "github.com/stretchr/testify/require" + + "github.com/bitcoin-sv/arc/pkg/test_utils" ) func TestMerklePaths(t *testing.T) { diff --git a/internal/blocktx/integration_test/reorg_integration_test.go b/internal/blocktx/integration_test/reorg_integration_test.go index 31f9698ee..5336a2808 100644 --- a/internal/blocktx/integration_test/reorg_integration_test.go +++ b/internal/blocktx/integration_test/reorg_integration_test.go @@ -33,6 +33,7 @@ import ( "time" "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" + "github.com/bitcoin-sv/arc/pkg/test_utils" _ "github.com/golang-migrate/migrate/v4/source/file" _ "github.com/lib/pq" @@ -41,8 +42,6 @@ import ( "github.com/libsv/go-p2p/chaincfg/chainhash" "github.com/libsv/go-p2p/wire" "github.com/stretchr/testify/require" - - testutils "github.com/bitcoin-sv/arc/internal/test_utils" ) func TestReorg(t *testing.T) { diff --git a/internal/blocktx/integration_test/setup_test.go b/internal/blocktx/integration_test/setup_test.go index 22787873d..e99bd9c18 100644 --- a/internal/blocktx/integration_test/setup_test.go +++ b/internal/blocktx/integration_test/setup_test.go @@ -6,10 +6,11 @@ import ( "os" "testing" - testutils "github.com/bitcoin-sv/arc/internal/test_utils" _ "github.com/golang-migrate/migrate/v4/source/file" _ "github.com/lib/pq" "github.com/ory/dockertest/v3" + + "github.com/bitcoin-sv/arc/pkg/test_utils" ) const migrationsPath = "file://../store/postgresql/migrations" diff --git a/internal/blocktx/processor.go b/internal/blocktx/processor.go index 2bb19d400..888a20135 100644 --- a/internal/blocktx/processor.go +++ b/internal/blocktx/processor.go @@ -22,7 +22,7 @@ import ( "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" "github.com/bitcoin-sv/arc/internal/blocktx/store" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/tracing" ) var ( diff --git a/internal/blocktx/store/postgresql/get_block_transactions_hashes.go b/internal/blocktx/store/postgresql/get_block_transactions_hashes.go index b4c6adbde..872a2532b 100644 --- a/internal/blocktx/store/postgresql/get_block_transactions_hashes.go +++ b/internal/blocktx/store/postgresql/get_block_transactions_hashes.go @@ -7,7 +7,7 @@ import ( "github.com/libsv/go-p2p/chaincfg/chainhash" "github.com/bitcoin-sv/arc/internal/blocktx/store" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/tracing" ) func (p *PostgreSQL) GetBlockTransactionsHashes(ctx context.Context, blockHash []byte) (txHashes []*chainhash.Hash, err error) { diff --git a/internal/blocktx/store/postgresql/get_transactions.go b/internal/blocktx/store/postgresql/get_transactions.go index c35ba5768..786d22c25 100644 --- a/internal/blocktx/store/postgresql/get_transactions.go +++ b/internal/blocktx/store/postgresql/get_transactions.go @@ -8,7 +8,7 @@ import ( "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" "github.com/bitcoin-sv/arc/internal/blocktx/store" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/tracing" ) func (p *PostgreSQL) GetMinedTransactions(ctx context.Context, hashes [][]byte, onlyLongestChain bool) (minedTransactions []store.BlockTransaction, err error) { diff --git a/internal/blocktx/store/postgresql/insert_block_transactions.go b/internal/blocktx/store/postgresql/insert_block_transactions.go index 37eddca10..e44472b51 100644 --- a/internal/blocktx/store/postgresql/insert_block_transactions.go +++ b/internal/blocktx/store/postgresql/insert_block_transactions.go @@ -11,7 +11,7 @@ import ( "github.com/jackc/pgx/v5/stdlib" "github.com/bitcoin-sv/arc/internal/blocktx/store" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/tracing" ) // InsertBlockTransactions inserts the transaction hashes for a given block hash diff --git a/internal/blocktx/store/postgresql/mark_block_as_done.go b/internal/blocktx/store/postgresql/mark_block_as_done.go index 6cda2c67b..11547f5ac 100644 --- a/internal/blocktx/store/postgresql/mark_block_as_done.go +++ b/internal/blocktx/store/postgresql/mark_block_as_done.go @@ -5,7 +5,7 @@ import ( "github.com/libsv/go-p2p/chaincfg/chainhash" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/tracing" ) func (p *PostgreSQL) MarkBlockAsDone(ctx context.Context, hash *chainhash.Hash, size uint64, txCount uint64) (err error) { diff --git a/internal/blocktx/store/postgresql/postgres_test.go b/internal/blocktx/store/postgresql/postgres_test.go index f5f36295d..09bf6f91a 100644 --- a/internal/blocktx/store/postgresql/postgres_test.go +++ b/internal/blocktx/store/postgresql/postgres_test.go @@ -12,6 +12,7 @@ import ( "github.com/lib/pq" "github.com/bitcoin-sv/arc/internal/testdata" + testutils "github.com/bitcoin-sv/arc/pkg/test_utils" _ "github.com/golang-migrate/migrate/v4/source/file" "github.com/jmoiron/sqlx" @@ -22,8 +23,6 @@ import ( "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" "github.com/bitcoin-sv/arc/internal/blocktx/store" - - testutils "github.com/bitcoin-sv/arc/internal/test_utils" ) type Block struct { diff --git a/internal/blocktx/store/postgresql/upsert_block.go b/internal/blocktx/store/postgresql/upsert_block.go index 1d9a361cf..04771b547 100644 --- a/internal/blocktx/store/postgresql/upsert_block.go +++ b/internal/blocktx/store/postgresql/upsert_block.go @@ -6,7 +6,7 @@ import ( "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" "github.com/bitcoin-sv/arc/internal/blocktx/store" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/tracing" ) func (p *PostgreSQL) UpsertBlock(ctx context.Context, block *blocktx_api.Block) (blockID uint64, err error) { diff --git a/internal/cache/redis_test.go b/internal/cache/redis_test.go index ed83a631e..f70733b12 100644 --- a/internal/cache/redis_test.go +++ b/internal/cache/redis_test.go @@ -13,7 +13,7 @@ import ( "github.com/ory/dockertest/v3" "github.com/stretchr/testify/require" - testutils "github.com/bitcoin-sv/arc/internal/test_utils" + "github.com/bitcoin-sv/arc/pkg/test_utils" ) var ( diff --git a/internal/callbacker/callbacker_api/callbacker_api.pb.go b/internal/callbacker/callbacker_api/callbacker_api.pb.go index f5d249cb0..9604ddab1 100644 --- a/internal/callbacker/callbacker_api/callbacker_api.pb.go +++ b/internal/callbacker/callbacker_api/callbacker_api.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.29.3 +// protoc v5.29.1 // source: internal/callbacker/callbacker_api/callbacker_api.proto package callbacker_api diff --git a/internal/callbacker/callbacker_api/callbacker_api_grpc.pb.go b/internal/callbacker/callbacker_api/callbacker_api_grpc.pb.go index 0e888c07d..70dd13b85 100644 --- a/internal/callbacker/callbacker_api/callbacker_api_grpc.pb.go +++ b/internal/callbacker/callbacker_api/callbacker_api_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.5.1 -// - protoc v5.29.3 +// - protoc v5.29.1 // source: internal/callbacker/callbacker_api/callbacker_api.proto package callbacker_api diff --git a/internal/callbacker/grpc_callbacker.go b/internal/callbacker/grpc_callbacker.go index 909bbf809..62dc3eae2 100644 --- a/internal/callbacker/grpc_callbacker.go +++ b/internal/callbacker/grpc_callbacker.go @@ -10,7 +10,7 @@ import ( "github.com/bitcoin-sv/arc/internal/callbacker/callbacker_api" "github.com/bitcoin-sv/arc/internal/metamorph/metamorph_api" "github.com/bitcoin-sv/arc/internal/metamorph/store" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/tracing" ) var minedDoubleSpendMsg = "previously double spend attempted" diff --git a/internal/callbacker/store/postgresql/postgres_test.go b/internal/callbacker/store/postgresql/postgres_test.go index 66b1f4d72..a0ca48eda 100644 --- a/internal/callbacker/store/postgresql/postgres_test.go +++ b/internal/callbacker/store/postgresql/postgres_test.go @@ -17,8 +17,8 @@ import ( "github.com/bitcoin-sv/arc/internal/callbacker/store" tutils "github.com/bitcoin-sv/arc/internal/callbacker/store/postgresql/internal/tests" - testutils "github.com/bitcoin-sv/arc/internal/test_utils" "github.com/bitcoin-sv/arc/internal/testdata" + testutils "github.com/bitcoin-sv/arc/pkg/test_utils" ) const ( diff --git a/internal/metamorph/client.go b/internal/metamorph/client.go index 9dc952a42..825b5a528 100644 --- a/internal/metamorph/client.go +++ b/internal/metamorph/client.go @@ -18,7 +18,7 @@ import ( "github.com/bitcoin-sv/arc/config" "github.com/bitcoin-sv/arc/internal/grpc_opts" "github.com/bitcoin-sv/arc/internal/metamorph/metamorph_api" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/tracing" ) var ( diff --git a/internal/metamorph/integration_test/double_spend_integration_test.go b/internal/metamorph/integration_test/double_spend_integration_test.go index 5ab7f18a1..9781897bc 100644 --- a/internal/metamorph/integration_test/double_spend_integration_test.go +++ b/internal/metamorph/integration_test/double_spend_integration_test.go @@ -33,7 +33,7 @@ import ( "github.com/bitcoin-sv/arc/internal/metamorph/metamorph_api" "github.com/bitcoin-sv/arc/internal/metamorph/mocks" "github.com/bitcoin-sv/arc/internal/metamorph/store/postgresql" - testutils "github.com/bitcoin-sv/arc/internal/test_utils" + "github.com/bitcoin-sv/arc/pkg/test_utils" ) const ( diff --git a/internal/metamorph/integration_test/helpers.go b/internal/metamorph/integration_test/helpers.go index d0abc12d8..06d4bcfe0 100644 --- a/internal/metamorph/integration_test/helpers.go +++ b/internal/metamorph/integration_test/helpers.go @@ -4,7 +4,7 @@ import ( "database/sql" "testing" - testutils "github.com/bitcoin-sv/arc/internal/test_utils" + "github.com/bitcoin-sv/arc/pkg/test_utils" ) func pruneTables(t *testing.T, db *sql.DB) { diff --git a/internal/metamorph/integration_test/processor_integration_test.go b/internal/metamorph/integration_test/processor_integration_test.go index 4512e2592..2f9baba49 100644 --- a/internal/metamorph/integration_test/processor_integration_test.go +++ b/internal/metamorph/integration_test/processor_integration_test.go @@ -6,14 +6,15 @@ import ( "time" "github.com/bitcoin-sv/arc/internal/cache" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_core" - nats_mocks "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_core/mocks" "github.com/bitcoin-sv/arc/internal/metamorph" "github.com/bitcoin-sv/arc/internal/metamorph/metamorph_api" "github.com/bitcoin-sv/arc/internal/metamorph/mocks" "github.com/bitcoin-sv/arc/internal/metamorph/store" "github.com/bitcoin-sv/arc/internal/metamorph/store/postgresql" - testutils "github.com/bitcoin-sv/arc/internal/test_utils" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_core" + nats_mocks "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_core/mocks" + "github.com/bitcoin-sv/arc/pkg/test_utils" + "github.com/libsv/go-p2p" "github.com/libsv/go-p2p/chaincfg/chainhash" "github.com/stretchr/testify/require" diff --git a/internal/metamorph/integration_test/setup_test.go b/internal/metamorph/integration_test/setup_test.go index 3e3f2e63f..0fc741bd7 100644 --- a/internal/metamorph/integration_test/setup_test.go +++ b/internal/metamorph/integration_test/setup_test.go @@ -8,9 +8,10 @@ import ( "os" "testing" - testutils "github.com/bitcoin-sv/arc/internal/test_utils" "github.com/go-redis/redis/v8" "github.com/ory/dockertest/v3" + + "github.com/bitcoin-sv/arc/pkg/test_utils" ) const ( diff --git a/internal/metamorph/metamorph_api/metamorph_api.pb.go b/internal/metamorph/metamorph_api/metamorph_api.pb.go index 4b3c230b3..f84e56862 100644 --- a/internal/metamorph/metamorph_api/metamorph_api.pb.go +++ b/internal/metamorph/metamorph_api/metamorph_api.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.29.3 +// protoc v5.29.1 // source: internal/metamorph/metamorph_api/metamorph_api.proto package metamorph_api diff --git a/internal/metamorph/metamorph_api/metamorph_api_grpc.pb.go b/internal/metamorph/metamorph_api/metamorph_api_grpc.pb.go index ab8ff637a..029f3aa10 100644 --- a/internal/metamorph/metamorph_api/metamorph_api_grpc.pb.go +++ b/internal/metamorph/metamorph_api/metamorph_api_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.5.1 -// - protoc v5.29.3 +// - protoc v5.29.1 // source: internal/metamorph/metamorph_api/metamorph_api.proto package metamorph_api diff --git a/internal/metamorph/processor.go b/internal/metamorph/processor.go index 34a3da922..21fdc73c3 100644 --- a/internal/metamorph/processor.go +++ b/internal/metamorph/processor.go @@ -18,7 +18,7 @@ import ( "github.com/bitcoin-sv/arc/internal/cache" "github.com/bitcoin-sv/arc/internal/metamorph/metamorph_api" "github.com/bitcoin-sv/arc/internal/metamorph/store" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/tracing" ) const ( diff --git a/internal/metamorph/server.go b/internal/metamorph/server.go index 332959993..84ce32fb3 100644 --- a/internal/metamorph/server.go +++ b/internal/metamorph/server.go @@ -24,7 +24,7 @@ import ( "github.com/bitcoin-sv/arc/internal/grpc_opts" "github.com/bitcoin-sv/arc/internal/metamorph/metamorph_api" "github.com/bitcoin-sv/arc/internal/metamorph/store" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/tracing" ) const ( diff --git a/internal/metamorph/store/postgresql/postgres.go b/internal/metamorph/store/postgresql/postgres.go index 660db6f1b..13865baf7 100644 --- a/internal/metamorph/store/postgresql/postgres.go +++ b/internal/metamorph/store/postgresql/postgres.go @@ -17,7 +17,7 @@ import ( "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" "github.com/bitcoin-sv/arc/internal/metamorph/metamorph_api" "github.com/bitcoin-sv/arc/internal/metamorph/store" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/tracing" ) const ( diff --git a/internal/metamorph/store/postgresql/postgres_test.go b/internal/metamorph/store/postgresql/postgres_test.go index 24bdd122d..573c5e29f 100644 --- a/internal/metamorph/store/postgresql/postgres_test.go +++ b/internal/metamorph/store/postgresql/postgres_test.go @@ -19,8 +19,8 @@ import ( "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" "github.com/bitcoin-sv/arc/internal/metamorph/metamorph_api" "github.com/bitcoin-sv/arc/internal/metamorph/store" - testutils "github.com/bitcoin-sv/arc/internal/test_utils" "github.com/bitcoin-sv/arc/internal/testdata" + testutils2 "github.com/bitcoin-sv/arc/pkg/test_utils" ) const ( @@ -41,7 +41,7 @@ func testmain(m *testing.M) int { } port := "5433" - resource, connStr, err := testutils.RunAndMigratePostgresql(pool, port, "metamorph", migrationsPath) + resource, connStr, err := testutils2.RunAndMigratePostgresql(pool, port, "metamorph", migrationsPath) if err != nil { log.Print(err) return 1 @@ -58,7 +58,7 @@ func testmain(m *testing.M) int { } func pruneTables(t *testing.T, db *sql.DB) { - testutils.PruneTables(t, db, "metamorph.transactions") + testutils2.PruneTables(t, db, "metamorph.transactions") } func TestPostgresDB(t *testing.T) { @@ -139,16 +139,16 @@ func TestPostgresDB(t *testing.T) { t.Run("get raw txs", func(t *testing.T) { defer pruneTables(t, postgresDB.db) - testutils.LoadFixtures(t, postgresDB.db, "fixtures/get_rawtxs") + testutils2.LoadFixtures(t, postgresDB.db, "fixtures/get_rawtxs") hash1 := "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853" hash2 := "21132d32cb5411c058bb4391f24f6a36ed9b810df851d0e36cac514fd03d6b4e" hash3 := "3e0b5b218c344110f09bf485bc58de4ea5378e55744185edf9c1dafa40068ecd" hashes := make([][]byte, 0) - hashes = append(hashes, testutils.RevChainhash(t, hash1).CloneBytes()) - hashes = append(hashes, testutils.RevChainhash(t, hash2).CloneBytes()) - hashes = append(hashes, testutils.RevChainhash(t, hash3).CloneBytes()) + hashes = append(hashes, testutils2.RevChainhash(t, hash1).CloneBytes()) + hashes = append(hashes, testutils2.RevChainhash(t, hash2).CloneBytes()) + hashes = append(hashes, testutils2.RevChainhash(t, hash3).CloneBytes()) expectedRawTxs := make([][]byte, 0) @@ -173,11 +173,11 @@ func TestPostgresDB(t *testing.T) { t.Run("get many", func(t *testing.T) { // when defer pruneTables(t, postgresDB.db) - testutils.LoadFixtures(t, postgresDB.db, "fixtures") + testutils2.LoadFixtures(t, postgresDB.db, "fixtures") keys := [][]byte{ - testutils.RevChainhash(t, "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853")[:], - testutils.RevChainhash(t, "ee76f5b746893d3e6ae6a14a15e464704f4ebd601537820933789740acdcf6aa")[:], + testutils2.RevChainhash(t, "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853")[:], + testutils2.RevChainhash(t, "ee76f5b746893d3e6ae6a14a15e464704f4ebd601537820933789740acdcf6aa")[:], } // then @@ -190,9 +190,9 @@ func TestPostgresDB(t *testing.T) { t.Run("set bulk", func(t *testing.T) { defer pruneTables(t, postgresDB.db) - testutils.LoadFixtures(t, postgresDB.db, "fixtures/set_bulk") + testutils2.LoadFixtures(t, postgresDB.db, "fixtures/set_bulk") - hash2 := testutils.RevChainhash(t, "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853") // hash already existing in db - no update expected + hash2 := testutils2.RevChainhash(t, "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853") // hash already existing in db - no update expected data := []*store.Data{ { @@ -250,17 +250,17 @@ func TestPostgresDB(t *testing.T) { t.Run("get unmined", func(t *testing.T) { defer pruneTables(t, postgresDB.db) - testutils.LoadFixtures(t, postgresDB.db, "fixtures") + testutils2.LoadFixtures(t, postgresDB.db, "fixtures") // locked by metamorph-1 - expectedHash0 := testutils.RevChainhash(t, "3e0b5b218c344110f09bf485bc58de4ea5378e55744185edf9c1dafa40068ecd") + expectedHash0 := testutils2.RevChainhash(t, "3e0b5b218c344110f09bf485bc58de4ea5378e55744185edf9c1dafa40068ecd") // offset 0 records, err := postgresDB.GetUnmined(ctx, time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC), 1, 0) require.NoError(t, err) require.Equal(t, expectedHash0, records[0].Hash) // locked by metamorph-1 - expectedHash1 := testutils.RevChainhash(t, "b16cea53fc823e146fbb9ae4ad3124f7c273f30562585ad6e4831495d609f430") + expectedHash1 := testutils2.RevChainhash(t, "b16cea53fc823e146fbb9ae4ad3124f7c273f30562585ad6e4831495d609f430") // offset 1 records, err = postgresDB.GetUnmined(ctx, time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC), 1, 1) require.NoError(t, err) @@ -269,20 +269,20 @@ func TestPostgresDB(t *testing.T) { t.Run("set locked by", func(t *testing.T) { defer pruneTables(t, postgresDB.db) - testutils.LoadFixtures(t, postgresDB.db, "fixtures") + testutils2.LoadFixtures(t, postgresDB.db, "fixtures") err := postgresDB.SetLocked(ctx, time.Date(2023, 9, 15, 1, 0, 0, 0, time.UTC), 2) require.NoError(t, err) // locked by NONE - expectedHash2 := testutils.RevChainhash(t, "12c04cfc5643f1cd25639ad42d6f8f0489557699d92071d7e0a5b940438c4357") + expectedHash2 := testutils2.RevChainhash(t, "12c04cfc5643f1cd25639ad42d6f8f0489557699d92071d7e0a5b940438c4357") // locked by NONE - expectedHash3 := testutils.RevChainhash(t, "319b5eb9d99084b72002640d1445f49b8c83539260a7e5b2cbb16c1d2954a743") + expectedHash3 := testutils2.RevChainhash(t, "319b5eb9d99084b72002640d1445f49b8c83539260a7e5b2cbb16c1d2954a743") // check if previously unlocked tx has b // locked by NONE - expectedHash4 := testutils.RevChainhash(t, "78d66c8391ff5e4a65b494e39645facb420b744f77f3f3b83a3aa8573282176e") + expectedHash4 := testutils2.RevChainhash(t, "78d66c8391ff5e4a65b494e39645facb420b744f77f3f3b83a3aa8573282176e") // check if previously unlocked tx has been locked dataReturned, err := postgresDB.Get(ctx, expectedHash2[:]) @@ -301,28 +301,28 @@ func TestPostgresDB(t *testing.T) { t.Run("set unlocked by name", func(t *testing.T) { defer pruneTables(t, postgresDB.db) - testutils.LoadFixtures(t, postgresDB.db, "fixtures/set_unlocked_by_name") + testutils2.LoadFixtures(t, postgresDB.db, "fixtures/set_unlocked_by_name") rows, err := postgresDB.SetUnlockedByName(ctx, "metamorph-3") require.NoError(t, err) require.Equal(t, int64(4), rows) - hash1 := testutils.RevChainhash(t, "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853") + hash1 := testutils2.RevChainhash(t, "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853") hash1Data, err := postgresDB.Get(ctx, hash1[:]) require.NoError(t, err) require.Equal(t, "NONE", hash1Data.LockedBy) - hash2 := testutils.RevChainhash(t, "21132d32cb5411c058bb4391f24f6a36ed9b810df851d0e36cac514fd03d6b4e") + hash2 := testutils2.RevChainhash(t, "21132d32cb5411c058bb4391f24f6a36ed9b810df851d0e36cac514fd03d6b4e") hash2Data, err := postgresDB.Get(ctx, hash2[:]) require.NoError(t, err) require.Equal(t, "NONE", hash2Data.LockedBy) - hash3 := testutils.RevChainhash(t, "f791ec50447e3001b9348930659527ea92dee506e9950014bcc7c5b146e2417f") + hash3 := testutils2.RevChainhash(t, "f791ec50447e3001b9348930659527ea92dee506e9950014bcc7c5b146e2417f") hash3Data, err := postgresDB.Get(ctx, hash3[:]) require.NoError(t, err) require.Equal(t, "NONE", hash3Data.LockedBy) - hash4 := testutils.RevChainhash(t, "89714f129748e5176a07fc4eb89cf27a9e60340117e6b56bb742acb2873f8140") + hash4 := testutils2.RevChainhash(t, "89714f129748e5176a07fc4eb89cf27a9e60340117e6b56bb742acb2873f8140") hash4Data, err := postgresDB.Get(ctx, hash4[:]) require.NoError(t, err) require.Equal(t, "NONE", hash4Data.LockedBy) @@ -330,40 +330,40 @@ func TestPostgresDB(t *testing.T) { t.Run("update status", func(t *testing.T) { defer pruneTables(t, postgresDB.db) - testutils.LoadFixtures(t, postgresDB.db, "fixtures/update_status") + testutils2.LoadFixtures(t, postgresDB.db, "fixtures/update_status") updates := []store.UpdateStatus{ { - Hash: *testutils.RevChainhash(t, "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853"), // update expected + Hash: *testutils2.RevChainhash(t, "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853"), // update expected Status: metamorph_api.Status_ACCEPTED_BY_NETWORK, }, { - Hash: *testutils.RevChainhash(t, "21132d32cb5411c058bb4391f24f6a36ed9b810df851d0e36cac514fd03d6b4e"), // update not expected - old status = new status + Hash: *testutils2.RevChainhash(t, "21132d32cb5411c058bb4391f24f6a36ed9b810df851d0e36cac514fd03d6b4e"), // update not expected - old status = new status Status: metamorph_api.Status_REQUESTED_BY_NETWORK, }, { - Hash: *testutils.RevChainhash(t, "b16cea53fc823e146fbb9ae4ad3124f7c273f30562585ad6e4831495d609f430"), // update expected + Hash: *testutils2.RevChainhash(t, "b16cea53fc823e146fbb9ae4ad3124f7c273f30562585ad6e4831495d609f430"), // update expected Status: metamorph_api.Status_REJECTED, Error: errors.New("missing inputs"), }, { - Hash: *testutils.RevChainhash(t, "ee76f5b746893d3e6ae6a14a15e464704f4ebd601537820933789740acdcf6aa"), // update expected + Hash: *testutils2.RevChainhash(t, "ee76f5b746893d3e6ae6a14a15e464704f4ebd601537820933789740acdcf6aa"), // update expected Status: metamorph_api.Status_SEEN_ON_NETWORK, }, { - Hash: *testutils.RevChainhash(t, "3e0b5b218c344110f09bf485bc58de4ea5378e55744185edf9c1dafa40068ecd"), // update not expected - status is mined + Hash: *testutils2.RevChainhash(t, "3e0b5b218c344110f09bf485bc58de4ea5378e55744185edf9c1dafa40068ecd"), // update not expected - status is mined Status: metamorph_api.Status_SENT_TO_NETWORK, }, { - Hash: *testutils.RevChainhash(t, "7809b730cbe7bb723f299a4e481fb5165f31175876392a54cde85569a18cc75f"), // update not expected - old status > new status + Hash: *testutils2.RevChainhash(t, "7809b730cbe7bb723f299a4e481fb5165f31175876392a54cde85569a18cc75f"), // update not expected - old status > new status Status: metamorph_api.Status_SENT_TO_NETWORK, }, { - Hash: *testutils.RevChainhash(t, "3ce1e0c6cbbbe2118c3f80d2e6899d2d487f319ef0923feb61f3d26335b2225c"), // update not expected - hash non-existent in db + Hash: *testutils2.RevChainhash(t, "3ce1e0c6cbbbe2118c3f80d2e6899d2d487f319ef0923feb61f3d26335b2225c"), // update not expected - hash non-existent in db Status: metamorph_api.Status_ANNOUNCED_TO_NETWORK, }, { - Hash: *testutils.RevChainhash(t, "7e3350ca12a0dd9375540e13637b02e054a3436336e9d6b82fe7f2b23c710002"), // update not expected - hash non-existent in db + Hash: *testutils2.RevChainhash(t, "7e3350ca12a0dd9375540e13637b02e054a3436336e9d6b82fe7f2b23c710002"), // update not expected - hash non-existent in db Status: metamorph_api.Status_ANNOUNCED_TO_NETWORK, }, } @@ -374,16 +374,16 @@ func TestPostgresDB(t *testing.T) { require.Len(t, statusUpdates, updatedStatuses) require.Equal(t, metamorph_api.Status_ACCEPTED_BY_NETWORK, statusUpdates[0].Status) - require.Equal(t, *testutils.RevChainhash(t, "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853"), *statusUpdates[0].Hash) + require.Equal(t, *testutils2.RevChainhash(t, "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853"), *statusUpdates[0].Hash) require.Equal(t, metamorph_api.Status_REJECTED, statusUpdates[1].Status) require.Equal(t, "missing inputs", statusUpdates[1].RejectReason) - require.Equal(t, *testutils.RevChainhash(t, "b16cea53fc823e146fbb9ae4ad3124f7c273f30562585ad6e4831495d609f430"), *statusUpdates[1].Hash) + require.Equal(t, *testutils2.RevChainhash(t, "b16cea53fc823e146fbb9ae4ad3124f7c273f30562585ad6e4831495d609f430"), *statusUpdates[1].Hash) require.Equal(t, metamorph_api.Status_SEEN_ON_NETWORK, statusUpdates[2].Status) - require.Equal(t, *testutils.RevChainhash(t, "ee76f5b746893d3e6ae6a14a15e464704f4ebd601537820933789740acdcf6aa"), *statusUpdates[2].Hash) + require.Equal(t, *testutils2.RevChainhash(t, "ee76f5b746893d3e6ae6a14a15e464704f4ebd601537820933789740acdcf6aa"), *statusUpdates[2].Hash) - returnedDataRequested, err := postgresDB.Get(ctx, testutils.RevChainhash(t, "7809b730cbe7bb723f299a4e481fb5165f31175876392a54cde85569a18cc75f")[:]) + returnedDataRequested, err := postgresDB.Get(ctx, testutils2.RevChainhash(t, "7809b730cbe7bb723f299a4e481fb5165f31175876392a54cde85569a18cc75f")[:]) require.NoError(t, err) require.Equal(t, metamorph_api.Status_ACCEPTED_BY_NETWORK, returnedDataRequested.Status) @@ -394,42 +394,42 @@ func TestPostgresDB(t *testing.T) { t.Run("update double spend status", func(t *testing.T) { defer pruneTables(t, postgresDB.db) - testutils.LoadFixtures(t, postgresDB.db, "fixtures/update_double_spend") + testutils2.LoadFixtures(t, postgresDB.db, "fixtures/update_double_spend") updates := []store.UpdateStatus{ { - Hash: *testutils.RevChainhash(t, "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853"), // update expected + Hash: *testutils2.RevChainhash(t, "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853"), // update expected Status: metamorph_api.Status_DOUBLE_SPEND_ATTEMPTED, CompetingTxs: []string{"5678"}, }, { - Hash: *testutils.RevChainhash(t, "21132d32cb5411c058bb4391f24f6a36ed9b810df851d0e36cac514fd03d6b4e"), // update expected + Hash: *testutils2.RevChainhash(t, "21132d32cb5411c058bb4391f24f6a36ed9b810df851d0e36cac514fd03d6b4e"), // update expected Status: metamorph_api.Status_DOUBLE_SPEND_ATTEMPTED, CompetingTxs: []string{"9999", "8888"}, }, { - Hash: *testutils.RevChainhash(t, "b16cea53fc823e146fbb9ae4ad3124f7c273f30562585ad6e4831495d609f430"), // update expected + Hash: *testutils2.RevChainhash(t, "b16cea53fc823e146fbb9ae4ad3124f7c273f30562585ad6e4831495d609f430"), // update expected Status: metamorph_api.Status_DOUBLE_SPEND_ATTEMPTED, CompetingTxs: []string{"1234"}, }, { - Hash: *testutils.RevChainhash(t, "3e0b5b218c344110f09bf485bc58de4ea5378e55744185edf9c1dafa40068ecd"), // update not expected - status is mined + Hash: *testutils2.RevChainhash(t, "3e0b5b218c344110f09bf485bc58de4ea5378e55744185edf9c1dafa40068ecd"), // update not expected - status is mined Status: metamorph_api.Status_DOUBLE_SPEND_ATTEMPTED, CompetingTxs: []string{"1234"}, }, { - Hash: *testutils.RevChainhash(t, "7809b730cbe7bb723f299a4e481fb5165f31175876392a54cde85569a18cc75f"), // update expected - old status < new status + Hash: *testutils2.RevChainhash(t, "7809b730cbe7bb723f299a4e481fb5165f31175876392a54cde85569a18cc75f"), // update expected - old status < new status Status: metamorph_api.Status_REJECTED, CompetingTxs: []string{"1234"}, Error: errors.New("double spend attempted"), }, { - Hash: *testutils.RevChainhash(t, "3ce1e0c6cbbbe2118c3f80d2e6899d2d487f319ef0923feb61f3d26335b2225c"), // update not expected - hash non-existent in db + Hash: *testutils2.RevChainhash(t, "3ce1e0c6cbbbe2118c3f80d2e6899d2d487f319ef0923feb61f3d26335b2225c"), // update not expected - hash non-existent in db Status: metamorph_api.Status_DOUBLE_SPEND_ATTEMPTED, CompetingTxs: []string{"1234"}, }, { - Hash: *testutils.RevChainhash(t, "7e3350ca12a0dd9375540e13637b02e054a3436336e9d6b82fe7f2b23c710002"), // update not expected - hash non-existent in db + Hash: *testutils2.RevChainhash(t, "7e3350ca12a0dd9375540e13637b02e054a3436336e9d6b82fe7f2b23c710002"), // update not expected - hash non-existent in db Status: metamorph_api.Status_DOUBLE_SPEND_ATTEMPTED, CompetingTxs: []string{"1234"}, }, @@ -441,19 +441,19 @@ func TestPostgresDB(t *testing.T) { require.Len(t, statusUpdates, updatedStatuses) require.Equal(t, metamorph_api.Status_DOUBLE_SPEND_ATTEMPTED, statusUpdates[0].Status) - require.Equal(t, *testutils.RevChainhash(t, "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853"), *statusUpdates[0].Hash) + require.Equal(t, *testutils2.RevChainhash(t, "cd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853"), *statusUpdates[0].Hash) require.True(t, unorderedEqual([]string{"5678", "1234"}, statusUpdates[0].CompetingTxs)) require.Equal(t, metamorph_api.Status_DOUBLE_SPEND_ATTEMPTED, statusUpdates[1].Status) - require.Equal(t, *testutils.RevChainhash(t, "21132d32cb5411c058bb4391f24f6a36ed9b810df851d0e36cac514fd03d6b4e"), *statusUpdates[1].Hash) + require.Equal(t, *testutils2.RevChainhash(t, "21132d32cb5411c058bb4391f24f6a36ed9b810df851d0e36cac514fd03d6b4e"), *statusUpdates[1].Hash) require.True(t, unorderedEqual([]string{"9999", "8888", "1234", "5678"}, statusUpdates[1].CompetingTxs)) require.Equal(t, metamorph_api.Status_DOUBLE_SPEND_ATTEMPTED, statusUpdates[2].Status) - require.Equal(t, *testutils.RevChainhash(t, "b16cea53fc823e146fbb9ae4ad3124f7c273f30562585ad6e4831495d609f430"), *statusUpdates[2].Hash) + require.Equal(t, *testutils2.RevChainhash(t, "b16cea53fc823e146fbb9ae4ad3124f7c273f30562585ad6e4831495d609f430"), *statusUpdates[2].Hash) require.Equal(t, []string{"1234"}, statusUpdates[2].CompetingTxs) require.Equal(t, metamorph_api.Status_REJECTED, statusUpdates[3].Status) - require.Equal(t, *testutils.RevChainhash(t, "7809b730cbe7bb723f299a4e481fb5165f31175876392a54cde85569a18cc75f"), *statusUpdates[3].Hash) + require.Equal(t, *testutils2.RevChainhash(t, "7809b730cbe7bb723f299a4e481fb5165f31175876392a54cde85569a18cc75f"), *statusUpdates[3].Hash) require.Equal(t, []string{"1234"}, statusUpdates[3].CompetingTxs) require.Equal(t, "double spend attempted", statusUpdates[3].RejectReason) @@ -464,16 +464,16 @@ func TestPostgresDB(t *testing.T) { t.Run("update mined", func(t *testing.T) { defer pruneTables(t, postgresDB.db) - testutils.LoadFixtures(t, postgresDB.db, "fixtures") + testutils2.LoadFixtures(t, postgresDB.db, "fixtures") unmined := *unminedData err = postgresDB.Set(ctx, &unmined) require.NoError(t, err) - chainHash2 := testutils.RevChainhash(t, "ee76f5b746893d3e6ae6a14a15e464704f4ebd601537820933789740acdcf6aa") - chainHash3 := testutils.RevChainhash(t, "a7fd98bd37f9b387dbef4f1a4e4790b9a0d48fb7bbb77455e8f39df0f8909db7") - competingHash := testutils.RevChainhash(t, "67fc757d9ed6d119fc0926ae5c82c1a2cf036ec823257cfaea396e49184ec7ff") - chainhash4 := testutils.RevChainhash(t, "3e0b5b218c344110f09bf485bc58de4ea5378e55744185edf9c1dafa40068ecd") + chainHash2 := testutils2.RevChainhash(t, "ee76f5b746893d3e6ae6a14a15e464704f4ebd601537820933789740acdcf6aa") + chainHash3 := testutils2.RevChainhash(t, "a7fd98bd37f9b387dbef4f1a4e4790b9a0d48fb7bbb77455e8f39df0f8909db7") + competingHash := testutils2.RevChainhash(t, "67fc757d9ed6d119fc0926ae5c82c1a2cf036ec823257cfaea396e49184ec7ff") + chainhash4 := testutils2.RevChainhash(t, "3e0b5b218c344110f09bf485bc58de4ea5378e55744185edf9c1dafa40068ecd") txBlocks := []*blocktx_api.TransactionBlock{ { @@ -886,7 +886,7 @@ func TestPostgresDB(t *testing.T) { t.Run("clear data", func(t *testing.T) { defer pruneTables(t, postgresDB.db) - testutils.LoadFixtures(t, postgresDB.db, "fixtures") + testutils2.LoadFixtures(t, postgresDB.db, "fixtures") res, err := postgresDB.ClearData(ctx, 14) require.NoError(t, err) @@ -900,9 +900,9 @@ func TestPostgresDB(t *testing.T) { t.Run("get seen on network txs", func(t *testing.T) { defer pruneTables(t, postgresDB.db) - testutils.LoadFixtures(t, postgresDB.db, "fixtures") + testutils2.LoadFixtures(t, postgresDB.db, "fixtures") - txHash := testutils.RevChainhash(t, "855b2aea1420df52a561fe851297653739677b14c89c0a08e3f70e1942bcb10f") + txHash := testutils2.RevChainhash(t, "855b2aea1420df52a561fe851297653739677b14c89c0a08e3f70e1942bcb10f") require.NoError(t, err) records, err := postgresDB.GetSeenOnNetwork(ctx, time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC), time.Date(2023, 1, 1, 3, 0, 0, 0, time.UTC), 2, 0) @@ -915,7 +915,7 @@ func TestPostgresDB(t *testing.T) { t.Run("get stats", func(t *testing.T) { defer pruneTables(t, postgresDB.db) - testutils.LoadFixtures(t, postgresDB.db, "fixtures/get_stats") + testutils2.LoadFixtures(t, postgresDB.db, "fixtures/get_stats") res, err := postgresDB.GetStats(ctx, time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC), 10*time.Minute, 20*time.Minute) require.NoError(t, err) diff --git a/internal/node_client/node_client.go b/internal/node_client/node_client.go index f450fc4ab..68acc93a8 100644 --- a/internal/node_client/node_client.go +++ b/internal/node_client/node_client.go @@ -12,7 +12,7 @@ import ( "github.com/ordishs/go-bitcoin" "go.opentelemetry.io/otel/attribute" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/tracing" ) var ( diff --git a/internal/node_client/node_client_test.go b/internal/node_client/node_client_test.go index 6fcf8af11..13c1cab1a 100644 --- a/internal/node_client/node_client_test.go +++ b/internal/node_client/node_client_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/require" "github.com/bitcoin-sv/arc/internal/node_client" - testutils "github.com/bitcoin-sv/arc/internal/test_utils" + "github.com/bitcoin-sv/arc/pkg/test_utils" ) var ( diff --git a/internal/tx_finder/cached_tx_finder.go b/internal/tx_finder/cached_tx_finder.go index d670ffe0c..0fe7f7770 100644 --- a/internal/tx_finder/cached_tx_finder.go +++ b/internal/tx_finder/cached_tx_finder.go @@ -9,8 +9,8 @@ import ( "github.com/patrickmn/go-cache" "go.opentelemetry.io/otel/attribute" - "github.com/bitcoin-sv/arc/internal/tracing" "github.com/bitcoin-sv/arc/internal/validator" + "github.com/bitcoin-sv/arc/pkg/tracing" ) const ( diff --git a/internal/tx_finder/tx_finder.go b/internal/tx_finder/tx_finder.go index 66b51bb62..b02542ad2 100644 --- a/internal/tx_finder/tx_finder.go +++ b/internal/tx_finder/tx_finder.go @@ -12,8 +12,8 @@ import ( "go.opentelemetry.io/otel/trace" "github.com/bitcoin-sv/arc/internal/metamorph" - "github.com/bitcoin-sv/arc/internal/tracing" "github.com/bitcoin-sv/arc/internal/validator" + "github.com/bitcoin-sv/arc/pkg/tracing" "github.com/bitcoin-sv/arc/pkg/woc_client" ) diff --git a/internal/validator/default/default_validator.go b/internal/validator/default/default_validator.go index 6d0097e2b..5722d558d 100644 --- a/internal/validator/default/default_validator.go +++ b/internal/validator/default/default_validator.go @@ -11,9 +11,9 @@ import ( internalApi "github.com/bitcoin-sv/arc/internal/api" "github.com/bitcoin-sv/arc/internal/fees" - "github.com/bitcoin-sv/arc/internal/tracing" "github.com/bitcoin-sv/arc/internal/validator" "github.com/bitcoin-sv/arc/pkg/api" + "github.com/bitcoin-sv/arc/pkg/tracing" ) var ( diff --git a/internal/validator/default/helpers.go b/internal/validator/default/helpers.go index 5a6c23d5a..55188e24a 100644 --- a/internal/validator/default/helpers.go +++ b/internal/validator/default/helpers.go @@ -8,8 +8,8 @@ import ( sdkTx "github.com/bitcoin-sv/go-sdk/transaction" "go.opentelemetry.io/otel/attribute" - "github.com/bitcoin-sv/arc/internal/tracing" "github.com/bitcoin-sv/arc/internal/validator" + "github.com/bitcoin-sv/arc/pkg/tracing" ) var ( diff --git a/internal/message_queue/nats/client/nats_core/integration_test/client_integration_test.go b/pkg/message_queue/nats/client/nats_core/integration_test/client_integration_test.go similarity index 60% rename from internal/message_queue/nats/client/nats_core/integration_test/client_integration_test.go rename to pkg/message_queue/nats/client/nats_core/integration_test/client_integration_test.go index df981b4a4..86742a27f 100644 --- a/internal/message_queue/nats/client/nats_core/integration_test/client_integration_test.go +++ b/pkg/message_queue/nats/client/nats_core/integration_test/client_integration_test.go @@ -13,12 +13,10 @@ import ( "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" - "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_core" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/nats_connection" - "github.com/bitcoin-sv/arc/internal/metamorph/metamorph_api" - testutils "github.com/bitcoin-sv/arc/internal/test_utils" - "github.com/bitcoin-sv/arc/internal/testdata" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_core" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/test_api" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/nats_connection" + "github.com/bitcoin-sv/arc/pkg/test_utils" ) const ( @@ -88,44 +86,38 @@ func TestNatsClient(t *testing.T) { t.Skip("skipping integration test") } - txBlock := &blocktx_api.TransactionBlock{ - BlockHash: testdata.Block1Hash[:], - BlockHeight: 1, - TransactionHash: testdata.TX1Hash[:], - MerklePath: "mp-1", + testMessage := &test_api.TestMessage{ + Ok: true, } t.Run("publish", func(t *testing.T) { // given mqClient = nats_core.New(natsConnClient) - submittedTxsChan := make(chan *metamorph_api.TransactionRequest, 100) - txRequest := &metamorph_api.TransactionRequest{ - CallbackUrl: "callback.example.com", - CallbackToken: "test-token", - RawTx: testdata.TX1Raw.Bytes(), - WaitForStatus: metamorph_api.Status_ANNOUNCED_TO_NETWORK, + messageChan := make(chan *test_api.TestMessage, 100) + message := &test_api.TestMessage{ + Ok: true, } // when t.Log("subscribe to topic") _, err := natsConnClient.QueueSubscribe(SubmitTxTopic, "queue", func(msg *nats.Msg) { - serialized := &metamorph_api.TransactionRequest{} + serialized := &test_api.TestMessage{} err := proto.Unmarshal(msg.Data, serialized) require.NoError(t, err) - submittedTxsChan <- serialized + messageChan <- serialized }) require.NoError(t, err) time.Sleep(1 * time.Second) t.Log("publish") - err = mqClient.PublishMarshal(context.TODO(), SubmitTxTopic, txRequest) + err = mqClient.PublishMarshal(context.TODO(), SubmitTxTopic, message) require.NoError(t, err) - err = mqClient.PublishMarshal(context.TODO(), SubmitTxTopic, txRequest) + err = mqClient.PublishMarshal(context.TODO(), SubmitTxTopic, message) require.NoError(t, err) - err = mqClient.PublishMarshal(context.TODO(), SubmitTxTopic, txRequest) + err = mqClient.PublishMarshal(context.TODO(), SubmitTxTopic, message) require.NoError(t, err) - err = mqClient.PublishMarshal(context.TODO(), SubmitTxTopic, txRequest) + err = mqClient.PublishMarshal(context.TODO(), SubmitTxTopic, message) require.NoError(t, err) counter := 0 @@ -138,12 +130,9 @@ func TestNatsClient(t *testing.T) { case <-time.NewTimer(500 * time.Millisecond).C: t.Log("timer finished") break loop - case data := <-submittedTxsChan: + case data := <-messageChan: counter++ - require.Equal(t, txRequest.CallbackUrl, data.CallbackUrl) - require.Equal(t, txRequest.CallbackToken, data.CallbackToken) - require.Equal(t, txRequest.RawTx, data.RawTx) - require.Equal(t, txRequest.WaitForStatus, data.WaitForStatus) + require.Equal(t, message.Ok, data.Ok) } } @@ -153,19 +142,19 @@ func TestNatsClient(t *testing.T) { t.Run("subscribe", func(t *testing.T) { // given mqClient = nats_core.New(natsConnClient) - minedTxsChan := make(chan *blocktx_api.TransactionBlock, 100) + messageChan := make(chan *test_api.TestMessage, 100) // when err := mqClient.Subscribe(MinedTxsTopic, func(msg []byte) error { - serialized := &blocktx_api.TransactionBlock{} + serialized := &test_api.TestMessage{} err := proto.Unmarshal(msg, serialized) require.NoError(t, err) - minedTxsChan <- serialized + messageChan <- serialized return nil }) require.NoError(t, err) - data, err := proto.Marshal(txBlock) + data, err := proto.Marshal(testMessage) require.NoError(t, err) time.Sleep(1 * time.Second) @@ -185,12 +174,9 @@ func TestNatsClient(t *testing.T) { select { case <-time.NewTimer(500 * time.Millisecond).C: break loop - case minedTxBlock := <-minedTxsChan: + case message := <-messageChan: counter++ - require.Equal(t, minedTxBlock.BlockHash, txBlock.BlockHash) - require.Equal(t, minedTxBlock.BlockHeight, txBlock.BlockHeight) - require.Equal(t, minedTxBlock.TransactionHash, txBlock.TransactionHash) - require.Equal(t, minedTxBlock.MerklePath, txBlock.MerklePath) + require.Equal(t, message.Ok, testMessage.Ok) } } require.Equal(t, 3, counter) diff --git a/internal/message_queue/nats/client/nats_core/mocks/nats_connection_mock.go b/pkg/message_queue/nats/client/nats_core/mocks/nats_connection_mock.go similarity index 98% rename from internal/message_queue/nats/client/nats_core/mocks/nats_connection_mock.go rename to pkg/message_queue/nats/client/nats_core/mocks/nats_connection_mock.go index d9d40086e..1f08a2569 100644 --- a/internal/message_queue/nats/client/nats_core/mocks/nats_connection_mock.go +++ b/pkg/message_queue/nats/client/nats_core/mocks/nats_connection_mock.go @@ -4,7 +4,7 @@ package mocks import ( - "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_core" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_core" "github.com/nats-io/nats.go" "sync" ) diff --git a/internal/message_queue/nats/client/nats_core/nats_core_client.go b/pkg/message_queue/nats/client/nats_core/nats_core_client.go similarity index 98% rename from internal/message_queue/nats/client/nats_core/nats_core_client.go rename to pkg/message_queue/nats/client/nats_core/nats_core_client.go index 1eabeed54..dfe4abe46 100644 --- a/internal/message_queue/nats/client/nats_core/nats_core_client.go +++ b/pkg/message_queue/nats/client/nats_core/nats_core_client.go @@ -12,7 +12,7 @@ import ( "go.opentelemetry.io/otel/attribute" "google.golang.org/protobuf/proto" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/tracing" ) var ( diff --git a/internal/message_queue/nats/client/nats_core/nats_core_client_test.go b/pkg/message_queue/nats/client/nats_core/nats_core_client_test.go similarity index 80% rename from internal/message_queue/nats/client/nats_core/nats_core_client_test.go rename to pkg/message_queue/nats/client/nats_core/nats_core_client_test.go index ecdfaac89..e8dcdfd48 100644 --- a/internal/message_queue/nats/client/nats_core/nats_core_client_test.go +++ b/pkg/message_queue/nats/client/nats_core/nats_core_client_test.go @@ -10,28 +10,24 @@ import ( "github.com/nats-io/nats.go" "github.com/stretchr/testify/require" - "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_core" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_core/mocks" - "github.com/bitcoin-sv/arc/internal/testdata" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_core" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_core/mocks" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/test_api" ) const ( - MinedTxsTopic = "mined-txs" - RegisterTxTopic = "register-tx" + topic1 = "topic-1" + topic2 = "topic-2" ) func TestPublishMarshal(t *testing.T) { - txBlock := &blocktx_api.TransactionBlock{ - BlockHash: testdata.Block1Hash[:], - BlockHeight: 1, - TransactionHash: testdata.TX1Hash[:], - MerklePath: "mp-1", + message := &test_api.TestMessage{ + Ok: true, } tt := []struct { name string - txsBlock *blocktx_api.TransactionBlock + txsBlock *test_api.TestMessage publishErr error expectedError error @@ -39,13 +35,13 @@ func TestPublishMarshal(t *testing.T) { }{ { name: "success", - txsBlock: txBlock, + txsBlock: message, expectedPublishCalls: 1, }, { name: "publish err", - txsBlock: txBlock, + txsBlock: message, publishErr: nats_core.ErrFailedToPublish, expectedError: nats_core.ErrFailedToPublish, @@ -65,7 +61,7 @@ func TestPublishMarshal(t *testing.T) { sut := nats_core.New(natsMock, nats_core.WithLogger(logger)) // when - err := sut.PublishMarshal(context.TODO(), MinedTxsTopic, tc.txsBlock) + err := sut.PublishMarshal(context.TODO(), topic2, tc.txsBlock) // then if tc.expectedError != nil { @@ -115,7 +111,7 @@ func TestPublish(t *testing.T) { ) // when - err := sut.Publish(context.TODO(), RegisterTxTopic, []byte("tx")) + err := sut.Publish(context.TODO(), topic1, []byte("tx")) // then if tc.expectedError != nil { @@ -168,8 +164,8 @@ func TestSubscribe(t *testing.T) { natsMock := &mocks.NatsConnectionMock{ QueueSubscribeFunc: func(subj string, queue string, cb nats.MsgHandler) (*nats.Subscription, error) { - require.Equal(t, "register-tx", subj) - require.Equal(t, "register-tx-group", queue) + require.Equal(t, "topic-1", subj) + require.Equal(t, "topic-1-group", queue) msgHandler = cb return nil, tc.subscribeErr }, @@ -180,7 +176,7 @@ func TestSubscribe(t *testing.T) { ) // when - err := sut.Subscribe(RegisterTxTopic, func(_ []byte) error { return tc.msgFuncErr }) + err := sut.Subscribe(topic1, func(_ []byte) error { return tc.msgFuncErr }) // then if tc.expectedError != nil { diff --git a/internal/message_queue/nats/client/nats_core/nats_core_mocks.go b/pkg/message_queue/nats/client/nats_core/nats_core_mocks.go similarity index 100% rename from internal/message_queue/nats/client/nats_core/nats_core_mocks.go rename to pkg/message_queue/nats/client/nats_core/nats_core_mocks.go diff --git a/internal/message_queue/nats/client/nats_jetstream/integration_test/client_integration_test.go b/pkg/message_queue/nats/client/nats_jetstream/integration_test/client_integration_test.go similarity index 62% rename from internal/message_queue/nats/client/nats_jetstream/integration_test/client_integration_test.go rename to pkg/message_queue/nats/client/nats_jetstream/integration_test/client_integration_test.go index 92aa010ad..6f3bfcdb4 100644 --- a/internal/message_queue/nats/client/nats_jetstream/integration_test/client_integration_test.go +++ b/pkg/message_queue/nats/client/nats_jetstream/integration_test/client_integration_test.go @@ -14,12 +14,10 @@ import ( "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" - "github.com/bitcoin-sv/arc/internal/blocktx/blocktx_api" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_jetstream" - "github.com/bitcoin-sv/arc/internal/message_queue/nats/nats_connection" - "github.com/bitcoin-sv/arc/internal/metamorph/metamorph_api" - testutils "github.com/bitcoin-sv/arc/internal/test_utils" - "github.com/bitcoin-sv/arc/internal/testdata" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/nats_jetstream" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/client/test_api" + "github.com/bitcoin-sv/arc/pkg/message_queue/nats/nats_connection" + "github.com/bitcoin-sv/arc/pkg/test_utils" ) var ( @@ -87,11 +85,8 @@ func TestNatsClient(t *testing.T) { t.Skip("skipping integration test") } - txBlock := &blocktx_api.TransactionBlock{ - BlockHash: testdata.Block1Hash[:], - BlockHeight: 1, - TransactionHash: testdata.TX1Hash[:], - MerklePath: "mp-1", + txBlock := &test_api.TestMessage{ + Ok: true, } t.Run("publish - work queue policy", func(t *testing.T) { // given @@ -99,31 +94,28 @@ func TestNatsClient(t *testing.T) { mqClient, err := nats_jetstream.New(natsConnClient, logger, nats_jetstream.WithWorkQueuePolicy(topic)) require.NoError(t, err) - submittedTxsChan := make(chan *metamorph_api.TransactionRequest, 100) - txRequest := &metamorph_api.TransactionRequest{ - CallbackUrl: "callback.example.com", - CallbackToken: "test-token", - RawTx: testdata.TX1Raw.Bytes(), - WaitForStatus: metamorph_api.Status_ANNOUNCED_TO_NETWORK, + messageChan := make(chan *test_api.TestMessage, 100) + testMessage := &test_api.TestMessage{ + Ok: true, } // when t.Log("subscribe to topic") _, err = natsConnClient.QueueSubscribe(topic, "queue", func(msg *nats.Msg) { - serialized := &metamorph_api.TransactionRequest{} + serialized := &test_api.TestMessage{} err := proto.Unmarshal(msg.Data, serialized) require.NoError(t, err) - submittedTxsChan <- serialized + messageChan <- serialized }) require.NoError(t, err) t.Log("publish") - err = mqClient.PublishMarshal(context.TODO(), topic, txRequest) + err = mqClient.PublishMarshal(context.TODO(), topic, testMessage) require.NoError(t, err) - err = mqClient.PublishMarshal(context.TODO(), topic, txRequest) + err = mqClient.PublishMarshal(context.TODO(), topic, testMessage) require.NoError(t, err) - err = mqClient.PublishMarshal(context.TODO(), topic, txRequest) + err = mqClient.PublishMarshal(context.TODO(), topic, testMessage) require.NoError(t, err) - err = mqClient.PublishMarshal(context.TODO(), topic, txRequest) + err = mqClient.PublishMarshal(context.TODO(), topic, testMessage) require.NoError(t, err) counter := 0 @@ -136,12 +128,9 @@ func TestNatsClient(t *testing.T) { case <-time.NewTimer(500 * time.Millisecond).C: t.Log("timer finished") break loop - case data := <-submittedTxsChan: + case data := <-messageChan: counter++ - require.Equal(t, txRequest.CallbackUrl, data.CallbackUrl) - require.Equal(t, txRequest.CallbackToken, data.CallbackToken) - require.Equal(t, txRequest.RawTx, data.RawTx) - require.Equal(t, txRequest.WaitForStatus, data.WaitForStatus) + require.Equal(t, testMessage.Ok, data.Ok) } } @@ -156,7 +145,7 @@ func TestNatsClient(t *testing.T) { mqClient, err := nats_jetstream.New(natsConnClient, logger, nats_jetstream.WithWorkQueuePolicy(topic)) require.NoError(t, err) - minedTxsChan := make(chan *blocktx_api.TransactionBlock, 100) + messageChan := make(chan *test_api.TestMessage, 100) // subscribe without initialized consumer, expect error err = mqClient.Subscribe(topic, func(_ []byte) error { @@ -169,12 +158,12 @@ func TestNatsClient(t *testing.T) { require.NoError(t, err) err = mqClient.Subscribe(topic, func(msg []byte) error { - serialized := &blocktx_api.TransactionBlock{} + serialized := &test_api.TestMessage{} unmarshalErr := proto.Unmarshal(msg, serialized) if unmarshalErr != nil { return unmarshalErr } - minedTxsChan <- serialized + messageChan <- serialized return nil }) require.NoError(t, err) @@ -199,12 +188,9 @@ func TestNatsClient(t *testing.T) { select { case <-time.NewTimer(500 * time.Millisecond).C: break loop - case minedTxBlock := <-minedTxsChan: + case minedTxBlock := <-messageChan: counter++ - require.Equal(t, minedTxBlock.BlockHash, txBlock.BlockHash) - require.Equal(t, minedTxBlock.BlockHeight, txBlock.BlockHeight) - require.Equal(t, minedTxBlock.TransactionHash, txBlock.TransactionHash) - require.Equal(t, minedTxBlock.MerklePath, txBlock.MerklePath) + require.Equal(t, minedTxBlock.Ok, txBlock.Ok) } } require.Equal(t, 3, counter) @@ -215,31 +201,28 @@ func TestNatsClient(t *testing.T) { const topic = "interest-txs" mqClient, err := nats_jetstream.New(natsConnClient, logger, nats_jetstream.WithInterestPolicy(topic)) require.NoError(t, err) - submittedTxsChan := make(chan *metamorph_api.TransactionRequest, 100) - txRequest := &metamorph_api.TransactionRequest{ - CallbackUrl: "callback.example.com", - CallbackToken: "test-token", - RawTx: testdata.TX1Raw.Bytes(), - WaitForStatus: metamorph_api.Status_ANNOUNCED_TO_NETWORK, + messageChan := make(chan *test_api.TestMessage, 100) + testMessage := &test_api.TestMessage{ + Ok: true, } // when t.Log("subscribe to topic") _, err = natsConnClient.QueueSubscribe(topic, "queue", func(msg *nats.Msg) { - serialized := &metamorph_api.TransactionRequest{} + serialized := &test_api.TestMessage{} err := proto.Unmarshal(msg.Data, serialized) require.NoError(t, err) - submittedTxsChan <- serialized + messageChan <- serialized }) require.NoError(t, err) t.Log("publish") - err = mqClient.PublishMarshal(context.TODO(), topic, txRequest) + err = mqClient.PublishMarshal(context.TODO(), topic, testMessage) require.NoError(t, err) - err = mqClient.PublishMarshal(context.TODO(), topic, txRequest) + err = mqClient.PublishMarshal(context.TODO(), topic, testMessage) require.NoError(t, err) - err = mqClient.PublishMarshal(context.TODO(), topic, txRequest) + err = mqClient.PublishMarshal(context.TODO(), topic, testMessage) require.NoError(t, err) - err = mqClient.PublishMarshal(context.TODO(), topic, txRequest) + err = mqClient.PublishMarshal(context.TODO(), topic, testMessage) require.NoError(t, err) counter := 0 @@ -252,12 +235,9 @@ func TestNatsClient(t *testing.T) { case <-time.NewTimer(500 * time.Millisecond).C: t.Log("timer finished") break loop - case data := <-submittedTxsChan: + case data := <-messageChan: counter++ - require.Equal(t, txRequest.CallbackUrl, data.CallbackUrl) - require.Equal(t, txRequest.CallbackToken, data.CallbackToken) - require.Equal(t, txRequest.RawTx, data.RawTx) - require.Equal(t, txRequest.WaitForStatus, data.WaitForStatus) + require.Equal(t, testMessage.Ok, data.Ok) } } @@ -268,8 +248,8 @@ func TestNatsClient(t *testing.T) { // given var err error const topic = "interest-blocks" - minedTxsChan1 := make(chan *blocktx_api.TransactionBlock, 100) - minedTxsChan2 := make(chan *blocktx_api.TransactionBlock, 100) + minedTxsChan1 := make(chan *test_api.TestMessage, 100) + minedTxsChan2 := make(chan *test_api.TestMessage, 100) mqClient = mqClientSubscribe(t, topic, "host1", minedTxsChan1) mqClient2 := mqClientSubscribe(t, topic, "host2", minedTxsChan2) @@ -296,16 +276,10 @@ func TestNatsClient(t *testing.T) { break loop case minedTxBlock := <-minedTxsChan1: counter++ - require.Equal(t, minedTxBlock.BlockHash, txBlock.BlockHash) - require.Equal(t, minedTxBlock.BlockHeight, txBlock.BlockHeight) - require.Equal(t, minedTxBlock.TransactionHash, txBlock.TransactionHash) - require.Equal(t, minedTxBlock.MerklePath, txBlock.MerklePath) + require.Equal(t, minedTxBlock.Ok, txBlock.Ok) case minedTxBlock := <-minedTxsChan2: counter2++ - require.Equal(t, minedTxBlock.BlockHash, txBlock.BlockHash) - require.Equal(t, minedTxBlock.BlockHeight, txBlock.BlockHeight) - require.Equal(t, minedTxBlock.TransactionHash, txBlock.TransactionHash) - require.Equal(t, minedTxBlock.MerklePath, txBlock.MerklePath) + require.Equal(t, minedTxBlock.Ok, txBlock.Ok) } } @@ -314,11 +288,11 @@ func TestNatsClient(t *testing.T) { }) } -func mqClientSubscribe(t *testing.T, topic string, hostName string, minedTxsChan chan *blocktx_api.TransactionBlock) *nats_jetstream.Client { +func mqClientSubscribe(t *testing.T, topic string, hostName string, minedTxsChan chan *test_api.TestMessage) *nats_jetstream.Client { client, err := nats_jetstream.New(natsConnClient, logger, nats_jetstream.WithSubscribedInterestPolicy(hostName, []string{topic}, true)) require.NoError(t, err) err = client.SubscribeMsg(topic, func(msg jetstream.Msg) error { - serialized := &blocktx_api.TransactionBlock{} + serialized := &test_api.TestMessage{} unmarshlErr := proto.Unmarshal(msg.Data(), serialized) require.NoError(t, unmarshlErr) diff --git a/internal/message_queue/nats/client/nats_jetstream/nats_jetstream_client.go b/pkg/message_queue/nats/client/nats_jetstream/nats_jetstream_client.go similarity index 99% rename from internal/message_queue/nats/client/nats_jetstream/nats_jetstream_client.go rename to pkg/message_queue/nats/client/nats_jetstream/nats_jetstream_client.go index d893af025..e78718315 100644 --- a/internal/message_queue/nats/client/nats_jetstream/nats_jetstream_client.go +++ b/pkg/message_queue/nats/client/nats_jetstream/nats_jetstream_client.go @@ -13,7 +13,7 @@ import ( "go.opentelemetry.io/otel/attribute" "google.golang.org/protobuf/proto" - "github.com/bitcoin-sv/arc/internal/tracing" + "github.com/bitcoin-sv/arc/pkg/tracing" ) type Client struct { diff --git a/pkg/message_queue/nats/client/test_api/test_api.pb.go b/pkg/message_queue/nats/client/test_api/test_api.pb.go new file mode 100644 index 000000000..347f2f66c --- /dev/null +++ b/pkg/message_queue/nats/client/test_api/test_api.pb.go @@ -0,0 +1,144 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v5.29.1 +// source: pkg/message_queue/nats/client/test_api/test_api.proto + +package test_api + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type TestMessage struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Ok bool `protobuf:"varint,1,opt,name=ok,proto3" json:"ok,omitempty"` +} + +func (x *TestMessage) Reset() { + *x = TestMessage{} + if protoimpl.UnsafeEnabled { + mi := &file_pkg_message_queue_nats_client_test_api_test_api_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TestMessage) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TestMessage) ProtoMessage() {} + +func (x *TestMessage) ProtoReflect() protoreflect.Message { + mi := &file_pkg_message_queue_nats_client_test_api_test_api_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TestMessage.ProtoReflect.Descriptor instead. +func (*TestMessage) Descriptor() ([]byte, []int) { + return file_pkg_message_queue_nats_client_test_api_test_api_proto_rawDescGZIP(), []int{0} +} + +func (x *TestMessage) GetOk() bool { + if x != nil { + return x.Ok + } + return false +} + +var File_pkg_message_queue_nats_client_test_api_test_api_proto protoreflect.FileDescriptor + +var file_pkg_message_queue_nats_client_test_api_test_api_proto_rawDesc = []byte{ + 0x0a, 0x35, 0x70, 0x6b, 0x67, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f, 0x71, 0x75, + 0x65, 0x75, 0x65, 0x2f, 0x6e, 0x61, 0x74, 0x73, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2f, + 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x70, 0x69, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x70, + 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x70, + 0x69, 0x22, 0x1d, 0x0a, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x02, 0x6f, 0x6b, + 0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x3b, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x61, 0x70, 0x69, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_pkg_message_queue_nats_client_test_api_test_api_proto_rawDescOnce sync.Once + file_pkg_message_queue_nats_client_test_api_test_api_proto_rawDescData = file_pkg_message_queue_nats_client_test_api_test_api_proto_rawDesc +) + +func file_pkg_message_queue_nats_client_test_api_test_api_proto_rawDescGZIP() []byte { + file_pkg_message_queue_nats_client_test_api_test_api_proto_rawDescOnce.Do(func() { + file_pkg_message_queue_nats_client_test_api_test_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_pkg_message_queue_nats_client_test_api_test_api_proto_rawDescData) + }) + return file_pkg_message_queue_nats_client_test_api_test_api_proto_rawDescData +} + +var file_pkg_message_queue_nats_client_test_api_test_api_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_pkg_message_queue_nats_client_test_api_test_api_proto_goTypes = []any{ + (*TestMessage)(nil), // 0: test_api.TestMessage +} +var file_pkg_message_queue_nats_client_test_api_test_api_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_pkg_message_queue_nats_client_test_api_test_api_proto_init() } +func file_pkg_message_queue_nats_client_test_api_test_api_proto_init() { + if File_pkg_message_queue_nats_client_test_api_test_api_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_pkg_message_queue_nats_client_test_api_test_api_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*TestMessage); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_pkg_message_queue_nats_client_test_api_test_api_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_pkg_message_queue_nats_client_test_api_test_api_proto_goTypes, + DependencyIndexes: file_pkg_message_queue_nats_client_test_api_test_api_proto_depIdxs, + MessageInfos: file_pkg_message_queue_nats_client_test_api_test_api_proto_msgTypes, + }.Build() + File_pkg_message_queue_nats_client_test_api_test_api_proto = out.File + file_pkg_message_queue_nats_client_test_api_test_api_proto_rawDesc = nil + file_pkg_message_queue_nats_client_test_api_test_api_proto_goTypes = nil + file_pkg_message_queue_nats_client_test_api_test_api_proto_depIdxs = nil +} diff --git a/pkg/message_queue/nats/client/test_api/test_api.proto b/pkg/message_queue/nats/client/test_api/test_api.proto new file mode 100644 index 000000000..d170046ee --- /dev/null +++ b/pkg/message_queue/nats/client/test_api/test_api.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +option go_package = ".;test_api"; + +package test_api; + +message TestMessage { + bool ok = 1; +} diff --git a/internal/message_queue/nats/nats_connection/nats_connection.go b/pkg/message_queue/nats/nats_connection/nats_connection.go similarity index 100% rename from internal/message_queue/nats/nats_connection/nats_connection.go rename to pkg/message_queue/nats/nats_connection/nats_connection.go diff --git a/internal/message_queue/nats/nats_connection/nats_connection_test.go b/pkg/message_queue/nats/nats_connection/nats_connection_test.go similarity index 95% rename from internal/message_queue/nats/nats_connection/nats_connection_test.go rename to pkg/message_queue/nats/nats_connection/nats_connection_test.go index 2b7c93c1b..68ed258c3 100644 --- a/internal/message_queue/nats/nats_connection/nats_connection_test.go +++ b/pkg/message_queue/nats/nats_connection/nats_connection_test.go @@ -6,9 +6,10 @@ import ( "os" "testing" - testutils "github.com/bitcoin-sv/arc/internal/test_utils" "github.com/ory/dockertest/v3" "github.com/stretchr/testify/require" + + "github.com/bitcoin-sv/arc/pkg/test_utils" ) var (