-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #597 from bitcoin-sv/test/utxo-create
Test/utxo create
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
|
||
}) | ||
} | ||
} |