Skip to content

Commit

Permalink
Remove unnecessary manual Unwrap() in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fxamacker committed Mar 23, 2023
1 parent 8db5046 commit 036f757
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
24 changes: 12 additions & 12 deletions array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestArrayAppendAndGet(t *testing.T) {
var indexOutOfBoundsError *IndexOutOfBoundsError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &indexOutOfBoundsError)
require.ErrorAs(t, userError.Unwrap(), &indexOutOfBoundsError)
require.ErrorAs(t, userError, &indexOutOfBoundsError)

verifyArray(t, storage, typeInfo, address, array, values, false)
}
Expand Down Expand Up @@ -327,7 +327,7 @@ func TestArraySetAndGet(t *testing.T) {
var indexOutOfBoundsError *IndexOutOfBoundsError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &indexOutOfBoundsError)
require.ErrorAs(t, userError.Unwrap(), &indexOutOfBoundsError)
require.ErrorAs(t, userError, &indexOutOfBoundsError)

verifyArray(t, storage, typeInfo, address, array, values, false)
})
Expand Down Expand Up @@ -444,7 +444,7 @@ func TestArrayInsertAndGet(t *testing.T) {
var indexOutOfBoundsError *IndexOutOfBoundsError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &indexOutOfBoundsError)
require.ErrorAs(t, userError.Unwrap(), &indexOutOfBoundsError)
require.ErrorAs(t, userError, &indexOutOfBoundsError)

verifyArray(t, storage, typeInfo, address, array, values, false)
})
Expand Down Expand Up @@ -630,7 +630,7 @@ func TestArrayRemove(t *testing.T) {
var indexOutOfBounds *IndexOutOfBoundsError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &indexOutOfBounds)
require.ErrorAs(t, userError.Unwrap(), &indexOutOfBounds)
require.ErrorAs(t, userError, &indexOutOfBounds)

verifyArray(t, storage, typeInfo, address, array, values, false)
})
Expand Down Expand Up @@ -870,7 +870,7 @@ func testArrayIterateRange(t *testing.T, storage *PersistentSlabStorage, array *
var userError *UserError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &sliceOutOfBoundsError)
require.ErrorAs(t, userError.Unwrap(), &sliceOutOfBoundsError)
require.ErrorAs(t, userError, &sliceOutOfBoundsError)
require.Equal(t, uint64(0), i)

// If endIndex > count, IterateRange returns SliceOutOfBoundsError
Expand All @@ -881,7 +881,7 @@ func testArrayIterateRange(t *testing.T, storage *PersistentSlabStorage, array *
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &sliceOutOfBoundsError)
require.ErrorAs(t, userError.Unwrap(), &sliceOutOfBoundsError)
require.ErrorAs(t, userError, &sliceOutOfBoundsError)
require.Equal(t, uint64(0), i)

// If startIndex > endIndex, IterateRange returns InvalidSliceIndexError
Expand All @@ -893,7 +893,7 @@ func testArrayIterateRange(t *testing.T, storage *PersistentSlabStorage, array *
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &invalidSliceIndexError)
require.ErrorAs(t, userError.Unwrap(), &invalidSliceIndexError)
require.ErrorAs(t, userError, &invalidSliceIndexError)
require.Equal(t, uint64(0), i)
}

Expand Down Expand Up @@ -1811,7 +1811,7 @@ func TestEmptyArray(t *testing.T) {
var indexOutOfBoundsError *IndexOutOfBoundsError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &indexOutOfBoundsError)
require.ErrorAs(t, userError.Unwrap(), &indexOutOfBoundsError)
require.ErrorAs(t, userError, &indexOutOfBoundsError)
require.Nil(t, s)
})

Expand All @@ -1822,7 +1822,7 @@ func TestEmptyArray(t *testing.T) {
var indexOutOfBoundsError *IndexOutOfBoundsError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &indexOutOfBoundsError)
require.ErrorAs(t, userError.Unwrap(), &indexOutOfBoundsError)
require.ErrorAs(t, userError, &indexOutOfBoundsError)
require.Nil(t, s)
})

Expand All @@ -1833,7 +1833,7 @@ func TestEmptyArray(t *testing.T) {
var indexOutOfBoundsError *IndexOutOfBoundsError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &indexOutOfBoundsError)
require.ErrorAs(t, userError.Unwrap(), &indexOutOfBoundsError)
require.ErrorAs(t, userError, &indexOutOfBoundsError)
})

t.Run("remove", func(t *testing.T) {
Expand All @@ -1843,7 +1843,7 @@ func TestEmptyArray(t *testing.T) {
var indexOutOfBoundsError *IndexOutOfBoundsError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &indexOutOfBoundsError)
require.ErrorAs(t, userError.Unwrap(), &indexOutOfBoundsError)
require.ErrorAs(t, userError, &indexOutOfBoundsError)
require.Nil(t, s)
})

Expand Down Expand Up @@ -1986,7 +1986,7 @@ func TestArrayStoredValue(t *testing.T) {
var notValueError *NotValueError
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &notValueError)
require.ErrorAs(t, fatalError.Unwrap(), &notValueError)
require.ErrorAs(t, fatalError, &notValueError)
require.Nil(t, value)
}
}
Expand Down
22 changes: 11 additions & 11 deletions map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ func TestMapGetKeyNotFound(t *testing.T) {
var keyNotFoundError *KeyNotFoundError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &keyNotFoundError)
require.ErrorAs(t, userError.Unwrap(), &keyNotFoundError)
require.ErrorAs(t, userError, &keyNotFoundError)

verifyMap(t, storage, typeInfo, address, m, keyValues, nil, false)
})
Expand Down Expand Up @@ -555,7 +555,7 @@ func TestMapGetKeyNotFound(t *testing.T) {
var keyNotFoundError *KeyNotFoundError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &keyNotFoundError)
require.ErrorAs(t, userError.Unwrap(), &keyNotFoundError)
require.ErrorAs(t, userError, &keyNotFoundError)

verifyMap(t, storage, typeInfo, address, m, keyValues, nil, false)
})
Expand Down Expand Up @@ -598,7 +598,7 @@ func TestMapGetKeyNotFound(t *testing.T) {
var keyNotFoundError *KeyNotFoundError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &keyNotFoundError)
require.ErrorAs(t, userError.Unwrap(), &keyNotFoundError)
require.ErrorAs(t, userError, &keyNotFoundError)

verifyMap(t, storage, typeInfo, address, m, keyValues, nil, false)
})
Expand Down Expand Up @@ -708,7 +708,7 @@ func testMapRemoveElement(t *testing.T, m *OrderedMap, k Value, expectedV Value)
var keyNotFoundError *KeyNotFoundError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &keyNotFoundError)
require.ErrorAs(t, userError.Unwrap(), &keyNotFoundError)
require.ErrorAs(t, userError, &keyNotFoundError)
require.Nil(t, removedKeyStorable)
require.Nil(t, removedValueStorable)
}
Expand Down Expand Up @@ -998,7 +998,7 @@ func TestMapRemove(t *testing.T) {
var keyNotFoundError *KeyNotFoundError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &keyNotFoundError)
require.ErrorAs(t, userError.Unwrap(), &keyNotFoundError)
require.ErrorAs(t, userError, &keyNotFoundError)

verifyMap(t, storage, typeInfo, address, m, keyValues, nil, false)
})
Expand Down Expand Up @@ -1042,7 +1042,7 @@ func TestMapRemove(t *testing.T) {
var keyNotFoundError *KeyNotFoundError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &keyNotFoundError)
require.ErrorAs(t, userError.Unwrap(), &keyNotFoundError)
require.ErrorAs(t, userError, &keyNotFoundError)

verifyMap(t, storage, typeInfo, address, m, keyValues, nil, false)
})
Expand Down Expand Up @@ -2816,7 +2816,7 @@ func TestMapStoredValue(t *testing.T) {
var notValueError *NotValueError
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &notValueError)
require.ErrorAs(t, fatalError.Unwrap(), &notValueError)
require.ErrorAs(t, fatalError, &notValueError)
require.Nil(t, value)
}
}
Expand Down Expand Up @@ -3043,7 +3043,7 @@ func TestEmptyMap(t *testing.T) {
var keyNotFoundError *KeyNotFoundError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &keyNotFoundError)
require.ErrorAs(t, userError.Unwrap(), &keyNotFoundError)
require.ErrorAs(t, userError, &keyNotFoundError)
require.Nil(t, s)
})

Expand All @@ -3054,7 +3054,7 @@ func TestEmptyMap(t *testing.T) {
var keyNotFoundError *KeyNotFoundError
require.ErrorAs(t, err, &userError)
require.ErrorAs(t, err, &keyNotFoundError)
require.ErrorAs(t, userError.Unwrap(), &keyNotFoundError)
require.ErrorAs(t, userError, &keyNotFoundError)
require.Nil(t, existingKey)
require.Nil(t, existingValue)
})
Expand Down Expand Up @@ -3982,7 +3982,7 @@ func TestMaxCollisionLimitPerDigest(t *testing.T) {
var collisionLimitError *CollisionLimitError
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &collisionLimitError)
require.ErrorAs(t, fatalError.Unwrap(), &collisionLimitError)
require.ErrorAs(t, fatalError, &collisionLimitError)
require.Nil(t, existingStorable)
}

Expand Down Expand Up @@ -4056,7 +4056,7 @@ func TestMaxCollisionLimitPerDigest(t *testing.T) {
var collisionLimitError *CollisionLimitError
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &collisionLimitError)
require.ErrorAs(t, fatalError.Unwrap(), &collisionLimitError)
require.ErrorAs(t, fatalError, &collisionLimitError)
require.Nil(t, existingStorable)
}

Expand Down
18 changes: 9 additions & 9 deletions slab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ func TestIsRootOfAnObject(t *testing.T) {
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &decodingError)
require.ErrorAs(t, fatalError.Unwrap(), &decodingError)
require.ErrorAs(t, fatalError, &decodingError)

isRoot, err = IsRootOfAnObject([]byte{})
require.False(t, isRoot)
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &decodingError)
require.ErrorAs(t, fatalError.Unwrap(), &decodingError)
require.ErrorAs(t, fatalError, &decodingError)

isRoot, err = IsRootOfAnObject([]byte{0x00})
require.False(t, isRoot)
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &decodingError)
require.ErrorAs(t, fatalError.Unwrap(), &decodingError)
require.ErrorAs(t, fatalError, &decodingError)
})
}

Expand Down Expand Up @@ -114,21 +114,21 @@ func TestHasPointers(t *testing.T) {
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &decodingError)
require.ErrorAs(t, fatalError.Unwrap(), &decodingError)
require.ErrorAs(t, fatalError, &decodingError)

hasPointers, err = HasPointers([]byte{})
require.False(t, hasPointers)
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &decodingError)
require.ErrorAs(t, fatalError.Unwrap(), &decodingError)
require.ErrorAs(t, fatalError, &decodingError)

hasPointers, err = HasPointers([]byte{0x00})
require.False(t, hasPointers)
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &decodingError)
require.ErrorAs(t, fatalError.Unwrap(), &decodingError)
require.ErrorAs(t, fatalError, &decodingError)
})
}

Expand Down Expand Up @@ -168,20 +168,20 @@ func TestHasSizeLimit(t *testing.T) {
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &decodingError)
require.ErrorAs(t, fatalError.Unwrap(), &decodingError)
require.ErrorAs(t, fatalError, &decodingError)

hasSizeLimit, err = HasSizeLimit([]byte{})
require.False(t, hasSizeLimit)
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &decodingError)
require.ErrorAs(t, fatalError.Unwrap(), &decodingError)
require.ErrorAs(t, fatalError, &decodingError)

hasSizeLimit, err = HasSizeLimit([]byte{0x00})
require.False(t, hasSizeLimit)
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &decodingError)
require.ErrorAs(t, fatalError.Unwrap(), &decodingError)
require.ErrorAs(t, fatalError, &decodingError)
})
}
12 changes: 6 additions & 6 deletions storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ func TestNewStorageIDFromRawBytes(t *testing.T) {
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &storageIDError)
require.ErrorAs(t, fatalError.Unwrap(), &storageIDError)
require.ErrorAs(t, fatalError, &storageIDError)

id, err = NewStorageIDFromRawBytes([]byte{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2})
require.Equal(t, StorageIDUndefined, id)
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &storageIDError)
require.ErrorAs(t, fatalError.Unwrap(), &storageIDError)
require.ErrorAs(t, fatalError, &storageIDError)
})

t.Run("data length == storage id size", func(t *testing.T) {
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestStorageIDToRawBytes(t *testing.T) {
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &storageIDError)
require.ErrorAs(t, fatalError.Unwrap(), &storageIDError)
require.ErrorAs(t, fatalError, &storageIDError)
})

t.Run("buffer too short", func(t *testing.T) {
Expand All @@ -111,7 +111,7 @@ func TestStorageIDToRawBytes(t *testing.T) {
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &storageIDError)
require.ErrorAs(t, fatalError.Unwrap(), &storageIDError)
require.ErrorAs(t, fatalError, &storageIDError)
})

t.Run("undefined", func(t *testing.T) {
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestStorageIDValid(t *testing.T) {
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &storageIDError)
require.ErrorAs(t, fatalError.Unwrap(), &storageIDError)
require.ErrorAs(t, fatalError, &storageIDError)
})
t.Run("temp index", func(t *testing.T) {
id := StorageID{Address: Address{1}, Index: StorageIndexUndefined}
Expand All @@ -201,7 +201,7 @@ func TestStorageIDValid(t *testing.T) {
require.Equal(t, 1, errorCategorizationCount(err))
require.ErrorAs(t, err, &fatalError)
require.ErrorAs(t, err, &storageIDError)
require.ErrorAs(t, fatalError.Unwrap(), &storageIDError)
require.ErrorAs(t, fatalError, &storageIDError)
})
t.Run("temp address", func(t *testing.T) {
id := StorageID{Address: AddressUndefined, Index: StorageIndex{1}}
Expand Down

0 comments on commit 036f757

Please sign in to comment.