Skip to content

Commit

Permalink
testutil,wallet: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Feb 15, 2024
1 parent 8840cc6 commit ea59ca4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions testutil/wallet.go
Expand Up @@ -72,7 +72,7 @@ func (et *ephemeralWalletUpdateTxn) RemoveSiacoinElements(ids []types.SiacoinOut
}

func (et *ephemeralWalletUpdateTxn) RevertIndex(index types.ChainIndex) error {
// remove any transactions that were added in the reverted block
// remove any events that were added in the reverted block
filtered := et.store.events[:0]
for i := range et.store.events {
if et.store.events[i].Index == index {
Expand All @@ -92,7 +92,7 @@ func (et *ephemeralWalletUpdateTxn) RevertIndex(index types.ChainIndex) error {
}

// WalletEvents returns the wallet's events.
func (es *EphemeralWalletStore) WalletEvents(limit, offset int) ([]wallet.Event, error) {
func (es *EphemeralWalletStore) WalletEvents(offset, limit int) ([]wallet.Event, error) {
es.mu.Lock()
defer es.mu.Unlock()

Expand Down
2 changes: 1 addition & 1 deletion wallet/update.go
Expand Up @@ -235,7 +235,7 @@ func ApplyChainUpdates(tx ApplyTx, address types.Address, updates []*chain.Apply
} else if err := tx.RemoveSiacoinElements(spentUTXOs); err != nil {
return fmt.Errorf("failed to remove siacoin elements: %w", err)
} else if err := tx.AddEvents(events); err != nil {
return fmt.Errorf("failed to add transactions: %w", err)
return fmt.Errorf("failed to add events: %w", err)
} else if err := tx.UpdateStateElements(stateElements); err != nil {
return fmt.Errorf("failed to update state elements: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions wallet/wallet.go
Expand Up @@ -97,7 +97,7 @@ type (
// WalletEvents returns a paginated list of transactions ordered by
// maturity height, descending. If no more transactions are available,
// (nil, nil) should be returned.
WalletEvents(limit, offset int) ([]Event, error)
WalletEvents(offset, limit int) ([]Event, error)
// WalletEventCount returns the total number of events relevant to the
// wallet.
WalletEventCount() (uint64, error)
Expand Down Expand Up @@ -215,8 +215,8 @@ func (sw *SingleAddressWallet) Balance() (balance Balance, err error) {

// Events returns a paginated list of events, ordered by maturity height, descending.
// If no more events are available, (nil, nil) is returned.
func (sw *SingleAddressWallet) Events(limit, offset int) ([]Event, error) {
return sw.store.WalletEvents(limit, offset)
func (sw *SingleAddressWallet) Events(offset, limit int) ([]Event, error) {
return sw.store.WalletEvents(offset, limit)
}

// EventCount returns the total number of events relevant to the wallet.
Expand Down
9 changes: 4 additions & 5 deletions wallet/wallet_test.go
Expand Up @@ -68,7 +68,7 @@ func TestWallet(t *testing.T) {

maturityHeight := cm.TipState().MaturityHeight()
// check that the wallet has a single event
if events, err := w.Events(100, 0); err != nil {
if events, err := w.Events(0, 100); err != nil {
t.Fatal(err)
} else if len(events) != 1 {
t.Fatalf("expected 1 event, got %v", len(events))
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestWallet(t *testing.T) {
}

// check that the payout transaction was created
events, err := w.Events(100, 0)
events, err := w.Events(0, 100)
if err != nil {
t.Fatal(err)
} else if len(events) != 1 {
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestWallet(t *testing.T) {
}

// check that the paginated transactions are in the proper order
events, err = w.Events(100, 0)
events, err = w.Events(0, 100)
if err != nil {
t.Fatal(err)
} else if len(events) != 2 {
Expand All @@ -213,7 +213,6 @@ func TestWallet(t *testing.T) {
sent[i].SiacoinOutputs = []types.SiacoinOutput{
{Address: types.VoidAddress, Value: sendAmount},
}

toSign, err := w.FundTransaction(&sent[i], sendAmount, false)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -246,7 +245,7 @@ func TestWallet(t *testing.T) {
}

// check that the paginated transactions are in the proper order
events, err = w.Events(20, 0) // limit of 20 so the original two transactions are not included
events, err = w.Events(0, 20) // limit of 20 so the original two transactions are not included
if err != nil {
t.Fatal(err)
} else if len(events) != 20 {
Expand Down

0 comments on commit ea59ca4

Please sign in to comment.