2018-06-27 19:42:54 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-11-06 17:49:17 +00:00
|
|
|
package psclient
|
2018-06-27 19:42:54 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-07-06 09:51:13 +01:00
|
|
|
"github.com/mr-tron/base58/base58"
|
2018-06-27 19:42:54 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2018-10-16 12:43:44 +01:00
|
|
|
|
2018-11-29 18:39:27 +00:00
|
|
|
"storj.io/storj/internal/identity"
|
2018-06-27 19:42:54 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewPieceID(t *testing.T) {
|
|
|
|
t.Run("should return an id string", func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
id := NewPieceID()
|
|
|
|
assert.Equal(id.IsValid(), true)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("should return a different string on each call", func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
assert.NotEqual(NewPieceID(), NewPieceID())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-07-06 09:51:13 +01:00
|
|
|
func TestDerivePieceID(t *testing.T) {
|
|
|
|
pid := NewPieceID()
|
2018-11-29 18:39:27 +00:00
|
|
|
fid, err := testidentity.NewTestIdentity()
|
2018-07-06 09:51:13 +01:00
|
|
|
assert.NoError(t, err)
|
2018-11-29 18:39:27 +00:00
|
|
|
did, err := pid.Derive(fid.ID.Bytes())
|
2018-07-16 20:22:34 +01:00
|
|
|
assert.NoError(t, err)
|
2018-07-06 09:51:13 +01:00
|
|
|
assert.NotEqual(t, pid, did)
|
|
|
|
|
2018-11-29 18:39:27 +00:00
|
|
|
did2, err := pid.Derive(fid.ID.Bytes())
|
2018-07-16 20:22:34 +01:00
|
|
|
assert.NoError(t, err)
|
2018-07-06 09:51:13 +01:00
|
|
|
assert.Equal(t, did, did2)
|
|
|
|
|
|
|
|
_, err = base58.Decode(did.String())
|
|
|
|
assert.NoError(t, err)
|
2018-06-27 19:42:54 +01:00
|
|
|
}
|