Skip to content

Instantly share code, notes, and snippets.

@SupunS
Created December 5, 2023 00:51
Show Gist options
  • Save SupunS/5d26a4319af2a4a5a69507b75d4a7ce4 to your computer and use it in GitHub Desktop.
Save SupunS/5d26a4319af2a4a5a69507b75d4a7ce4 to your computer and use it in GitHub Desktop.
commit ee46be92ede193a06c9123e2d37370467c878bd6
Merge: 787812ff3 b48fd6b85
Author: Supun Setunga <supun.setunga@gmail.com>
Date: Mon Dec 4 14:06:33 2023 -0800
Merge branch 'master' of https://github.com/onflow/cadence into supun/sc-sync-master
diff --git a/encoding/ccf/decode_type.go b/encoding/ccf/decode_type.go
remerge CONFLICT (content): Merge conflict in encoding/ccf/decode_type.go
index 8dd68597a..cd190c308 100644
--- a/encoding/ccf/decode_type.go
+++ b/encoding/ccf/decode_type.go
@@ -109,181 +109,8 @@ func (d *Decoder) decodeSimpleTypeID() (cadence.Type, error) {
return nil, err
}
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
ty := typeBySimpleTypeID(SimpleType(simpleTypeID))
if ty == nil {
-=======
- switch simpleTypeID {
- case TypeBool:
- return cadence.TheBoolType, nil
-
- case TypeString:
- return cadence.TheStringType, nil
-
- case TypeCharacter:
- return cadence.TheCharacterType, nil
-
- case TypeAddress:
- return cadence.TheAddressType, nil
-
- case TypeInt:
- return cadence.TheIntType, nil
-
- case TypeInt8:
- return cadence.TheInt8Type, nil
-
- case TypeInt16:
- return cadence.TheInt16Type, nil
-
- case TypeInt32:
- return cadence.TheInt32Type, nil
-
- case TypeInt64:
- return cadence.TheInt64Type, nil
-
- case TypeInt128:
- return cadence.TheInt128Type, nil
-
- case TypeInt256:
- return cadence.TheInt256Type, nil
-
- case TypeUInt:
- return cadence.TheUIntType, nil
-
- case TypeUInt8:
- return cadence.TheUInt8Type, nil
-
- case TypeUInt16:
- return cadence.TheUInt16Type, nil
-
- case TypeUInt32:
- return cadence.TheUInt32Type, nil
-
- case TypeUInt64:
- return cadence.TheUInt64Type, nil
-
- case TypeUInt128:
- return cadence.TheUInt128Type, nil
-
- case TypeUInt256:
- return cadence.TheUInt256Type, nil
-
- case TypeWord8:
- return cadence.TheWord8Type, nil
-
- case TypeWord16:
- return cadence.TheWord16Type, nil
-
- case TypeWord32:
- return cadence.TheWord32Type, nil
-
- case TypeWord64:
- return cadence.TheWord64Type, nil
-
- case TypeWord128:
- return cadence.TheWord128Type, nil
-
- case TypeWord256:
- return cadence.TheWord256Type, nil
-
- case TypeFix64:
- return cadence.TheFix64Type, nil
-
- case TypeUFix64:
- return cadence.TheUFix64Type, nil
-
- case TypePath:
- return cadence.ThePathType, nil
-
- case TypeCapabilityPath:
- return cadence.TheCapabilityPathType, nil
-
- case TypeStoragePath:
- return cadence.TheStoragePathType, nil
-
- case TypePublicPath:
- return cadence.ThePublicPathType, nil
-
- case TypePrivatePath:
- return cadence.ThePrivatePathType, nil
-
- case TypeAuthAccount:
- return cadence.TheAuthAccountType, nil
-
- case TypePublicAccount:
- return cadence.ThePublicAccountType, nil
-
- case TypeAuthAccountKeys:
- return cadence.TheAuthAccountKeysType, nil
-
- case TypePublicAccountKeys:
- return cadence.ThePublicAccountKeysType, nil
-
- case TypeAuthAccountContracts:
- return cadence.TheAuthAccountContractsType, nil
-
- case TypePublicAccountContracts:
- return cadence.ThePublicAccountContractsType, nil
-
- case TypeDeployedContract:
- return cadence.TheDeployedContractType, nil
-
- case TypeAccountKey:
- return cadence.TheAccountKeyType, nil
-
- case TypeBlock:
- return cadence.TheBlockType, nil
-
- case TypeAny:
- return cadence.TheAnyType, nil
-
- case TypeAnyStruct:
- return cadence.TheAnyStructType, nil
-
- case TypeHashableStruct:
- return cadence.TheHashableStructType, nil
-
- case TypeAnyResource:
- return cadence.TheAnyResourceType, nil
-
- case TypeMetaType:
- return cadence.TheMetaType, nil
-
- case TypeNever:
- return cadence.TheNeverType, nil
-
- case TypeNumber:
- return cadence.TheNumberType, nil
-
- case TypeSignedNumber:
- return cadence.TheSignedNumberType, nil
-
- case TypeInteger:
- return cadence.TheIntegerType, nil
-
- case TypeSignedInteger:
- return cadence.TheSignedIntegerType, nil
-
- case TypeFixedPoint:
- return cadence.TheFixedPointType, nil
-
- case TypeSignedFixedPoint:
- return cadence.TheSignedFixedPointType, nil
-
- case TypeBytes:
- return cadence.TheBytesType, nil
-
- case TypeVoid:
- return cadence.TheVoidType, nil
-
- case TypeAnyStructAttachmentType:
- return cadence.TheAnyStructAttachmentType, nil
-
- case TypeAnyResourceAttachmentType:
- return cadence.TheAnyResourceAttachmentType, nil
-
- default:
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
return nil, fmt.Errorf("unsupported encoded simple type ID %d", simpleTypeID)
}
diff --git a/encoding/ccf/simple_type_utils.go b/encoding/ccf/simple_type_utils.go
deleted file mode 100644
remerge CONFLICT (modify/delete): encoding/ccf/simple_type_utils.go deleted in 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface) and modified in b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42). Version b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42) of encoding/ccf/simple_type_utils.go left in tree.
index aec556449..000000000
--- a/encoding/ccf/simple_type_utils.go
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * Cadence - The resource-oriented smart contract programming language
- *
- * Copyright Dapper Labs, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package ccf
-
-import "github.com/onflow/cadence"
-
-// IMPORTANT:
-//
-// Don't change existing simple type IDs.
-//
-// When new simple cadence.Type is added,
-// - add new ID to the end of existing IDs,
-// - add new simple cadence.Type and its ID in simpleTypeIDByType()
-
-const ( // Cadence simple type IDs
- TypeBool = iota
- TypeString
- TypeCharacter
- TypeAddress
- TypeInt
- TypeInt8
- TypeInt16
- TypeInt32
- TypeInt64
- TypeInt128
- TypeInt256
- TypeUInt
- TypeUInt8
- TypeUInt16
- TypeUInt32
- TypeUInt64
- TypeUInt128
- TypeUInt256
- TypeWord8
- TypeWord16
- TypeWord32
- TypeWord64
- TypeFix64
- TypeUFix64
- TypePath
- TypeCapabilityPath
- TypeStoragePath
- TypePublicPath
- TypePrivatePath
- TypeAuthAccount
- TypePublicAccount
- TypeAuthAccountKeys
- TypePublicAccountKeys
- TypeAuthAccountContracts
- TypePublicAccountContracts
- TypeDeployedContract
- TypeAccountKey
- TypeBlock
- TypeAny
- TypeAnyStruct
- TypeAnyResource
- TypeMetaType
- TypeNever
- TypeNumber
- TypeSignedNumber
- TypeInteger
- TypeSignedInteger
- TypeFixedPoint
- TypeSignedFixedPoint
- TypeBytes
- TypeVoid
- TypeFunction
- TypeWord128
- TypeWord256
- TypeAnyStructAttachmentType
- TypeAnyResourceAttachmentType
- TypeHashableStruct
-)
-
-// NOTE: cadence.FunctionType isn't included in simpleTypeIDByType
-// because this function is used by both inline-type and type-value.
-// cadence.FunctionType needs to be handled differently when this
-// function is used by inline-type and type-value.
-func simpleTypeIDByType(typ cadence.Type) (uint64, bool) {
- switch typ.(type) {
- case cadence.AnyType:
- return TypeAny, true
-
- case cadence.AnyStructType:
- return TypeAnyStruct, true
-
- case cadence.HashableStructType:
- return TypeHashableStruct, true
-
- case cadence.AnyResourceType:
- return TypeAnyResource, true
-
- case cadence.AddressType:
- return TypeAddress, true
-
- case cadence.MetaType:
- return TypeMetaType, true
-
- case cadence.VoidType:
- return TypeVoid, true
-
- case cadence.NeverType:
- return TypeNever, true
-
- case cadence.BoolType:
- return TypeBool, true
-
- case cadence.StringType:
- return TypeString, true
-
- case cadence.CharacterType:
- return TypeCharacter, true
-
- case cadence.BytesType:
- return TypeBytes, true
-
- case cadence.NumberType:
- return TypeNumber, true
-
- case cadence.SignedNumberType:
- return TypeSignedNumber, true
-
- case cadence.IntegerType:
- return TypeInteger, true
-
- case cadence.SignedIntegerType:
- return TypeSignedInteger, true
-
- case cadence.FixedPointType:
- return TypeFixedPoint, true
-
- case cadence.SignedFixedPointType:
- return TypeSignedFixedPoint, true
-
- case cadence.IntType:
- return TypeInt, true
-
- case cadence.Int8Type:
- return TypeInt8, true
-
- case cadence.Int16Type:
- return TypeInt16, true
-
- case cadence.Int32Type:
- return TypeInt32, true
-
- case cadence.Int64Type:
- return TypeInt64, true
-
- case cadence.Int128Type:
- return TypeInt128, true
-
- case cadence.Int256Type:
- return TypeInt256, true
-
- case cadence.UIntType:
- return TypeUInt, true
-
- case cadence.UInt8Type:
- return TypeUInt8, true
-
- case cadence.UInt16Type:
- return TypeUInt16, true
-
- case cadence.UInt32Type:
- return TypeUInt32, true
-
- case cadence.UInt64Type:
- return TypeUInt64, true
-
- case cadence.UInt128Type:
- return TypeUInt128, true
-
- case cadence.UInt256Type:
- return TypeUInt256, true
-
- case cadence.Word8Type:
- return TypeWord8, true
-
- case cadence.Word16Type:
- return TypeWord16, true
-
- case cadence.Word32Type:
- return TypeWord32, true
-
- case cadence.Word64Type:
- return TypeWord64, true
-
- case cadence.Word128Type:
- return TypeWord128, true
-
- case cadence.Word256Type:
- return TypeWord256, true
-
- case cadence.Fix64Type:
- return TypeFix64, true
-
- case cadence.UFix64Type:
- return TypeUFix64, true
-
- case cadence.BlockType:
- return TypeBlock, true
-
- case cadence.PathType:
- return TypePath, true
-
- case cadence.CapabilityPathType:
- return TypeCapabilityPath, true
-
- case cadence.StoragePathType:
- return TypeStoragePath, true
-
- case cadence.PublicPathType:
- return TypePublicPath, true
-
- case cadence.PrivatePathType:
- return TypePrivatePath, true
-
- case cadence.AccountKeyType:
- return TypeAccountKey, true
-
- case cadence.AuthAccountContractsType:
- return TypeAuthAccountContracts, true
-
- case cadence.AuthAccountKeysType:
- return TypeAuthAccountKeys, true
-
- case cadence.AuthAccountType:
- return TypeAuthAccount, true
-
- case cadence.PublicAccountContractsType:
- return TypePublicAccountContracts, true
-
- case cadence.PublicAccountKeysType:
- return TypePublicAccountKeys, true
-
- case cadence.PublicAccountType:
- return TypePublicAccount, true
-
- case cadence.DeployedContractType:
- return TypeDeployedContract, true
-
- case cadence.AnyStructAttachmentType:
- return TypeAnyStructAttachmentType, true
-
- case cadence.AnyResourceAttachmentType:
- return TypeAnyResourceAttachmentType, true
- }
-
- return 0, false
-}
diff --git a/encoding/json/decode.go b/encoding/json/decode.go
remerge CONFLICT (content): Merge conflict in encoding/json/decode.go
index 6050e1b10..9f4fbfece 100644
--- a/encoding/json/decode.go
+++ b/encoding/json/decode.go
@@ -1276,121 +1276,6 @@ func (d *Decoder) decodeType(valueJSON any, results typeDecodingResults) cadence
d.decodeAuthorization(obj.Get(authorizationKey)),
d.decodeType(obj.Get(typeKey), results),
)
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
-=======
- case "Any":
- return cadence.TheAnyType
- case "AnyStruct":
- return cadence.TheAnyStructType
- case "HashableStruct":
- return cadence.TheHashableStructType
- case "AnyStructAttachment":
- return cadence.TheAnyStructAttachmentType
- case "AnyResource":
- return cadence.TheAnyResourceType
- case "AnyResourceAttachment":
- return cadence.TheAnyResourceAttachmentType
- case "Type":
- return cadence.TheMetaType
- case "Void":
- return cadence.TheVoidType
- case "Never":
- return cadence.TheNeverType
- case "Bool":
- return cadence.TheBoolType
- case "String":
- return cadence.TheStringType
- case "Character":
- return cadence.TheCharacterType
- case "Bytes":
- return cadence.TheBytesType
- case "Address":
- return cadence.TheAddressType
- case "Number":
- return cadence.TheNumberType
- case "SignedNumber":
- return cadence.TheSignedNumberType
- case "Integer":
- return cadence.TheIntegerType
- case "SignedInteger":
- return cadence.TheSignedIntegerType
- case "FixedPoint":
- return cadence.TheFixedPointType
- case "SignedFixedPoint":
- return cadence.TheSignedFixedPointType
- case "Int":
- return cadence.TheIntType
- case "Int8":
- return cadence.TheInt8Type
- case "Int16":
- return cadence.TheInt16Type
- case "Int32":
- return cadence.TheInt32Type
- case "Int64":
- return cadence.TheInt64Type
- case "Int128":
- return cadence.TheInt128Type
- case "Int256":
- return cadence.TheInt256Type
- case "UInt":
- return cadence.TheUIntType
- case "UInt8":
- return cadence.TheUInt8Type
- case "UInt16":
- return cadence.TheUInt16Type
- case "UInt32":
- return cadence.TheUInt32Type
- case "UInt64":
- return cadence.TheUInt64Type
- case "UInt128":
- return cadence.TheUInt128Type
- case "UInt256":
- return cadence.TheUInt256Type
- case "Word8":
- return cadence.TheWord8Type
- case "Word16":
- return cadence.TheWord16Type
- case "Word32":
- return cadence.TheWord32Type
- case "Word64":
- return cadence.TheWord64Type
- case "Word128":
- return cadence.TheWord128Type
- case "Word256":
- return cadence.TheWord256Type
- case "Fix64":
- return cadence.TheFix64Type
- case "UFix64":
- return cadence.TheUFix64Type
- case "Path":
- return cadence.ThePathType
- case "CapabilityPath":
- return cadence.TheCapabilityPathType
- case "StoragePath":
- return cadence.TheStoragePathType
- case "PublicPath":
- return cadence.ThePublicPathType
- case "PrivatePath":
- return cadence.ThePrivatePathType
- case "AuthAccount":
- return cadence.TheAuthAccountType
- case "PublicAccount":
- return cadence.ThePublicAccountType
- case "AuthAccount.Keys":
- return cadence.TheAuthAccountKeysType
- case "PublicAccount.Keys":
- return cadence.ThePublicAccountKeysType
- case "AuthAccount.Contracts":
- return cadence.TheAuthAccountContractsType
- case "PublicAccount.Contracts":
- return cadence.ThePublicAccountContractsType
- case "DeployedContract":
- return cadence.TheDeployedContractType
- case "AccountKey":
- return cadence.TheAccountKeyType
- case "Block":
- return cadence.TheBlockType
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
default:
simpleType, ok := simpleTypes[kindValue]
if ok {
diff --git a/encoding/json/encode.go b/encoding/json/encode.go
remerge CONFLICT (content): Merge conflict in encoding/json/encode.go
index 77ced57df..38c07d18b 100644
--- a/encoding/json/encode.go
+++ b/encoding/json/encode.go
@@ -765,66 +765,7 @@ func prepareType(typ cadence.Type, results typePreparationResults) jsonValue {
}
switch typ := typ.(type) {
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
case cadence.BytesType:
-=======
- case cadence.AnyType,
- cadence.AnyStructType,
- cadence.HashableStructType,
- cadence.AnyStructAttachmentType,
- cadence.AnyResourceType,
- cadence.AnyResourceAttachmentType,
- cadence.AddressType,
- cadence.MetaType,
- cadence.VoidType,
- cadence.NeverType,
- cadence.BoolType,
- cadence.StringType,
- cadence.CharacterType,
- cadence.BytesType,
- cadence.NumberType,
- cadence.SignedNumberType,
- cadence.IntegerType,
- cadence.SignedIntegerType,
- cadence.FixedPointType,
- cadence.SignedFixedPointType,
- cadence.IntType,
- cadence.Int8Type,
- cadence.Int16Type,
- cadence.Int32Type,
- cadence.Int64Type,
- cadence.Int128Type,
- cadence.Int256Type,
- cadence.UIntType,
- cadence.UInt8Type,
- cadence.UInt16Type,
- cadence.UInt32Type,
- cadence.UInt64Type,
- cadence.UInt128Type,
- cadence.UInt256Type,
- cadence.Word8Type,
- cadence.Word16Type,
- cadence.Word32Type,
- cadence.Word64Type,
- cadence.Word128Type,
- cadence.Word256Type,
- cadence.Fix64Type,
- cadence.UFix64Type,
- cadence.BlockType,
- cadence.PathType,
- cadence.CapabilityPathType,
- cadence.StoragePathType,
- cadence.PublicPathType,
- cadence.PrivatePathType,
- cadence.AccountKeyType,
- cadence.AuthAccountContractsType,
- cadence.AuthAccountKeysType,
- cadence.AuthAccountType,
- cadence.PublicAccountContractsType,
- cadence.PublicAccountKeysType,
- cadence.PublicAccountType,
- cadence.DeployedContractType:
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
return jsonSimpleType{
Kind: typ.ID(),
}
diff --git a/encoding/json/encoding_test.go b/encoding/json/encoding_test.go
remerge CONFLICT (content): Merge conflict in encoding/json/encoding_test.go
index 8c25fea47..46cca7db4 100644
--- a/encoding/json/encoding_test.go
+++ b/encoding/json/encoding_test.go
@@ -1698,65 +1698,8 @@ func TestEncodeSimpleTypes(t *testing.T) {
var tests []encodeTest
for _, ty := range []cadence.Type{
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
cadence.AnyType,
cadence.TheBytesType,
-=======
- cadence.AnyType{},
- cadence.AnyStructType{},
- cadence.HashableStructType{},
- cadence.AnyStructAttachmentType{},
- cadence.AnyResourceType{},
- cadence.AnyResourceAttachmentType{},
- cadence.MetaType{},
- cadence.VoidType{},
- cadence.NeverType{},
- cadence.BoolType{},
- cadence.StringType{},
- cadence.CharacterType{},
- cadence.BytesType{},
- cadence.AddressType{},
- cadence.SignedNumberType{},
- cadence.IntegerType{},
- cadence.SignedIntegerType{},
- cadence.FixedPointType{},
- cadence.IntType{},
- cadence.Int8Type{},
- cadence.Int16Type{},
- cadence.Int32Type{},
- cadence.Int64Type{},
- cadence.Int128Type{},
- cadence.Int256Type{},
- cadence.UIntType{},
- cadence.UInt8Type{},
- cadence.UInt16Type{},
- cadence.UInt32Type{},
- cadence.UInt64Type{},
- cadence.UInt128Type{},
- cadence.UInt256Type{},
- cadence.Word8Type{},
- cadence.Word16Type{},
- cadence.Word32Type{},
- cadence.Word64Type{},
- cadence.Word128Type{},
- cadence.Word256Type{},
- cadence.Fix64Type{},
- cadence.UFix64Type{},
- cadence.BlockType{},
- cadence.PathType{},
- cadence.CapabilityPathType{},
- cadence.StoragePathType{},
- cadence.PublicPathType{},
- cadence.PrivatePathType{},
- cadence.AccountKeyType{},
- cadence.AuthAccountContractsType{},
- cadence.AuthAccountKeysType{},
- cadence.AuthAccountType{},
- cadence.PublicAccountContractsType{},
- cadence.PublicAccountKeysType{},
- cadence.PublicAccountType{},
- cadence.DeployedContractType{},
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
} {
tests = append(tests, encodeTest{
name: fmt.Sprintf("with static %s", ty.ID()),
diff --git a/npm-packages/cadence-parser/package.json b/npm-packages/cadence-parser/package.json
remerge CONFLICT (content): Merge conflict in npm-packages/cadence-parser/package.json
index 8db826aee..1ffb0dc10 100644
--- a/npm-packages/cadence-parser/package.json
+++ b/npm-packages/cadence-parser/package.json
@@ -1,10 +1,6 @@
{
"name": "@onflow/cadence-parser",
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
"version": "1.0.0-preview.1",
-=======
- "version": "0.42.5",
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
"description": "The Cadence parser",
"homepage": "https://github.com/onflow/cadence",
"repository": {
diff --git a/runtime/ast/block.go b/runtime/ast/block.go
index 2b7092565..6ffb34c52 100644
--- a/runtime/ast/block.go
+++ b/runtime/ast/block.go
@@ -231,6 +231,7 @@ func (b *FunctionBlock) HasConditions() bool {
// Condition
type Condition interface {
+ Element
isCondition()
CodeElement() Element
Doc() prettier.Doc
@@ -244,6 +245,17 @@ type TestCondition struct {
Message Expression
}
+func (c TestCondition) ElementType() ElementType {
+ return ElementTypeUnknown
+}
+
+func (c TestCondition) Walk(walkChild func(Element)) {
+ walkChild(c.Test)
+ if c.Message != nil {
+ walkChild(c.Message)
+ }
+}
+
var _ Condition = TestCondition{}
func (c TestCondition) isCondition() {}
@@ -333,6 +345,14 @@ func (c *EmitCondition) MarshalJSON() ([]byte, error) {
})
}
+func (c *EmitCondition) ElementType() ElementType {
+ return (*EmitStatement)(c).ElementType()
+}
+
+func (c *EmitCondition) Walk(walkChild func(Element)) {
+ (*EmitStatement)(c).Walk(walkChild)
+}
+
// Conditions
type Conditions []Condition
@@ -376,9 +396,6 @@ func (c *Conditions) Walk(walkChild func(Element)) {
}
for _, condition := range *c {
- walkChild(condition.Test)
- if condition.Message != nil {
- walkChild(condition.Message)
- }
+ walkChild(condition)
}
}
diff --git a/runtime/contract_update_test.go b/runtime/contract_update_test.go
remerge CONFLICT (content): Merge conflict in runtime/contract_update_test.go
index 11ff9c772..22a8eacd4 100644
--- a/runtime/contract_update_test.go
+++ b/runtime/contract_update_test.go
@@ -214,7 +214,6 @@ func TestRuntimeContractUpdateWithDependencies(t *testing.T) {
require.NoError(t, err)
}
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
func TestRuntimeContractUpdateWithPrecedingIdentifiers(t *testing.T) {
t.Parallel()
@@ -295,10 +294,7 @@ func TestRuntimeContractUpdateWithPrecedingIdentifiers(t *testing.T) {
}
-func TestRuntimeInvalidContractRedeploy(t *testing.T) {
-=======
func TestRuntimeContractRedeployInSameTransaction(t *testing.T) {
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
t.Parallel()
@@ -326,16 +322,6 @@ func TestRuntimeContractRedeployInSameTransaction(t *testing.T) {
}
`)
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
- tx := []byte(`
- transaction(foo1: String, foo2: String) {
- prepare(signer: auth(Contracts) &Account) {
- signer.contracts.add(name: "Foo", code: foo1.utf8)
- signer.contracts.add(name: "Foo", code: foo2.utf8)
- }
- }
- `)
-=======
foo2 := []byte(`
access(all)
contract Foo {
@@ -354,137 +340,44 @@ func TestRuntimeContractRedeployInSameTransaction(t *testing.T) {
tx := []byte(`
transaction(foo1: String, foo2: String) {
- prepare(signer: AuthAccount) {
+ prepare(signer: auth(Contracts) &Account) {
signer.contracts.add(name: "Foo", code: foo1.utf8)
signer.contracts.add(name: "Foo", code: foo2.utf8)
}
}
`)
- runtime := newTestInterpreterRuntime()
- runtime.defaultConfig.AtreeValidationEnabled = false
-
- address := common.MustBytesToAddress([]byte{0x1})
-
- runtimeInterface := &testRuntimeInterface{
- storage: newTestLedger(nil, nil),
- getSigningAccounts: func() ([]Address, error) {
- return []Address{address}, nil
- },
- getAccountContractCode: func(location common.AddressLocation) ([]byte, error) {
- return nil, nil
- },
- resolveLocation: singleIdentifierLocationResolver(t),
- updateAccountContractCode: func(location common.AddressLocation, code []byte) error {
- // "delay"
- return nil
- },
- emitEvent: func(event cadence.Event) error {
- return nil
- },
- decodeArgument: func(b []byte, t cadence.Type) (value cadence.Value, err error) {
- return json.Decode(nil, b)
- },
- }
-
- nextTransactionLocation := newTransactionLocationGenerator()
-
- // Deploy
-
- err := runtime.ExecuteTransaction(
- Script{
- Source: tx,
- Arguments: encodeArgs([]cadence.Value{
- cadence.String(foo1),
- cadence.String(foo2),
- }),
- },
- Context{
- Interface: runtimeInterface,
- Location: nextTransactionLocation(),
- },
- )
-
- RequireError(t, err)
- require.ErrorContains(t, err, "cannot overwrite existing contract")
+ runtime := NewTestInterpreterRuntimeWithConfig(Config{
+ AtreeValidationEnabled: false,
})
- t.Run("add and update", func(t *testing.T) {
-
- foo1 := []byte(`
- access(all)
- contract Foo {
-
- access(all)
- resource R {
-
- access(all)
- var x: Int
-
- init() {
- self.x = 0
- }
- }
-
- access(all)
- fun createR(): @R {
- return <-create R()
- }
- }
- `)
-
- foo2 := []byte(`
- access(all)
- contract Foo {
-
- access(all)
- struct R {
- access(all)
- var x: Int
-
- init() {
- self.x = 0
- }
- }
- }
- `)
-
- tx := []byte(`
- transaction(foo1: String, foo2: String) {
- prepare(signer: AuthAccount) {
- signer.contracts.add(name: "Foo", code: foo1.utf8)
- signer.contracts.update__experimental(name: "Foo", code: foo2.utf8)
- }
- }
- `)
-
- runtime := newTestInterpreterRuntime()
- runtime.defaultConfig.AtreeValidationEnabled = false
-
address := common.MustBytesToAddress([]byte{0x1})
- runtimeInterface := &testRuntimeInterface{
- storage: newTestLedger(nil, nil),
- getSigningAccounts: func() ([]Address, error) {
+ var events []cadence.Event
+
+ runtimeInterface := &TestRuntimeInterface{
+ Storage: NewTestLedger(nil, nil),
+ OnGetSigningAccounts: func() ([]Address, error) {
return []Address{address}, nil
},
- getAccountContractCode: func(location common.AddressLocation) ([]byte, error) {
+ OnGetAccountContractCode: func(location common.AddressLocation) ([]byte, error) {
return nil, nil
},
- resolveLocation: singleIdentifierLocationResolver(t),
- updateAccountContractCode: func(location common.AddressLocation, code []byte) error {
+ OnResolveLocation: NewSingleIdentifierLocationResolver(t),
+ OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error {
// "delay"
return nil
},
- emitEvent: func(event cadence.Event) error {
+ OnEmitEvent: func(event cadence.Event) error {
+ events = append(events, event)
return nil
},
- decodeArgument: func(b []byte, t cadence.Type) (value cadence.Value, err error) {
+ OnDecodeArgument: func(b []byte, t cadence.Type) (value cadence.Value, err error) {
return json.Decode(nil, b)
},
}
- nextTransactionLocation := newTransactionLocationGenerator()
+ nextTransactionLocation := NewTransactionLocationGenerator()
// Deploy
@@ -503,7 +396,7 @@ func TestRuntimeContractRedeployInSameTransaction(t *testing.T) {
)
RequireError(t, err)
- require.ErrorContains(t, err, "cannot update non-existing contract")
+ require.ErrorContains(t, err, "cannot overwrite existing contract")
})
}
@@ -529,33 +422,34 @@ func TestRuntimeNestedContractDeployment(t *testing.T) {
}
`)
- runtime := newTestInterpreterRuntime()
- runtime.defaultConfig.AtreeValidationEnabled = false
+ runtime := NewTestInterpreterRuntimeWithConfig(Config{
+ AtreeValidationEnabled: false,
+ })
address := common.MustBytesToAddress([]byte{0x1})
- runtimeInterface := &testRuntimeInterface{
- storage: newTestLedger(nil, nil),
- getSigningAccounts: func() ([]Address, error) {
+ runtimeInterface := &TestRuntimeInterface{
+ Storage: NewTestLedger(nil, nil),
+ OnGetSigningAccounts: func() ([]Address, error) {
return []Address{address}, nil
},
- getAccountContractCode: func(location common.AddressLocation) ([]byte, error) {
+ OnGetAccountContractCode: func(location common.AddressLocation) ([]byte, error) {
return nil, nil
},
- resolveLocation: singleIdentifierLocationResolver(t),
- updateAccountContractCode: func(location common.AddressLocation, code []byte) error {
+ OnResolveLocation: NewSingleIdentifierLocationResolver(t),
+ OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error {
// "delay"
return nil
},
- emitEvent: func(event cadence.Event) error {
+ OnEmitEvent: func(event cadence.Event) error {
return nil
},
- decodeArgument: func(b []byte, t cadence.Type) (value cadence.Value, err error) {
+ OnDecodeArgument: func(b []byte, t cadence.Type) (value cadence.Value, err error) {
return json.Decode(nil, b)
},
}
- nextTransactionLocation := newTransactionLocationGenerator()
+ nextTransactionLocation := NewTransactionLocationGenerator()
// Deploy
@@ -593,33 +487,34 @@ func TestRuntimeNestedContractDeployment(t *testing.T) {
}
`)
- runtime := newTestInterpreterRuntime()
- runtime.defaultConfig.AtreeValidationEnabled = false
+ runtime := NewTestInterpreterRuntimeWithConfig(Config{
+ AtreeValidationEnabled: false,
+ })
address := common.MustBytesToAddress([]byte{0x1})
- runtimeInterface := &testRuntimeInterface{
- storage: newTestLedger(nil, nil),
- getSigningAccounts: func() ([]Address, error) {
+ runtimeInterface := &TestRuntimeInterface{
+ Storage: NewTestLedger(nil, nil),
+ OnGetSigningAccounts: func() ([]Address, error) {
return []Address{address}, nil
},
- getAccountContractCode: func(location common.AddressLocation) ([]byte, error) {
+ OnGetAccountContractCode: func(location common.AddressLocation) ([]byte, error) {
return nil, nil
},
- resolveLocation: singleIdentifierLocationResolver(t),
- updateAccountContractCode: func(location common.AddressLocation, code []byte) error {
+ OnResolveLocation: NewSingleIdentifierLocationResolver(t),
+ OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error {
// "delay"
return nil
},
- emitEvent: func(event cadence.Event) error {
+ OnEmitEvent: func(event cadence.Event) error {
return nil
},
- decodeArgument: func(b []byte, t cadence.Type) (value cadence.Value, err error) {
+ OnDecodeArgument: func(b []byte, t cadence.Type) (value cadence.Value, err error) {
return json.Decode(nil, b)
},
}
- nextTransactionLocation := newTransactionLocationGenerator()
+ nextTransactionLocation := NewTransactionLocationGenerator()
// Deploy
@@ -666,34 +561,35 @@ func TestRuntimeNestedContractDeployment(t *testing.T) {
}
`)
- runtime := newTestInterpreterRuntime()
- runtime.defaultConfig.AtreeValidationEnabled = false
+ runtime := NewTestInterpreterRuntimeWithConfig(Config{
+ AtreeValidationEnabled: false,
+ })
address := common.MustBytesToAddress([]byte{0x1})
- runtimeInterface := &testRuntimeInterface{
- storage: newTestLedger(nil, nil),
- getSigningAccounts: func() ([]Address, error) {
+ runtimeInterface := &TestRuntimeInterface{
+ Storage: NewTestLedger(nil, nil),
+ OnGetSigningAccounts: func() ([]Address, error) {
return []Address{address}, nil
},
- getAccountContractCode: func(location common.AddressLocation) ([]byte, error) {
+ OnGetAccountContractCode: func(location common.AddressLocation) ([]byte, error) {
return deployedContract, nil
},
- resolveLocation: singleIdentifierLocationResolver(t),
- updateAccountContractCode: func(location common.AddressLocation, code []byte) error {
+ OnResolveLocation: NewSingleIdentifierLocationResolver(t),
+ OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error {
// "delay"
deployedContract = code
return nil
},
- emitEvent: func(event cadence.Event) error {
+ OnEmitEvent: func(event cadence.Event) error {
return nil
},
- decodeArgument: func(b []byte, t cadence.Type) (value cadence.Value, err error) {
+ OnDecodeArgument: func(b []byte, t cadence.Type) (value cadence.Value, err error) {
return json.Decode(nil, b)
},
}
- nextTransactionLocation := newTransactionLocationGenerator()
+ nextTransactionLocation := NewTransactionLocationGenerator()
// Update
@@ -723,7 +619,6 @@ func TestRuntimeContractRedeploymentInSeparateTransactions(t *testing.T) {
access(all) resource Bar {}
}
`)
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
runtime := NewTestInterpreterRuntimeWithConfig(Config{
AtreeValidationEnabled: false,
@@ -738,28 +633,15 @@ func TestRuntimeContractRedeploymentInSeparateTransactions(t *testing.T) {
OnGetSigningAccounts: func() ([]Address, error) {
return []Address{address}, nil
},
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
OnGetAccountContractCode: func(location common.AddressLocation) ([]byte, error) {
- return nil, nil
- },
- OnResolveLocation: NewSingleIdentifierLocationResolver(t),
- OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error {
- // "delay"
- return nil
- },
- OnEmitEvent: func(event cadence.Event) error {
- events = append(events, event)
-=======
- getAccountContractCode: func(location common.AddressLocation) ([]byte, error) {
return contractCode, nil
},
- resolveLocation: singleIdentifierLocationResolver(t),
- updateAccountContractCode: func(_ common.AddressLocation, code []byte) error {
+ OnResolveLocation: NewSingleIdentifierLocationResolver(t),
+ OnUpdateAccountContractCode: func(_ common.AddressLocation, code []byte) error {
contractCode = code
return nil
},
- emitEvent: func(event cadence.Event) error {
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
+ OnEmitEvent: func(event cadence.Event) error {
return nil
},
OnDecodeArgument: func(b []byte, t cadence.Type) (value cadence.Value, err error) {
@@ -781,12 +663,7 @@ func TestRuntimeContractRedeploymentInSeparateTransactions(t *testing.T) {
Location: nextTransactionLocation(),
},
)
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
-
- RequireError(t, err)
-=======
require.NoError(t, err)
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
// Update
// Updating in a separate transaction is OK, and should not abort.
diff --git a/runtime/convertTypes.go b/runtime/convertTypes.go
remerge CONFLICT (content): Merge conflict in runtime/convertTypes.go
index a2874d7a1..de43807c3 100644
--- a/runtime/convertTypes.go
+++ b/runtime/convertTypes.go
@@ -132,6 +132,8 @@ func ExportMeteredType(
return cadence.AnyType
case sema.AnyStructType:
return cadence.AnyStructType
+ case sema.HashableStructType:
+ return cadence.TheHashableStructType
case sema.AnyResourceType:
return cadence.AnyResourceType
case sema.AnyStructAttachmentType:
@@ -256,120 +258,7 @@ func ExportMeteredType(
return exportCapabilityType(gauge, t, results)
}
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
panic(fmt.Sprintf("cannot export type %s", t))
-=======
- switch t {
- case sema.NumberType:
- return cadence.TheNumberType
- case sema.SignedNumberType:
- return cadence.TheSignedNumberType
- case sema.IntegerType:
- return cadence.TheIntegerType
- case sema.SignedIntegerType:
- return cadence.TheSignedIntegerType
- case sema.FixedPointType:
- return cadence.TheFixedPointType
- case sema.SignedFixedPointType:
- return cadence.TheSignedFixedPointType
- case sema.IntType:
- return cadence.TheIntType
- case sema.Int8Type:
- return cadence.TheInt8Type
- case sema.Int16Type:
- return cadence.TheInt16Type
- case sema.Int32Type:
- return cadence.TheInt32Type
- case sema.Int64Type:
- return cadence.TheInt64Type
- case sema.Int128Type:
- return cadence.TheInt128Type
- case sema.Int256Type:
- return cadence.TheInt256Type
- case sema.UIntType:
- return cadence.TheUIntType
- case sema.UInt8Type:
- return cadence.TheUInt8Type
- case sema.UInt16Type:
- return cadence.TheUInt16Type
- case sema.UInt32Type:
- return cadence.TheUInt32Type
- case sema.UInt64Type:
- return cadence.TheUInt64Type
- case sema.UInt128Type:
- return cadence.TheUInt128Type
- case sema.UInt256Type:
- return cadence.TheUInt256Type
- case sema.Word8Type:
- return cadence.TheWord8Type
- case sema.Word16Type:
- return cadence.TheWord16Type
- case sema.Word32Type:
- return cadence.TheWord32Type
- case sema.Word64Type:
- return cadence.TheWord64Type
- case sema.Word128Type:
- return cadence.TheWord128Type
- case sema.Word256Type:
- return cadence.TheWord256Type
- case sema.Fix64Type:
- return cadence.TheFix64Type
- case sema.UFix64Type:
- return cadence.TheUFix64Type
- case sema.PathType:
- return cadence.ThePathType
- case sema.StoragePathType:
- return cadence.TheStoragePathType
- case sema.PrivatePathType:
- return cadence.ThePrivatePathType
- case sema.PublicPathType:
- return cadence.ThePublicPathType
- case sema.CapabilityPathType:
- return cadence.TheCapabilityPathType
- case sema.NeverType:
- return cadence.TheNeverType
- case sema.VoidType:
- return cadence.TheVoidType
- case sema.InvalidType:
- return nil
- case sema.MetaType:
- return cadence.TheMetaType
- case sema.BoolType:
- return cadence.TheBoolType
- case sema.CharacterType:
- return cadence.TheCharacterType
- case sema.AnyType:
- return cadence.TheAnyType
- case sema.AnyStructType:
- return cadence.TheAnyStructType
- case sema.HashableStructType:
- return cadence.TheHashableStructType
- case sema.AnyResourceType:
- return cadence.TheAnyResourceType
- case sema.BlockType:
- return cadence.TheBlockType
- case sema.StringType:
- return cadence.TheStringType
- case sema.AccountKeyType:
- return cadence.TheAccountKeyType
- case sema.PublicAccountContractsType:
- return cadence.ThePublicAccountContractsType
- case sema.AuthAccountContractsType:
- return cadence.TheAuthAccountContractsType
- case sema.PublicAccountKeysType:
- return cadence.ThePublicAccountKeysType
- case sema.AuthAccountKeysType:
- return cadence.TheAuthAccountKeysType
- case sema.PublicAccountType:
- return cadence.ThePublicAccountType
- case sema.AuthAccountType:
- return cadence.TheAuthAccountType
- case sema.DeployedContractType:
- return cadence.TheDeployedContractType
- }
-
- panic(fmt.Sprintf("cannot export type of type %T", t))
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
}()
results[typeID] = result
@@ -769,23 +658,15 @@ func importAuthorization(memoryGauge common.MemoryGauge, auth cadence.Authorizat
func ImportType(memoryGauge common.MemoryGauge, t cadence.Type) interpreter.StaticType {
switch t := t.(type) {
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
case cadence.PrimitiveType:
return interpreter.NewPrimitiveStaticType(
memoryGauge,
interpreter.PrimitiveStaticType(t),
)
-=======
- case cadence.AnyType:
- return interpreter.NewPrimitiveStaticType(memoryGauge, interpreter.PrimitiveStaticTypeAny)
- case cadence.AnyStructType:
- return interpreter.NewPrimitiveStaticType(memoryGauge, interpreter.PrimitiveStaticTypeAnyStruct)
case cadence.HashableStructType:
return interpreter.NewPrimitiveStaticType(memoryGauge, interpreter.PrimitiveStaticTypeHashableStruct)
- case cadence.AnyResourceType:
- return interpreter.NewPrimitiveStaticType(memoryGauge, interpreter.PrimitiveStaticTypeAnyResource)
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
+
case *cadence.OptionalType:
return interpreter.NewOptionalStaticType(
memoryGauge,
diff --git a/runtime/convertValues_test.go b/runtime/convertValues_test.go
remerge CONFLICT (content): Merge conflict in runtime/convertValues_test.go
index 8954e71a0..a86bcaedf 100644
--- a/runtime/convertValues_test.go
+++ b/runtime/convertValues_test.go
@@ -227,7 +227,7 @@ func TestRuntimeExportValue(t *testing.T) {
return interpreter.NewArrayValue(
inter,
interpreter.EmptyLocationRange,
- interpreter.VariableSizedStaticType{
+ &interpreter.VariableSizedStaticType{
Type: interpreter.PrimitiveStaticTypeHashableStruct,
},
common.ZeroAddress,
@@ -239,7 +239,7 @@ func TestRuntimeExportValue(t *testing.T) {
cadence.NewInt(42),
cadence.String("foo"),
}).WithType(&cadence.VariableSizedArrayType{
- ElementType: cadence.HashableStructType{},
+ ElementType: cadence.HashableStructType,
}),
},
{
@@ -927,7 +927,7 @@ func TestRuntimeImportRuntimeType(t *testing.T) {
},
{
label: "HashableStruct",
- actual: cadence.HashableStructType{},
+ actual: cadence.HashableStructType,
expected: interpreter.PrimitiveStaticTypeHashableStruct,
},
{
@@ -2809,7 +2809,7 @@ func TestRuntimeComplexStructArgumentPassing(t *testing.T) {
},
{
Identifier: "k",
- Type: cadence.HashableStructType{},
+ Type: cadence.HashableStructType,
},
},
},
@@ -2870,7 +2870,6 @@ func TestRuntimeComplexStructArgumentPassing(t *testing.T) {
return arg
}
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
access(all) struct Foo {
access(all) var a: String?
access(all) var b: {String: String}
@@ -2882,20 +2881,7 @@ func TestRuntimeComplexStructArgumentPassing(t *testing.T) {
access(all) var h: PublicPath
access(all) var i: PrivatePath
access(all) var j: AnyStruct
-=======
- pub struct Foo {
- pub var a: String?
- pub var b: {String: String}
- pub var c: [String]
- pub var d: [String; 2]
- pub var e: Address
- pub var f: Bool
- pub var g: StoragePath
- pub var h: PublicPath
- pub var i: PrivatePath
- pub var j: AnyStruct
- pub var k: HashableStruct
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
+ access(all) var k: HashableStruct
init() {
self.a = "Hello"
@@ -3030,8 +3016,7 @@ func TestRuntimeComplexStructWithAnyStructFields(t *testing.T) {
actual, err := executeTestScript(t, script, complexStructValue)
require.NoError(t, err)
- expected := complexStructValue
- assert.Equal(t, expected, actual)
+ assert.Equal(t, complexStructValue, actual)
}
func TestRuntimeComplexStructWithHashableStructFields(t *testing.T) {
@@ -3047,32 +3032,32 @@ func TestRuntimeComplexStructWithHashableStructFields(t *testing.T) {
{
Identifier: "a",
Type: &cadence.OptionalType{
- Type: cadence.HashableStructType{},
+ Type: cadence.HashableStructType,
},
},
{
Identifier: "b",
Type: &cadence.DictionaryType{
- KeyType: cadence.StringType{},
- ElementType: cadence.HashableStructType{},
+ KeyType: cadence.StringType,
+ ElementType: cadence.HashableStructType,
},
},
{
Identifier: "c",
Type: &cadence.VariableSizedArrayType{
- ElementType: cadence.HashableStructType{},
+ ElementType: cadence.HashableStructType,
},
},
{
Identifier: "d",
Type: &cadence.ConstantSizedArrayType{
- ElementType: cadence.HashableStructType{},
+ ElementType: cadence.HashableStructType,
Size: 2,
},
},
{
Identifier: "e",
- Type: cadence.HashableStructType{},
+ Type: cadence.HashableStructType,
},
},
},
@@ -3085,20 +3070,20 @@ func TestRuntimeComplexStructWithHashableStructFields(t *testing.T) {
Value: cadence.String("Doe"),
},
}).WithType(&cadence.DictionaryType{
- KeyType: cadence.StringType{},
- ElementType: cadence.HashableStructType{},
+ KeyType: cadence.StringType,
+ ElementType: cadence.HashableStructType,
}),
cadence.NewArray([]cadence.Value{
cadence.String("foo"),
cadence.String("bar"),
}).WithType(&cadence.VariableSizedArrayType{
- ElementType: cadence.HashableStructType{},
+ ElementType: cadence.HashableStructType,
}),
cadence.NewArray([]cadence.Value{
cadence.String("foo"),
cadence.String("bar"),
}).WithType(&cadence.ConstantSizedArrayType{
- ElementType: cadence.HashableStructType{},
+ ElementType: cadence.HashableStructType,
Size: 2,
}),
cadence.Path{
@@ -3139,7 +3124,7 @@ func TestRuntimeComplexStructWithHashableStructFields(t *testing.T) {
actual, err := executeTestScript(t, script, complexStructValue)
require.NoError(t, err)
- expected := cadence.ValueWithCachedTypeID(complexStructValue)
+ expected := complexStructValue
assert.Equal(t, expected, actual)
}
@@ -3895,14 +3880,6 @@ func TestRuntimeImportExportDictionaryValue(t *testing.T) {
t.Run("import dictionary with heterogeneous keys", func(t *testing.T) {
t.Parallel()
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
- script :=
- `access(all) fun main(arg: Foo) {
- }
-
- access(all) struct Foo {
- access(all) var a: AnyStruct
-=======
dictionaryWithHeterogenousKeys := cadence.NewDictionary([]cadence.KeyValuePair{
{
Key: cadence.String("foo"),
@@ -3914,8 +3891,7 @@ func TestRuntimeImportExportDictionaryValue(t *testing.T) {
},
})
- inter := newTestInterpreter(t)
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
+ inter := NewTestInterpreter(t)
actual, err := ImportValue(
inter,
@@ -3926,28 +3902,15 @@ func TestRuntimeImportExportDictionaryValue(t *testing.T) {
)
require.NoError(t, err)
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
- // Struct with nested malformed dictionary value
- malformedStruct := cadence.Struct{
- StructType: &cadence.StructType{
- Location: common.ScriptLocation{},
- QualifiedIdentifier: "Foo",
- Fields: []cadence.Field{
- {
- Identifier: "a",
- Type: cadence.AnyStructType,
- },
-=======
AssertValuesEqual(
t,
inter,
interpreter.NewDictionaryValue(
inter,
interpreter.EmptyLocationRange,
- interpreter.DictionaryStaticType{
+ &interpreter.DictionaryStaticType{
KeyType: interpreter.PrimitiveStaticTypeHashableStruct,
ValueType: interpreter.PrimitiveStaticTypeString,
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
},
interpreter.NewUnmeteredStringValue("foo"),
diff --git a/runtime/interpreter/interpreter.go b/runtime/interpreter/interpreter.go
remerge CONFLICT (content): Merge conflict in runtime/interpreter/interpreter.go
index a375db11e..172a313ef 100644
--- a/runtime/interpreter/interpreter.go
+++ b/runtime/interpreter/interpreter.go
@@ -3338,45 +3338,7 @@ func init() {
sema.DictionaryTypeFunctionName,
NewUnmeteredHostFunctionValue(
sema.DictionaryTypeFunctionType,
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
dictionaryTypeFunction,
-=======
- func(invocation Invocation) Value {
- keyTypeValue, ok := invocation.Arguments[0].(TypeValue)
- if !ok {
- panic(errors.NewUnreachableError())
- }
-
- valueTypeValue, ok := invocation.Arguments[1].(TypeValue)
- if !ok {
- panic(errors.NewUnreachableError())
- }
-
- keyType := keyTypeValue.Type
- valueType := valueTypeValue.Type
-
- // if the given key is not a valid dictionary key, it wouldn't make sense to create this type
- if keyType == nil ||
- !sema.IsSubType(
- invocation.Interpreter.MustConvertStaticToSemaType(keyType),
- sema.HashableStructType,
- ) {
- return Nil
- }
-
- return NewSomeValueNonCopying(
- invocation.Interpreter,
- NewTypeValue(
- invocation.Interpreter,
- NewDictionaryStaticType(
- invocation.Interpreter,
- keyType,
- valueType,
- ),
- ),
- )
- },
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
))
defineBaseValue(
@@ -3441,7 +3403,10 @@ func dictionaryTypeFunction(invocation Invocation) Value {
// if the given key is not a valid dictionary key, it wouldn't make sense to create this type
if keyType == nil ||
- !sema.IsValidDictionaryKeyType(invocation.Interpreter.MustConvertStaticToSemaType(keyType)) {
+ !sema.IsSubType(
+ invocation.Interpreter.MustConvertStaticToSemaType(keyType),
+ sema.HashableStructType,
+ ) {
return Nil
}
diff --git a/runtime/interpreter/primitivestatictype.go b/runtime/interpreter/primitivestatictype.go
remerge CONFLICT (content): Merge conflict in runtime/interpreter/primitivestatictype.go
index 73c93e419..bbc0517ba 100644
--- a/runtime/interpreter/primitivestatictype.go
+++ b/runtime/interpreter/primitivestatictype.go
@@ -79,15 +79,10 @@ const (
PrimitiveStaticTypeCharacter
PrimitiveStaticTypeMetaType
PrimitiveStaticTypeBlock
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
PrimitiveStaticTypeAnyResourceAttachment
PrimitiveStaticTypeAnyStructAttachment
-=======
PrimitiveStaticTypeHashableStruct
_
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
- _
- _
_
_
@@ -270,12 +265,9 @@ func (t PrimitiveStaticType) elementSize() uint {
PrimitiveStaticTypeAnyStruct,
PrimitiveStaticTypeAnyResource,
PrimitiveStaticTypeAny,
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
PrimitiveStaticTypeAnyStructAttachment,
- PrimitiveStaticTypeAnyResourceAttachment:
-=======
+ PrimitiveStaticTypeAnyResourceAttachment,
PrimitiveStaticTypeHashableStruct:
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
return UnknownElementSize
case PrimitiveStaticTypeVoid:
diff --git a/runtime/interpreter/primitivestatictype_string.go b/runtime/interpreter/primitivestatictype_string.go
remerge CONFLICT (content): Merge conflict in runtime/interpreter/primitivestatictype_string.go
index 192d70711..d789ff9e6 100644
--- a/runtime/interpreter/primitivestatictype_string.go
+++ b/runtime/interpreter/primitivestatictype_string.go
@@ -20,12 +20,9 @@ func _() {
_ = x[PrimitiveStaticTypeCharacter-9]
_ = x[PrimitiveStaticTypeMetaType-10]
_ = x[PrimitiveStaticTypeBlock-11]
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
_ = x[PrimitiveStaticTypeAnyResourceAttachment-12]
_ = x[PrimitiveStaticTypeAnyStructAttachment-13]
-=======
- _ = x[PrimitiveStaticTypeHashableStruct-12]
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
+ _ = x[PrimitiveStaticTypeHashableStruct-14]
_ = x[PrimitiveStaticTypeNumber-18]
_ = x[PrimitiveStaticTypeSignedNumber-19]
_ = x[PrimitiveStaticTypeInteger-24]
@@ -117,11 +114,7 @@ func _() {
_ = x[PrimitiveStaticType_Count-152]
}
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
const _PrimitiveStaticType_name = "UnknownVoidAnyNeverAnyStructAnyResourceBoolAddressStringCharacterMetaTypeBlockAnyResourceAttachmentAnyStructAttachmentNumberSignedNumberIntegerSignedIntegerFixedPointSignedFixedPointIntInt8Int16Int32Int64Int128Int256UIntUInt8UInt16UInt32UInt64UInt128UInt256Word8Word16Word32Word64Word128Word256Fix64UFix64PathCapabilityStoragePathCapabilityPathPublicPathPrivatePathAuthAccountPublicAccountDeployedContractAuthAccountContractsPublicAccountContractsAuthAccountKeysPublicAccountKeysAccountKeyAuthAccountInboxStorageCapabilityControllerAccountCapabilityControllerAuthAccountStorageCapabilitiesAuthAccountAccountCapabilitiesAuthAccountCapabilitiesPublicAccountCapabilitiesAccountAccount_ContractsAccount_KeysAccount_InboxAccount_StorageCapabilitiesAccount_AccountCapabilitiesAccount_CapabilitiesAccount_StorageMutateInsertRemoveIdentityStorageSaveValueLoadValueCopyValueBorrowValueContractsAddContractUpdateContractRemoveContractKeysAddKeyRevokeKeyInboxPublishInboxCapabilityUnpublishInboxCapabilityClaimInboxCapabilityCapabilitiesStorageCapabilitiesAccountCapabilitiesPublishCapabilityUnpublishCapabilityGetStorageCapabilityControllerIssueStorageCapabilityControllerGetAccountCapabilityControllerIssueAccountCapabilityControllerCapabilitiesMappingAccountMapping_Count"
-=======
-const _PrimitiveStaticType_name = "UnknownVoidAnyNeverAnyStructAnyResourceBoolAddressStringCharacterMetaTypeBlockHashableStructNumberSignedNumberIntegerSignedIntegerFixedPointSignedFixedPointIntInt8Int16Int32Int64Int128Int256UIntUInt8UInt16UInt32UInt64UInt128UInt256Word8Word16Word32Word64Word128Word256Fix64UFix64PathCapabilityStoragePathCapabilityPathPublicPathPrivatePathAuthAccountPublicAccountDeployedContractAuthAccountContractsPublicAccountContractsAuthAccountKeysPublicAccountKeysAccountKeyAuthAccountInboxStorageCapabilityControllerAccountCapabilityControllerAuthAccountStorageCapabilitiesAuthAccountAccountCapabilitiesAuthAccountCapabilitiesPublicAccountCapabilities_Count"
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
var _PrimitiveStaticType_map = map[PrimitiveStaticType]string{
0: _PrimitiveStaticType_name[0:7],
@@ -136,7 +129,6 @@ var _PrimitiveStaticType_map = map[PrimitiveStaticType]string{
9: _PrimitiveStaticType_name[56:65],
10: _PrimitiveStaticType_name[65:73],
11: _PrimitiveStaticType_name[73:78],
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
12: _PrimitiveStaticType_name[78:99],
13: _PrimitiveStaticType_name[99:118],
18: _PrimitiveStaticType_name[118:124],
@@ -228,59 +220,6 @@ var _PrimitiveStaticType_map = map[PrimitiveStaticType]string{
150: _PrimitiveStaticType_name[1224:1243],
151: _PrimitiveStaticType_name[1243:1257],
152: _PrimitiveStaticType_name[1257:1263],
-=======
- 12: _PrimitiveStaticType_name[78:92],
- 18: _PrimitiveStaticType_name[92:98],
- 19: _PrimitiveStaticType_name[98:110],
- 24: _PrimitiveStaticType_name[110:117],
- 25: _PrimitiveStaticType_name[117:130],
- 30: _PrimitiveStaticType_name[130:140],
- 31: _PrimitiveStaticType_name[140:156],
- 36: _PrimitiveStaticType_name[156:159],
- 37: _PrimitiveStaticType_name[159:163],
- 38: _PrimitiveStaticType_name[163:168],
- 39: _PrimitiveStaticType_name[168:173],
- 40: _PrimitiveStaticType_name[173:178],
- 41: _PrimitiveStaticType_name[178:184],
- 42: _PrimitiveStaticType_name[184:190],
- 44: _PrimitiveStaticType_name[190:194],
- 45: _PrimitiveStaticType_name[194:199],
- 46: _PrimitiveStaticType_name[199:205],
- 47: _PrimitiveStaticType_name[205:211],
- 48: _PrimitiveStaticType_name[211:217],
- 49: _PrimitiveStaticType_name[217:224],
- 50: _PrimitiveStaticType_name[224:231],
- 53: _PrimitiveStaticType_name[231:236],
- 54: _PrimitiveStaticType_name[236:242],
- 55: _PrimitiveStaticType_name[242:248],
- 56: _PrimitiveStaticType_name[248:254],
- 57: _PrimitiveStaticType_name[254:261],
- 58: _PrimitiveStaticType_name[261:268],
- 64: _PrimitiveStaticType_name[268:273],
- 72: _PrimitiveStaticType_name[273:279],
- 76: _PrimitiveStaticType_name[279:283],
- 77: _PrimitiveStaticType_name[283:293],
- 78: _PrimitiveStaticType_name[293:304],
- 79: _PrimitiveStaticType_name[304:318],
- 80: _PrimitiveStaticType_name[318:328],
- 81: _PrimitiveStaticType_name[328:339],
- 90: _PrimitiveStaticType_name[339:350],
- 91: _PrimitiveStaticType_name[350:363],
- 92: _PrimitiveStaticType_name[363:379],
- 93: _PrimitiveStaticType_name[379:399],
- 94: _PrimitiveStaticType_name[399:421],
- 95: _PrimitiveStaticType_name[421:436],
- 96: _PrimitiveStaticType_name[436:453],
- 97: _PrimitiveStaticType_name[453:463],
- 98: _PrimitiveStaticType_name[463:479],
- 99: _PrimitiveStaticType_name[479:506],
- 100: _PrimitiveStaticType_name[506:533],
- 101: _PrimitiveStaticType_name[533:563],
- 102: _PrimitiveStaticType_name[563:593],
- 103: _PrimitiveStaticType_name[593:616],
- 104: _PrimitiveStaticType_name[616:641],
- 105: _PrimitiveStaticType_name[641:647],
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
}
func (i PrimitiveStaticType) String() string {
diff --git a/runtime/interpreter/value.go b/runtime/interpreter/value.go
remerge CONFLICT (content): Merge conflict in runtime/interpreter/value.go
index 7ecd40702..d9f785ded 100644
--- a/runtime/interpreter/value.go
+++ b/runtime/interpreter/value.go
@@ -17291,27 +17291,10 @@ func (v *CompositeValue) Transfer(
config := interpreter.SharedState.Config
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
- v.checkInvalidatedResourceUse(interpreter, locationRange)
-
- interpreter.ReportComputation(
- common.ComputationKindTransferCompositeValue,
- 1,
- )
-=======
// Should be checked before accessing `v.dictionary`.
- if config.InvalidatedResourceValidationEnabled {
- v.checkInvalidatedResourceUse(locationRange)
- }
-
- baseUse, elementOverhead, dataUse, metaDataUse := common.NewCompositeMemoryUsages(v.dictionary.Count(), 0)
- common.UseMemory(interpreter, baseUse)
- common.UseMemory(interpreter, elementOverhead)
- common.UseMemory(interpreter, dataUse)
- common.UseMemory(interpreter, metaDataUse)
+ v.checkInvalidatedResourceUse(interpreter, locationRange)
interpreter.ReportComputation(common.ComputationKindTransferCompositeValue, 1)
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
if config.TracingEnabled {
startTime := time.Now()
diff --git a/runtime/literal_test.go b/runtime/literal_test.go
remerge CONFLICT (content): Merge conflict in runtime/literal_test.go
index e3f8f32a4..1fe645037 100644
--- a/runtime/literal_test.go
+++ b/runtime/literal_test.go
@@ -153,7 +153,7 @@ func TestRuntimeParseLiteral(t *testing.T) {
)
require.NoError(t, err)
require.Equal(t,
- cadence.NewArray([]cadence.Value{}).WithType(cadence.NewVariableSizedArrayType(cadence.BoolType{})),
+ cadence.NewArray([]cadence.Value{}).WithType(cadence.NewVariableSizedArrayType(cadence.BoolType)),
value,
)
})
@@ -168,7 +168,7 @@ func TestRuntimeParseLiteral(t *testing.T) {
require.Equal(t,
cadence.NewArray([]cadence.Value{
cadence.NewBool(true),
- }).WithType(cadence.NewVariableSizedArrayType(cadence.BoolType{})),
+ }).WithType(cadence.NewVariableSizedArrayType(cadence.BoolType)),
value,
)
})
@@ -194,7 +194,7 @@ func TestRuntimeParseLiteral(t *testing.T) {
require.Equal(t,
cadence.NewArray(
[]cadence.Value{},
- ).WithType(cadence.NewConstantSizedArrayType(0, cadence.BoolType{})),
+ ).WithType(cadence.NewConstantSizedArrayType(0, cadence.BoolType)),
value,
)
@@ -203,19 +203,14 @@ func TestRuntimeParseLiteral(t *testing.T) {
t.Run("ConstantSizedArray, one element", func(t *testing.T) {
value, err := ParseLiteral(
`[true]`,
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
- &sema.ConstantSizedType{Type: sema.BoolType},
- NewTestInterpreter(t),
-=======
&sema.ConstantSizedType{Type: sema.BoolType, Size: 1},
- newTestInterpreter(t),
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
+ NewTestInterpreter(t),
)
require.NoError(t, err)
require.Equal(t,
cadence.NewArray([]cadence.Value{
cadence.NewBool(true),
- }).WithType(cadence.NewConstantSizedArrayType(1, cadence.BoolType{})),
+ }).WithType(cadence.NewConstantSizedArrayType(1, cadence.BoolType)),
value,
)
})
@@ -242,7 +237,7 @@ func TestRuntimeParseLiteral(t *testing.T) {
)
require.NoError(t, err)
require.Equal(t,
- cadence.NewDictionary([]cadence.KeyValuePair{}).WithType(cadence.NewDictionaryType(cadence.StringType{}, cadence.BoolType{})),
+ cadence.NewDictionary([]cadence.KeyValuePair{}).WithType(cadence.NewDictionaryType(cadence.StringType, cadence.BoolType)),
value,
)
})
@@ -263,7 +258,7 @@ func TestRuntimeParseLiteral(t *testing.T) {
Key: cadence.String("hello"),
Value: cadence.NewBool(true),
},
- }).WithType(cadence.NewDictionaryType(cadence.StringType{}, cadence.BoolType{})),
+ }).WithType(cadence.NewDictionaryType(cadence.StringType, cadence.BoolType)),
value,
)
})
diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go
remerge CONFLICT (content): Merge conflict in runtime/runtime_test.go
index c6aaca58e..79fa003bf 100644
--- a/runtime/runtime_test.go
+++ b/runtime/runtime_test.go
@@ -2539,45 +2539,31 @@ func TestRuntimeTransaction_CreateAccount(t *testing.T) {
script := []byte(`
transaction {
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
prepare(signer: auth(Storage) &Account) {
- Account(payer: signer)
-=======
- prepare(signer: AuthAccount) {
// Important: Perform a write which will be pending until the end of the transaction,
// but should be (temporarily) committed when the AuthAccount constructor is called
signer.save(42, to: /storage/answer)
- AuthAccount(payer: signer)
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
+ Account(payer: signer)
}
}
`)
var events []cadence.Event
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
- runtimeInterface := &TestRuntimeInterface{
- Storage: NewTestLedger(nil, nil),
- OnGetSigningAccounts: func() ([]Address, error) {
- return []Address{{42}}, nil
- },
- OnCreateAccount: func(payer Address) (address Address, err error) {
-=======
var performedWrite bool
onWrite := func(owner, key, value []byte) {
performedWrite = true
}
- runtimeInterface := &testRuntimeInterface{
- storage: newTestLedger(nil, onWrite),
- getSigningAccounts: func() ([]Address, error) {
+ runtimeInterface := &TestRuntimeInterface{
+ Storage: NewTestLedger(nil, onWrite),
+ OnGetSigningAccounts: func() ([]Address, error) {
return []Address{{42}}, nil
},
- createAccount: func(payer Address) (address Address, err error) {
+ OnCreateAccount: func(payer Address) (address Address, err error) {
// Check that pending writes were committed before
assert.True(t, performedWrite)
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
return Address{42}, nil
},
OnEmitEvent: func(event cadence.Event) error {
@@ -7921,30 +7907,30 @@ func TestRuntimeInvalidatedResourceUse(t *testing.T) {
))
victim := []byte(`
- access(all) contract VictimContract {
- access(all) resource Vault {
+ pub contract VictimContract {
+ pub resource Vault {
// Balance of a user's Vault
// we use unsigned fixed point numbers for balances
// because they can represent decimals and do not allow negative values
- access(all) var balance: UFix64
+ pub var balance: UFix64
init(balance: UFix64) {
self.balance = balance
}
- access(all) fun withdraw(amount: UFix64): @Vault {
+ pub fun withdraw(amount: UFix64): @Vault {
self.balance = self.balance - amount
return <-create Vault(balance: amount)
}
- access(all) fun deposit(from: @Vault) {
+ pub fun deposit(from: @Vault) {
self.balance = self.balance + from.balance
destroy from
}
}
- access(all) fun faucet(): @VictimContract.Vault {
+ pub fun faucet(): @VictimContract.Vault {
return <- create VictimContract.Vault(balance: 5.0)
}
}
@@ -8007,17 +7993,16 @@ func TestRuntimeInvalidatedResourceUse(t *testing.T) {
)
RequireError(t, err)
- require.ErrorAs(t, err, &interpreter.InvalidatedResourceReferenceError{})
+ var destroyedResourceErr interpreter.DestroyedResourceError
+ require.ErrorAs(t, err, &destroyedResourceErr)
}
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
-=======
func TestRuntimeInvalidatedResourceUse2(t *testing.T) {
t.Parallel()
- runtime := newTestInterpreterRuntime()
+ runtime := NewTestInterpreterRuntime()
signerAccount := common.MustBytesToAddress([]byte{0x1})
@@ -8026,29 +8011,29 @@ func TestRuntimeInvalidatedResourceUse2(t *testing.T) {
accountCodes := map[Location][]byte{}
var events []cadence.Event
- runtimeInterface := &testRuntimeInterface{
- getCode: func(location Location) (bytes []byte, err error) {
+ runtimeInterface := &TestRuntimeInterface{
+ OnGetCode: func(location Location) (bytes []byte, err error) {
return accountCodes[location], nil
},
- storage: newTestLedger(nil, nil),
- getSigningAccounts: func() ([]Address, error) {
+ Storage: NewTestLedger(nil, nil),
+ OnGetSigningAccounts: func() ([]Address, error) {
return signers, nil
},
- resolveLocation: singleIdentifierLocationResolver(t),
- getAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
+ OnResolveLocation: NewSingleIdentifierLocationResolver(t),
+ OnGetAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
return accountCodes[location], nil
},
- updateAccountContractCode: func(location common.AddressLocation, code []byte) (err error) {
+ OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) (err error) {
accountCodes[location] = code
return nil
},
- emitEvent: func(event cadence.Event) error {
+ OnEmitEvent: func(event cadence.Event) error {
events = append(events, event)
return nil
},
}
- nextTransactionLocation := newTransactionLocationGenerator()
+ nextTransactionLocation := NewTransactionLocationGenerator()
attacker := []byte(fmt.Sprintf(`
import VictimContract from %s
@@ -8129,30 +8114,30 @@ func TestRuntimeInvalidatedResourceUse2(t *testing.T) {
))
victim := []byte(`
- pub contract VictimContract {
- pub resource Vault {
+ access(all) contract VictimContract {
+ access(all) resource Vault {
// Balance of a user's Vault
// we use unsigned fixed point numbers for balances
// because they can represent decimals and do not allow negative values
- pub var balance: UFix64
+ access(all) var balance: UFix64
init(balance: UFix64) {
self.balance = balance
}
- pub fun withdraw(amount: UFix64): @Vault {
+ access(all) fun withdraw(amount: UFix64): @Vault {
self.balance = self.balance - amount
return <-create Vault(balance: amount)
}
- pub fun deposit(from: @Vault) {
+ access(all) fun deposit(from: @Vault) {
self.balance = self.balance + from.balance
destroy from
}
}
- pub fun faucet(): @VictimContract.Vault {
+ access(all) fun faucet(): @VictimContract.Vault {
return <- create VictimContract.Vault(balance: 5.0)
}
}
@@ -8213,235 +8198,12 @@ func TestRuntimeInvalidatedResourceUse2(t *testing.T) {
Location: nextTransactionLocation(),
},
)
-
- RequireError(t, err)
-
- var destroyedResourceErr interpreter.DestroyedResourceError
- require.ErrorAs(t, err, &destroyedResourceErr)
-}
-
-func TestRuntimeInvalidRecursiveTransferViaVariableDeclaration(t *testing.T) {
-
- t.Parallel()
-
- runtime := newTestInterpreterRuntime()
- runtime.defaultConfig.AtreeValidationEnabled = false
-
- address := common.MustBytesToAddress([]byte{0x1})
-
- contract := []byte(`
- pub contract Test{
-
- pub resource Holder{
-
- pub var vaults: @[AnyResource]
-
- init(_ vaults: @[AnyResource]){
- self.vaults <- vaults
- }
-
- pub fun x(): @[AnyResource] {
- var x <- self.vaults <- [<-Test.dummy()]
- return <-x
- }
-
- destroy() {
- var t <- self.vaults[0] <- self.vaults // here is the problem
- destroy t
- Test.account.save(<- self.x(), to: /storage/x42)
- }
- }
-
- pub fun createHolder(_ vaults: @[AnyResource]): @Holder {
- return <- create Holder(<-vaults)
- }
-
- pub resource Dummy {}
-
- pub fun dummy(): @Dummy {
- return <- create Dummy()
- }
- }
- `)
-
- tx := []byte(`
- import Test from 0x1
-
- transaction {
-
- prepare(acct: AuthAccount) {
- var holder <- Test.createHolder(<-[<-Test.dummy(), <-Test.dummy()])
- destroy holder
- }
- }
- `)
-
- deploy := DeploymentTransaction("Test", contract)
-
- var accountCode []byte
- var events []cadence.Event
-
- runtimeInterface := &testRuntimeInterface{
- getCode: func(_ Location) (bytes []byte, err error) {
- return accountCode, nil
- },
- storage: newTestLedger(nil, nil),
- getSigningAccounts: func() ([]Address, error) {
- return []Address{address}, nil
- },
- resolveLocation: singleIdentifierLocationResolver(t),
- getAccountContractCode: func(_ common.AddressLocation) (code []byte, err error) {
- return accountCode, nil
- },
- updateAccountContractCode: func(_ common.AddressLocation, code []byte) error {
- accountCode = code
- return nil
- },
- emitEvent: func(event cadence.Event) error {
- events = append(events, event)
- return nil
- },
- }
-
- nextTransactionLocation := newTransactionLocationGenerator()
-
- // Deploy
-
- err := runtime.ExecuteTransaction(
- Script{
- Source: deploy,
- },
- Context{
- Interface: runtimeInterface,
- Location: nextTransactionLocation(),
- },
- )
- require.NoError(t, err)
-
- // Test
-
- err = runtime.ExecuteTransaction(
- Script{
- Source: tx,
- },
- Context{
- Interface: runtimeInterface,
- Location: nextTransactionLocation(),
- },
- )
RequireError(t, err)
- require.ErrorAs(t, err, &interpreter.RecursiveTransferError{})
-}
-
-func TestRuntimeInvalidRecursiveTransferViaFunctionArgument(t *testing.T) {
-
- t.Parallel()
-
- runtime := newTestInterpreterRuntime()
- runtime.defaultConfig.AtreeValidationEnabled = false
-
- address := common.MustBytesToAddress([]byte{0x1})
-
- contract := []byte(`
- pub contract Test{
-
- pub resource Holder {
-
- pub var vaults: @[AnyResource]
-
- init(_ vaults: @[AnyResource]) {
- self.vaults <- vaults
- }
-
- destroy() {
- self.vaults.append(<-self.vaults)
- }
- }
-
- pub fun createHolder(_ vaults: @[AnyResource]): @Holder {
- return <- create Holder(<-vaults)
- }
-
- pub resource Dummy {}
-
- pub fun dummy(): @Dummy {
- return <- create Dummy()
- }
- }
- `)
-
- tx := []byte(`
- import Test from 0x1
-
- transaction {
-
- prepare(acct: AuthAccount) {
- var holder <- Test.createHolder(<-[<-Test.dummy(), <-Test.dummy()])
- destroy holder
- }
- }
- `)
-
- deploy := DeploymentTransaction("Test", contract)
-
- var accountCode []byte
- var events []cadence.Event
-
- runtimeInterface := &testRuntimeInterface{
- getCode: func(_ Location) (bytes []byte, err error) {
- return accountCode, nil
- },
- storage: newTestLedger(nil, nil),
- getSigningAccounts: func() ([]Address, error) {
- return []Address{address}, nil
- },
- resolveLocation: singleIdentifierLocationResolver(t),
- getAccountContractCode: func(_ common.AddressLocation) (code []byte, err error) {
- return accountCode, nil
- },
- updateAccountContractCode: func(_ common.AddressLocation, code []byte) error {
- accountCode = code
- return nil
- },
- emitEvent: func(event cadence.Event) error {
- events = append(events, event)
- return nil
- },
- }
-
- nextTransactionLocation := newTransactionLocationGenerator()
-
- // Deploy
-
- err := runtime.ExecuteTransaction(
- Script{
- Source: deploy,
- },
- Context{
- Interface: runtimeInterface,
- Location: nextTransactionLocation(),
- },
- )
- require.NoError(t, err)
-
- // Test
-
- err = runtime.ExecuteTransaction(
- Script{
- Source: tx,
- },
- Context{
- Interface: runtimeInterface,
- Location: nextTransactionLocation(),
- },
- )
- RequireError(t, err)
+ require.ErrorAs(t, err, &interpreter.InvalidatedResourceReferenceError{})
- require.ErrorAs(t, err, &interpreter.RecursiveTransferError{})
}
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
func TestRuntimeOptionalReferenceAttack(t *testing.T) {
t.Parallel()
@@ -9334,7 +9096,7 @@ func TestRuntimeNestedResourceMoveInDestructor(t *testing.T) {
t.Parallel()
- runtime := newTestInterpreterRuntime()
+ runtime := NewTestInterpreterRuntime()
signerAccount := common.MustBytesToAddress([]byte{0x1})
@@ -9342,28 +9104,28 @@ func TestRuntimeNestedResourceMoveInDestructor(t *testing.T) {
accountCodes := map[Location][]byte{}
- runtimeInterface := &testRuntimeInterface{
- getCode: func(location Location) (bytes []byte, err error) {
+ runtimeInterface := &TestRuntimeInterface{
+ OnGetCode: func(location Location) (bytes []byte, err error) {
return accountCodes[location], nil
},
- storage: newTestLedger(nil, nil),
- getSigningAccounts: func() ([]Address, error) {
+ Storage: NewTestLedger(nil, nil),
+ OnGetSigningAccounts: func() ([]Address, error) {
return signers, nil
},
- resolveLocation: singleIdentifierLocationResolver(t),
- getAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
+ OnResolveLocation: NewSingleIdentifierLocationResolver(t),
+ OnGetAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
return accountCodes[location], nil
},
- updateAccountContractCode: func(location common.AddressLocation, code []byte) (err error) {
+ OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) (err error) {
accountCodes[location] = code
return nil
},
- emitEvent: func(event cadence.Event) error {
+ OnEmitEvent: func(event cadence.Event) error {
return nil
},
}
- nextTransactionLocation := newTransactionLocationGenerator()
+ nextTransactionLocation := NewTransactionLocationGenerator()
attacker := []byte(fmt.Sprintf(`
import Bar from %[1]s
@@ -9519,7 +9281,7 @@ func TestRuntimeNestedResourceMoveWithSecondTransferInDestructor(t *testing.T) {
t.Parallel()
- runtime := newTestInterpreterRuntime()
+ runtime := NewTestInterpreterRuntime()
signerAccount := common.MustBytesToAddress([]byte{0x1})
@@ -9527,28 +9289,28 @@ func TestRuntimeNestedResourceMoveWithSecondTransferInDestructor(t *testing.T) {
accountCodes := map[Location][]byte{}
- runtimeInterface := &testRuntimeInterface{
- getCode: func(location Location) (bytes []byte, err error) {
+ runtimeInterface := &TestRuntimeInterface{
+ OnGetCode: func(location Location) (bytes []byte, err error) {
return accountCodes[location], nil
},
- storage: newTestLedger(nil, nil),
- getSigningAccounts: func() ([]Address, error) {
+ Storage: NewTestLedger(nil, nil),
+ OnGetSigningAccounts: func() ([]Address, error) {
return signers, nil
},
- resolveLocation: singleIdentifierLocationResolver(t),
- getAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
+ OnResolveLocation: NewSingleIdentifierLocationResolver(t),
+ OnGetAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
return accountCodes[location], nil
},
- updateAccountContractCode: func(location common.AddressLocation, code []byte) (err error) {
+ OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) (err error) {
accountCodes[location] = code
return nil
},
- emitEvent: func(event cadence.Event) error {
+ OnEmitEvent: func(event cadence.Event) error {
return nil
},
}
- nextTransactionLocation := newTransactionLocationGenerator()
+ nextTransactionLocation := NewTransactionLocationGenerator()
attacker := []byte(fmt.Sprintf(`
import Bar from %[1]s
@@ -9706,7 +9468,7 @@ func TestRuntimeNestedResourceMoveInTransaction(t *testing.T) {
t.Parallel()
- runtime := newTestInterpreterRuntime()
+ runtime := NewTestInterpreterRuntime()
signerAccount := common.MustBytesToAddress([]byte{0x1})
@@ -9714,31 +9476,28 @@ func TestRuntimeNestedResourceMoveInTransaction(t *testing.T) {
accountCodes := map[Location][]byte{}
- runtimeInterface := &testRuntimeInterface{
- getCode: func(location Location) (bytes []byte, err error) {
+ runtimeInterface := &TestRuntimeInterface{
+ OnGetCode: func(location Location) (bytes []byte, err error) {
return accountCodes[location], nil
},
- storage: newTestLedger(nil, nil),
- getSigningAccounts: func() ([]Address, error) {
+ Storage: NewTestLedger(nil, nil),
+ OnGetSigningAccounts: func() ([]Address, error) {
return signers, nil
},
- resolveLocation: singleIdentifierLocationResolver(t),
- getAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
+ OnResolveLocation: NewSingleIdentifierLocationResolver(t),
+ OnGetAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
return accountCodes[location], nil
},
- updateAccountContractCode: func(location common.AddressLocation, code []byte) (err error) {
+ OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) (err error) {
accountCodes[location] = code
return nil
},
- emitEvent: func(event cadence.Event) error {
+ OnEmitEvent: func(event cadence.Event) error {
return nil
},
- log: func(s string) {
- fmt.Println(s)
- },
}
- nextTransactionLocation := newTransactionLocationGenerator()
+ nextTransactionLocation := NewTransactionLocationGenerator()
foo := []byte(`
pub contract Foo {
@@ -9802,7 +9561,7 @@ func TestRuntimePreconditionDuplication(t *testing.T) {
t.Parallel()
- runtime := newTestInterpreterRuntime()
+ runtime := NewTestInterpreterRuntime()
signerAccount := common.MustBytesToAddress([]byte{0x1})
@@ -9810,28 +9569,28 @@ func TestRuntimePreconditionDuplication(t *testing.T) {
accountCodes := map[Location][]byte{}
- runtimeInterface := &testRuntimeInterface{
- getCode: func(location Location) (bytes []byte, err error) {
+ runtimeInterface := &TestRuntimeInterface{
+ OnGetCode: func(location Location) (bytes []byte, err error) {
return accountCodes[location], nil
},
- storage: newTestLedger(nil, nil),
- getSigningAccounts: func() ([]Address, error) {
+ Storage: NewTestLedger(nil, nil),
+ OnGetSigningAccounts: func() ([]Address, error) {
return signers, nil
},
- resolveLocation: singleIdentifierLocationResolver(t),
- getAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
+ OnResolveLocation: NewSingleIdentifierLocationResolver(t),
+ OnGetAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
return accountCodes[location], nil
},
- updateAccountContractCode: func(location common.AddressLocation, code []byte) (err error) {
+ OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) (err error) {
accountCodes[location] = code
return nil
},
- emitEvent: func(event cadence.Event) error {
+ OnEmitEvent: func(event cadence.Event) error {
return nil
},
}
- nextTransactionLocation := newTransactionLocationGenerator()
+ nextTransactionLocation := NewTransactionLocationGenerator()
attacker := []byte(fmt.Sprintf(`
import Bar from %[1]s
@@ -9995,7 +9754,7 @@ func TestRuntimeIfLetElseBranchConfusion(t *testing.T) {
t.Parallel()
- runtime := newTestInterpreterRuntime()
+ runtime := NewTestInterpreterRuntime()
signerAccount := common.MustBytesToAddress([]byte{0x1})
@@ -10003,31 +9762,28 @@ func TestRuntimeIfLetElseBranchConfusion(t *testing.T) {
accountCodes := map[Location][]byte{}
- runtimeInterface := &testRuntimeInterface{
- getCode: func(location Location) (bytes []byte, err error) {
+ runtimeInterface := &TestRuntimeInterface{
+ OnGetCode: func(location Location) (bytes []byte, err error) {
return accountCodes[location], nil
},
- storage: newTestLedger(nil, nil),
- getSigningAccounts: func() ([]Address, error) {
+ Storage: NewTestLedger(nil, nil),
+ OnGetSigningAccounts: func() ([]Address, error) {
return signers, nil
},
- resolveLocation: singleIdentifierLocationResolver(t),
- getAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
+ OnResolveLocation: NewSingleIdentifierLocationResolver(t),
+ OnGetAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
return accountCodes[location], nil
},
- updateAccountContractCode: func(location common.AddressLocation, code []byte) (err error) {
+ OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) (err error) {
accountCodes[location] = code
return nil
},
- emitEvent: func(event cadence.Event) error {
+ OnEmitEvent: func(event cadence.Event) error {
return nil
},
- log: func(s string) {
- fmt.Println(s)
- },
}
- nextTransactionLocation := newTransactionLocationGenerator()
+ nextTransactionLocation := NewTransactionLocationGenerator()
attacker := []byte(fmt.Sprintf(`
import Bar from %[1]s
@@ -10152,7 +9908,6 @@ func TestRuntimeIfLetElseBranchConfusion(t *testing.T) {
var flow <- vault.withdraw(amount: 42.0)
var doubled <- Foo.doubler(<-flow)
- log(doubled.balance)
destroy doubled
}
}`,
diff --git a/runtime/sema/check_assignment.go b/runtime/sema/check_assignment.go
remerge CONFLICT (content): Merge conflict in runtime/sema/check_assignment.go
index df83f0559..eaaf16ee9 100644
--- a/runtime/sema/check_assignment.go
+++ b/runtime/sema/check_assignment.go
@@ -112,9 +112,8 @@ func (checker *Checker) checkAssignment(
ResourceInvalidationKindMoveDefinite,
)
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
checker.recordReferenceCreation(target, value)
-=======
+
// Track nested resource moves.
// Even though this is needed only for second value transfers, it is added here because:
// 1) The second value transfers are checked as assignments,
@@ -126,7 +125,6 @@ func (checker *Checker) checkAssignment(
if valueIsResource {
checker.elaborateNestedResourceMoveExpression(value)
}
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
return
}
diff --git a/runtime/sema/check_member_expression.go b/runtime/sema/check_member_expression.go
remerge CONFLICT (content): Merge conflict in runtime/sema/check_member_expression.go
index 200cf594c..5e6b12265 100644
--- a/runtime/sema/check_member_expression.go
+++ b/runtime/sema/check_member_expression.go
@@ -276,48 +276,7 @@ func (checker *Checker) visitMember(expression *ast.MemberExpression, isAssignme
)
}
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
return
-=======
- if checker.PositionInfo != nil {
- checker.PositionInfo.recordMemberOccurrence(
- accessedType,
- identifier,
- identifierStartPosition,
- identifierEndPosition,
- )
- }
-
- // Check access and report if inaccessible
-
- if !checker.isReadableMember(member) {
- checker.report(
- &InvalidAccessError{
- Name: member.Identifier.Identifier,
- RestrictingAccess: member.Access,
- DeclarationKind: member.DeclarationKind,
- Range: ast.NewRangeFromPositioned(checker.memoryGauge, expression),
- },
- )
- }
-
- // Check that the member access is not to a function of resource type
- // outside of an invocation of it.
- //
- // This would result in a bound method for a resource, which is invalid.
-
- if !checker.inInvocation &&
- member.DeclarationKind == common.DeclarationKindFunction &&
- !accessedType.IsInvalidType() &&
- accessedType.IsResourceType() {
-
- checker.report(
- &ResourceMethodBindingError{
- Range: ast.NewRangeFromPositioned(checker.memoryGauge, expression),
- },
- )
- }
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
}
if checker.PositionInfo != nil {
@@ -377,8 +336,7 @@ func (checker *Checker) visitMember(expression *ast.MemberExpression, isAssignme
//
// This would result in a bound method for a resource, which is invalid.
- if !checker.inAssignment &&
- !checker.inInvocation &&
+ if !checker.inInvocation &&
member.DeclarationKind == common.DeclarationKindFunction &&
!accessedType.IsInvalidType() &&
accessedType.IsResourceType() {
@@ -509,7 +467,8 @@ func (checker *Checker) mapAccess(
// we could use this to then extract a `auth(Insert, Remove) &[T]` reference to that array by accessing `member`
// on an owned copy of `S`. As such, when in an assignment, we return the full codomain here as the "granted authorization"
// of the access expression, since the checker will later enforce that the incoming reference value is a subtype of that full codomain.
- if checker.inAssignment {
+ // TODO:
+ if true /*checker.inAssignment*/ {
return true, mappedAccess.Codomain()
}
return true, grantedAccess
diff --git a/runtime/sema/hashable_struct.cdc b/runtime/sema/hashable_struct.cdc
index 486041fff..2e8e966fd 100644
--- a/runtime/sema/hashable_struct.cdc
+++ b/runtime/sema/hashable_struct.cdc
@@ -1,4 +1,4 @@
/// HashableStructType represents the type that can be used as a Dictionary key type.
-pub struct HashableStruct: Storable, Exportable, Importable {
+access(all) struct HashableStruct: Storable, Exportable, Importable {
}
diff --git a/runtime/sema/hashable_struct.gen.go b/runtime/sema/hashable_struct.gen.go
index 48da711c3..383d7d0d1 100644
--- a/runtime/sema/hashable_struct.gen.go
+++ b/runtime/sema/hashable_struct.gen.go
@@ -25,11 +25,12 @@ var HashableStructType = &SimpleType{
Name: HashableStructTypeName,
QualifiedName: HashableStructTypeName,
TypeID: HashableStructTypeName,
- tag: HashableStructTypeTag,
+ TypeTag: HashableStructTypeTag,
IsResource: false,
Storable: true,
Equatable: false,
Comparable: false,
Exportable: true,
Importable: true,
+ ContainFields: false,
}
diff --git a/runtime/sema/type.go b/runtime/sema/type.go
remerge CONFLICT (content): Merge conflict in runtime/sema/type.go
index b796b9d3e..33b666c31 100644
--- a/runtime/sema/type.go
+++ b/runtime/sema/type.go
@@ -3758,11 +3758,8 @@ func init() {
HashAlgorithmType,
StorageCapabilityControllerType,
AccountCapabilityControllerType,
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
DeploymentResultType,
-=======
HashableStructType,
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
},
)
diff --git a/runtime/stdlib/account.go b/runtime/stdlib/account.go
remerge CONFLICT (content): Merge conflict in runtime/stdlib/account.go
index 5abcb5064..a0b504bbc 100644
--- a/runtime/stdlib/account.go
+++ b/runtime/stdlib/account.go
@@ -77,15 +77,11 @@ type AccountIDGenerator interface {
GenerateAccountID(address common.Address) (uint64, error)
}
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
-type AccountHandler interface {
-=======
type StorageCommitter interface {
CommitStorageTemporarily(inter *interpreter.Interpreter) error
}
-type AuthAccountHandler interface {
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
+type AccountHandler interface {
AccountIDGenerator
BalanceProvider
AvailableBalanceProvider
@@ -1465,7 +1461,10 @@ func changeAccountContracts(
// Ensure that no contract/contract interface with the given name exists already,
// and no contract deploy or update was recorded before
- if len(existingCode) > 0 || handler.ContractUpdateRecorded(location) {
+ if len(existingCode) > 0 ||
+ handler.ContractUpdateRecorded(location) ||
+ handler.IsContractBeingAdded(location) {
+
panic(errors.NewDefaultUserError(
"cannot overwrite existing contract with name %q in account %s",
contractName,
@@ -1575,23 +1574,9 @@ func changeAccountContracts(
// Validate the contract update
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
if isUpdate {
oldCode, err := handler.GetAccountContractCode(location)
handleContractUpdateError(err)
-=======
- if len(existingCode) > 0 ||
- handler.ContractUpdateRecorded(location) ||
- handler.IsContractBeingAdded(location) {
-
- panic(errors.NewDefaultUserError(
- "cannot overwrite existing contract with name %q in account %s",
- contractName,
- address.ShortHexWithPrefix(),
- ))
- }
- }
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
oldProgram, err := parser.ParseProgram(
invocation.Interpreter.SharedState.Config.MemoryGauge,
diff --git a/runtime/stdlib/contracts/scripts/crypto_get_key_from_list.cdc b/runtime/stdlib/contracts/scripts/crypto_get_key_from_list.cdc
deleted file mode 100644
remerge CONFLICT (modify/delete): runtime/stdlib/contracts/scripts/crypto_get_key_from_list.cdc deleted in b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42) and modified in 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface). Version 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface) of runtime/stdlib/contracts/scripts/crypto_get_key_from_list.cdc left in tree.
index 4d8f6a641..000000000
--- a/runtime/stdlib/contracts/scripts/crypto_get_key_from_list.cdc
+++ /dev/null
@@ -1,21 +0,0 @@
-import "Crypto"
-
-access(self) fun main(): Bool {
- let keyList = Crypto.KeyList()
-
- let publicKey = PublicKey(
- publicKey:
- "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(),
- signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
- )
- keyList.add(
- publicKey,
- hashAlgorithm: HashAlgorithm.SHA3_256,
- weight: 1.0
- )
-
- assert(keyList.get(keyIndex: 0) != nil)
- assert(keyList.get(keyIndex: 2) == nil)
-
- return true
-}
diff --git a/runtime/stdlib/contracts/scripts/crypto_hash.cdc b/runtime/stdlib/contracts/scripts/crypto_hash.cdc
deleted file mode 100644
remerge CONFLICT (modify/delete): runtime/stdlib/contracts/scripts/crypto_hash.cdc deleted in b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42) and modified in 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface). Version 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface) of runtime/stdlib/contracts/scripts/crypto_hash.cdc left in tree.
index 9b4ef47af..000000000
--- a/runtime/stdlib/contracts/scripts/crypto_hash.cdc
+++ /dev/null
@@ -1,6 +0,0 @@
-import "Crypto"
-
-access(self) fun main(): Bool {
- let hash = Crypto.hash([1, 2, 3], algorithm: HashAlgorithm.SHA3_256)
- return hash.length == 32
-}
diff --git a/runtime/stdlib/contracts/scripts/crypto_hash_with_tag.cdc b/runtime/stdlib/contracts/scripts/crypto_hash_with_tag.cdc
deleted file mode 100644
remerge CONFLICT (modify/delete): runtime/stdlib/contracts/scripts/crypto_hash_with_tag.cdc deleted in b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42) and modified in 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface). Version 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface) of runtime/stdlib/contracts/scripts/crypto_hash_with_tag.cdc left in tree.
index 2e841a50d..000000000
--- a/runtime/stdlib/contracts/scripts/crypto_hash_with_tag.cdc
+++ /dev/null
@@ -1,10 +0,0 @@
-import "Crypto"
-
-access(self) fun main(): Bool {
- let hash = Crypto.hashWithTag(
- [1, 2, 3],
- tag: "v0.1.tag",
- algorithm: HashAlgorithm.SHA3_256
- )
- return hash.length == 32
-}
diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_add.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_add.cdc
deleted file mode 100644
remerge CONFLICT (modify/delete): runtime/stdlib/contracts/scripts/crypto_key_list_add.cdc deleted in b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42) and modified in 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface). Version 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface) of runtime/stdlib/contracts/scripts/crypto_key_list_add.cdc left in tree.
index 5f95e575c..000000000
--- a/runtime/stdlib/contracts/scripts/crypto_key_list_add.cdc
+++ /dev/null
@@ -1,18 +0,0 @@
-import "Crypto"
-
-access(self) fun main(): Bool {
- let keyList = Crypto.KeyList()
-
- let publicKey = PublicKey(
- publicKey:
- "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(),
- signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
- )
- keyList.add(
- publicKey,
- hashAlgorithm: HashAlgorithm.SHA3_256,
- weight: 1.0
- )
-
- return keyList.get(keyIndex: 0) != nil
-}
diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_verify.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_verify.cdc
deleted file mode 100644
remerge CONFLICT (modify/delete): runtime/stdlib/contracts/scripts/crypto_key_list_verify.cdc deleted in b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42) and modified in 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface). Version 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface) of runtime/stdlib/contracts/scripts/crypto_key_list_verify.cdc left in tree.
index ab0c3f0f4..000000000
--- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify.cdc
+++ /dev/null
@@ -1,51 +0,0 @@
-import "Crypto"
-
-access(self) fun main(): Bool {
- let keyList = Crypto.KeyList()
-
- let publicKeyA = PublicKey(
- publicKey:
- "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(),
- signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
- )
-
- keyList.add(
- publicKeyA,
- hashAlgorithm: HashAlgorithm.SHA3_256,
- weight: 0.5
- )
-
- let publicKeyB = PublicKey(
- publicKey:
- "df9609ee588dd4a6f7789df8d56f03f545d4516f0c99b200d73b9a3afafc14de5d21a4fc7a2a2015719dc95c9e756cfa44f2a445151aaf42479e7120d83df956".decodeHex(),
- signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
- )
-
- keyList.add(
- publicKeyB,
- hashAlgorithm: HashAlgorithm.SHA3_256,
- weight: 0.5
- )
-
- let signatureSet = [
- Crypto.KeyListSignature(
- keyIndex: 0,
- signature:
- "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex()
- ),
- Crypto.KeyListSignature(
- keyIndex: 1,
- signature:
- "bbdc5591c3f937a730d4f6c0a6fde61a0a6ceaa531ccb367c3559335ab9734f4f2b9da8adbe371f1f7da913b5a3fdd96a871e04f078928ca89a83d841c72fadf".decodeHex()
- )
- ]
-
- // "foo", encoded as UTF-8, in hex representation
- let signedData = "666f6f".decodeHex()
-
- let isValid = keyList.verify(
- signatureSet: signatureSet,
- signedData: signedData
- )
- return isValid
-}
diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_duplicate_signature.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_duplicate_signature.cdc
deleted file mode 100644
remerge CONFLICT (modify/delete): runtime/stdlib/contracts/scripts/crypto_key_list_verify_duplicate_signature.cdc deleted in b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42) and modified in 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface). Version 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface) of runtime/stdlib/contracts/scripts/crypto_key_list_verify_duplicate_signature.cdc left in tree.
index 1ca7ef69b..000000000
--- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_duplicate_signature.cdc
+++ /dev/null
@@ -1,39 +0,0 @@
-import "Crypto"
-
-access(self) fun main(): Bool {
- let keyList = Crypto.KeyList()
-
- let publicKey = PublicKey(
- publicKey:
- "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(),
- signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
- )
- keyList.add(
- publicKey,
- hashAlgorithm: HashAlgorithm.SHA3_256,
- weight: 0.5
- )
-
- let signatureSet = [
- Crypto.KeyListSignature(
- keyIndex: 0,
- signature:
- "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex()
- ),
- Crypto.KeyListSignature(
- keyIndex: 0,
- signature:
- "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex()
- )
- ]
-
- // "foo", encoded as UTF-8, in hex representation
- let signedData = "666f6f".decodeHex()
-
- var isValid = keyList.verify(
- signatureSet: signatureSet,
- signedData: signedData
- )
-
- return !isValid
-}
diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_insufficient_weights.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_insufficient_weights.cdc
deleted file mode 100644
remerge CONFLICT (modify/delete): runtime/stdlib/contracts/scripts/crypto_key_list_verify_insufficient_weights.cdc deleted in b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42) and modified in 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface). Version 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface) of runtime/stdlib/contracts/scripts/crypto_key_list_verify_insufficient_weights.cdc left in tree.
index cd1f6d99f..000000000
--- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_insufficient_weights.cdc
+++ /dev/null
@@ -1,51 +0,0 @@
-import "Crypto"
-
-access(self) fun main(): Bool {
- let keyList = Crypto.KeyList()
-
- let publicKeyA = PublicKey(
- publicKey:
- "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(),
- signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
- )
-
- keyList.add(
- publicKeyA,
- hashAlgorithm: HashAlgorithm.SHA3_256,
- weight: 0.4
- )
-
- let publicKeyB = PublicKey(
- publicKey:
- "df9609ee588dd4a6f7789df8d56f03f545d4516f0c99b200d73b9a3afafc14de5d21a4fc7a2a2015719dc95c9e756cfa44f2a445151aaf42479e7120d83df956".decodeHex(),
- signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
- )
-
- keyList.add(
- publicKeyB,
- hashAlgorithm: HashAlgorithm.SHA3_256,
- weight: 0.5
- )
-
- let signatureSet = [
- Crypto.KeyListSignature(
- keyIndex: 0,
- signature:
- "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex()
- ),
- Crypto.KeyListSignature(
- keyIndex: 1,
- signature:
- "bbdc5591c3f937a730d4f6c0a6fde61a0a6ceaa531ccb367c3559335ab9734f4f2b9da8adbe371f1f7da913b5a3fdd96a871e04f078928ca89a83d841c72fadf".decodeHex()
- )
- ]
-
- // "foo", encoded as UTF-8, in hex representation
- let signedData = "666f6f".decodeHex()
-
- let isValid = keyList.verify(
- signatureSet: signatureSet,
- signedData: signedData
- )
- return !isValid
-}
diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_invalid_signature.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_invalid_signature.cdc
deleted file mode 100644
remerge CONFLICT (modify/delete): runtime/stdlib/contracts/scripts/crypto_key_list_verify_invalid_signature.cdc deleted in b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42) and modified in 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface). Version 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface) of runtime/stdlib/contracts/scripts/crypto_key_list_verify_invalid_signature.cdc left in tree.
index 47449c0bb..000000000
--- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_invalid_signature.cdc
+++ /dev/null
@@ -1,34 +0,0 @@
-import "Crypto"
-
-access(self) fun main(): Bool {
- let keyList = Crypto.KeyList()
-
- let publicKey = PublicKey(
- publicKey:
- "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(),
- signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
- )
- keyList.add(
- publicKey,
- hashAlgorithm: HashAlgorithm.SHA3_256,
- weight: 0.5
- )
-
- let signatureSet = [
- Crypto.KeyListSignature(
- keyIndex: 0,
- signature:
- "db70a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex()
- )
- ]
-
- // "foo", encoded as UTF-8, in hex representation
- let signedData = "666f6f".decodeHex()
-
- var isValid = keyList.verify(
- signatureSet: signatureSet,
- signedData: signedData
- )
-
- return !isValid
-}
diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_missing_signature.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_missing_signature.cdc
deleted file mode 100644
remerge CONFLICT (modify/delete): runtime/stdlib/contracts/scripts/crypto_key_list_verify_missing_signature.cdc deleted in b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42) and modified in 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface). Version 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface) of runtime/stdlib/contracts/scripts/crypto_key_list_verify_missing_signature.cdc left in tree.
index 851309e25..000000000
--- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_missing_signature.cdc
+++ /dev/null
@@ -1,34 +0,0 @@
-import "Crypto"
-
-access(self) fun main(): Bool {
- let keyList = Crypto.KeyList()
-
- let publicKey = PublicKey(
- publicKey:
- "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(),
- signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
- )
- keyList.add(
- publicKey,
- hashAlgorithm: HashAlgorithm.SHA3_256,
- weight: 0.5
- )
-
- let signatureSet = [
- Crypto.KeyListSignature(
- keyIndex: 1,
- signature:
- "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex()
- )
- ]
-
- // "foo", encoded as UTF-8, in hex representation
- let signedData = "666f6f".decodeHex()
-
- var isValid = keyList.verify(
- signatureSet: signatureSet,
- signedData: signedData
- )
-
- return !isValid
-}
diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_revoked.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_revoked.cdc
deleted file mode 100644
remerge CONFLICT (modify/delete): runtime/stdlib/contracts/scripts/crypto_key_list_verify_revoked.cdc deleted in b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42) and modified in 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface). Version 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface) of runtime/stdlib/contracts/scripts/crypto_key_list_verify_revoked.cdc left in tree.
index 1cc9c18f9..000000000
--- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_revoked.cdc
+++ /dev/null
@@ -1,36 +0,0 @@
-import "Crypto"
-
-access(self) fun main(): Bool {
- let keyList = Crypto.KeyList()
-
- let publicKey = PublicKey(
- publicKey:
- "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(),
- signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
- )
- keyList.add(
- publicKey,
- hashAlgorithm: HashAlgorithm.SHA3_256,
- weight: 0.5
- )
-
- let signatureSet = [
- Crypto.KeyListSignature(
- keyIndex: 0,
- signature:
- "8870a8cbe6f44932ba59e0d15a706214cc4ad2538deb12c0cf718d86f32c47765462a92ce2da15d4a29eb4e2b6fa05d08c7db5d5b2a2cd8c2cb98ded73da31f6".decodeHex()
- )
- ]
-
- // "foo", encoded as UTF-8, in hex representation
- let signedData = "666f6f".decodeHex()
-
- keyList.revoke(keyIndex: 0)
-
- var isValid = keyList.verify(
- signatureSet: signatureSet,
- signedData: signedData
- )
-
- return !isValid
-}
diff --git a/runtime/stdlib/contracts/scripts/crypto_revoke_key_from_list.cdc b/runtime/stdlib/contracts/scripts/crypto_revoke_key_from_list.cdc
deleted file mode 100644
remerge CONFLICT (modify/delete): runtime/stdlib/contracts/scripts/crypto_revoke_key_from_list.cdc deleted in b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42) and modified in 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface). Version 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface) of runtime/stdlib/contracts/scripts/crypto_revoke_key_from_list.cdc left in tree.
index 7a3e40e74..000000000
--- a/runtime/stdlib/contracts/scripts/crypto_revoke_key_from_list.cdc
+++ /dev/null
@@ -1,24 +0,0 @@
-import "Crypto"
-
-access(self) fun main(): Bool {
- let keyList = Crypto.KeyList()
-
- let publicKey = PublicKey(
- publicKey:
- "db04940e18ec414664ccfd31d5d2d4ece3985acb8cb17a2025b2f1673427267968e52e2bbf3599059649d4b2cce98fdb8a3048e68abf5abe3e710129e90696ca".decodeHex(),
- signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
- )
- keyList.add(
- publicKey,
- hashAlgorithm: HashAlgorithm.SHA3_256,
- weight: 0.5
- )
-
- keyList.revoke(keyIndex: 0)
- keyList.revoke(keyIndex: 2)
-
- assert(keyList.get(keyIndex: 0)!.isRevoked)
- assert(keyList.get(keyIndex: 2) == nil)
-
- return true
-}
diff --git a/runtime/stdlib/random.go b/runtime/stdlib/random.go
remerge CONFLICT (content): Merge conflict in runtime/stdlib/random.go
index df161c72a..88dc2d289 100644
--- a/runtime/stdlib/random.go
+++ b/runtime/stdlib/random.go
@@ -34,19 +34,11 @@ NOTE: The use of this function is unsafe if not used correctly.
Follow best practices to prevent security issues when using this function
`
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
-var unsafeRandomFunctionType = sema.NewSimpleFunctionType(
+var revertibleRandomFunctionType = sema.NewSimpleFunctionType(
sema.FunctionPurityImpure,
nil,
sema.UInt64TypeAnnotation,
)
-=======
-var revertibleRandomFunctionType = &sema.FunctionType{
- ReturnTypeAnnotation: sema.NewTypeAnnotation(
- sema.UInt64Type,
- ),
-}
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
type RandomGenerator interface {
// ReadRandom reads pseudo-random bytes into the input slice, using distributed randomness.
diff --git a/runtime/stdlib/test_test.go b/runtime/stdlib/test_test.go
remerge CONFLICT (content): Merge conflict in runtime/stdlib/test_test.go
index 0488261ee..c390d0616 100644
--- a/runtime/stdlib/test_test.go
+++ b/runtime/stdlib/test_test.go
@@ -1868,11 +1868,7 @@ func TestTestExpect(t *testing.T) {
_, err = inter.Invoke("test")
require.Error(t, err)
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
assert.ErrorAs(t, err, &interpreter.TypeMismatchError{})
-=======
- assert.ErrorAs(t, err, &AssertionError{})
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
})
t.Run("with explicit types", func(t *testing.T) {
@@ -2821,20 +2817,17 @@ func TestBlockchainAccount(t *testing.T) {
`
testFramework := &mockedTestFramework{
- emulatorBackend: func() stdlib.Blockchain {
+ emulatorBackend: func() Blockchain {
return &mockedBlockchain{
- createAccount: func() (*stdlib.Account, error) {
- return &stdlib.Account{
- PublicKey: &stdlib.PublicKey{
+ createAccount: func() (*Account, error) {
+ return &Account{
+ PublicKey: &PublicKey{
PublicKey: []byte{1, 2, 3},
SignAlgo: sema.SignatureAlgorithmECDSA_P256,
},
Address: common.Address{1},
}, nil
},
- stdlibHandler: func() stdlib.StandardLibraryHandler {
- return nil
- },
}
},
}
diff --git a/runtime/tests/interpreter/resources_test.go b/runtime/tests/interpreter/resources_test.go
remerge CONFLICT (content): Merge conflict in runtime/tests/interpreter/resources_test.go
index f46a30779..52faaacf2 100644
--- a/runtime/tests/interpreter/resources_test.go
+++ b/runtime/tests/interpreter/resources_test.go
@@ -2089,55 +2089,11 @@ func TestInterpretArrayOptionalResourceReference(t *testing.T) {
func TestInterpretResourceDestroyedInPreCondition(t *testing.T) {
t.Parallel()
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
- didError := false
- _, err := parseCheckAndInterpretWithOptions(t,
- `
- resource interface I {
- access(all) fun receiveResource(_ r: @Bar) {
- pre {
- destroyResource(<-r)
- }
- }
- }
-
- fun destroyResource(_ r: @Bar): Bool {
- destroy r
- return true
- }
-
- resource Foo: I {
- access(all) fun receiveResource(_ r: @Bar) {
- destroy r
- }
- }
-
- resource Bar {}
-
- fun test() {
- let foo <- create Foo()
- let bar <- create Bar()
- foo.receiveResource(<- bar)
- destroy foo
- }
- `,
- ParseCheckAndInterpretOptions{
- HandleCheckerError: func(err error) {
- require.IsType(t, err, &sema.CheckerError{})
- require.IsType(t, err.(*sema.CheckerError).Errors[0], &sema.PurityError{})
- didError = true
- },
- },
- )
-
- require.NoError(t, err)
- require.True(t, didError)
-=======
inter, err := parseCheckAndInterpretWithOptions(
t,
`
resource interface I {
- pub fun receiveResource(_ r: @Bar) {
+ access(all) fun receiveResource(_ r: @Bar) {
pre {
destroyResource(<-r)
}
@@ -2150,7 +2106,7 @@ func TestInterpretResourceDestroyedInPreCondition(t *testing.T) {
}
resource Foo: I {
- pub fun receiveResource(_ r: @Bar) {
+ access(all) fun receiveResource(_ r: @Bar) {
destroy r
}
}
@@ -2333,48 +2289,6 @@ func TestInterpretInvalidReentrantResourceDestruction(t *testing.T) {
})
}
-func TestInterpretResourceFunctionInvocationAfterDestruction(t *testing.T) {
-
- t.Parallel()
-
- inter := parseCheckAndInterpret(t, `
- pub resource Vault {
- pub fun foo(_ ignored: Bool) {}
- }
-
- pub resource Attacker {
- pub var vault: @Vault
-
- init() {
- self.vault <- create Vault()
- }
-
- pub fun shenanigans(): Bool {
- var temp <- create Vault()
- self.vault <-> temp
- destroy temp
- return true
- }
-
- destroy() {
- destroy self.vault
- }
- }
-
- pub fun main() {
- let a <- create Attacker()
- a.vault.foo(a.shenanigans())
- destroy a
- }
- `)
-
- _, err := inter.Invoke("main")
- RequireError(t, err)
-
- require.ErrorAs(t, err, &interpreter.DestroyedResourceError{})
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
-}
-
func TestInterpretResourceFunctionReferenceValidity(t *testing.T) {
t.Parallel()
diff --git a/types.go b/types.go
remerge CONFLICT (content): Merge conflict in types.go
index c30352e70..ac62eb8c4 100644
--- a/types.go
+++ b/types.go
@@ -123,6 +123,7 @@ var AnyStructType = PrimitiveType(interpreter.PrimitiveStaticTypeAnyStruct)
var AnyResourceType = PrimitiveType(interpreter.PrimitiveStaticTypeAnyResource)
var AnyStructAttachmentType = PrimitiveType(interpreter.PrimitiveStaticTypeAnyStructAttachment)
var AnyResourceAttachmentType = PrimitiveType(interpreter.PrimitiveStaticTypeAnyResourceAttachment)
+var HashableStructType = PrimitiveType(interpreter.PrimitiveStaticTypeHashableStruct)
var BoolType = PrimitiveType(interpreter.PrimitiveStaticTypeBool)
var AddressType = PrimitiveType(interpreter.PrimitiveStaticTypeAddress)
@@ -1730,213 +1731,3 @@ func (t *EnumType) Equal(other Type) bool {
return t.Location == otherType.Location &&
t.QualifiedIdentifier == otherType.QualifiedIdentifier
}
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
-=======
-
-// AuthAccountType
-type AuthAccountType struct{}
-
-var TheAuthAccountType = AuthAccountType{}
-
-func NewAuthAccountType() AuthAccountType {
- return TheAuthAccountType
-}
-
-func (AuthAccountType) isType() {}
-
-func (AuthAccountType) ID() string {
- return "AuthAccount"
-}
-
-func (t AuthAccountType) Equal(other Type) bool {
- return t == other
-}
-
-// PublicAccountType
-type PublicAccountType struct{}
-
-var ThePublicAccountType = PublicAccountType{}
-
-func NewPublicAccountType() PublicAccountType {
- return ThePublicAccountType
-}
-
-func (PublicAccountType) isType() {}
-
-func (PublicAccountType) ID() string {
- return "PublicAccount"
-}
-
-func (t PublicAccountType) Equal(other Type) bool {
- return t == other
-}
-
-// DeployedContractType
-type DeployedContractType struct{}
-
-var TheDeployedContractType = DeployedContractType{}
-
-func NewDeployedContractType() DeployedContractType {
- return TheDeployedContractType
-}
-
-func (DeployedContractType) isType() {}
-
-func (DeployedContractType) ID() string {
- return "DeployedContract"
-}
-
-func (t DeployedContractType) Equal(other Type) bool {
- return t == other
-}
-
-// AuthAccountContractsType
-type AuthAccountContractsType struct{}
-
-var TheAuthAccountContractsType = AuthAccountContractsType{}
-
-func NewAuthAccountContractsType() AuthAccountContractsType {
- return TheAuthAccountContractsType
-}
-
-func (AuthAccountContractsType) isType() {}
-
-func (AuthAccountContractsType) ID() string {
- return "AuthAccount.Contracts"
-}
-
-func (t AuthAccountContractsType) Equal(other Type) bool {
- return t == other
-}
-
-// PublicAccountContractsType
-type PublicAccountContractsType struct{}
-
-var ThePublicAccountContractsType = PublicAccountContractsType{}
-
-func NewPublicAccountContractsType() PublicAccountContractsType {
- return ThePublicAccountContractsType
-}
-
-func (PublicAccountContractsType) isType() {}
-
-func (PublicAccountContractsType) ID() string {
- return "PublicAccount.Contracts"
-}
-
-func (t PublicAccountContractsType) Equal(other Type) bool {
- return t == other
-}
-
-// AuthAccountKeysType
-type AuthAccountKeysType struct{}
-
-var TheAuthAccountKeysType = AuthAccountKeysType{}
-
-func NewAuthAccountKeysType() AuthAccountKeysType {
- return TheAuthAccountKeysType
-}
-
-func (AuthAccountKeysType) isType() {}
-
-func (AuthAccountKeysType) ID() string {
- return "AuthAccount.Keys"
-}
-
-func (t AuthAccountKeysType) Equal(other Type) bool {
- return t == other
-}
-
-// PublicAccountKeysType
-type PublicAccountKeysType struct{}
-
-var ThePublicAccountKeysType = PublicAccountKeysType{}
-
-func NewPublicAccountKeysType() PublicAccountKeysType {
- return ThePublicAccountKeysType
-}
-
-func (PublicAccountKeysType) isType() {}
-
-func (PublicAccountKeysType) ID() string {
- return "PublicAccount.Keys"
-}
-
-func (t PublicAccountKeysType) Equal(other Type) bool {
- return t == other
-}
-
-// AccountKeyType
-type AccountKeyType struct{}
-
-var TheAccountKeyType = AccountKeyType{}
-
-func NewAccountKeyType() AccountKeyType {
- return TheAccountKeyType
-}
-
-func (AccountKeyType) isType() {}
-
-func (AccountKeyType) ID() string {
- return "AccountKey"
-}
-
-func (t AccountKeyType) Equal(other Type) bool {
- return t == other
-}
-
-// HashableStructType
-type HashableStructType struct{}
-
-var TheHashableStructType = HashableStructType{}
-var _ Type = &HashableStructType{}
-
-func NewHashableStruct() HashableStructType {
- return TheHashableStructType
-}
-
-func (HashableStructType) isType() {}
-
-func (HashableStructType) ID() string {
- return "HashableStruct"
-}
-
-func (t HashableStructType) Equal(other Type) bool {
- return t == other
-}
-
-// TypeWithCachedTypeID recursively caches type ID of type t.
-// This is needed because each type ID is lazily cached on
-// its first use in ID() to avoid performance penalty.
-func TypeWithCachedTypeID(t Type) Type {
- if t == nil {
- return t
- }
-
- // Cache type ID by calling ID()
- t.ID()
-
- switch t := t.(type) {
-
- case CompositeType:
- fields := t.CompositeFields()
- for _, f := range fields {
- TypeWithCachedTypeID(f.Type)
- }
-
- initializers := t.CompositeInitializers()
- for _, params := range initializers {
- for _, p := range params {
- TypeWithCachedTypeID(p.Type)
- }
- }
-
- case *RestrictedType:
- for _, restriction := range t.Restrictions {
- TypeWithCachedTypeID(restriction)
- }
- }
-
- return t
-}
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
diff --git a/version.go b/version.go
remerge CONFLICT (content): Merge conflict in version.go
index 53ad33631..df4564bfc 100644
--- a/version.go
+++ b/version.go
@@ -21,8 +21,4 @@
package cadence
-<<<<<<< 787812ff3 (Merge pull request #2946 from onflow/sainati/supported-entitlements-interface)
const Version = "v1.0.0-preview.1"
-=======
-const Version = "v0.42.5"
->>>>>>> b48fd6b85 (Merge pull request #2956 from onflow/supun/sync-with-0.42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment