Skip to content

Commit

Permalink
client: add test case for enabling a dex account
Browse files Browse the repository at this point in the history
Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon committed Sep 4, 2024
1 parent 11883cb commit d2b0482
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions client/core/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (c *Core) ToggleAccountStatus(pw []byte, addr string, disable bool) error {
return newError(unknownDEXErr, "error retrieving dex conn: %w", err)
}

if dc.acct.isDisabled() == disable {
return nil // no-op
}

if disable {
// Check active orders or bonds.
if dc.hasActiveOrders() {
Expand Down
15 changes: 11 additions & 4 deletions client/core/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,20 @@ func TestToggleAccountStatus(t *testing.T) {
{}: {metaData: &db.OrderMetaData{Status: order.OrderStatusBooked}},
}

// TODO: Add test case for enable dex account
tests := []struct {
name, host string
recryptErr, acctErr, disableAcctErr error
wantErr, wantErrCode, loseConns, wantDisable bool
activeTrades map[order.OrderID]*trackedTrade
errCode int
}{{
name: "ok",
name: "ok: disable account",
host: tDexHost,
wantDisable: true,
}, {
name: "ok: enable account",
host: tDexHost,
wantDisable: false,
}, {
name: "password error",
host: tDexHost,
Expand Down Expand Up @@ -143,8 +146,8 @@ func TestToggleAccountStatus(t *testing.T) {
t.Fatalf("unexpected error for test %v: %v", test.name, err)
}
if test.wantDisable {
if _, found := tCore.conns[test.host]; found {
t.Fatal("found disabled account dex connection")
if dc, found := tCore.conns[test.host]; found && !dc.acct.isDisabled() {
t.Fatal("expected disabled account dex connection")
}
if rig.db.disabledHost == nil {
t.Fatal("expected a disable dex server host")
Expand All @@ -153,6 +156,10 @@ func TestToggleAccountStatus(t *testing.T) {
t.Fatalf("expected db account to match test host, want: %v"+
" got: %v", test.host, *rig.db.disabledHost)
}
} else {
if dc, found := tCore.conns[test.host]; found && dc.acct.isDisabled() {
t.Fatal("expected enabled dex account")
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/html/dexsettings.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,4 @@

</div>
{{template "bottom"}}
{{end}}
{{end}}

0 comments on commit d2b0482

Please sign in to comment.