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

Commit

Permalink
test(BUX-175): add separate test or checking beef capability
Browse files Browse the repository at this point in the history
  • Loading branch information
pawellewandowski98 committed Sep 11, 2023
1 parent 585b456 commit e709f46
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions paymail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,32 @@ func Test_hasP2P(t *testing.T) {
t.Parallel()

t.Run("no p2p capabilities", func(t *testing.T) {
capabilities := server.GenericCapabilities(paymail.DefaultBsvAliasVersion, 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}"

success, _, p2pDestinationURL, p2pSubmitTxURL := hasP2P(capabilities)
assert.Equal(t, true, success)
assert.Equal(t, capabilities.Capabilities[paymail.BRFCP2PPaymentDestination], p2pDestinationURL)
assert.Equal(t, capabilities.Capabilities[paymail.BRFCP2PTransactions], p2pSubmitTxURL)
})
}

// Test_hasP2P_beefCapabilities will test the method hasP2P() but with BEEF capabilities
func Test_hasP2P_beefCapabilities(t *testing.T) {
t.Parallel()

t.Run("no beef capabilities", func(t *testing.T) {
capabilities := server.GenericCapabilities(paymail.DefaultBsvAliasVersion, false)
success, useBeef, p2pDestinationURL, p2pSubmitTxURL := hasP2P(capabilities)
assert.Equal(t, false, success)
Expand All @@ -121,14 +147,14 @@ func Test_hasP2P(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.Capabilities[paymail.BRFCBeefTransaction] = "/receive-beef-transaction/{alias}@{domain.tld}"

success, useBeef, p2pDestinationURL, p2pSubmitTxURL := hasP2P(capabilities)
assert.Equal(t, true, success)
assert.Equal(t, true, useBeef)
assert.Equal(t, capabilities.Capabilities[paymail.BRFCP2PPaymentDestination], p2pDestinationURL)
assert.Equal(t, capabilities.Capabilities[paymail.BRFCP2PTransactions], p2pSubmitTxURL)
assert.Equal(t, capabilities.Capabilities[paymail.BRFCBeefTransaction], p2pSubmitTxURL)
})
}

Expand Down

0 comments on commit e709f46

Please sign in to comment.