generated from mrz1836/go-template
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SPV-1075) new broadcaster (#737)
- Loading branch information
1 parent
38fdab7
commit 5fadf0f
Showing
94 changed files
with
1,356 additions
and
2,593 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
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
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
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
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
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
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
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
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
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,18 @@ | ||
package config | ||
|
||
import "github.com/bitcoin-sv/spv-wallet/engine/spverrors" | ||
|
||
// Validate validates the custom fee unit configuration | ||
func (cf *FeeUnitConfig) Validate() error { | ||
if cf == nil { | ||
return nil | ||
} | ||
|
||
if cf.Bytes <= 0 { | ||
return spverrors.Newf("invalid custom fee unit - bytes value is equal or less than zero: %d", cf.Bytes) | ||
} | ||
if cf.Satoshis < 0 { | ||
return spverrors.Newf("invalid custom fee unit - satoshis value is less than zero: %d", cf.Satoshis) | ||
} | ||
return nil | ||
} |
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,98 @@ | ||
package config_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/bitcoin-sv/spv-wallet/config" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestValidateFeeUnit(t *testing.T) { | ||
validConfigTests := map[string]struct { | ||
scenario func(cfg *config.AppConfig) | ||
}{ | ||
"Not defined is valid": { | ||
scenario: func(cfg *config.AppConfig) { | ||
cfg.CustomFeeUnit = nil | ||
}, | ||
}, | ||
"Standard": { | ||
scenario: func(cfg *config.AppConfig) { | ||
cfg.CustomFeeUnit = &config.FeeUnitConfig{ | ||
Satoshis: 1, | ||
Bytes: 1000, | ||
} | ||
}, | ||
}, | ||
"Zero Satoshi is valid": { | ||
scenario: func(cfg *config.AppConfig) { | ||
cfg.CustomFeeUnit = &config.FeeUnitConfig{ | ||
Satoshis: 0, | ||
Bytes: 1000, | ||
} | ||
}, | ||
}, | ||
} | ||
for name, test := range validConfigTests { | ||
t.Run(name, func(t *testing.T) { | ||
// given: | ||
cfg := config.GetDefaultAppConfig() | ||
|
||
test.scenario(cfg) | ||
|
||
// when: | ||
err := cfg.Validate() | ||
|
||
// then: | ||
require.NoError(t, err) | ||
}) | ||
} | ||
|
||
invalidConfigTests := map[string]struct { | ||
scenario func(cfg *config.AppConfig) | ||
}{ | ||
"Empty is not ok": { | ||
scenario: func(cfg *config.AppConfig) { | ||
cfg.CustomFeeUnit = &config.FeeUnitConfig{} | ||
}, | ||
}, | ||
"Negative satoshis": { | ||
scenario: func(cfg *config.AppConfig) { | ||
cfg.CustomFeeUnit = &config.FeeUnitConfig{ | ||
Satoshis: -1, | ||
Bytes: 1000, | ||
} | ||
}, | ||
}, | ||
"Zero bytes": { | ||
scenario: func(cfg *config.AppConfig) { | ||
cfg.CustomFeeUnit = &config.FeeUnitConfig{ | ||
Satoshis: 1, | ||
Bytes: 0, | ||
} | ||
}, | ||
}, | ||
"Negative bytes": { | ||
scenario: func(cfg *config.AppConfig) { | ||
cfg.CustomFeeUnit = &config.FeeUnitConfig{ | ||
Satoshis: 1, | ||
Bytes: -1, | ||
} | ||
}, | ||
}, | ||
} | ||
for name, test := range invalidConfigTests { | ||
t.Run(name, func(t *testing.T) { | ||
// given: | ||
cfg := config.GetDefaultAppConfig() | ||
|
||
test.scenario(cfg) | ||
|
||
// when: | ||
err := cfg.Validate() | ||
|
||
// then: | ||
require.Error(t, err) | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.