From e432ef1eb322409eec5a7877d8ab24bbb5073732 Mon Sep 17 00:00:00 2001 From: Krzysztof Tomecki <152964795+chris-4chain@users.noreply.github.com> Date: Tue, 23 Jan 2024 09:44:31 +0100 Subject: [PATCH 1/2] fix(BUX-497): update to go-paymail 12.1 --- go.mod | 2 +- go.sum | 4 ++-- paymail_test.go | 40 ++++++++++++++++++++++++++-------------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 9d0fd462..e76d4128 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/99designs/gqlgen v0.17.42 github.com/DATA-DOG/go-sqlmock v1.5.2 github.com/bitcoin-sv/go-broadcast-client v0.16.0 - github.com/bitcoin-sv/go-paymail v0.12.0 + github.com/bitcoin-sv/go-paymail v0.12.1 github.com/bitcoinschema/go-bitcoin/v2 v2.0.5 github.com/bitcoinschema/go-map v0.1.0 github.com/centrifugal/centrifuge-go v0.10.2 diff --git a/go.sum b/go.sum index 1fc3e207..184266a8 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,8 @@ github.com/aws/aws-sdk-go v1.43.45 h1:2708Bj4uV+ym62MOtBnErm/CDX61C4mFe9V2gXy1ca github.com/aws/aws-sdk-go v1.43.45/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= github.com/bitcoin-sv/go-broadcast-client v0.16.0 h1:KadOLv+i9Y6xAOkHsSl2PIECQ59SpUyYurY6Ysvpz5A= github.com/bitcoin-sv/go-broadcast-client v0.16.0/go.mod h1:GRAliwumNBjEbLRIEkXqIKJpsgmMfjvlIDqgyw/NoJE= -github.com/bitcoin-sv/go-paymail v0.12.0 h1:y9Kc89wovrObllz0vilG/7olbMrba97D0XJR9YDBw6s= -github.com/bitcoin-sv/go-paymail v0.12.0/go.mod h1:/BGu//F4Ji7jIzvkcHxlwBB9vU90yVRx/tovX91Tbw0= +github.com/bitcoin-sv/go-paymail v0.12.1 h1:MDdMFFOZalymT5O5WDUN0EVVWdn3ygo6EhKsWimkM/E= +github.com/bitcoin-sv/go-paymail v0.12.1/go.mod h1:/BGu//F4Ji7jIzvkcHxlwBB9vU90yVRx/tovX91Tbw0= github.com/bitcoinschema/go-bitcoin/v2 v2.0.5 h1:Sgh5Eb746Zck/46rFDrZZEXZWyO53fMuWYhNoZa1tck= github.com/bitcoinschema/go-bitcoin/v2 v2.0.5/go.mod h1:JjO1ivfZv6vhK0uAXzyH08AAHlzNMAfnyK1Fiv9r4ZA= github.com/bitcoinschema/go-bob v0.4.0 h1:adsAEboLQCg0D6e9vwcJUJEJScszsouAYCYu35UAiGo= diff --git a/paymail_test.go b/paymail_test.go index 9bf0081b..72478bce 100644 --- a/paymail_test.go +++ b/paymail_test.go @@ -105,12 +105,33 @@ func TestPaymailClient(t *testing.T) { require.NotNil(t, client) } +func exampleGenericCapabilities(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 := exampleGenericCapabilities(t, false, false) success, p2pDestinationURL, p2pSubmitTxURL, _ := hasP2P(capabilities) assert.Equal(t, false, success) assert.Equal(t, "", p2pDestinationURL) @@ -118,11 +139,7 @@ func Test_hasP2P(t *testing.T) { }) 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 := exampleGenericCapabilities(t, true, false) success, p2pDestinationURL, p2pSubmitTxURL, _ := hasP2P(capabilities) assert.Equal(t, true, success) @@ -136,7 +153,7 @@ 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 := exampleGenericCapabilities(t, false, false) success, p2pDestinationURL, p2pSubmitTxURL, format := hasP2P(capabilities) assert.Equal(t, false, success) assert.Equal(t, BasicPaymailPayloadFormat, format) @@ -144,13 +161,8 @@ func Test_hasP2P_beefCapabilities(t *testing.T) { 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 := exampleGenericCapabilities(t, true, true) success, p2pDestinationURL, p2pSubmitTxURL, format := hasP2P(capabilities) assert.Equal(t, true, success) assert.Equal(t, BeefPaymailPayloadFormat, format) From ac741b51d5319d81dff3f83c0e848571fd82ee25 Mon Sep 17 00:00:00 2001 From: Krzysztof Tomecki <152964795+chris-4chain@users.noreply.github.com> Date: Tue, 23 Jan 2024 10:20:23 +0100 Subject: [PATCH 2/2] fix(BUX-497): mockCapabilities --- paymail_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/paymail_test.go b/paymail_test.go index 72478bce..cc878fed 100644 --- a/paymail_test.go +++ b/paymail_test.go @@ -105,7 +105,7 @@ func TestPaymailClient(t *testing.T) { require.NotNil(t, client) } -func exampleGenericCapabilities(t *testing.T, p2pEnabled, beefEnabled bool) *paymail.CapabilitiesPayload { +func mockCapabilities(t *testing.T, p2pEnabled, beefEnabled bool) *paymail.CapabilitiesPayload { options := []server.ConfigOps{ server.WithDomain("test.com"), } @@ -131,7 +131,7 @@ func Test_hasP2P(t *testing.T) { t.Parallel() t.Run("no p2p capabilities", func(t *testing.T) { - capabilities := exampleGenericCapabilities(t, false, false) + capabilities := mockCapabilities(t, false, false) success, p2pDestinationURL, p2pSubmitTxURL, _ := hasP2P(capabilities) assert.Equal(t, false, success) assert.Equal(t, "", p2pDestinationURL) @@ -139,7 +139,7 @@ func Test_hasP2P(t *testing.T) { }) t.Run("valid p2p capabilities", func(t *testing.T) { - capabilities := exampleGenericCapabilities(t, true, false) + capabilities := mockCapabilities(t, true, false) success, p2pDestinationURL, p2pSubmitTxURL, _ := hasP2P(capabilities) assert.Equal(t, true, success) @@ -153,7 +153,7 @@ func Test_hasP2P_beefCapabilities(t *testing.T) { t.Parallel() t.Run("no beef capabilities", func(t *testing.T) { - capabilities := exampleGenericCapabilities(t, false, false) + capabilities := mockCapabilities(t, false, false) success, p2pDestinationURL, p2pSubmitTxURL, format := hasP2P(capabilities) assert.Equal(t, false, success) assert.Equal(t, BasicPaymailPayloadFormat, format) @@ -162,7 +162,7 @@ func Test_hasP2P_beefCapabilities(t *testing.T) { }) t.Run("valid beef capabilities", func(t *testing.T) { - capabilities := exampleGenericCapabilities(t, true, true) + capabilities := mockCapabilities(t, true, true) success, p2pDestinationURL, p2pSubmitTxURL, format := hasP2P(capabilities) assert.Equal(t, true, success) assert.Equal(t, BeefPaymailPayloadFormat, format)