Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
istae committed Jun 4, 2021
1 parent 62502f9 commit 06d7504
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 30 deletions.
2 changes: 0 additions & 2 deletions pkg/localstore/localstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ func New(path string, baseKey []byte, o *Options, logger logging.Logger) (db *DB
return value, nil
},
DecodeValue: func(keyItem shed.Item, value []byte) (e shed.Item, err error) {
e = keyItem
e.BatchID = make([]byte, 32)
copy(e.BatchID, value[:32])
e.Index = make([]byte, postage.IndexSize)
Expand Down Expand Up @@ -508,7 +507,6 @@ func New(path string, baseKey []byte, o *Options, logger logging.Logger) (db *DB
return value, nil
},
DecodeValue: func(keyItem shed.Item, value []byte) (e shed.Item, err error) {
e = keyItem
e.Address = value[:32]
e.Timestamp = value[32:]
return e, nil
Expand Down
20 changes: 10 additions & 10 deletions pkg/localstore/mode_put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,8 @@ func TestModePut_SameStamp(t *testing.T) {
stamp := postagetesting.MustNewStamp()
ts := time.Now().Unix()

modes := []storage.ModePut{storage.ModePutRequest, storage.ModePutRequestPin, storage.ModePutSync, storage.ModePutUpload, storage.ModePutUploadPin}

for _, modeTc1 := range modes {
for _, modeTc2 := range modes {
for _, modeTc1 := range storage.PutModes {
for _, modeTc2 := range storage.PutModes {
for _, tc := range []struct {
persistChunk swarm.Chunk
discardChunk swarm.Chunk
Expand Down Expand Up @@ -530,7 +528,9 @@ func TestModePut_SameStamp(t *testing.T) {
newItemsCountTest(db.postageChunksIndex, 1)(t)
newItemsCountTest(db.postageRadiusIndex, 1)(t)
newItemsCountTest(db.postageIndexIndex, 1)(t)
newItemsCountTest(db.pullIndex, 1)(t)
if modeTc1 != storage.ModePutRequestCache {
newItemsCountTest(db.pullIndex, 1)(t)
}

_, err = db.Get(ctx, storage.ModeGetLookup, tc.persistChunk.Address())
if err != nil {
Expand All @@ -552,10 +552,8 @@ func TestModePut_ImmutableStamp(t *testing.T) {
stamp := postagetesting.MustNewStamp()
ts := time.Now().Unix()

modes := []storage.ModePut{storage.ModePutRequest, storage.ModePutRequestPin, storage.ModePutSync, storage.ModePutUpload, storage.ModePutUploadPin}

for _, modeTc1 := range modes {
for _, modeTc2 := range modes {
for _, modeTc1 := range storage.PutModes {
for _, modeTc2 := range storage.PutModes {
for _, tc := range []struct {
name string
persistChunk swarm.Chunk
Expand Down Expand Up @@ -596,7 +594,9 @@ func TestModePut_ImmutableStamp(t *testing.T) {
newItemsCountTest(db.postageChunksIndex, 1)(t)
newItemsCountTest(db.postageRadiusIndex, 1)(t)
newItemsCountTest(db.postageIndexIndex, 1)(t)
newItemsCountTest(db.pullIndex, 1)(t)
if modeTc1 != storage.ModePutRequestCache {
newItemsCountTest(db.pullIndex, 1)(t)
}

_, err = db.Get(ctx, storage.ModeGetLookup, tc.persistChunk.Address())
if err != nil {
Expand Down
14 changes: 0 additions & 14 deletions pkg/localstore/mode_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,8 @@ func TestModeSetRemove_WithSync(t *testing.T) {
}

t.Run("retrieve indexes", func(t *testing.T) {
for _, ch := range chs {
wantErr := leveldb.ErrNotFound
_, err := db.retrievalDataIndex.Get(addressToItem(ch.Address()))
if !errors.Is(err, wantErr) {
t.Errorf("got error %v, want %v", err, wantErr)
}

// access index should not be set
_, err = db.retrievalAccessIndex.Get(addressToItem(ch.Address()))
if !errors.Is(err, wantErr) {
t.Errorf("got error %v, want %v", err, wantErr)
}
}

t.Run("retrieve data index count", newItemsCountTest(db.retrievalDataIndex, 0))

t.Run("retrieve access index count", newItemsCountTest(db.retrievalAccessIndex, 0))
})

Expand Down
4 changes: 1 addition & 3 deletions pkg/postage/listener/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ func TestListener(t *testing.T) {
owner: addr[:],
amount: big.NewInt(42),
normalisedAmount: big.NewInt(43),
// bucketDepth: 10,
depth: 100,
// immutable: true,
depth: 100,
}

ev, evC := newEventUpdaterMock()
Expand Down
2 changes: 1 addition & 1 deletion pkg/postage/stamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (s *Stamp) Timestamp() []byte {
}

// MarshalBinary gives the byte slice serialisation of a stamp:
// batchID[32]|index[32]|SignatureUser[65]|SignatureOwner[65].
// batchID[32]|index[8]|Signature[65].
func (s *Stamp) MarshalBinary() ([]byte, error) {
buf := make([]byte, StampSize)
copy(buf, s.batchID)
Expand Down
2 changes: 2 additions & 0 deletions pkg/storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const (
ModeGetRequestPin
)

var PutModes = []ModePut{ModePutRequest, ModePutRequestPin, ModePutSync, ModePutUpload, ModePutUploadPin, ModePutRequestCache}

// ModePut enumerates different Putter modes.
type ModePut int

Expand Down

0 comments on commit 06d7504

Please sign in to comment.