-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
admin: Add account endpoint. #455
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ package pg | |
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
"decred.org/dcrdex/server/account" | ||
|
@@ -89,6 +91,49 @@ func TestAccounts(t *testing.T) { | |
t.Fatal("accounts has unexpected data") | ||
} | ||
|
||
anAcct, err := archie.AccountInfo(accts[0].AccountID) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's also test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a separate nullifying section. |
||
if err != nil { | ||
t.Fatalf("error getting account info: %v", err) | ||
} | ||
if !reflect.DeepEqual(accts[0], anAcct) { | ||
t.Fatal("error getting account info: actual does not equal expected") | ||
} | ||
|
||
// The Account ID cannot be null. broken_rule has a default value of 0 | ||
// and is unexpected to become null. | ||
nullAccounts := `UPDATE %s | ||
SET | ||
pubkey = null , | ||
fee_address = null, | ||
fee_coin = null;` | ||
Comment on lines
+102
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm good with these tests, although note that that the account id is the hash of the pubkey, so they will both be set always unless the DB is corrupted. Still the db scheme doesn't prevent pubkey from being null so I think this is a good test. |
||
|
||
stmt := fmt.Sprintf(nullAccounts, archie.tables.accounts) | ||
if _, err = sqlExec(archie.db, stmt); err != nil { | ||
t.Fatalf("error nullifying account: %v", err) | ||
} | ||
|
||
accts, err = archie.Accounts() | ||
if err != nil { | ||
t.Fatalf("error getting null accounts: %v", err) | ||
} | ||
|
||
// All fields except account ID are null. | ||
if accts[0].AccountID.String() != "0a9912205b2cbab0c25c2de30bda9074de0ae23b065489a99199bad763f102cc" || | ||
accts[0].Pubkey.String() != "" || | ||
accts[0].FeeAddress != "" || | ||
accts[0].FeeCoin.String() != "" || | ||
byte(accts[0].BrokenRule) != byte(0) { | ||
t.Fatal("accounts has unexpected data") | ||
} | ||
|
||
anAcct, err = archie.AccountInfo(accts[0].AccountID) | ||
if err != nil { | ||
t.Fatalf("error getting null account info: %v", err) | ||
} | ||
if !reflect.DeepEqual(accts[0], anAcct) { | ||
t.Fatal("error getting null account info: actual does not equal expected") | ||
} | ||
|
||
// Close the account for failure to complete a swap. | ||
archie.CloseAccount(tAcctID, account.FailureToAct) | ||
_, _, open = archie.Account(tAcctID) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a brutal gotcha here. You actually need to create a new bytes slice and
copy
the bytes because the sql driver reuses src and the underlying buffer changes all the data you already scanned in.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. That saves a bunch of headaches down the road.