Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Browser Support #295

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions bamboozle_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcwallet/walletdb"
"github.com/lightninglabs/neutrino/headerfs"
_ "github.com/linden/tempdb"
)

func decodeHashNoError(str string) *chainhash.Hash {
Expand Down Expand Up @@ -525,9 +526,7 @@ func runCheckCFCheckptSanityTestCase(t *testing.T, testCase *cfCheckptTestCase)
}
defer os.RemoveAll(tempDir)

db, err := walletdb.Create(
"bdb", tempDir+"/weks.db", true, dbOpenTimeout,
)
db, err := walletdb.Create("tempdb", "weks.db")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can instead modify the tests to use a build tag to specify tempdb vs bdb?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a NewTestDB func defined for the build w/ and w/o the build tag defined.

if err != nil {
t.Fatalf("Error opening DB: %s", err)
}
Expand Down
27 changes: 5 additions & 22 deletions banman/store_test.go
Original file line number Diff line number Diff line change
@@ -1,46 +1,30 @@
package banman_test

import (
"io/ioutil"
"net"
"os"
"path/filepath"
"testing"
"time"

"github.com/btcsuite/btcwallet/walletdb"
_ "github.com/btcsuite/btcwallet/walletdb/bdb"
"github.com/lightninglabs/neutrino/banman"
_ "github.com/linden/tempdb"
)

// createTestBanStore creates a test Store backed by a boltdb instance.
func createTestBanStore(t *testing.T) (banman.Store, func()) {
func createTestBanStore(t *testing.T) banman.Store {
t.Helper()

dbDir, err := ioutil.TempDir("", "")
db, err := walletdb.Create("tempdb", "test.db")
if err != nil {
t.Fatalf("unable to create db dir: %v", err)
}
dbPath := filepath.Join(dbDir, "test.db")

db, err := walletdb.Create("bdb", dbPath, true, time.Second*10)
if err != nil {
os.RemoveAll(dbDir)
t.Fatalf("unable to create db: %v", err)
}

cleanUp := func() {
db.Close()
os.RemoveAll(dbDir)
}

banStore, err := banman.NewStore(db)
if err != nil {
cleanUp()
t.Fatalf("unable to create ban store: %v", err)
}

return banStore, cleanUp
return banStore
}

// TestBanStore ensures that the BanStore's state correctly reflects the
Expand All @@ -50,8 +34,7 @@ func TestBanStore(t *testing.T) {

// We'll start by creating our test BanStore backed by a boltdb
// instance.
banStore, cleanUp := createTestBanStore(t)
defer cleanUp()
banStore := createTestBanStore(t)

// checkBanStore is a helper closure to ensure to the IP network's ban
// status is correctly reflected within the BanStore.
Expand Down
11 changes: 8 additions & 3 deletions blockmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/rand"
"reflect"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -59,9 +60,7 @@ func setupBlockManager(t *testing.T) (*blockManager, headerfs.BlockHeaderStore,

// Set up the block and filter header stores.
tempDir := t.TempDir()
db, err := walletdb.Create(
"bdb", tempDir+"/weks.db", true, dbOpenTimeout,
)
db, err := walletdb.Create("tempdb", "weks.db")
if err != nil {
return nil, nil, nil, fmt.Errorf("error opening DB: %s", err)
}
Expand Down Expand Up @@ -876,6 +875,12 @@ func TestBlockManagerDetectBadPeers(t *testing.T) {
func TestHandleHeaders(t *testing.T) {
t.Parallel()

// skip this test because we can't spawn a process in the browser.
// https://github.com/linden/wasmexec/issues/2.
if runtime.GOOS == "js" {
t.Skip("start process is unsupported in the browser, skipping test.")
}

// First, we set up a block manager and a fake peer that will act as the
// test's remote peer.
bm, _, _, err := setupBlockManager(t)
Expand Down
12 changes: 2 additions & 10 deletions filterdb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,19 @@ package filterdb
import (
"math/rand"
"testing"
"time"

"github.com/btcsuite/btcd/btcutil/gcs"
"github.com/btcsuite/btcd/btcutil/gcs/builder"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcwallet/walletdb"
_ "github.com/btcsuite/btcwallet/walletdb/bdb"
_ "github.com/linden/tempdb"
"github.com/stretchr/testify/require"
)

func createTestDatabase(t *testing.T) FilterDatabase {
tempDir := t.TempDir()

db, err := walletdb.Create(
"bdb", tempDir+"/test.db", true, time.Second*10,
)
db, err := walletdb.Create("tempdb", "test.db")
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, db.Close())
})

filterDB, err := New(db, chaincfg.SimNetParams)
require.NoError(t, err)
Expand Down
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ require (
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcwallet/wallet/txauthor v1.2.3
github.com/btcsuite/btcwallet/walletdb v1.3.5
github.com/btcsuite/btcwallet/walletdb v1.4.0
github.com/btcsuite/btcwallet/wtxmgr v1.5.0
github.com/davecgh/go-spew v1.1.1
github.com/lightninglabs/neutrino/cache v1.1.0
github.com/lightningnetwork/lnd/queue v1.0.1
github.com/linden/indexeddb v0.0.0-20240218035359-81389d584a5e
github.com/linden/tempdb v0.0.0-20240218031655-83bc03e79f51
github.com/stretchr/testify v1.8.1
)

Expand All @@ -28,10 +30,11 @@ require (
github.com/lightningnetwork/lnd/clock v1.0.1 // indirect
github.com/lightningnetwork/lnd/ticker v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.etcd.io/bbolt v1.3.5-0.20200615073812-232d8fc87f50 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

go 1.18
go 1.21.2

toolchain go1.21.5
7 changes: 6 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ github.com/btcsuite/btcwallet/wallet/txrules v1.2.0 h1:BtEN5Empw62/RVnZ0VcJaVtVl
github.com/btcsuite/btcwallet/wallet/txrules v1.2.0/go.mod h1:AtkqiL7ccKWxuLYtZm8Bu8G6q82w4yIZdgq6riy60z0=
github.com/btcsuite/btcwallet/wallet/txsizes v1.1.0 h1:wZnOolEAeNOHzHTnznw/wQv+j35ftCIokNrnOTOU5o8=
github.com/btcsuite/btcwallet/wallet/txsizes v1.1.0/go.mod h1:pauEU8UuMFiThe5PB3EO+gO5kx87Me5NvdQDsTuq6cs=
github.com/btcsuite/btcwallet/walletdb v1.3.5 h1:SoxUPLgJUkyO1XqON6X7x+rjHJoIpRQov8o8X6gNoz8=
github.com/btcsuite/btcwallet/walletdb v1.3.5/go.mod h1:oJDxAEUHVtnmIIBaa22wSBPTVcs6hUp5NKWmI8xDwwU=
github.com/btcsuite/btcwallet/walletdb v1.4.0 h1:/C5JRF+dTuE2CNMCO/or5N8epsrhmSM4710uBQoYPTQ=
github.com/btcsuite/btcwallet/walletdb v1.4.0/go.mod h1:oJDxAEUHVtnmIIBaa22wSBPTVcs6hUp5NKWmI8xDwwU=
github.com/btcsuite/btcwallet/wtxmgr v1.5.0 h1:WO0KyN4l6H3JWnlFxfGR7r3gDnlGT7W2cL8vl6av4SU=
github.com/btcsuite/btcwallet/wtxmgr v1.5.0/go.mod h1:TQVDhFxseiGtZwEPvLgtfyxuNUDsIdaJdshvWzR0HJ4=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw=
Expand Down Expand Up @@ -83,6 +84,10 @@ github.com/lightningnetwork/lnd/queue v1.0.1 h1:jzJKcTy3Nj5lQrooJ3aaw9Lau3I0IwvQ
github.com/lightningnetwork/lnd/queue v1.0.1/go.mod h1:vaQwexir73flPW43Mrm7JOgJHmcEFBWWSl9HlyASoms=
github.com/lightningnetwork/lnd/ticker v1.0.0 h1:S1b60TEGoTtCe2A0yeB+ecoj/kkS4qpwh6l+AkQEZwU=
github.com/lightningnetwork/lnd/ticker v1.0.0/go.mod h1:iaLXJiVgI1sPANIF2qYYUJXjoksPNvGNYowB8aRbpX0=
github.com/linden/indexeddb v0.0.0-20240218035359-81389d584a5e h1:6FTMUiW0wI+my/+7w4CEEYt5zvGmbAjugt2q/fCUyBM=
github.com/linden/indexeddb v0.0.0-20240218035359-81389d584a5e/go.mod h1:2AP38q2ks+pRwMc2EhmCexlyri456KCewavN30MZQ8Y=
github.com/linden/tempdb v0.0.0-20240218031655-83bc03e79f51 h1:RfZREkHD3XpItaIN2I1/tb2hCzE2TN5e14OkTH6Sv74=
github.com/linden/tempdb v0.0.0-20240218031655-83bc03e79f51/go.mod h1:xR9HUmc4girdp/lNzw1jOt53GaCSmctyB8t+Q6EkWp8=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
Loading
Loading