Skip to content

Commit

Permalink
feat(SPV-904): fix transactions test
Browse files Browse the repository at this point in the history
  • Loading branch information
yarex-4chain committed Oct 1, 2024
1 parent 221b70f commit dcc69ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
8 changes: 4 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package walletclient

import "github.com/bitcoin-sv/spv-wallet/models"
import "github.com/bitcoin-sv/spv-wallet/models/response"

// TransportType the type of transport being used ('http' for usage or 'mock' for testing)
type TransportType string
Expand All @@ -18,9 +18,9 @@ const (

// Recipients is a struct for recipients
type Recipients struct {
OpReturn *models.OpReturn `json:"op_return"`
Satoshis uint64 `json:"satoshis"`
To string `json:"to"`
OpReturn *response.OpReturn `json:"opReturn"`
Satoshis uint64 `json:"satoshis"`
To string `json:"to"`
}

const (
Expand Down
28 changes: 16 additions & 12 deletions transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,30 @@ import (
"testing"

"github.com/bitcoin-sv/spv-wallet-go-client/fixtures"
"github.com/bitcoin-sv/spv-wallet/models"
"github.com/bitcoin-sv/spv-wallet/models/filter"
"github.com/bitcoin-sv/spv-wallet/models/response"
"github.com/stretchr/testify/require"
)

func TestTransactions(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/v1/transaction":
handleTransaction(w, r)
case "/v1/transaction/search":
json.NewEncoder(w).Encode([]*models.Transaction{fixtures.Transaction})
case "/v1/transaction/count":
json.NewEncoder(w).Encode(1)
case "/v1/transaction/record":
if r.Method == http.MethodPost {
case "/v1/transactions":
switch r.Method {
case http.MethodGet:
json.NewEncoder(w).Encode([]*response.Transaction{fixtures.Transaction})
case http.MethodPost:
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(fixtures.Transaction)
} else {
w.WriteHeader(http.StatusMethodNotAllowed)
}
case "/v1/transactions/" + fixtures.Transaction.ID:
switch r.Method {
case http.MethodGet, http.MethodPatch:
handleTransaction(w, r)
}
case "/v1/transactions/drafts":
if r.Method == http.MethodPost {
handleTransaction(w, r)
}
default:
w.WriteHeader(http.StatusNotFound)
Expand All @@ -51,7 +55,7 @@ func TestTransactions(t *testing.T) {
}
txs, err := client.GetTransactions(context.Background(), conditions, fixtures.TestMetadata, nil)
require.NoError(t, err)
require.Equal(t, []*models.Transaction{fixtures.Transaction}, txs)
require.Equal(t, []*response.Transaction{fixtures.Transaction}, txs)
})

t.Run("GetTransactionsCount", func(t *testing.T) {
Expand Down

0 comments on commit dcc69ed

Please sign in to comment.