Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
add TestDefragOutputExhaustion
Browse files Browse the repository at this point in the history
  • Loading branch information
avahowell authored and David Vorick committed Jan 18, 2017
1 parent 442bce1 commit aa463a2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/wallet/defrag.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
defragThreshold = 50

// defragBatchSize defines how many outputs are combined during one defrag.
defragBatchSize = 40
defragBatchSize = 35

// defragStartIndex is the number of outputs to skip over when performing a
// defrag.
Expand Down
41 changes: 41 additions & 0 deletions modules/wallet/defrag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,44 @@ func TestDefragWalletDust(t *testing.T) {
t.Fatal("defrag consolidated dust outputs")
}
}

// TestDefragOutputExhaustion verifies that a malicious actor cannot use the
// defragger to prevent a wallet from sending coins.
func TestDefragOutputExhaustion(t *testing.T) {
if testing.Short() {
t.SkipNow()
}

wt, err := createWalletTester("TestDefragOutputExhaustion")
if err != nil {
t.Fatal(err)
}
defer wt.closeWt()

// mine a bunch of blocks continuously at a high enough rate to keep the
// defragger running.
closechan := make(chan struct{})
go func() {
for {
select {
case <-closechan:
return
case <-time.After(time.Millisecond * 500):
_, err := wt.miner.AddBlock()
if err != nil {
t.Fatal(err)
}
}
}
}()

time.Sleep(time.Second * 5)

sendAmount := types.SiacoinPrecision.Mul64(2000)
_, err = wt.wallet.SendSiacoins(sendAmount, types.UnlockHash{})
if err != nil {
t.Fatal(err)
}

close(closechan)
}

0 comments on commit aa463a2

Please sign in to comment.