Skip to content

Commit

Permalink
feat(BUX-000): fix brfc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadiuszos4chain committed Sep 7, 2023
1 parent 028d53e commit bf11e6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 59 deletions.
65 changes: 7 additions & 58 deletions brfc_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package paymail

import (
"fmt"
"encoding/json"
"testing"
)

Expand Down Expand Up @@ -44,24 +44,6 @@ func TestBRFCSpec_Generate(t *testing.T) {
}
}

// ExampleBRFCSpec_Generate example using Generate()
//
// See more examples in /examples/
func ExampleBRFCSpec_Generate() {
// Start with a new BRFC specification
newBRFC := &BRFCSpec{
Author: "MrZ",
Title: "New BRFC",
Version: "1",
}
if err := newBRFC.Generate(); err != nil {
fmt.Printf("error occurred: %s", err.Error())
} else {
fmt.Printf("id generated: %s", newBRFC.ID)
}
// Output:id generated: e898079d7d1a
}

// BenchmarkBRFCSpec_Generate benchmarks the method Generate()
func BenchmarkBRFCSpec_Generate(b *testing.B) {
newBRFC := &BRFCSpec{Author: "MrZ", Title: "New BRFC", Version: "1"}
Expand Down Expand Up @@ -122,27 +104,6 @@ func TestBRFCSpec_Validate(t *testing.T) {
}
}

// ExampleBRFCSpec_Validate example using Validate()
//
// See more examples in /examples/
func ExampleBRFCSpec_Validate() {
// Start with an existing BRFC specification
newBRFC := &BRFCSpec{
Author: "MrZ",
ID: "e898079d7d1a",
Title: "New BRFC",
Version: "1",
}
if valid, id, err := newBRFC.Validate(); err != nil {
fmt.Printf("error occurred: %s", err.Error())
} else if !valid {
fmt.Printf("id is invalid: %s vs %s", newBRFC.ID, id)
} else {
fmt.Printf("brfc is valid: %s", id)
}
// Output:brfc is valid: e898079d7d1a
}

// BenchmarkBRFCSpec_Validate benchmarks the method Validate()
func BenchmarkBRFCSpec_Validate(b *testing.B) {
newBRFC := &BRFCSpec{Author: "MrZ", ID: "e898079d7d1a", Title: "New BRFC", Version: "1"}
Expand All @@ -158,13 +119,17 @@ func TestLoadBRFCs(t *testing.T) {
// Create a client with options
// client := newTestClient(t)

specs := make([]*BRFCSpec, 0)
_ = json.Unmarshal([]byte(BRFCKnownSpecifications), &specs)
defSpecsLen := len(specs)

var tests = []struct {
specJSON string
expectedLength int
expectedError bool
}{
{`[{"author": "andy (nChain)","id": "57dd1f54fc67","title": "BRFC Specifications","url": "http://bsvalias.org/01-02-brfc-id-assignment.html","version": "1"}]`, 24, false},
{`[{"invalid:1}]`, 23, true},
{`[{"author": "andy (nChain)","id": "57dd1f54fc67","title": "BRFC Specifications","url": "http://bsvalias.org/01-02-brfc-id-assignment.html","version": "1"}]`, defSpecsLen + 1, false},
{`[{"invalid:1}]`, defSpecsLen, true},
{`[{"author": "andy (nChain), Ryan X. Charles (Money Button)","title":"invalid-spec","id": "17dd1f54fc66"}]`, 0, true},
{`[{"author": "andy (nChain), Ryan X. Charles (Money Button)","title":""}]`, 0, true},
}
Expand All @@ -180,22 +145,6 @@ func TestLoadBRFCs(t *testing.T) {
}
}

// ExampleLoadBRFCs example using LoadBRFCs()
//
// See more examples in /examples/
func ExampleLoadBRFCs() {
// Load additional specification(s)
additionalSpec := `[{"author": "andy (nChain)","id": "57dd1f54fc67","title": "BRFC Specifications","url": "http://bsvalias.org/01-02-brfc-id-assignment.html","version": "1"}]`
specs, err := LoadBRFCs(additionalSpec)
if err != nil {
fmt.Printf("error occurred: %s", err.Error())
return
}
fmt.Printf("total specifications found: %d", len(specs))

// Output:total specifications found: 24
}

// BenchmarkLoadBRFCs benchmarks the method LoadBRFCs()
func BenchmarkLoadBRFCs(b *testing.B) {
additionalSpec := `[{"author": "andy (nChain)","id": "57dd1f54fc67","title": "BRFC Specifications","url": "http://bsvalias.org/01-02-brfc-id-assignment.html","version": "1"}]`
Expand Down
9 changes: 8 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package paymail

import (
"encoding/json"
"fmt"
"net"
"testing"
Expand Down Expand Up @@ -159,12 +160,18 @@ func TestNewClient(t *testing.T) {
func TestClient_GetBRFCs(t *testing.T) {
t.Parallel()

// get default brfcs
t.Run("get brfcs", func(t *testing.T) {
client, err := NewClient()
assert.NoError(t, err)
assert.NotNil(t, client)

brfcs := client.GetBRFCs()
assert.Equal(t, 23, len(brfcs))

specs := make([]*BRFCSpec, 0)
_ = json.Unmarshal([]byte(BRFCKnownSpecifications), &specs)

assert.Equal(t, len(specs), len(brfcs))
assert.Equal(t, "b2aa66e26b43", brfcs[0].ID)
})
}
Expand Down

0 comments on commit bf11e6b

Please sign in to comment.