Skip to content

Commit

Permalink
fixup! CurrencyManager: Set AssetEnabled when StorePairs(enabled)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Nov 27, 2024
1 parent d650ca9 commit 4d14ef6
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions currency/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,65 +462,47 @@ func TestEnablePair(t *testing.T) {
}
}

func TestIsAssetEnabled_SetAssetEnabled(t *testing.T) {
func TestAssetEnabled(t *testing.T) {
t.Parallel()
p := initTest(t)

err := p.IsAssetEnabled(asset.Empty)
if !errors.Is(err, asset.ErrNotSupported) {
t.Fatalf("received: '%v' but expected: '%v'", err, asset.ErrNotSupported)
}
assert.ErrorIs(t, err, asset.ErrNotSupported)

p.Pairs = nil

// Test enabling a pair when the pair manager is not initialised
err = p.IsAssetEnabled(asset.Spot)
if err == nil {
t.Error("unexpected result")
}
assert.ErrorIs(t, err, ErrPairManagerNotInitialised)

err = p.SetAssetEnabled(asset.Spot, true)
if err == nil {
t.Fatal("unexpected result")
}
assert.ErrorIs(t, err, ErrPairManagerNotInitialised)

// Test asset type which doesn't exist
p = initTest(t)

p.Pairs[asset.Spot].AssetEnabled = false

err = p.IsAssetEnabled(asset.Spot)
if err == nil {
t.Error("unexpected result")
}
assert.ErrorIs(t, err, asset.ErrNotEnabled)

err = p.SetAssetEnabled(asset.Spot, false)
if err != nil {
t.Fatal(err)
}
assert.NoError(t, err)

err = p.SetAssetEnabled(asset.Spot, false)
if err == nil {
t.Fatal("unexpected result")
}
assert.NoError(t, err, "Setting to disabled twice should not error")

err = p.IsAssetEnabled(asset.Spot)
if err == nil {
t.Error("unexpected result")
}
assert.ErrorIs(t, err, asset.ErrNotEnabled)

err = p.SetAssetEnabled(asset.Spot, true)
if err != nil {
t.Fatal(err)
}
assert.NoError(t, err)

err = p.SetAssetEnabled(asset.Spot, true)
if err == nil {
t.Fatal("unexpected result")
}
assert.NoError(t, err, "Setting to enabled twice should not error")

err = p.IsAssetEnabled(asset.Spot)
if err != nil {
t.Error("unexpected result")
}
assert.NoError(t, err, "IsAssetEnabled should not error")
}

// TestFullStoreUnmarshalMarshal tests json Mashal and Unmarshal
Expand Down

0 comments on commit 4d14ef6

Please sign in to comment.