Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #546 from BuxOrg/fix-497-paymail-12.1
Browse files Browse the repository at this point in the history
fix(BUX-497): update to go-paymail 12.1
  • Loading branch information
chris-4chain authored Jan 23, 2024
2 parents c108973 + ac741b5 commit 160b9f5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 26 additions & 14 deletions paymail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,41 @@ func TestPaymailClient(t *testing.T) {
require.NotNil(t, client)
}

func mockCapabilities(t *testing.T, p2pEnabled, beefEnabled bool) *paymail.CapabilitiesPayload {
options := []server.ConfigOps{
server.WithDomain("test.com"),
}
if p2pEnabled {
options = append(options, server.WithP2PCapabilities())
}
if beefEnabled {
options = append(options, server.WithBeefCapabilities())
}
config, err := server.NewConfig(new(mockServiceProvider), options...)
assert.NoError(t, err)
capPayload, err := config.EnrichCapabilities("test.com")
if err != nil {
return &paymail.CapabilitiesPayload{
BsvAlias: "",
}
}
return capPayload
}

// Test_hasP2P will test the method hasP2P()
func Test_hasP2P(t *testing.T) {
t.Parallel()

t.Run("no p2p capabilities", func(t *testing.T) {
capabilities := server.GenericCapabilities(paymail.DefaultBsvAliasVersion, false)
capabilities := mockCapabilities(t, false, false)
success, p2pDestinationURL, p2pSubmitTxURL, _ := hasP2P(capabilities)
assert.Equal(t, false, success)
assert.Equal(t, "", p2pDestinationURL)
assert.Equal(t, "", p2pSubmitTxURL)
})

t.Run("valid p2p capabilities", func(t *testing.T) {
capabilities := server.GenericCapabilities(paymail.DefaultBsvAliasVersion, false)

// Add the P2P
capabilities.Capabilities[paymail.BRFCP2PTransactions] = "/receive-transaction/{alias}@{domain.tld}"
capabilities.Capabilities[paymail.BRFCP2PPaymentDestination] = "/p2p-payment-destination/{alias}@{domain.tld}"
capabilities := mockCapabilities(t, true, false)

success, p2pDestinationURL, p2pSubmitTxURL, _ := hasP2P(capabilities)
assert.Equal(t, true, success)
Expand All @@ -136,21 +153,16 @@ func Test_hasP2P_beefCapabilities(t *testing.T) {
t.Parallel()

t.Run("no beef capabilities", func(t *testing.T) {
capabilities := server.GenericCapabilities(paymail.DefaultBsvAliasVersion, false)
capabilities := mockCapabilities(t, false, false)
success, p2pDestinationURL, p2pSubmitTxURL, format := hasP2P(capabilities)
assert.Equal(t, false, success)
assert.Equal(t, BasicPaymailPayloadFormat, format)
assert.Equal(t, "", p2pDestinationURL)
assert.Equal(t, "", p2pSubmitTxURL)
})

t.Run("valid p2p capabilities", func(t *testing.T) {
capabilities := server.GenericCapabilities(paymail.DefaultBsvAliasVersion, false)

// Add the P2P
capabilities.Capabilities[paymail.BRFCP2PPaymentDestination] = "/p2p-payment-destination/{alias}@{domain.tld}"
capabilities.Capabilities[paymail.BRFCBeefTransaction] = "/receive-beef-transaction/{alias}@{domain.tld}"

t.Run("valid beef capabilities", func(t *testing.T) {
capabilities := mockCapabilities(t, true, true)
success, p2pDestinationURL, p2pSubmitTxURL, format := hasP2P(capabilities)
assert.Equal(t, true, success)
assert.Equal(t, BeefPaymailPayloadFormat, format)
Expand Down

0 comments on commit 160b9f5

Please sign in to comment.