storj/pkg/bwagreement/test/server_test.go

60 lines
1.7 KiB
Go
Raw Normal View History

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package test
import (
"context"
2018-12-07 12:11:35 +00:00
"crypto/ecdsa"
"testing"
"github.com/stretchr/testify/assert"
2018-12-07 12:11:35 +00:00
"go.uber.org/zap"
"storj.io/storj/internal/identity"
"storj.io/storj/internal/testcontext"
"storj.io/storj/pkg/bwagreement"
"storj.io/storj/pkg/pb"
2018-12-07 12:11:35 +00:00
"storj.io/storj/satellite/satellitedb"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
)
func TestBandwidthAgreements(t *testing.T) {
2018-12-11 09:30:09 +00:00
satellitedbtest.Run(t, func(t *testing.T, db *satellitedb.DB) {
2018-12-07 12:11:35 +00:00
ctx := testcontext.New(t)
defer ctx.Cleanup()
satellitePubKey, satellitePrivKey, uplinkPrivKey := generateKeys(ctx, t)
server := bwagreement.NewServer(db.BandwidthAgreement(), zap.NewNop(), satellitePubKey)
pba, err := GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satellitePrivKey)
assert.NoError(t, err)
2018-12-07 12:11:35 +00:00
rba, err := GenerateRenterBandwidthAllocation(pba, uplinkPrivKey)
assert.NoError(t, err)
2018-12-07 12:11:35 +00:00
/* emulate sending the bwagreement stream from piecestore node */
replay, err := server.BandwidthAgreements(ctx, rba)
assert.NoError(t, err)
assert.Equal(t, pb.AgreementsSummary_OK, replay.Status)
2018-12-07 12:11:35 +00:00
})
}
func generateKeys(ctx context.Context, t *testing.T) (satellitePubKey *ecdsa.PublicKey, satellitePrivKey *ecdsa.PrivateKey, uplinkPrivKey *ecdsa.PrivateKey) {
fiS, err := testidentity.NewTestIdentity()
assert.NoError(t, err)
2018-12-07 12:11:35 +00:00
satellitePubKey, ok := fiS.Leaf.PublicKey.(*ecdsa.PublicKey)
assert.True(t, ok)
satellitePrivKey, ok = fiS.Key.(*ecdsa.PrivateKey)
assert.True(t, ok)
fiU, err := testidentity.NewTestIdentity()
assert.NoError(t, err)
2018-12-07 12:11:35 +00:00
uplinkPrivKey, ok = fiU.Key.(*ecdsa.PrivateKey)
assert.True(t, ok)
return
}