Skip to content

Commit

Permalink
sqlite: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Jan 23, 2024
1 parent 4476d33 commit df2bed8
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions persist/sqlite/peers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"go.sia.tech/walletd/syncer"
"go.sia.tech/coreutils/syncer"
"go.uber.org/zap/zaptest"
)

Expand All @@ -20,15 +20,13 @@ func TestAddPeer(t *testing.T) {

const peer = "1.2.3.4:9981"

if err := db.AddPeer(peer); err != nil {
t.Fatal(err)
}
db.AddPeer(peer)

lastConnect := time.Now().Truncate(time.Second) // stored as unix milliseconds
syncedBlocks := uint64(15)
syncDuration := 5 * time.Second

err = db.UpdatePeerInfo(peer, func(info *syncer.PeerInfo) {
db.UpdatePeerInfo(peer, func(info *syncer.PeerInfo) {
info.LastConnect = lastConnect
info.SyncedBlocks = syncedBlocks
info.SyncDuration = syncDuration
Expand All @@ -37,9 +35,9 @@ func TestAddPeer(t *testing.T) {
t.Fatal(err)
}

info, err := db.PeerInfo(peer)
if err != nil {
t.Fatal(err)
info, ok := db.PeerInfo(peer)
if !ok {
t.Fatal("expected peer to be in database")
}

if !info.LastConnect.Equal(lastConnect) {
Expand Down Expand Up @@ -68,9 +66,7 @@ func TestBanPeer(t *testing.T) {
}

// ban the peer
if err := db.Ban(peer, time.Second, "test"); err != nil {
t.Fatal(err)
}
db.Ban(peer, time.Second, "test")

if !db.Banned(peer) {
t.Fatal("expected peer to be banned")
Expand All @@ -90,11 +86,7 @@ func TestBanPeer(t *testing.T) {
}

t.Log("banning", subnet)

Check failure on line 88 in persist/sqlite/peers_test.go

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.20)

Test go.sia.tech/walletd/persist/sqlite/TestBanPeer failed in 1.02s

peers_test.go:88: banning 1.2.3.0/24

if err := db.Ban(subnet.String(), time.Second, "test"); err != nil {
t.Fatal(err)
}

db.Ban(subnet.String(), time.Second, "test")
if !db.Banned(peer) {
t.Fatal("expected peer to be banned")

Check failure on line 91 in persist/sqlite/peers_test.go

View workflow job for this annotation

GitHub Actions / test (macos-latest, 1.20)

Test go.sia.tech/walletd/persist/sqlite/TestBanPeer failed in 1.02s

peers_test.go:91: expected peer to be banned
}
Expand Down

0 comments on commit df2bed8

Please sign in to comment.