Skip to content

Commit

Permalink
Merge pull request #153 from SiaFoundation/nate/fix-wallet-reset
Browse files Browse the repository at this point in the history
Reset wallet metrics when resetting wallet
  • Loading branch information
n8maninger committed Aug 21, 2023
2 parents 94e8ebc + a81b952 commit c62bf6d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions persist/sqlite/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ func (s *Store) ResetWallet(seedHash types.Hash256) error {
return fmt.Errorf("failed to delete wallet utxos: %w", err)
} else if _, err := tx.Exec(`DELETE FROM wallet_transactions`); err != nil {
return fmt.Errorf("failed to delete wallet transactions: %w", err)
} else if _, err := tx.Exec(`DELETE FROM host_stats WHERE stat=$1`, metricWalletBalance); err != nil {
return fmt.Errorf("failed to delete wallet metrics: %w", err)
} else if _, err := tx.Exec(`UPDATE global_settings SET wallet_last_processed_change=NULL, wallet_height=NULL, wallet_hash=?`, sqlHash256(seedHash)); err != nil {
return fmt.Errorf("failed to reset wallet settings: %w", err)
}
Expand Down
14 changes: 14 additions & 0 deletions wallet/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ func TestWalletReset(t *testing.T) {
t.Fatal("expected transactions")
}

m, err := w.Store().Metrics(time.Now())
if err != nil {
t.Fatal(err)
} else if m.Balance.IsZero() {
t.Fatal("expected non-zero balance")
}

// close the wallet and trigger a reset by using a different private key
w.Close()

Expand Down Expand Up @@ -310,4 +317,11 @@ func TestWalletReset(t *testing.T) {
} else if len(txns) != 0 {
t.Fatal("expected no transactions")
}

m, err = w.Store().Metrics(time.Now())
if err != nil {
t.Fatal(err)
} else if !m.Balance.IsZero() {
t.Fatal("expected zero balance")
}
}

0 comments on commit c62bf6d

Please sign in to comment.