Skip to content

Commit

Permalink
handle nil in PathCapabilityValue and TypeValue in entitlements migra…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
turbolent committed Feb 15, 2024
1 parent fa57449 commit cab2c8a
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion migrations/entitlements/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,11 @@ func TestConvertToEntitledValue(t *testing.T) {
),
Name: "[Type]",
},
{
Input: interpreter.NewTypeValue(inter, nil),
Output: interpreter.NewTypeValue(inter, nil),
Name: "Type(nil)",
},
{
Input: interpreter.NewDictionaryValue(
inter,
Expand Down Expand Up @@ -1041,6 +1046,19 @@ func TestConvertToEntitledValue(t *testing.T) {
},
Name: "PathCapability<&S>",
},
{
Input: &interpreter.PathCapabilityValue{ //nolint:staticcheck
Address: interpreter.NewAddressValue(inter, testAddress),
Path: testPathValue,
BorrowType: nil,
},
Output: &interpreter.PathCapabilityValue{ //nolint:staticcheck
Address: interpreter.NewAddressValue(inter, testAddress),
Path: testPathValue,
BorrowType: nil,
},
Name: "PathCapability<nil>",
},
{
Input: interpreter.NewCapabilityValue(
inter,
Expand Down Expand Up @@ -1276,6 +1294,21 @@ func TestConvertToEntitledValue(t *testing.T) {
}
return true

case interpreter.TypeValue:
// TypeValue considers missing type "unknown"/"invalid",
// and "unknown"/"invalid" type values unequal.
// However, we want to consider those equal here for testing/asserting purposes
other, ok := output.(interpreter.TypeValue)
if !ok {
return false
}

if other.Type == nil {
return v.Type == nil
} else {
return other.Type.Equal(v.Type)
}

case *interpreter.EphemeralReferenceValue:
otherReference, ok := output.(*interpreter.EphemeralReferenceValue)
if !ok || !v.Authorization.Equal(otherReference.Authorization) {
Expand Down Expand Up @@ -1304,7 +1337,7 @@ func TestConvertToEntitledValue(t *testing.T) {
convertedValue := convertEntireTestValue(inter, storage, testAddress, test.Input)
switch convertedValue := convertedValue.(type) {
case interpreter.EquatableValue:
require.True(t, referencePeekingEqual(convertedValue, test.Output))
require.True(t, referencePeekingEqual(convertedValue, test.Output), "expected: %s\nactual: %s", test.Output, convertedValue)
default:
require.Equal(t, convertedValue, test.Output)
}
Expand Down

0 comments on commit cab2c8a

Please sign in to comment.