storj/pkg/accounting/tally/tally_test.go
Jennifer Li Johnson a2fa5c4c5a Proper NodeType Handling (#873)
* adds enums to nodetype

* updating nodetype todos

* ran pb updates

* reorder nodetypes

* adding checks

* wip

* wip

* wip

* bug in test-captplanet

* wip

* add values to storagenode, satellite, captplanet binaries

* Cleanup

* more cleanup

* wip

* lint

* lint

* wip

* fixes bug

* regenerate protos

Change-Id: Id270212e8c7479e52641058042cf23b5317ab773

* limit node type changes to kademlia

Change-Id: I9c1a6cc4a79e05086627f0fdeb5028c62ce754f4

* dpanic

Change-Id: Id952a2ad13c807ebaea0ec0a875405e267d81c3e

* review comments

Change-Id: I7f9b77ef22779dd012fd490375b136014f51f834
2019-01-02 11:47:34 -07:00

80 lines
2.2 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package tally
import (
"crypto/ecdsa"
"testing"
"time"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"storj.io/storj/internal/testcontext"
"storj.io/storj/internal/testidentity"
"storj.io/storj/pkg/bwagreement"
"storj.io/storj/pkg/bwagreement/test"
"storj.io/storj/pkg/overlay"
"storj.io/storj/pkg/overlay/mocks"
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/pointerdb"
"storj.io/storj/satellite/satellitedb"
"storj.io/storj/storage/teststore"
)
func TestQueryNoAgreements(t *testing.T) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
pointerdb := pointerdb.NewServer(teststore.New(), &overlay.Cache{}, zap.NewNop(), pointerdb.Config{}, nil)
overlayServer := mocks.NewOverlay([]*pb.Node{})
db, err := satellitedb.NewInMemory()
assert.NoError(t, err)
defer ctx.Check(db.Close)
assert.NoError(t, db.CreateTables())
tally := newTally(zap.NewNop(), db.Accounting(), db.BandwidthAgreement(), pointerdb, overlayServer, 0, time.Second)
err = tally.queryBW(ctx)
assert.NoError(t, err)
}
func TestQueryWithBw(t *testing.T) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
pointerdb := pointerdb.NewServer(teststore.New(), &overlay.Cache{}, zap.NewNop(), pointerdb.Config{}, nil)
overlayServer := mocks.NewOverlay([]*pb.Node{})
db, err := satellitedb.NewInMemory()
assert.NoError(t, err)
defer ctx.Check(db.Close)
assert.NoError(t, db.CreateTables())
bwDb := db.BandwidthAgreement()
tally := newTally(zap.NewNop(), db.Accounting(), bwDb, pointerdb, overlayServer, 0, time.Second)
//get a private key
fiC, err := testidentity.NewTestIdentity(ctx)
assert.NoError(t, err)
k, ok := fiC.Key.(*ecdsa.PrivateKey)
assert.True(t, ok)
//generate an agreement with the key
pba, err := test.GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, k)
assert.NoError(t, err)
rba, err := test.GenerateRenterBandwidthAllocation(pba, k)
assert.NoError(t, err)
//save to db
err = bwDb.CreateAgreement(ctx, bwagreement.Agreement{Signature: rba.GetSignature(), Agreement: rba.GetData()})
assert.NoError(t, err)
//check the db
err = tally.queryBW(ctx)
assert.NoError(t, err)
}