Skip to content

Commit

Permalink
Use new API requiring *EntitlementSetAuthorization
Browse files Browse the repository at this point in the history
This commit updates code to use the new API which
uses pointer to EntitlementSetAuthorization.
  • Loading branch information
fxamacker committed Feb 28, 2024
1 parent e08df90 commit 4f184f6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
24 changes: 19 additions & 5 deletions encoding/ccf/ccf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
Expand Down Expand Up @@ -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"},
},
Expand All @@ -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"},
},
Expand Down Expand Up @@ -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"},
},
Expand Down Expand Up @@ -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"}
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions encoding/ccf/encode_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 4f184f6

Please sign in to comment.