Skip to content

Commit

Permalink
Merge branch 'master' into BUX-399/ConfirmContact
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadiuszos4chain authored Mar 13, 2024
2 parents a223083 + e88eba0 commit 64c7fc7
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 47 deletions.
5 changes: 0 additions & 5 deletions actions/access_keys/access_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

Expand All @@ -29,9 +27,6 @@ func (ts *TestSuite) TearDownSuite() {
func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

// Load the router & register routes
ts.Router = gin.Default()
require.NotNil(ts.T(), ts.Router)
routes := NewHandler(ts.AppConfig, ts.Services)
routes.RegisterAPIEndpoints(ts.Router.Group("/" + config.APIVersion))
}
Expand Down
4 changes: 0 additions & 4 deletions actions/admin/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

Expand All @@ -30,8 +28,6 @@ func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

// Load the router & register routes
ts.Router = gin.Default()
require.NotNil(ts.T(), ts.Router)
adminRoutes := NewHandler(ts.AppConfig, ts.Services)
adminRoutes.RegisterAdminEndpoints(ts.Router.Group("/" + config.APIVersion))
}
Expand Down
4 changes: 0 additions & 4 deletions actions/base/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"testing"

"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

Expand All @@ -29,8 +27,6 @@ func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

// Load the router & register routes
ts.Router = gin.Default()
require.NotNil(ts.T(), ts.Router)
routes := NewHandler()
routes.RegisterBaseEndpoints(ts.Router.Group(""))
}
Expand Down
4 changes: 0 additions & 4 deletions actions/contacts/contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

Expand All @@ -30,8 +28,6 @@ func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

// Load the router & register routes
ts.Router = gin.Default()
require.NotNil(ts.T(), ts.Router)
routes := NewHandler(ts.AppConfig, ts.Services)
routes.RegisterAPIEndpoints(ts.Router.Group("/" + config.APIVersion))
}
Expand Down
4 changes: 0 additions & 4 deletions actions/destinations/destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

Expand All @@ -30,8 +28,6 @@ func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

// Load the router & register routes
ts.Router = gin.Default()
require.NotNil(ts.T(), ts.Router)
basicRoutes, apiRoutes := NewHandler(ts.AppConfig, ts.Services)
basicRoutes.RegisterBasicEndpoints(ts.Router.Group("/" + config.APIVersion))
apiRoutes.RegisterAPIEndpoints(ts.Router.Group("/" + config.APIVersion))
Expand Down
4 changes: 0 additions & 4 deletions actions/transactions/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

Expand All @@ -30,8 +28,6 @@ func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

// Load the router & register routes
ts.Router = gin.Default()
require.NotNil(ts.T(), ts.Router)
basicRoutes, apiRoutes, callbackRoutes := NewHandler(ts.AppConfig, ts.Services)
basicRoutes.RegisterBasicEndpoints(ts.Router.Group("/" + config.APIVersion))
apiRoutes.RegisterAPIEndpoints(ts.Router.Group("/" + config.APIVersion))
Expand Down
4 changes: 0 additions & 4 deletions actions/utxos/utxo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

Expand All @@ -30,8 +28,6 @@ func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

// Load the router & register routes
ts.Router = gin.Default()
require.NotNil(ts.T(), ts.Router)
apiRoutes := NewHandler(ts.AppConfig, ts.Services)
apiRoutes.RegisterAPIEndpoints(ts.Router.Group("/" + config.APIVersion))
}
Expand Down
4 changes: 0 additions & 4 deletions actions/xpubs/xpubs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

Expand All @@ -30,8 +28,6 @@ func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

// Load the router & register routes
ts.Router = gin.Default()
require.NotNil(ts.T(), ts.Router)
routes := NewHandler(ts.AppConfig, ts.Services)
routes.RegisterAPIEndpoints(ts.Router.Group("/" + config.APIVersion))
}
Expand Down
7 changes: 4 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import (
"context"
"testing"

"github.com/bitcoin-sv/spv-wallet/logging"
"github.com/mrz1836/go-cachestore"
"github.com/mrz1836/go-datastore"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// newTestConfig will make a new test config
func newTestConfig(t *testing.T) (ac *AppConfig) {
defaultLogger := logging.GetDefaultLogger()
ac, err := Load(defaultLogger)
nop := zerolog.Nop()
ac, err := Load(&nop)

require.NoError(t, err)
require.NotNil(t, ac)
return
Expand Down
14 changes: 13 additions & 1 deletion config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,25 @@ func Load(logger *zerolog.Logger) (appConfig *AppConfig, err error) {
if err != nil {
logger.Error().Msg("Unable to decode App Config to json")
} else {
fmt.Printf("loaded config: %s", cfg)
logger.Debug().Msgf("loaded config: %s", cfg)
}
}

return appConfig, nil
}

// LoadForTest returns test AppConfig
func LoadForTest() (appConfig *AppConfig) {

appConfig = getDefaultAppConfig()
appConfig.Debug = false
appConfig.DebugProfiling = false
appConfig.Logging.Level = zerolog.LevelErrorValue
appConfig.Logging.Format = "console"

return appConfig
}

func setDefaults() error {
viper.SetDefault(ConfigFilePathKey, DefaultConfigFilePath)

Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ configs:
frontend-env-config:
content: |
{
"paymailDomain": "${RUN_PAYMAIL_DOMAIN}",
"apiUrl": "http${RUN_SECURED_PROTOCOL_SUFFIX}://${RUN_API_DOMAIN}",
"wsUrl": "ws${RUN_SECURED_PROTOCOL_SUFFIX}://${RUN_API_DOMAIN}/api/websocket"
}
Expand Down
1 change: 1 addition & 0 deletions server/auth/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func SignatureMiddleware(appConfig *config.AppConfig, requireSigning, adminRequi
return func(c *gin.Context) {
if c.Request.Body == nil {
c.AbortWithStatusJSON(http.StatusUnauthorized, "missing body")
return
}
defer func() {
_ = c.Request.Body.Close()
Expand Down
4 changes: 0 additions & 4 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/bitcoin-sv/spv-wallet/engine/utils"
"github.com/bitcoin-sv/spv-wallet/models"
"github.com/bitcoin-sv/spv-wallet/tests"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -40,9 +39,6 @@ func (ts *TestSuite) TearDownSuite() {
func (ts *TestSuite) SetupTest() {
ts.BaseSetupTest()

// Load the router & register routes
ts.Router = gin.Default()
require.NotNil(ts.T(), ts.Router)
SetupServerRoutes(ts.AppConfig, ts.Services, ts.Router)
}

Expand Down
18 changes: 13 additions & 5 deletions tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (

"github.com/bitcoin-sv/spv-wallet/config"
"github.com/bitcoin-sv/spv-wallet/logging"
"github.com/bitcoin-sv/spv-wallet/server/auth"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
Expand All @@ -22,11 +24,7 @@ type TestSuite struct {

// BaseSetupSuite runs at the start of the suite
func (ts *TestSuite) BaseSetupSuite() {
// Load the configuration
defaultLogger := logging.GetDefaultLogger()
var err error
ts.AppConfig, err = config.Load(defaultLogger)
require.NoError(ts.T(), err)
ts.AppConfig = config.LoadForTest()
}

// BaseTearDownSuite runs after the suite finishes
Expand All @@ -46,6 +44,16 @@ func (ts *TestSuite) BaseTearDownSuite() {
func (ts *TestSuite) BaseSetupTest() {
// Load the services
var err error
nop := zerolog.Nop()

gin.SetMode(gin.ReleaseMode)
engine := gin.New()
engine.Use(logging.GinMiddleware(&nop), gin.Recovery())
engine.Use(auth.CorsMiddleware())

ts.Router = engine
require.NotNil(ts.T(), ts.Router)

ts.Services, err = ts.AppConfig.LoadTestServices(context.Background())
require.NoError(ts.T(), err)
}
Expand Down

0 comments on commit 64c7fc7

Please sign in to comment.