From 4f184f60e6212cd2bf711121a61259eb5981a684 Mon Sep 17 00:00:00 2001 From: Faye Amacker <33205765+fxamacker@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:08:52 -0600 Subject: [PATCH] Use new API requiring *EntitlementSetAuthorization This commit updates code to use the new API which uses pointer to EntitlementSetAuthorization. --- encoding/ccf/ccf_test.go | 24 +++++++++++++++++++----- encoding/ccf/encode_type.go | 4 ++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/encoding/ccf/ccf_test.go b/encoding/ccf/ccf_test.go index 6cf1bd806a..cd3b97a32d 100644 --- a/encoding/ccf/ccf_test.go +++ b/encoding/ccf/ccf_test.go @@ -10209,7 +10209,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: &cadence.ReferenceType{ - Authorization: cadence.EntitlementSetAuthorization{ + Authorization: &cadence.EntitlementSetAuthorization{ Kind: cadence.Conjunction, Entitlements: []common.TypeID{"foo", "bar"}, }, @@ -10259,7 +10259,7 @@ func TestEncodeType(t *testing.T) { }, cadence.TypeValue{ StaticType: &cadence.ReferenceType{ - Authorization: cadence.EntitlementSetAuthorization{ + Authorization: &cadence.EntitlementSetAuthorization{ Kind: cadence.Conjunction, Entitlements: []common.TypeID{"bar", "foo"}, }, @@ -10277,7 +10277,7 @@ func TestEncodeType(t *testing.T) { t, cadence.TypeValue{ StaticType: &cadence.ReferenceType{ - Authorization: cadence.EntitlementSetAuthorization{ + Authorization: &cadence.EntitlementSetAuthorization{ Kind: cadence.Disjunction, Entitlements: []common.TypeID{"foo", "bar"}, }, @@ -10327,7 +10327,7 @@ func TestEncodeType(t *testing.T) { }, cadence.TypeValue{ StaticType: &cadence.ReferenceType{ - Authorization: cadence.EntitlementSetAuthorization{ + Authorization: &cadence.EntitlementSetAuthorization{ Kind: cadence.Disjunction, Entitlements: []common.TypeID{"bar", "foo"}, }, @@ -15774,6 +15774,20 @@ func TestSortEntitlementSet(t *testing.T) { ), )) + expectedVal := cadence.NewArray([]cadence.Value{ + cadence.String("a"), + cadence.String("b"), + }).WithType(cadence.NewVariableSizedArrayType( + cadence.NewReferenceType( + cadence.NewEntitlementSetAuthorization( + nil, + []common.TypeID{"foo", "bar"}, + cadence.Conjunction, + ), + cadence.StringType, + ), + )) + expectedCBOR := []byte{ // language=json, format=json-cdc // {"value":[{"value":"a","type":"String"},{"value":"b","type":"String"}],"type":"Array"} @@ -15835,7 +15849,7 @@ func TestSortEntitlementSet(t *testing.T) { // Decode value without enforcing sorting. decodedVal, err := ccf.Decode(nil, actualCBOR) require.NoError(t, err) - assert.Equal(t, val, decodedVal) + assert.Equal(t, expectedVal, decodedVal) // Decode value enforcing sorting of entitlement types should return error. _, err = enforceSortedEntitlementTypesDecMode.Decode(nil, actualCBOR) diff --git a/encoding/ccf/encode_type.go b/encoding/ccf/encode_type.go index 0ceb42ae33..16f405a977 100644 --- a/encoding/ccf/encode_type.go +++ b/encoding/ccf/encode_type.go @@ -413,7 +413,7 @@ func (e *Encoder) encodeAuthorization( case cadence.Unauthorized: return e.enc.EncodeNil() - case cadence.EntitlementSetAuthorization: + case *cadence.EntitlementSetAuthorization: var rawTagNum []byte if isType { rawTagNum = []byte{0xd8, CBORTagEntitlementSetAuthorizationAccessType} @@ -456,7 +456,7 @@ func (e *Encoder) encodeAuthorization( // entitlements: +[string] // ]) func (e *Encoder) encodeEntitlementSetAuthorizationWithRawTag( - auth cadence.EntitlementSetAuthorization, + auth *cadence.EntitlementSetAuthorization, rawTagNum []byte, ) error { // Encode CBOR tag number.