liquidity: add default parameters struct

pull/289/head
carla 4 years ago
parent ad8b5d0552
commit 559abd1eea
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -45,6 +45,12 @@ const (
)
var (
// defaultParameters contains the default parameters that we start our
// liquidity manger with.
defaultParameters = Parameters{
ChannelRules: make(map[lnwire.ShortChannelID]*ThresholdRule),
}
// ErrZeroChannelID is returned if we get a rule for a 0 channel ID.
ErrZeroChannelID = fmt.Errorf("zero channel ID not allowed")
)
@ -71,13 +77,6 @@ type Parameters struct {
ChannelRules map[lnwire.ShortChannelID]*ThresholdRule
}
// newParameters creates an empty set of parameters.
func newParameters() Parameters {
return Parameters{
ChannelRules: make(map[lnwire.ShortChannelID]*ThresholdRule),
}
}
// String returns the string representation of our parameters.
func (p Parameters) String() string {
channelRules := make([]string, 0, len(p.ChannelRules))
@ -127,7 +126,7 @@ type Manager struct {
func NewManager(cfg *Config) *Manager {
return &Manager{
cfg: cfg,
params: newParameters(),
params: defaultParameters,
}
}

@ -73,7 +73,7 @@ func TestParameters(t *testing.T) {
// Start with the case where we have no rules set.
startParams := manager.GetParameters()
require.Equal(t, newParameters(), startParams)
require.Equal(t, defaultParameters, startParams)
// Mutate the parameters returned by our get function.
startParams.ChannelRules[chanID] = NewThresholdRule(1, 1)
@ -81,15 +81,14 @@ func TestParameters(t *testing.T) {
// Make sure that we have not mutated the liquidity manager's params
// by making this change.
params := manager.GetParameters()
require.Equal(t, newParameters(), params)
require.Equal(t, defaultParameters, params)
// Provide a valid set of parameters and validate assert that they are
// set.
originalRule := NewThresholdRule(10, 10)
expected := Parameters{
ChannelRules: map[lnwire.ShortChannelID]*ThresholdRule{
chanID: originalRule,
},
expected := defaultParameters
expected.ChannelRules = map[lnwire.ShortChannelID]*ThresholdRule{
chanID: originalRule,
}
err := manager.SetParameters(expected)

Loading…
Cancel
Save