Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Restricted Type from Cadence #2596

Merged
merged 18 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 34 additions & 129 deletions encoding/ccf/ccf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6661,7 +6661,6 @@ func TestEncodeValueOfIntersectionType(t *testing.T) {
)

countSumIntersectionType := cadence.NewIntersectionType(
nil,
[]cadence.Type{
hasCountInterfaceType,
hasSumInterfaceType,
Expand All @@ -6688,7 +6687,6 @@ func TestEncodeValueOfIntersectionType(t *testing.T) {
)

expectedCountSumIntersectionType := cadence.NewIntersectionType(
nil,
[]cadence.Type{
hasSumInterfaceType,
hasCountInterfaceType,
Expand Down Expand Up @@ -6807,11 +6805,6 @@ func TestEncodeValueOfIntersectionType(t *testing.T) {
0xd8, ccf.CBORTagIntersectionType,
// array, 2 items follow
0x82,
// type
// null
0xf6,
// array, 2 items follow
0x82,
// tag
0xd8, ccf.CBORTagTypeRef,
// bytes, 1 byte follows
Expand Down Expand Up @@ -6882,7 +6875,6 @@ func TestEncodeValueOfIntersectionType(t *testing.T) {
)

countSumIntersectionType := cadence.NewIntersectionType(
statsType,
[]cadence.Type{
hasCountInterfaceType,
hasSumInterfaceType,
fxamacker marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -6909,7 +6901,6 @@ func TestEncodeValueOfIntersectionType(t *testing.T) {
)

expectedCountSumIntersectionType := cadence.NewIntersectionType(
expectedStatsType,
[]cadence.Type{
hasSumInterfaceType,
hasCountInterfaceType,
Expand Down Expand Up @@ -7028,13 +7019,6 @@ func TestEncodeValueOfIntersectionType(t *testing.T) {
0xd8, ccf.CBORTagIntersectionType,
// array, 2 items follow
0x82,
// type
// tag
0xd8, ccf.CBORTagTypeRef,
// bytes, 0 byte follows
0x40,
// array, 2 items follow
0x82,
// tag
0xd8, ccf.CBORTagTypeRef,
// bytes, 1 byte follows
Expand Down Expand Up @@ -9465,13 +9449,7 @@ func TestEncodeType(t *testing.T) {
t.Run("with static nil intersection type", func(t *testing.T) {
t.Parallel()

testEncodeAndDecode(
t,
cadence.TypeValue{
StaticType: &cadence.IntersectionType{
Types: []cadence.Type{},
},
},
encodedData :=
[]byte{
// language=json, format=json-cdc
// {"value":{"staticType":{"kind":"Intersection","type":"","types":[]}},"type":"Type"}
Expand All @@ -9490,62 +9468,44 @@ func TestEncodeType(t *testing.T) {
0x18, 0x29,
// tag
0xd8, ccf.CBORTagIntersectionTypeValue,
// array, 2 elements follow
0x82,
// null
0xf6,
// array, 0 element follows
0x80,
},
)
}

_, err := ccf.Decode(nil, encodedData)
require.Error(t, err)
assert.Equal(t, "ccf: failed to decode: unexpected empty intersection type", err.Error())
fxamacker marked this conversation as resolved.
Show resolved Hide resolved

})

t.Run("with static no intersection type", func(t *testing.T) {
t.Parallel()

testEncodeAndDecodeEx(
t,
cadence.TypeValue{
StaticType: &cadence.IntersectionType{
Types: []cadence.Type{},
Type: cadence.IntType{},
},
},
[]byte{
// language=json, format=json-cdc
// {"value":{"staticType":{"kind":"Intersection","typeID":"Int{String}","type":{"kind":"Int"},"types":[]}},"type":"Type"}
//
// language=edn, format=ccf
// 130([137(41), 191([185(4), []])])
//
// language=cbor, format=ccf
// tag
0xd8, ccf.CBORTagTypeAndValue,
// array, 2 elements follow
0x82,
// tag
0xd8, ccf.CBORTagSimpleType,
// Meta type ID (41)
0x18, 0x29,
// tag
0xd8, ccf.CBORTagIntersectionTypeValue,
// array, 2 elements follow
0x82,
// tag
0xd8, ccf.CBORTagSimpleTypeValue,
// Int type ID (4)
0x04,
// array, 0 element follows
0x80,
},
// Expected decoded IntersectionType doesn't have type ID.
cadence.TypeValue{
StaticType: &cadence.IntersectionType{
Types: []cadence.Type{},
Type: cadence.IntType{},
},
},
)
encodedData := []byte{
// language=json, format=json-cdc
// {"value":{"staticType":{"kind":"Intersection","typeID":"Int{String}","type":{"kind":"Int"},"types":[]}},"type":"Type"}
//
// language=edn, format=ccf
// 130([137(41), 191([185(4), []])])
//
// language=cbor, format=ccf
// tag
0xd8, ccf.CBORTagTypeAndValue,
// array, 2 elements follow
0x82,
// tag
0xd8, ccf.CBORTagSimpleType,
// Meta type ID (41)
0x18, 0x29,
// tag
0xd8, ccf.CBORTagIntersectionTypeValue,
// array, 0 element follows
0x80,
}

_, err := ccf.Decode(nil, encodedData)
require.Error(t, err)
assert.Equal(t, "ccf: failed to decode: unexpected empty intersection type", err.Error())
})

t.Run("with static intersection type", func(t *testing.T) {
Expand All @@ -9558,7 +9518,6 @@ func TestEncodeType(t *testing.T) {
Types: []cadence.Type{
cadence.StringType{},
},
Type: cadence.IntType{},
},
},
[]byte{
Expand All @@ -9579,12 +9538,6 @@ func TestEncodeType(t *testing.T) {
0x18, 0x29,
// tag
0xd8, ccf.CBORTagIntersectionTypeValue,
// array, 2 elements follow
0x82,
// tag
0xd8, ccf.CBORTagSimpleTypeValue,
// Int type ID (4)
0x04,
// array, 1 element follows
0x81,
// tag
Expand All @@ -9598,7 +9551,6 @@ func TestEncodeType(t *testing.T) {
Types: []cadence.Type{
cadence.StringType{},
},
Type: cadence.IntType{},
},
},
)
Expand All @@ -9616,7 +9568,6 @@ func TestEncodeType(t *testing.T) {
cadence.NewAnyStructType(),
cadence.StringType{},
},
Type: cadence.IntType{},
},
},
[]byte{
Expand All @@ -9637,12 +9588,6 @@ func TestEncodeType(t *testing.T) {
0x18, 0x29,
// tag
0xd8, ccf.CBORTagIntersectionTypeValue,
// array, 2 elements follow
0x82,
// tag
0xd8, ccf.CBORTagSimpleTypeValue,
// Int type ID (4)
0x04,
// array, 2 element follows
0x82,
// tag
Expand All @@ -9661,7 +9606,6 @@ func TestEncodeType(t *testing.T) {
cadence.StringType{},
cadence.NewAnyStructType(),
},
Type: cadence.IntType{},
},
},
)
Expand All @@ -9675,7 +9619,6 @@ func TestEncodeType(t *testing.T) {
t,
cadence.TypeValue{
StaticType: &cadence.IntersectionType{
Type: cadence.TheAnyStructType,
Types: []cadence.Type{
cadence.NewStructInterfaceType(
common.NewAddressLocation(nil, common.Address{0x01}, "TypeA"),
Expand Down Expand Up @@ -9716,12 +9659,6 @@ func TestEncodeType(t *testing.T) {
0x18, 0x29,
// tag
0xd8, ccf.CBORTagIntersectionTypeValue,
// array, 2 elements follow
0x82,
// tag
0xd8, ccf.CBORTagSimpleTypeValue,
// AnyStruct type ID (39)
0x18, 0x27,
// 3 sorted types
// array, 3 element follows
0x83,
Expand Down Expand Up @@ -9790,7 +9727,6 @@ func TestEncodeType(t *testing.T) {
// Expected decoded IntersectionType has sorted types and no type ID.
cadence.TypeValue{
StaticType: &cadence.IntersectionType{
Type: cadence.TheAnyStructType,
Types: []cadence.Type{
cadence.NewStructInterfaceType(
common.IdentifierLocation("LocationC"),
Expand Down Expand Up @@ -14439,7 +14375,7 @@ func TestEncodeValueOfIntersectedInterface(t *testing.T) {
}

struct MiddleStruct {
var field: AnyStruct{Interface}
var field: {Interface}
}

struct interface Interface {}
Expand Down Expand Up @@ -14468,7 +14404,7 @@ func TestEncodeValueOfIntersectedInterface(t *testing.T) {
[]cadence.Field{
{
Type: cadence.NewIntersectionType(
cadence.TheAnyStructType, []cadence.Type{interfaceType}),
[]cadence.Type{interfaceType}),
Identifier: "field",
},
},
Expand Down Expand Up @@ -14599,12 +14535,6 @@ func TestEncodeValueOfIntersectedInterface(t *testing.T) {
0x66, 0x69, 0x65, 0x6c, 0x64,
// tag
0xd8, ccf.CBORTagIntersectionType,
// array, 2 item follows
0x82,
// tag
0xd8, ccf.CBORTagSimpleType,
// AnyStruct type ID (39)
0x18, 0x27,
// array, 1 item follows
0x81,
// tag
Expand Down Expand Up @@ -14781,7 +14711,6 @@ func TestSortOptions(t *testing.T) {
)

countSumIntersectionType := cadence.NewIntersectionType(
nil,
[]cadence.Type{
hasCountInterfaceType,
hasSumInterfaceType,
Expand Down Expand Up @@ -14809,7 +14738,6 @@ func TestSortOptions(t *testing.T) {
)

expectedCountSumIntersectionType := cadence.NewIntersectionType(
nil,
[]cadence.Type{
hasCountInterfaceType,
hasSumInterfaceType,
Expand Down Expand Up @@ -14925,11 +14853,6 @@ func TestSortOptions(t *testing.T) {
0xd8, ccf.CBORTagIntersectionType,
// array, 2 items follow
0x82,
// type
// null
0xf6,
// array, 2 items follow
0x82,
// tag
0xd8, ccf.CBORTagTypeRef,
// bytes, 1 byte follows
Expand Down Expand Up @@ -15004,7 +14927,6 @@ func TestSortOptions(t *testing.T) {
)

expectedCountSumIntersectionType := cadence.NewIntersectionType(
nil,
[]cadence.Type{
hasCountInterfaceType,
hasSumInterfaceType,
Expand Down Expand Up @@ -15120,11 +15042,6 @@ func TestSortOptions(t *testing.T) {
0xd8, ccf.CBORTagIntersectionType,
// array, 2 items follow
0x82,
// type
// null
0xf6,
// array, 2 items follow
0x82,
// tag
0xd8, ccf.CBORTagTypeRef,
// bytes, 1 byte follows
Expand Down Expand Up @@ -15199,7 +15116,6 @@ func TestSortOptions(t *testing.T) {
)

expectedCountSumIntersectionType := cadence.NewIntersectionType(
nil,
[]cadence.Type{
hasSumInterfaceType,
hasCountInterfaceType,
Expand Down Expand Up @@ -15315,11 +15231,6 @@ func TestSortOptions(t *testing.T) {
0xd8, ccf.CBORTagIntersectionType,
// array, 2 items follow
0x82,
// type
// null
0xf6,
// array, 2 items follow
0x82,
// tag
0xd8, ccf.CBORTagTypeRef,
// bytes, 1 byte follows
Expand Down Expand Up @@ -15394,7 +15305,6 @@ func TestSortOptions(t *testing.T) {
)

expectedCountSumIntersectionType := cadence.NewIntersectionType(
nil,
[]cadence.Type{
hasSumInterfaceType,
hasCountInterfaceType,
Expand Down Expand Up @@ -15510,11 +15420,6 @@ func TestSortOptions(t *testing.T) {
0xd8, ccf.CBORTagIntersectionType,
// array, 2 items follow
0x82,
// type
// null
0xf6,
// array, 2 items follow
0x82,
// tag
0xd8, ccf.CBORTagTypeRef,
// bytes, 1 byte follows
Expand Down
Loading