<commit_before>package wallet

import (
	"testing"

	"github.com/NebulousLabs/Sia/types"

	"github.com/NebulousLabs/bolt"
)

func TestDBHistoricHelpers(t *testing.T) {
	wt, err := createBlankWalletTester("TestDBHistoricOutputs")
	if err != nil {
		t.Fatal(err)
	}
	defer wt.closeWt()

	id := types.OutputID{1, 2, 3}
	c := types.NewCurrency64(7)
	wt.wallet.db.Update(func(tx *bolt.Tx) error {
		return dbPutHistoricOutput(tx, id, c)
	})
	wt.wallet.db.View(func(tx *bolt.Tx) error {
		c2, err := dbGetHistoricOutput(tx, id)
		if err != nil {
			t.Fatal(err)
		} else if c2.Cmp(c) != 0 {
			t.Fatal(c, c2)
		}
		return nil
	})

	soid := types.SiafundOutputID{1, 2, 3}
	c = types.NewCurrency64(7)
	wt.wallet.db.Update(func(tx *bolt.Tx) error {
		return dbPutHistoricClaimStart(tx, soid, c)
	})
	wt.wallet.db.View(func(tx *bolt.Tx) error {<commit_msg>add TestDBOpen<commit_after>package wallet

import (
	"os"
	"path/filepath"
	"testing"

	"github.com/NebulousLabs/Sia/build"
	"github.com/NebulousLabs/Sia/modules"
	"github.com/NebulousLabs/Sia/types"

	"github.com/NebulousLabs/bolt"
)

// TestDBOpen tests the wallet.openDB method.
func TestDBOpen(t *testing.T) {
	w := new(Wallet)
	err := w.openDB("")
	if err == nil {
		t.Fatal("expected error, got nil")
	}

	testdir := build.TempDir(modules.WalletDir, "TestDBOpen")
	os.MkdirAll(testdir, 0700)
	err = w.openDB(filepath.Join(testdir, dbFile))
	if err != nil {
		t.Fatal(err)
	}
	w.db.View(func(tx *bolt.Tx) error {
		buckets := [][]byte{
			bucketHistoricOutputs,
			bucketHistoricClaimStarts,
		}
		for _, b := range buckets {
			if tx.Bucket(b) == nil {
				t.Error("bucket", string(b), "does not exist")
			}
		}
		return nil
	})
	w.db.Close()
}

// TestDBHistoricHelpers tests the get/put helpers for the HistoricOutputs and
// HistoricClaimStarts buckets.
func TestDBHistoricHelpers(t *testing.T) {
	wt, err := createBlankWalletTester("TestDBHistoricOutputs")
	if err != nil {
		t.Fatal(err)
	}
	defer wt.closeWt()

	id := types.OutputID{1, 2, 3}
	c := types.NewCurrency64(7)
	wt.wallet.db.Update(func(tx *bolt.Tx) error {
		return dbPutHistoricOutput(tx, id, c)
	})
	wt.wallet.db.View(func(tx *bolt.Tx) error {
		c2, err := dbGetHistoricOutput(tx, id)
		if err != nil {
			t.Fatal(err)
		} else if c2.Cmp(c) != 0 {
			t.Fatal(c, c2)
		}
		return nil
	})

	soid := types.SiafundOutputID{1, 2, 3}
	c = types.NewCurrency64(7)
	wt.wallet.db.Update(func(tx *bolt.Tx) error {
		return dbPutHistoricClaimStart(tx, soid, c)
	})
	wt.wallet.db.View(func(tx *bolt.Tx) error {
{'fraction_non_alphanumeric': 0.1599206349206349, 'fraction_numerical': 0.014285714285714285, 'mean_word_length': 3.876208897485493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2990830', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1071, 'n_words': 201}