Skip to content

Commit

Permalink
dcrdtest: Use adjusted simnet miner for tests
Browse files Browse the repository at this point in the history
This speeds up test execution.
  • Loading branch information
matheusd committed Nov 16, 2022
1 parent ae0f762 commit 8af2c42
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dcrdlogs
8 changes: 8 additions & 0 deletions dcrdtest/simnet_miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,11 @@ func AdjustedSimnetMiner(ctx context.Context, client *rpcclient.Client, nb uint3

return hashes, nil
}

// AdjustedSimnetMinerForClient returns a miner function that closes over the
// passed rpclient to use the adjusted simnet miner to generate blocks.
func AdjustedSimnetMinerForClient(c *rpcclient.Client) func(ctx context.Context, nb uint32) ([]*chainhash.Hash, error) {
return func(ctx context.Context, nb uint32) ([]*chainhash.Hash, error) {
return AdjustedSimnetMiner(ctx, c, nb)
}
}
9 changes: 8 additions & 1 deletion dcrdtest/votingwallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func TestMinimalVotingWallet(t *testing.T) {
logDir := "./dcrdlogs"
extraArgs := []string{
"--debuglevel=debug",
"--logdir=" + logDir,
}

info, err := os.Stat(logDir)
Expand All @@ -87,12 +88,16 @@ func TestMinimalVotingWallet(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

err = hn.SetUp(ctx, true, 8)
err = hn.SetUp(ctx, false, 0)
if err != nil {
t.Fatal(err)
}
defer hn.TearDown()

if _, err := AdjustedSimnetMiner(ctx, hn.Node, 64); err != nil {
t.Fatal(err)
}

type testCase struct {
name string
f func(ctx context.Context, t *testing.T, vw *VotingWallet)
Expand All @@ -113,6 +118,8 @@ func TestMinimalVotingWallet(t *testing.T) {
t1.Fatalf("unable to create voting wallet for test: %v", err)
}

vw.SetMiner(AdjustedSimnetMinerForClient(hn.Node))

err = vw.Start(ctx)
if err != nil {
t1.Fatalf("unable to setup voting wallet: %v", err)
Expand Down

0 comments on commit 8af2c42

Please sign in to comment.