Skip to content

Commit

Permalink
Merge pull request #597 from bitcoin-sv/test/utxo-create
Browse files Browse the repository at this point in the history
Test/utxo create
  • Loading branch information
kameshraj23 authored Oct 2, 2024
2 parents 1905473 + 3574f9e commit f160760
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions internal/broadcaster/utxo_creator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package broadcaster_test

import (
"errors"
"testing"

"github.com/bitcoin-sv/arc/internal/broadcaster/mocks"
"github.com/stretchr/testify/require"
)

func TestUTXOCreator(t *testing.T) {
tt := []struct {
name string
outputs int
satoshisPerOutput uint64
startFunc func(outputs int, satoshisPerOutput uint64) error
expectedError error
expectedStartCalls int
}{
{
name: "successful start",
outputs: 5,
satoshisPerOutput: 1000,
startFunc: func(outputs int, satoshisPerOutput uint64) error {
return nil
},
expectedError: nil,
expectedStartCalls: 1,
},
{
name: "error on start",
outputs: 5,
satoshisPerOutput: 1000,
startFunc: func(outputs int, satoshisPerOutput uint64) error {
return errors.New("failed to start UTXO creation")
},
expectedError: errors.New("failed to start UTXO creation"),
expectedStartCalls: 1,
},
{
name: "invalid input - zero outputs",
outputs: 0,
satoshisPerOutput: 1000,
startFunc: func(outputs int, satoshisPerOutput uint64) error {
return nil // Simulate success to test input handling
},
expectedError: nil, // Start should handle zero outputs gracefully
expectedStartCalls: 1,
},
{
name: "invalid input - zero satoshis per output",
outputs: 5,
satoshisPerOutput: 0,
startFunc: func(outputs int, satoshisPerOutput uint64) error {
return nil // Simulate success to test input handling
},
expectedError: nil, // Start should handle zero satoshis gracefully
expectedStartCalls: 1,
},
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
// Given
mockedCreator := &mocks.CreatorMock{
StartFunc: tc.startFunc,
}
// When
err := mockedCreator.Start(tc.outputs, tc.satoshisPerOutput)

// Then
if tc.expectedError != nil {
require.Error(t, err)
require.EqualError(t, err, tc.expectedError.Error())
} else {
require.NoError(t, err)
}

require.Equal(t, tc.expectedStartCalls, len(mockedCreator.StartCalls()))

})
}
}

0 comments on commit f160760

Please sign in to comment.