diff --git a/encoding/ccf/ccf_test.go b/encoding/ccf/ccf_test.go index 5695835a8c..934ed4de66 100644 --- a/encoding/ccf/ccf_test.go +++ b/encoding/ccf/ccf_test.go @@ -13214,7 +13214,7 @@ func TestDeployedEvents(t *testing.T) { } func newFlowFeesFeesDeductedEventType() *cadence.EventType { - // pub event FeesDeducted(amount: UFix64, inclusionEffort: UFix64, executionEffort: UFix64) + // access(all) event FeesDeducted(amount: UFix64, inclusionEffort: UFix64, executionEffort: UFix64) address, _ := common.HexToAddress("f919ee77447b7497") location := common.NewAddressLocation(nil, address, "FlowFees") @@ -13258,7 +13258,7 @@ func createFlowFeesFeesDeductedEvent() cadence.Event { } func newFlowFeesTokensWithdrawnEventType() *cadence.EventType { - // pub event TokensWithdrawn(amount: UFix64) + // access(all) event TokensWithdrawn(amount: UFix64) address, _ := common.HexToAddress("f919ee77447b7497") location := common.NewAddressLocation(nil, address, "FlowFees") @@ -13290,7 +13290,7 @@ func createFlowFeesTokensWithdrawnEvent() cadence.Event { } func newFlowTokenTokensDepositedEventType() *cadence.EventType { - // pub event TokensDeposited(amount: UFix64, to: Address?) + // access(all) event TokensDeposited(amount: UFix64, to: Address?) address, _ := common.HexToAddress("1654653399040a61") location := common.NewAddressLocation(nil, address, "FlowToken") @@ -13348,7 +13348,7 @@ func createFlowTokenTokensDepositedEvent() cadence.Event { } func newFlowTokenTokensMintedEventType() *cadence.EventType { - // pub event TokensMinted(amount: UFix64) + // access(all) event TokensMinted(amount: UFix64) address, _ := common.HexToAddress("1654653399040a61") location := common.NewAddressLocation(nil, address, "FlowToken") @@ -13380,7 +13380,7 @@ func createFlowTokenTokensMintedEvent() cadence.Event { } func newFlowTokenTokensWithdrawnEventType() *cadence.EventType { - // pub event TokensWithdrawn(amount: UFix64, from: Address?) + // access(all) event TokensWithdrawn(amount: UFix64, from: Address?) address, _ := common.HexToAddress("1654653399040a61") location := common.NewAddressLocation(nil, address, "FlowToken") @@ -13422,7 +13422,7 @@ func createFlowTokenTokensWithdrawnEvent() cadence.Event { } func newFlowIDTableStakingDelegatorRewardsPaidEventType() *cadence.EventType { - // pub event DelegatorRewardsPaid(nodeID: String, delegatorID: UInt32, amount: UFix64) + // access(all) event DelegatorRewardsPaid(nodeID: String, delegatorID: UInt32, amount: UFix64) address, _ := common.HexToAddress("8624b52f9ddcd04a") location := common.NewAddressLocation(nil, address, "FlowIDTableStaking") @@ -13466,7 +13466,7 @@ func createFlowIDTableStakingDelegatorRewardsPaidEvent() cadence.Event { } func newFlowIDTableStakingEpochTotalRewardsPaidEventType() *cadence.EventType { - // pub event EpochTotalRewardsPaid(total: UFix64, fromFees: UFix64, minted: UFix64, feesBurned: UFix64) + // access(all) event EpochTotalRewardsPaid(total: UFix64, fromFees: UFix64, minted: UFix64, feesBurned: UFix64) address, _ := common.HexToAddress("8624b52f9ddcd04a") location := common.NewAddressLocation(nil, address, "FlowIDTableStaking") @@ -13516,7 +13516,7 @@ func createFlowIDTableStakingEpochTotalRewardsPaidEvent() cadence.Event { } func newFlowIDTableStakingNewWeeklyPayoutEventType() *cadence.EventType { - // pub event NewWeeklyPayout(newPayout: UFix64) + // access(all) event NewWeeklyPayout(newPayout: UFix64) address, _ := common.HexToAddress("8624b52f9ddcd04a") location := common.NewAddressLocation(nil, address, "FlowIDTableStaking") @@ -13548,7 +13548,7 @@ func createFlowIDTableStakingNewWeeklyPayoutEvent() cadence.Event { } func newFlowIDTableStakingRewardsPaidEventType() *cadence.EventType { - // pub event RewardsPaid(nodeID: String, amount: UFix64) + // access(all) event RewardsPaid(nodeID: String, amount: UFix64) address, _ := common.HexToAddress("8624b52f9ddcd04a") location := common.NewAddressLocation(nil, address, "FlowIDTableStaking") diff --git a/examples/quicksort.cdc b/examples/quicksort.cdc index 0332febcdc..b11c1e8b03 100644 --- a/examples/quicksort.cdc +++ b/examples/quicksort.cdc @@ -4,7 +4,7 @@ /// > Our version of quicksort is not the fastest possible, /// > but it's one of the simplest. /// -pub fun quickSort(_ items: &[AnyStruct], isLess: ((Int, Int): Bool)) { +access(all) fun quickSort(_ items: &[AnyStruct], isLess: ((Int, Int): Bool)) { fun quickSortPart(leftIndex: Int, rightIndex: Int) { @@ -38,7 +38,7 @@ pub fun quickSort(_ items: &[AnyStruct], isLess: ((Int, Int): Bool)) { ) } -pub fun main() { +access(all) fun main() { let items = [5, 3, 7, 6, 2, 9] quickSort( &items as &[AnyStruct], diff --git a/go.cap b/go.cap index 34dba49742..c54c21c9f9 100644 --- a/go.cap +++ b/go.cap @@ -1,7 +1,9 @@ github.com/onflow/cadence () github.com/davecgh/go-spew/spew (file) +github.com/k0kubun/pp (file, runtime) github.com/klauspost/cpuid/v2 (file, runtime) +github.com/mattn/go-colorable (file) github.com/onflow/cadence/runtime/errors (runtime) github.com/onflow/cadence/runtime/parser (file) github.com/onflow/cadence/runtime/pretty (runtime) @@ -9,4 +11,5 @@ github.com/stretchr/testify/assert (runtime, file, network) github.com/stretchr/testify/require (network) github.com/texttheater/golang-levenshtein/levenshtein (file) github.com/zeebo/blake3/internal/consts (file) +golang.org/x/sys/unix (runtime, syscall) golang.org/x/xerrors (runtime) diff --git a/go.mod b/go.mod index e0693bdce2..52669fba70 100644 --- a/go.mod +++ b/go.mod @@ -32,6 +32,7 @@ require ( require ( github.com/SaveTheRbtz/mph v0.1.2 github.com/bytecodealliance/wasmtime-go/v7 v7.0.0 + github.com/k0kubun/pp v3.0.1+incompatible github.com/k0kubun/pp/v3 v3.2.0 github.com/logrusorgru/aurora/v4 v4.0.0 ) @@ -41,6 +42,7 @@ require github.com/zeebo/xxh3 v1.0.2 // indirect require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/fxamacker/circlehash v0.3.0 // indirect + github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect github.com/klauspost/cpuid/v2 v2.2.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.16 // indirect diff --git a/go.sum b/go.sum index 8d8502ebc7..5472e78ef4 100644 --- a/go.sum +++ b/go.sum @@ -20,7 +20,11 @@ github.com/go-test/deep v1.0.5 h1:AKODKU3pDH1RzZzm6YZu77YWtEAq6uh1rLIAQlay2qc= github.com/go-test/deep v1.0.5/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM= +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw= +github.com/k0kubun/pp v3.0.1+incompatible h1:3tqvf7QgUnZ5tXO6pNAZlrvHgl6DvifjDrd9g2S9Z40= +github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg= github.com/k0kubun/pp/v3 v3.2.0 h1:h33hNTZ9nVFNP3u2Fsgz8JXiF5JINoZfFq4SvKJwNcs= github.com/k0kubun/pp/v3 v3.2.0/go.mod h1:ODtJQbQcIRfAD3N+theGCV1m/CBxweERz2dapdz1EwA= github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= diff --git a/runtime/account_test.go b/runtime/account_test.go index 5fd6db73a2..6089428707 100644 --- a/runtime/account_test.go +++ b/runtime/account_test.go @@ -46,7 +46,7 @@ func TestRuntimeAccountKeyConstructor(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main(): AccountKey { + access(all) fun main(): AccountKey { let key = AccountKey( PublicKey( publicKey: "0102".decodeHex(), @@ -87,7 +87,7 @@ func TestRuntimeReturnPublicAccount(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main(): PublicAccount { + access(all) fun main(): PublicAccount { let acc = getAccount(0x02) return acc } @@ -121,7 +121,7 @@ func TestRuntimeReturnAuthAccount(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main(): AuthAccount { + access(all) fun main(): AuthAccount { let acc = getAuthAccount(0x02) return acc } @@ -544,7 +544,7 @@ func TestRuntimePublicAccountKeys(t *testing.T) { testEnv := initTestEnv(accountKeyA, accountKeyB) test := accountKeyTestCase{ code: ` - pub fun main(): AccountKey? { + access(all) fun main(): AccountKey? { let acc = getAccount(0x02) return acc.keys.get(keyIndex: 0) } @@ -581,7 +581,7 @@ func TestRuntimePublicAccountKeys(t *testing.T) { test := accountKeyTestCase{ code: ` - pub fun main(): AccountKey? { + access(all) fun main(): AccountKey? { let acc = getAccount(0x02) return acc.keys.get(keyIndex: 1) } @@ -617,7 +617,7 @@ func TestRuntimePublicAccountKeys(t *testing.T) { test := accountKeyTestCase{ code: ` - pub fun main(): AccountKey? { + access(all) fun main(): AccountKey? { let acc = getAccount(0x02) return acc.keys.get(keyIndex: 4) } @@ -643,7 +643,7 @@ func TestRuntimePublicAccountKeys(t *testing.T) { test := accountKeyTestCase{ code: ` - pub fun main(): AccountKey? { + access(all) fun main(): AccountKey? { let acc = getAccount(0x02) var keys: PublicAccount.Keys = acc.keys return keys.get(keyIndex: 0) @@ -679,7 +679,7 @@ func TestRuntimePublicAccountKeys(t *testing.T) { test := accountKeyTestCase{ code: ` - pub fun main(): UInt64 { + access(all) fun main(): UInt64 { return getAccount(0x02).keys.count } `, @@ -699,7 +699,7 @@ func TestRuntimePublicAccountKeys(t *testing.T) { testEnv := initTestEnv(revokedAccountKeyA, accountKeyB) test := accountKeyTestCase{ code: ` - pub fun main() { + access(all) fun main() { getAccount(0x02).keys.forEach(fun(key: AccountKey): Bool { log(key.keyIndex) return true @@ -738,7 +738,7 @@ func TestRuntimeHashAlgorithm(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main(): [HashAlgorithm?] { + access(all) fun main(): [HashAlgorithm?] { var key1: HashAlgorithm? = HashAlgorithm.SHA3_256 var key2: HashAlgorithm? = HashAlgorithm(rawValue: 3) @@ -810,7 +810,7 @@ func TestRuntimeSignatureAlgorithm(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main(): [SignatureAlgorithm?] { + access(all) fun main(): [SignatureAlgorithm?] { var key1: SignatureAlgorithm? = SignatureAlgorithm.ECDSA_secp256k1 var key2: SignatureAlgorithm? = SignatureAlgorithm(rawValue: 2) @@ -1168,7 +1168,7 @@ func TestRuntimePublicKey(t *testing.T) { t.Parallel() script := ` - pub fun main(): PublicKey { + access(all) fun main(): PublicKey { let publicKey = PublicKey( publicKey: "0102".decodeHex(), signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 @@ -1207,7 +1207,7 @@ func TestRuntimePublicKey(t *testing.T) { t.Parallel() script := ` - pub fun main(): Bool { + access(all) fun main(): Bool { let publicKey = PublicKey( publicKey: "0102".decodeHex(), signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 @@ -1229,7 +1229,7 @@ func TestRuntimePublicKey(t *testing.T) { t.Parallel() script := ` - pub fun main(): PublicKey { + access(all) fun main(): PublicKey { let publicKey = PublicKey( publicKey: "0102".decodeHex(), signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 @@ -1279,7 +1279,7 @@ func TestRuntimePublicKey(t *testing.T) { for index := range storage.keys { script := fmt.Sprintf( ` - pub fun main(): PublicKey { + access(all) fun main(): PublicKey { // Get a public key from host env let acc = getAccount(0x02) let publicKey = acc.keys.get(keyIndex: %d)!.publicKey @@ -1311,7 +1311,7 @@ func TestRuntimePublicKey(t *testing.T) { t.Parallel() script := ` - pub fun main(): Bool { + access(all) fun main(): Bool { let publicKey = PublicKey( publicKey: "0102".decodeHex(), signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 @@ -1360,7 +1360,7 @@ func TestRuntimePublicKey(t *testing.T) { storage.keys = append(storage.keys, accountKeyA, accountKeyB) script := ` - pub fun main(): Bool { + access(all) fun main(): Bool { // Get a public key from host env let acc = getAccount(0x02) let publicKey = acc.keys.get(keyIndex: 0)!.publicKey @@ -1400,7 +1400,7 @@ func TestRuntimePublicKey(t *testing.T) { t.Parallel() script := ` - pub fun main(): PublicKey { + access(all) fun main(): PublicKey { let publicKey = PublicKey( publicKey: "0102".decodeHex(), signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 @@ -1432,7 +1432,7 @@ func TestRuntimePublicKey(t *testing.T) { t.Parallel() script := ` - pub fun main(): PublicKey { + access(all) fun main(): PublicKey { let publicKey = PublicKey( publicKey: "0102".decodeHex(), signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 @@ -1461,7 +1461,7 @@ func TestRuntimePublicKey(t *testing.T) { t.Parallel() script := ` - pub fun main(): PublicKey { + access(all) fun main(): PublicKey { let publicKey = PublicKey( publicKey: "0102".decodeHex(), signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 @@ -1624,9 +1624,9 @@ func TestAuthAccountContracts(t *testing.T) { err := rt.ExecuteTransaction( Script{ Source: DeploymentTransaction("HelloInterface", []byte(` - pub contract interface HelloInterface { + access(all) contract interface HelloInterface { - pub fun hello(): String + access(all) fun hello(): String } `)), }, @@ -1643,9 +1643,9 @@ func TestAuthAccountContracts(t *testing.T) { Source: DeploymentTransaction("Hello", []byte(` import HelloInterface from 0x42 - pub contract Hello: HelloInterface { + access(all) contract Hello: HelloInterface { - pub fun hello(): String { + access(all) fun hello(): String { return "Hello!" } } @@ -1717,9 +1717,9 @@ func TestAuthAccountContracts(t *testing.T) { err := rt.ExecuteTransaction( Script{ Source: DeploymentTransaction("HelloInterface", []byte(` - pub contract interface HelloInterface { + access(all) contract interface HelloInterface { - pub fun hello(): String + access(all) fun hello(): String } `)), }, @@ -1734,9 +1734,9 @@ func TestAuthAccountContracts(t *testing.T) { err = rt.ExecuteTransaction( Script{ Source: DeploymentTransaction("Hello", []byte(` - pub contract Hello { + access(all) contract Hello { - pub fun hello(): String { + access(all) fun hello(): String { return "Hello!" } } @@ -1940,7 +1940,7 @@ func TestPublicAccountContracts(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main(): [AnyStruct] { + access(all) fun main(): [AnyStruct] { let acc = getAccount(0x02) let deployedContract = acc.contracts.get(name: "foo") @@ -1998,7 +1998,7 @@ func TestPublicAccountContracts(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main() { + access(all) fun main() { let acc = getAccount(0x02) assert(acc.contracts.get(name: "foo") == nil) } @@ -2036,7 +2036,7 @@ func TestPublicAccountContracts(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main(): [String] { + access(all) fun main(): [String] { let acc = getAccount(0x02) return acc.contracts.names } @@ -2081,7 +2081,7 @@ func TestPublicAccountContracts(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main(): [String] { + access(all) fun main(): [String] { let acc = getAccount(0x02) acc.contracts.names[0] = "baz" return acc.contracts.names @@ -2117,7 +2117,7 @@ func TestPublicAccountContracts(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main(): [String] { + access(all) fun main(): [String] { let acc = getAccount(0x02) acc.contracts.names.append("baz") return acc.contracts.names @@ -2158,7 +2158,7 @@ func TestGetAuthAccount(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main(): UInt64 { + access(all) fun main(): UInt64 { let acc = getAuthAccount(0x02) return acc.storageUsed } @@ -2190,7 +2190,7 @@ func TestGetAuthAccount(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main() { + access(all) fun main() { let acc = getAuthAccount("") } `) @@ -2218,7 +2218,7 @@ func TestGetAuthAccount(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main() { + access(all) fun main() { let acc = getAuthAccount() } `) @@ -2246,7 +2246,7 @@ func TestGetAuthAccount(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main() { + access(all) fun main() { let acc = getAuthAccount(0x1, 0x2) } `) @@ -2610,9 +2610,9 @@ func TestRuntimeAccountLink(t *testing.T) { // should have no influence #allowAccountLinking - pub contract AccountLinker { + access(all) contract AccountLinker { - pub fun link(_ account: AuthAccount) { + access(all) fun link(_ account: AuthAccount) { account.linkAccount(/private/foo) } } @@ -2702,9 +2702,9 @@ func TestRuntimeAccountLink(t *testing.T) { Source: DeploymentTransaction( "AccountLinker", []byte(` - pub contract AccountLinker { + access(all) contract AccountLinker { - pub fun link(_ account: AuthAccount) { + access(all) fun link(_ account: AuthAccount) { account.linkAccount(/private/foo) } } @@ -2812,9 +2812,9 @@ func TestRuntimeAccountLink(t *testing.T) { Source: DeploymentTransaction( "AccountLinker", []byte(` - pub contract AccountLinker { + access(all) contract AccountLinker { - pub fun link(_ account: AuthAccount) { + access(all) fun link(_ account: AuthAccount) { account.linkAccount(/private/foo) } } @@ -2836,7 +2836,7 @@ func TestRuntimeAccountLink(t *testing.T) { import AccountLinker from 0x1 - pub fun main() { + access(all) fun main() { AccountLinker.link(getAuthAccount(0x1)) } `) diff --git a/runtime/ast/access.go b/runtime/ast/access.go index a12725a359..8a18b04716 100644 --- a/runtime/ast/access.go +++ b/runtime/ast/access.go @@ -156,7 +156,7 @@ func (e EntitlementAccess) subset(other EntitlementAccess) bool { func (e EntitlementAccess) IsLessPermissiveThan(other Access) bool { switch other := other.(type) { case PrimitiveAccess: - return other == AccessPublic || other == AccessPublicSettable + return other == AccessAll case EntitlementAccess: return e.subset(other) default: @@ -170,11 +170,10 @@ type PrimitiveAccess uint8 const ( AccessNotSpecified PrimitiveAccess = iota - AccessPrivate + AccessSelf AccessContract AccessAccount - AccessPublic - AccessPublicSettable + AccessAll ) func PrimitiveAccessCount() int { @@ -189,9 +188,8 @@ func (PrimitiveAccess) isAccess() {} var BasicAccesses = []PrimitiveAccess{ AccessNotSpecified, - AccessPrivate, - AccessPublic, - AccessPublicSettable, + AccessSelf, + AccessAll, } var AllAccesses = append(BasicAccesses[:], @@ -203,12 +201,10 @@ func (a PrimitiveAccess) Keyword() string { switch a { case AccessNotSpecified: return "" - case AccessPrivate: - return "priv" - case AccessPublic: - return "pub" - case AccessPublicSettable: - return "pub(set)" + case AccessSelf: + return "access(self)" + case AccessAll: + return "access(all)" case AccessAccount: return "access(account)" case AccessContract: @@ -222,12 +218,10 @@ func (a PrimitiveAccess) Description() string { switch a { case AccessNotSpecified: return "not specified" - case AccessPrivate: - return "private" - case AccessPublic: - return "public" - case AccessPublicSettable: - return "public settable" + case AccessSelf: + return "self" + case AccessAll: + return "all" case AccessAccount: return "account" case AccessContract: diff --git a/runtime/ast/attachment_test.go b/runtime/ast/attachment_test.go index da66f81c68..bc54bbfb16 100644 --- a/runtime/ast/attachment_test.go +++ b/runtime/ast/attachment_test.go @@ -32,7 +32,7 @@ func TestAttachmentDeclaration_MarshallJSON(t *testing.T) { t.Parallel() decl := &AttachmentDeclaration{ - Access: AccessPublic, + Access: AccessAll, Identifier: NewIdentifier( nil, "Foo", @@ -88,7 +88,7 @@ func TestAttachmentDeclaration_MarshallJSON(t *testing.T) { ` { "Type": "AttachmentDeclaration", - "Access": "AccessPublic", + "Access": "AccessAll", "StartPos": {"Offset": 1, "Line": 2, "Column": 3}, "EndPos": {"Offset": 4, "Line": 5, "Column": 6}, "Identifier": { @@ -155,7 +155,7 @@ func TestAttachmentDeclaration_Doc(t *testing.T) { t.Parallel() decl := &AttachmentDeclaration{ - Access: AccessPublic, + Access: AccessAll, Identifier: NewIdentifier( nil, "Foo", @@ -206,7 +206,7 @@ func TestAttachmentDeclaration_Doc(t *testing.T) { require.Equal( t, prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Text(" "), prettier.Text("attachment"), prettier.Text(" "), @@ -258,7 +258,7 @@ func TestAttachmentDeclaration_Doc(t *testing.T) { decl.Doc(), ) - require.Equal(t, "pub attachment Foo for Bar: Baz {\nrequire entitlement X\nrequire entitlement Y\n}", decl.String()) + require.Equal(t, "access(all) attachment Foo for Bar: Baz {\nrequire entitlement X\nrequire entitlement Y\n}", decl.String()) } func TestAttachExpressionMarshallJSON(t *testing.T) { diff --git a/runtime/ast/composite_test.go b/runtime/ast/composite_test.go index 9ed1a604ef..cf24f7cbbd 100644 --- a/runtime/ast/composite_test.go +++ b/runtime/ast/composite_test.go @@ -34,7 +34,7 @@ func TestFieldDeclaration_MarshalJSON(t *testing.T) { t.Parallel() decl := &FieldDeclaration{ - Access: AccessPublic, + Access: AccessAll, Flags: FieldDeclarationFlagsIsStatic | FieldDeclarationFlagsIsNative, VariableKind: VariableKindConstant, Identifier: Identifier{ @@ -66,7 +66,7 @@ func TestFieldDeclaration_MarshalJSON(t *testing.T) { ` { "Type": "FieldDeclaration", - "Access": "AccessPublic", + "Access": "AccessAll", "IsStatic": true, "IsNative": true, "VariableKind": "VariableKindConstant", @@ -108,7 +108,7 @@ func TestFieldDeclaration_Doc(t *testing.T) { t.Parallel() decl := &FieldDeclaration{ - Access: AccessPublic, + Access: AccessAll, VariableKind: VariableKindConstant, Flags: FieldDeclarationFlagsIsNative | FieldDeclarationFlagsIsStatic, Identifier: Identifier{ @@ -128,7 +128,7 @@ func TestFieldDeclaration_Doc(t *testing.T) { t, prettier.Group{ Doc: prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Text(" "), prettier.Text("static"), prettier.Text(" "), @@ -199,7 +199,7 @@ func TestFieldDeclaration_Doc(t *testing.T) { t.Parallel() decl := &FieldDeclaration{ - Access: AccessPublic, + Access: AccessAll, Identifier: Identifier{ Identifier: "xyz", }, @@ -217,7 +217,7 @@ func TestFieldDeclaration_Doc(t *testing.T) { t, prettier.Group{ Doc: prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Text(" "), prettier.Group{ Doc: prettier.Concat{ @@ -281,7 +281,7 @@ func TestFieldDeclaration_String(t *testing.T) { t.Parallel() decl := &FieldDeclaration{ - Access: AccessPublic, + Access: AccessAll, VariableKind: VariableKindConstant, Identifier: Identifier{ Identifier: "xyz", @@ -298,7 +298,7 @@ func TestFieldDeclaration_String(t *testing.T) { require.Equal( t, - "pub let xyz: @CD", + "access(all) let xyz: @CD", decl.String(), ) }) @@ -335,7 +335,7 @@ func TestFieldDeclaration_String(t *testing.T) { t.Parallel() decl := &FieldDeclaration{ - Access: AccessPublic, + Access: AccessAll, Identifier: Identifier{ Identifier: "xyz", }, @@ -351,7 +351,7 @@ func TestFieldDeclaration_String(t *testing.T) { require.Equal( t, - "pub xyz: @CD", + "access(all) xyz: @CD", decl.String(), ) @@ -390,7 +390,7 @@ func TestCompositeDeclaration_MarshalJSON(t *testing.T) { t.Parallel() decl := &CompositeDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindResource, Identifier: Identifier{ Identifier: "AB", @@ -420,7 +420,7 @@ func TestCompositeDeclaration_MarshalJSON(t *testing.T) { ` { "Type": "CompositeDeclaration", - "Access": "AccessPublic", + "Access": "AccessAll", "CompositeKind": "CompositeKindResource", "Identifier": { "Identifier": "AB", @@ -460,7 +460,7 @@ func TestCompositeDeclaration_Doc(t *testing.T) { t.Parallel() decl := &CompositeDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindResource, Identifier: Identifier{ Identifier: "AB", @@ -483,7 +483,7 @@ func TestCompositeDeclaration_Doc(t *testing.T) { require.Equal( t, prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Text(" "), prettier.Text("resource"), prettier.Text(" "), @@ -518,7 +518,7 @@ func TestCompositeDeclaration_Doc(t *testing.T) { t.Parallel() decl := &CompositeDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindResource, Identifier: Identifier{ Identifier: "AB", @@ -555,7 +555,7 @@ func TestCompositeDeclaration_Doc(t *testing.T) { require.Equal( t, prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Text(" "), prettier.Text("resource"), prettier.Text(" "), @@ -606,7 +606,7 @@ func TestCompositeDeclaration_Doc(t *testing.T) { t.Parallel() decl := &CompositeDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindEvent, Identifier: Identifier{ Identifier: "AB", @@ -636,7 +636,7 @@ func TestCompositeDeclaration_Doc(t *testing.T) { require.Equal( t, prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Text(" "), prettier.Text("event"), prettier.Text(" "), @@ -668,7 +668,7 @@ func TestCompositeDeclaration_Doc(t *testing.T) { t.Parallel() decl := &CompositeDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindEnum, Identifier: Identifier{ Identifier: "AB", @@ -693,7 +693,7 @@ func TestCompositeDeclaration_Doc(t *testing.T) { require.Equal( t, prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Text(" "), prettier.Text("enum"), prettier.Text(" "), @@ -741,7 +741,7 @@ func TestCompositeDeclaration_String(t *testing.T) { t.Parallel() decl := &CompositeDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindResource, Identifier: Identifier{ Identifier: "AB", @@ -763,7 +763,7 @@ func TestCompositeDeclaration_String(t *testing.T) { require.Equal( t, - "pub resource AB: CD, EF {}", + "access(all) resource AB: CD, EF {}", decl.String(), ) }) @@ -773,7 +773,7 @@ func TestCompositeDeclaration_String(t *testing.T) { t.Parallel() decl := &CompositeDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindResource, Identifier: Identifier{ Identifier: "AB", @@ -809,7 +809,7 @@ func TestCompositeDeclaration_String(t *testing.T) { require.Equal( t, - "pub resource AB: CD, EF {\n"+ + "access(all) resource AB: CD, EF {\n"+ " x: X\n"+ "}", decl.String(), @@ -821,7 +821,7 @@ func TestCompositeDeclaration_String(t *testing.T) { t.Parallel() decl := &CompositeDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindEvent, Identifier: Identifier{ Identifier: "AB", @@ -850,7 +850,7 @@ func TestCompositeDeclaration_String(t *testing.T) { require.Equal( t, - "pub event AB(e: E)", + "access(all) event AB(e: E)", decl.String(), ) }) @@ -860,7 +860,7 @@ func TestCompositeDeclaration_String(t *testing.T) { t.Parallel() decl := &CompositeDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindEnum, Identifier: Identifier{ Identifier: "AB", @@ -884,7 +884,7 @@ func TestCompositeDeclaration_String(t *testing.T) { require.Equal( t, - "pub enum AB: CD {\n"+ + "access(all) enum AB: CD {\n"+ " case x\n"+ "}", decl.String(), diff --git a/runtime/ast/entitlement_declaration_test.go b/runtime/ast/entitlement_declaration_test.go index 9c648204b2..59d54b1a08 100644 --- a/runtime/ast/entitlement_declaration_test.go +++ b/runtime/ast/entitlement_declaration_test.go @@ -32,7 +32,7 @@ func TestEntitlementDeclaration_MarshalJSON(t *testing.T) { t.Parallel() decl := &EntitlementDeclaration{ - Access: AccessPublic, + Access: AccessAll, Identifier: Identifier{ Identifier: "AB", Pos: Position{Offset: 1, Line: 2, Column: 3}, @@ -52,7 +52,7 @@ func TestEntitlementDeclaration_MarshalJSON(t *testing.T) { ` { "Type": "EntitlementDeclaration", - "Access": "AccessPublic", + "Access": "AccessAll", "Identifier": { "Identifier": "AB", "StartPos": {"Offset": 1, "Line": 2, "Column": 3}, @@ -76,7 +76,7 @@ func TestEntitlementDeclaration_Doc(t *testing.T) { t.Parallel() decl := &EntitlementDeclaration{ - Access: AccessPublic, + Access: AccessAll, Identifier: Identifier{ Identifier: "AB", }, @@ -85,7 +85,7 @@ func TestEntitlementDeclaration_Doc(t *testing.T) { require.Equal( t, prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Text(" "), prettier.Text("entitlement "), prettier.Text("AB"), @@ -105,7 +105,7 @@ func TestEntitlementDeclaration_String(t *testing.T) { t.Parallel() decl := &EntitlementDeclaration{ - Access: AccessPublic, + Access: AccessAll, Identifier: Identifier{ Identifier: "AB", }, @@ -113,7 +113,7 @@ func TestEntitlementDeclaration_String(t *testing.T) { require.Equal( t, - "pub entitlement AB", + "access(all) entitlement AB", decl.String(), ) @@ -125,7 +125,7 @@ func TestEntitlementMappingDeclaration_MarshalJSON(t *testing.T) { t.Parallel() decl := &EntitlementMappingDeclaration{ - Access: AccessPublic, + Access: AccessAll, Identifier: Identifier{ Identifier: "AB", Pos: Position{Offset: 1, Line: 2, Column: 3}, @@ -161,7 +161,7 @@ func TestEntitlementMappingDeclaration_MarshalJSON(t *testing.T) { ` { "Type": "EntitlementMappingDeclaration", - "Access": "AccessPublic", + "Access": "AccessAll", "Identifier": { "Identifier": "AB", "StartPos": {"Offset": 1, "Line": 2, "Column": 3}, @@ -205,7 +205,7 @@ func TestEntitlementMappingDeclaration_Doc(t *testing.T) { t.Parallel() decl := &EntitlementMappingDeclaration{ - Access: AccessPublic, + Access: AccessAll, Identifier: Identifier{ Identifier: "AB", Pos: Position{Offset: 1, Line: 2, Column: 3}, @@ -236,7 +236,7 @@ func TestEntitlementMappingDeclaration_Doc(t *testing.T) { require.Equal( t, prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Text(" "), prettier.Text("entitlement "), prettier.Text("mapping "), @@ -266,7 +266,7 @@ func TestEntitlementMappingDeclaration_String(t *testing.T) { t.Parallel() decl := &EntitlementMappingDeclaration{ - Access: AccessPublic, + Access: AccessAll, Identifier: Identifier{ Identifier: "AB", Pos: Position{Offset: 1, Line: 2, Column: 3}, @@ -296,7 +296,7 @@ func TestEntitlementMappingDeclaration_String(t *testing.T) { require.Equal( t, - `pub entitlement mapping AB { + `access(all) entitlement mapping AB { X -> Y }`, decl.String(), diff --git a/runtime/ast/function_declaration_test.go b/runtime/ast/function_declaration_test.go index ec6022e719..f87471d236 100644 --- a/runtime/ast/function_declaration_test.go +++ b/runtime/ast/function_declaration_test.go @@ -34,7 +34,7 @@ func TestFunctionDeclaration_MarshalJSON(t *testing.T) { t.Parallel() decl := &FunctionDeclaration{ - Access: AccessPublic, + Access: AccessAll, Flags: FunctionDeclarationFlagsIsStatic | FunctionDeclarationFlagsIsNative, Identifier: Identifier{ Identifier: "xyz", @@ -125,7 +125,7 @@ func TestFunctionDeclaration_MarshalJSON(t *testing.T) { ` { "Type": "FunctionDeclaration", - "Access": "AccessPublic", + "Access": "AccessAll", "IsStatic": true, "IsNative": true, "Identifier": { @@ -289,7 +289,7 @@ func TestFunctionDeclaration_Doc(t *testing.T) { t.Parallel() decl := &FunctionDeclaration{ - Access: AccessPublic, + Access: AccessAll, Purity: FunctionPurityView, Flags: FunctionDeclarationFlagsIsStatic | FunctionDeclarationFlagsIsNative, Identifier: Identifier{ @@ -330,7 +330,7 @@ func TestFunctionDeclaration_Doc(t *testing.T) { require.Equal(t, prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Space, prettier.Text("view"), prettier.Space, @@ -383,7 +383,7 @@ func TestFunctionDeclaration_String(t *testing.T) { t.Parallel() decl := &FunctionDeclaration{ - Access: AccessPublic, + Access: AccessAll, Identifier: Identifier{ Identifier: "xyz", }, @@ -420,7 +420,7 @@ func TestFunctionDeclaration_String(t *testing.T) { } require.Equal(t, - "pub fun xyz(ok foobar: AB): @CD {}", + "access(all) fun xyz(ok foobar: AB): @CD {}", decl.String(), ) @@ -430,7 +430,7 @@ func TestFunctionDeclaration_String(t *testing.T) { t.Parallel() decl := &FunctionDeclaration{ - Access: AccessPublic, + Access: AccessAll, Identifier: Identifier{ Identifier: "xyz", }, @@ -488,7 +488,7 @@ func TestFunctionDeclaration_String(t *testing.T) { } require.Equal(t, - "pub fun xyz(ok foobar: AB): @CD {}", + "access(all) fun xyz(ok foobar: AB): @CD {}", decl.String(), ) }) diff --git a/runtime/ast/interface_test.go b/runtime/ast/interface_test.go index 38ad49c71f..bbb2c2a558 100644 --- a/runtime/ast/interface_test.go +++ b/runtime/ast/interface_test.go @@ -36,7 +36,7 @@ func TestInterfaceDeclaration_MarshalJSON(t *testing.T) { t.Run("no conformances", func(t *testing.T) { decl := &InterfaceDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindResource, Identifier: Identifier{ Identifier: "AB", @@ -58,7 +58,7 @@ func TestInterfaceDeclaration_MarshalJSON(t *testing.T) { ` { "Type": "InterfaceDeclaration", - "Access": "AccessPublic", + "Access": "AccessAll", "CompositeKind": "CompositeKindResource", "Identifier": { "Identifier": "AB", @@ -81,7 +81,7 @@ func TestInterfaceDeclaration_MarshalJSON(t *testing.T) { t.Run("with conformances", func(t *testing.T) { decl := &InterfaceDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindResource, Identifier: Identifier{ Identifier: "AB", @@ -110,7 +110,7 @@ func TestInterfaceDeclaration_MarshalJSON(t *testing.T) { ` { "Type": "InterfaceDeclaration", - "Access": "AccessPublic", + "Access": "AccessAll", "CompositeKind": "CompositeKindResource", "Identifier": { "Identifier": "AB", @@ -151,7 +151,7 @@ func TestInterfaceDeclaration_Doc(t *testing.T) { t.Parallel() decl := &InterfaceDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindResource, Identifier: Identifier{ Identifier: "AB", @@ -162,7 +162,7 @@ func TestInterfaceDeclaration_Doc(t *testing.T) { require.Equal( t, prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Text(" "), prettier.Text("resource"), prettier.Text(" "), @@ -181,7 +181,7 @@ func TestInterfaceDeclaration_Doc(t *testing.T) { t.Parallel() decl := &InterfaceDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindResource, Identifier: Identifier{ Identifier: "AB", @@ -206,7 +206,7 @@ func TestInterfaceDeclaration_Doc(t *testing.T) { require.Equal( t, prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Text(" "), prettier.Text("resource"), prettier.Text(" "), @@ -246,7 +246,7 @@ func TestInterfaceDeclaration_String(t *testing.T) { t.Parallel() decl := &InterfaceDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindResource, Identifier: Identifier{ Identifier: "AB", @@ -256,7 +256,7 @@ func TestInterfaceDeclaration_String(t *testing.T) { require.Equal( t, - "pub resource interface AB {}", + "access(all) resource interface AB {}", decl.String(), ) @@ -267,7 +267,7 @@ func TestInterfaceDeclaration_String(t *testing.T) { t.Parallel() decl := &InterfaceDeclaration{ - Access: AccessPublic, + Access: AccessAll, CompositeKind: common.CompositeKindResource, Identifier: Identifier{ Identifier: "AB", @@ -291,7 +291,7 @@ func TestInterfaceDeclaration_String(t *testing.T) { require.Equal( t, - "pub resource interface AB {\n"+ + "access(all) resource interface AB {\n"+ " x: X\n"+ "}", decl.String(), diff --git a/runtime/ast/primitiveaccess_string.go b/runtime/ast/primitiveaccess_string.go index 447c8aea17..40ebd6decd 100644 --- a/runtime/ast/primitiveaccess_string.go +++ b/runtime/ast/primitiveaccess_string.go @@ -9,16 +9,15 @@ func _() { // Re-run the stringer command to generate them again. var x [1]struct{} _ = x[AccessNotSpecified-0] - _ = x[AccessPrivate-1] + _ = x[AccessSelf-1] _ = x[AccessContract-2] _ = x[AccessAccount-3] - _ = x[AccessPublic-4] - _ = x[AccessPublicSettable-5] + _ = x[AccessAll-4] } -const _PrimitiveAccess_name = "AccessNotSpecifiedAccessPrivateAccessContractAccessAccountAccessPublicAccessPublicSettable" +const _PrimitiveAccess_name = "AccessNotSpecifiedAccessSelfAccessContractAccessAccountAccessAll" -var _PrimitiveAccess_index = [...]uint8{0, 18, 31, 45, 58, 70, 90} +var _PrimitiveAccess_index = [...]uint8{0, 18, 28, 42, 55, 64} func (i PrimitiveAccess) String() string { if i >= PrimitiveAccess(len(_PrimitiveAccess_index)-1) { diff --git a/runtime/ast/transaction_declaration_test.go b/runtime/ast/transaction_declaration_test.go index c1987d6683..d4f4c17d32 100644 --- a/runtime/ast/transaction_declaration_test.go +++ b/runtime/ast/transaction_declaration_test.go @@ -103,7 +103,7 @@ func TestTransactionDeclaration_Doc(t *testing.T) { }, Fields: []*FieldDeclaration{ { - Access: AccessPublic, + Access: AccessAll, VariableKind: VariableKindConstant, Identifier: Identifier{ Identifier: "f", @@ -210,7 +210,7 @@ func TestTransactionDeclaration_Doc(t *testing.T) { prettier.HardLine{}, prettier.Group{ Doc: prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Text(" "), prettier.Text("let"), prettier.Text(" "), @@ -367,7 +367,7 @@ func TestTransactionDeclaration_String(t *testing.T) { }, Fields: []*FieldDeclaration{ { - Access: AccessPublic, + Access: AccessAll, VariableKind: VariableKindConstant, Identifier: Identifier{ Identifier: "f", @@ -448,7 +448,7 @@ func TestTransactionDeclaration_String(t *testing.T) { require.Equal( t, "transaction(x: X) {\n"+ - " pub let f: @F\n"+ + " access(all) let f: @F\n"+ " \n"+ " prepare(signer: AuthAccount) {}\n"+ " \n"+ diff --git a/runtime/ast/variable_declaration_test.go b/runtime/ast/variable_declaration_test.go index 9f77168ccf..ae43b35e48 100644 --- a/runtime/ast/variable_declaration_test.go +++ b/runtime/ast/variable_declaration_test.go @@ -32,7 +32,7 @@ func TestVariableDeclaration_MarshalJSON(t *testing.T) { t.Parallel() decl := &VariableDeclaration{ - Access: AccessPublic, + Access: AccessAll, IsConstant: true, Identifier: Identifier{ Identifier: "foo", @@ -82,7 +82,7 @@ func TestVariableDeclaration_MarshalJSON(t *testing.T) { ` { "Type": "VariableDeclaration", - "Access": "AccessPublic", + "Access": "AccessAll", "IsConstant": true, "Identifier": { "Identifier": "foo", @@ -146,7 +146,7 @@ func TestVariableDeclaration_Doc(t *testing.T) { t.Parallel() decl := &VariableDeclaration{ - Access: AccessPublic, + Access: AccessAll, IsConstant: true, Identifier: Identifier{ Identifier: "foo", @@ -170,7 +170,7 @@ func TestVariableDeclaration_Doc(t *testing.T) { require.Equal(t, prettier.Group{ Doc: prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Text(" "), prettier.Text("let"), prettier.Text(" "), @@ -209,7 +209,7 @@ func TestVariableDeclaration_Doc(t *testing.T) { t.Parallel() decl := &VariableDeclaration{ - Access: AccessPublic, + Access: AccessAll, IsConstant: true, Identifier: Identifier{ Identifier: "foo", @@ -239,7 +239,7 @@ func TestVariableDeclaration_Doc(t *testing.T) { require.Equal(t, prettier.Group{ Doc: prettier.Concat{ - prettier.Text("pub"), + prettier.Text("access(all)"), prettier.Text(" "), prettier.Text("let"), prettier.Text(" "), @@ -287,7 +287,7 @@ func TestVariableDeclaration_String(t *testing.T) { t.Parallel() decl := &VariableDeclaration{ - Access: AccessPublic, + Access: AccessAll, IsConstant: true, Identifier: Identifier{ Identifier: "foo", @@ -309,7 +309,7 @@ func TestVariableDeclaration_String(t *testing.T) { } require.Equal(t, - "pub let foo: @AB <- true", + "access(all) let foo: @AB <- true", decl.String(), ) }) @@ -319,7 +319,7 @@ func TestVariableDeclaration_String(t *testing.T) { t.Parallel() decl := &VariableDeclaration{ - Access: AccessPublic, + Access: AccessAll, IsConstant: true, Identifier: Identifier{ Identifier: "foo", @@ -347,7 +347,7 @@ func TestVariableDeclaration_String(t *testing.T) { } require.Equal(t, - "pub let foo: @AB <- true <- false", + "access(all) let foo: @AB <- true <- false", decl.String(), ) }) diff --git a/runtime/attachments_test.go b/runtime/attachments_test.go index f49111262b..7a05f902df 100644 --- a/runtime/attachments_test.go +++ b/runtime/attachments_test.go @@ -46,18 +46,18 @@ func TestAccountAttachmentSaveAndLoad(t *testing.T) { accountCodes := map[Location][]byte{} deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub resource R { - pub fun foo(): Int { + access(all) contract Test { + access(all) resource R { + access(all) fun foo(): Int { return 3 } } - pub attachment A for R { - pub fun foo(): Int { + access(all) attachment A for R { + access(all) fun foo(): Int { return base.foo() } } - pub fun makeRWithA(): @R { + access(all) fun makeRWithA(): @R { return <- attach A() to <-create R() } } @@ -157,10 +157,10 @@ func TestAccountAttachmentExportFailure(t *testing.T) { accountCodes := map[Location][]byte{} deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub resource R {} - pub attachment A for R {} - pub fun makeRWithA(): @R { + access(all) contract Test { + access(all) resource R {} + access(all) attachment A for R {} + access(all) fun makeRWithA(): @R { return <- attach A() to <-create R() } } @@ -168,7 +168,7 @@ func TestAccountAttachmentExportFailure(t *testing.T) { script := []byte(` import Test from 0x1 - pub fun main(): &Test.A? { + access(all) fun main(): &Test.A? { let r <- Test.makeRWithA() let a = r[Test.A] destroy r @@ -238,10 +238,10 @@ func TestAccountAttachmentExport(t *testing.T) { accountCodes := map[Location][]byte{} deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub resource R {} - pub attachment A for R {} - pub fun makeRWithA(): @R { + access(all) contract Test { + access(all) resource R {} + access(all) attachment A for R {} + access(all) fun makeRWithA(): @R { return <- attach A() to <-create R() } } @@ -249,7 +249,7 @@ func TestAccountAttachmentExport(t *testing.T) { script := []byte(` import Test from 0x1 - pub fun main(): &Test.A? { + access(all) fun main(): &Test.A? { let r <- Test.makeRWithA() let authAccount = getAuthAccount(0x1) authAccount.save(<-r, to: /storage/foo) @@ -323,10 +323,10 @@ func TestAccountAttachedExport(t *testing.T) { accountCodes := map[Location][]byte{} deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub resource R {} - pub attachment A for R {} - pub fun makeRWithA(): @R { + access(all) contract Test { + access(all) resource R {} + access(all) attachment A for R {} + access(all) fun makeRWithA(): @R { return <- attach A() to <-create R() } } @@ -334,7 +334,7 @@ func TestAccountAttachedExport(t *testing.T) { script := []byte(` import Test from 0x1 - pub fun main(): @Test.R { + access(all) fun main(): @Test.R { return <-Test.makeRWithA() } `) @@ -404,21 +404,21 @@ func TestAccountAttachmentSaveAndBorrow(t *testing.T) { accountCodes := map[Location][]byte{} deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub resource interface I { - pub fun foo(): Int + access(all) contract Test { + access(all) resource interface I { + access(all) fun foo(): Int } - pub resource R: I { - pub fun foo(): Int { + access(all) resource R: I { + access(all) fun foo(): Int { return 3 } } - pub attachment A for I { - pub fun foo(): Int { + access(all) attachment A for I { + access(all) fun foo(): Int { return base.foo() } } - pub fun makeRWithA(): @R { + access(all) fun makeRWithA(): @R { return <- attach A() to <-create R() } } @@ -518,21 +518,21 @@ func TestAccountAttachmentCapability(t *testing.T) { accountCodes := map[Location][]byte{} deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub resource interface I { - pub fun foo(): Int + access(all) contract Test { + access(all) resource interface I { + access(all) fun foo(): Int } - pub resource R: I { - pub fun foo(): Int { + access(all) resource R: I { + access(all) fun foo(): Int { return 3 } } - pub attachment A for I { - pub fun foo(): Int { + access(all) attachment A for I { + access(all) fun foo(): Int { return base.foo() } } - pub fun makeRWithA(): @R { + access(all) fun makeRWithA(): @R { return <- attach A() to <-create R() } } diff --git a/runtime/capabilitycontrollers_test.go b/runtime/capabilitycontrollers_test.go index 930102670f..7e8ba64427 100644 --- a/runtime/capabilitycontrollers_test.go +++ b/runtime/capabilitycontrollers_test.go @@ -51,29 +51,29 @@ func TestRuntimeCapabilityControllers(t *testing.T) { "Test", // language=cadence []byte(` - pub contract Test { + access(all) contract Test { - pub entitlement X + access(all) entitlement X - pub resource R { + access(all) resource R { - pub let id: Int + access(all) let id: Int init(id: Int) { self.id = id } } - pub resource S {} + access(all) resource S {} - pub fun createAndSaveR(id: Int, storagePath: StoragePath) { + access(all) fun createAndSaveR(id: Int, storagePath: StoragePath) { self.account.save( <-create R(id: id), to: storagePath ) } - pub fun createAndSaveS(storagePath: StoragePath) { + access(all) fun createAndSaveS(storagePath: StoragePath) { self.account.save( <-create S(), to: storagePath @@ -85,7 +85,7 @@ func TestRuntimeCapabilityControllers(t *testing.T) { /// > Our version of quicksort is not the fastest possible, /// > but it's one of the simplest. /// - pub fun quickSort(_ items: &[AnyStruct], isLess: fun(Int, Int): Bool) { + access(all) fun quickSort(_ items: &[AnyStruct], isLess: fun(Int, Int): Bool) { fun quickSortPart(leftIndex: Int, rightIndex: Int) { @@ -2528,7 +2528,7 @@ func TestRuntimeCapabilityControllers(t *testing.T) { assert(controller2.tag == "") // Act - controller1.tag = "something" + controller1.setTag("something") // Assert let controller3: &StorageCapabilityController = @@ -3005,7 +3005,7 @@ func TestRuntimeCapabilityControllers(t *testing.T) { assert(controller2.tag == "") // Act - controller1.tag = "something" + controller1.setTag("something") // Assert let controller3: &AccountCapabilityController = diff --git a/runtime/cmd/compile/main.go b/runtime/cmd/compile/main.go index 252d1b1977..52e8a4be71 100644 --- a/runtime/cmd/compile/main.go +++ b/runtime/cmd/compile/main.go @@ -67,7 +67,7 @@ func main() { // Export all public functions for i, functionDeclaration := range functionDeclarations { - if functionDeclaration.Access != ast.AccessPublic { + if functionDeclaration.Access != ast.AccessAll { continue } diff --git a/runtime/contract_test.go b/runtime/contract_test.go index 21d2d08540..467be3b0b6 100644 --- a/runtime/contract_test.go +++ b/runtime/contract_test.go @@ -510,8 +510,8 @@ func TestRuntimeContract(t *testing.T) { t.Run("valid contract, correct name", func(t *testing.T) { test(t, testCase{ name: "Test", - code: `pub contract Test {}`, - code2: `pub contract Test { pub fun test() {} }`, + code: `access(all) contract Test {}`, + code2: `access(all) contract Test { access(all) fun test() {} }`, valid: true, isInterface: false, }) @@ -520,8 +520,8 @@ func TestRuntimeContract(t *testing.T) { t.Run("valid contract interface, correct name", func(t *testing.T) { test(t, testCase{ name: "Test", - code: `pub contract interface Test {}`, - code2: `pub contract interface Test { pub fun test() }`, + code: `access(all) contract interface Test {}`, + code2: `access(all) contract interface Test { access(all) fun test() }`, valid: true, isInterface: true, }) @@ -530,7 +530,7 @@ func TestRuntimeContract(t *testing.T) { t.Run("valid contract, wrong name", func(t *testing.T) { test(t, testCase{ name: "XYZ", - code: `pub contract Test {}`, + code: `access(all) contract Test {}`, valid: false, isInterface: false, }) @@ -539,7 +539,7 @@ func TestRuntimeContract(t *testing.T) { t.Run("valid contract interface, wrong name", func(t *testing.T) { test(t, testCase{ name: "XYZ", - code: `pub contract interface Test {}`, + code: `access(all) contract interface Test {}`, valid: false, isInterface: true, }) @@ -567,9 +567,9 @@ func TestRuntimeContract(t *testing.T) { test(t, testCase{ name: "Test", code: ` - pub contract Test {} + access(all) contract Test {} - pub contract Test2 {} + access(all) contract Test2 {} `, valid: false, isInterface: false, @@ -580,9 +580,9 @@ func TestRuntimeContract(t *testing.T) { test(t, testCase{ name: "Test", code: ` - pub contract interface Test {} + access(all) contract interface Test {} - pub contract interface Test2 {} + access(all) contract interface Test2 {} `, valid: false, isInterface: true, @@ -593,9 +593,9 @@ func TestRuntimeContract(t *testing.T) { test(t, testCase{ name: "Test", code: ` - pub contract Test {} + access(all) contract Test {} - pub contract interface Test2 {} + access(all) contract interface Test2 {} `, valid: false, isInterface: false, @@ -608,18 +608,18 @@ func TestRuntimeImportMultipleContracts(t *testing.T) { t.Parallel() contractA := ` - pub contract A { + access(all) contract A { - pub fun a(): Int { + access(all) fun a(): Int { return 1 } } ` contractB := ` - pub contract B { + access(all) contract B { - pub fun b(): Int { + access(all) fun b(): Int { return 2 } } @@ -628,9 +628,9 @@ func TestRuntimeImportMultipleContracts(t *testing.T) { contractC := ` import A, B from 0x1 - pub contract C { + access(all) contract C { - pub fun c(): Int { + access(all) fun c(): Int { return A.a() + B.b() } } diff --git a/runtime/contract_update_test.go b/runtime/contract_update_test.go index 24610c3d1b..9ac36a3258 100644 --- a/runtime/contract_update_test.go +++ b/runtime/contract_update_test.go @@ -104,15 +104,15 @@ func TestContractUpdateWithDependencies(t *testing.T) { nextTransactionLocation := newTransactionLocationGenerator() const fooContractV1 = ` - pub contract Foo { + access(all) contract Foo { init() {} - pub fun hello() {} + access(all) fun hello() {} } ` const barContractV1 = ` import Foo from 0x01 - pub contract Bar { + access(all) contract Bar { init() { Foo.hello() } @@ -120,16 +120,16 @@ func TestContractUpdateWithDependencies(t *testing.T) { ` const fooContractV2 = ` - pub contract Foo { + access(all) contract Foo { init() {} - pub fun hello(_ a: Int) {} + access(all) fun hello(_ a: Int) {} } ` const barContractV2 = ` import Foo from 0x01 - pub contract Bar { + access(all) contract Bar { init() { Foo.hello(5) } @@ -225,9 +225,9 @@ func TestContractUpdateWithPrecedingIdentifiers(t *testing.T) { } const fooContractV1 = ` - pub contract Foo { + access(all) contract Foo { // NOTE: invalid preceding identifier in member declaration - bar pub let foo: Int + bar access(all) let foo: Int init() { self.foo = 1 @@ -236,8 +236,8 @@ func TestContractUpdateWithPrecedingIdentifiers(t *testing.T) { ` const fooContractV2 = ` - pub contract Foo { - pub let foo: Int + access(all) contract Foo { + access(all) let foo: Int init() { self.foo = 1 diff --git a/runtime/contract_update_validation_test.go b/runtime/contract_update_validation_test.go index 837db9bf57..147dcc204f 100644 --- a/runtime/contract_update_validation_test.go +++ b/runtime/contract_update_validation_test.go @@ -155,8 +155,8 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub var a: String + access(all) contract Test { + access(all) var a: String init() { self.a = "hello" } @@ -164,8 +164,8 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { - pub var a: Int + access(all) contract Test { + access(all) var a: Int init() { self.a = 0 } @@ -184,8 +184,8 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub var a: String + access(all) contract Test { + access(all) var a: String init() { self.a = "hello" @@ -194,9 +194,9 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { - pub var a: String - pub var b: Int + access(all) contract Test { + access(all) var a: String + access(all) var b: Int init() { self.a = "hello" @@ -217,9 +217,9 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub var a: String - pub var b: Int + access(all) contract Test { + access(all) var a: String + access(all) var b: Int init() { self.a = "hello" @@ -229,8 +229,8 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { - pub var a: String + access(all) contract Test { + access(all) var a: String init() { self.a = "hello" @@ -247,17 +247,17 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { - pub var a: @TestResource + access(all) var a: @TestResource init() { self.a <- create Test.TestResource() } - pub resource TestResource { + access(all) resource TestResource { - pub let b: Int + access(all) let b: Int init() { self.b = 1234 @@ -267,17 +267,17 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { + access(all) contract Test { - pub var a: @Test.TestResource + access(all) var a: @Test.TestResource init() { self.a <- create Test.TestResource() } - pub resource TestResource { + access(all) resource TestResource { - pub let b: String + access(all) let b: String init() { self.b = "string_1234" @@ -298,17 +298,17 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { - pub var a: @TestResource + access(all) var a: @TestResource init() { self.a <- create Test.TestResource() } - pub resource TestResource { + access(all) resource TestResource { - pub var b: String + access(all) var b: String init() { self.b = "hello" @@ -318,18 +318,18 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { + access(all) contract Test { - pub var a: @Test.TestResource + access(all) var a: @Test.TestResource init() { self.a <- create Test.TestResource() } - pub resource TestResource { + access(all) resource TestResource { - pub var b: String - pub var c: Int + access(all) var b: String + access(all) var c: Int init() { self.b = "hello" @@ -351,17 +351,17 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { - pub var x: [TestStruct; 1] + access(all) var x: [TestStruct; 1] init() { self.x = [TestStruct()] } - pub struct TestStruct { - pub let a: Int - pub var b: Int + access(all) struct TestStruct { + access(all) let a: Int + access(all) var b: Int init() { self.a = 123 @@ -372,17 +372,17 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { + access(all) contract Test { - pub var x: [TestStruct; 1] + access(all) var x: [TestStruct; 1] init() { self.x = [TestStruct()] } - pub struct TestStruct { - pub let a: Int - pub var b: String + access(all) struct TestStruct { + access(all) let a: Int + access(all) var b: String init() { self.a = 123 @@ -404,18 +404,18 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { - pub var x: {String: Foo} + access(all) var x: {String: Foo} init() { self.x = { "foo" : Foo() } } - pub struct Foo { + access(all) struct Foo { - pub let a: Foo? - pub let b: Bar + access(all) let a: Foo? + access(all) let b: Bar init() { self.a = nil @@ -423,10 +423,10 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { } } - pub struct Bar { + access(all) struct Bar { - pub let c: Foo? - pub let d: Bar? + access(all) let c: Foo? + access(all) let d: Bar? init() { self.c = nil @@ -437,18 +437,18 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { + access(all) contract Test { - pub var x: {String: Foo} + access(all) var x: {String: Foo} init() { self.x = { "foo" : Foo() } } - pub struct Foo { + access(all) struct Foo { - pub let a: Foo? - pub let b: Bar + access(all) let a: Foo? + access(all) let b: Bar init() { self.a = nil @@ -456,10 +456,10 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { } } - pub struct Bar { + access(all) struct Bar { - pub let c: Foo? - pub let d: String + access(all) let c: Foo? + access(all) let d: String init() { self.c = nil @@ -481,18 +481,18 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { - pub var x: Test.TestStruct - pub var y: TestStruct + access(all) var x: Test.TestStruct + access(all) var y: TestStruct init() { self.x = Test.TestStruct() self.y = TestStruct() } - pub struct TestStruct { - pub let a: Int + access(all) struct TestStruct { + access(all) let a: Int init() { self.a = 123 @@ -502,18 +502,18 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { + access(all) contract Test { - pub var x: TestStruct - pub var y: Test.TestStruct + access(all) var x: TestStruct + access(all) var y: Test.TestStruct init() { self.x = TestStruct() self.y = Test.TestStruct() } - pub struct TestStruct { - pub let a: Int + access(all) struct TestStruct { + access(all) let a: Int init() { self.a = 123 @@ -531,11 +531,11 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const importCode = ` - pub contract TestImport { + access(all) contract TestImport { - pub struct TestStruct { - pub let a: Int - pub var b: Int + access(all) struct TestStruct { + access(all) let a: Int + access(all) var b: Int init() { self.a = 123 @@ -553,9 +553,9 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { const oldCode = ` import TestImport from 0x42 - pub contract Test { + access(all) contract Test { - pub var x: TestImport.TestStruct + access(all) var x: TestImport.TestStruct init() { self.x = TestImport.TestStruct() @@ -564,17 +564,17 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { + access(all) contract Test { - pub var x: TestStruct + access(all) var x: TestStruct init() { self.x = TestStruct() } - pub struct TestStruct { - pub let a: Int - pub var b: Int + access(all) struct TestStruct { + access(all) let a: Int + access(all) var b: Int init() { self.a = 123 @@ -599,16 +599,16 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract interface Test { - pub var a: String - pub fun getA() : String + access(all) contract interface Test { + access(all) var a: String + access(all) fun getA() : String } ` const newCode = ` - pub contract interface Test { - pub var a: Int - pub fun getA() : Int + access(all) contract interface Test { + access(all) var a: Int + access(all) fun getA() : Int } ` @@ -624,22 +624,22 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract interface Test { - pub var a: String - pub fun getA() : String + access(all) contract interface Test { + access(all) var a: String + access(all) fun getA() : String } ` const newCode = ` - pub contract Test { + access(all) contract Test { - pub var a: String + access(all) var a: String init() { self.a = "hello" } - pub fun getA() : String { + access(all) fun getA() : String { return self.a } } @@ -663,24 +663,24 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { - pub var a: String + access(all) var a: String init() { self.a = "hello" } - pub fun getA() : String { + access(all) fun getA() : String { return self.a } } ` const newCode = ` - pub contract interface Test { - pub var a: String - pub fun getA() : String + access(all) contract interface Test { + access(all) var a: String + access(all) fun getA() : String } ` @@ -702,34 +702,34 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { - pub var x: UsedStruct + access(all) var x: UsedStruct init() { self.x = UsedStruct() } - pub struct UsedStruct { - pub let a: Int + access(all) struct UsedStruct { + access(all) let a: Int init() { self.a = 123 } - pub fun getA() : Int { + access(all) fun getA() : Int { return self.a } } - pub struct UnusedStruct { - pub let a: Int + access(all) struct UnusedStruct { + access(all) let a: Int init() { self.a = 123 } - pub fun getA() : Int { + access(all) fun getA() : Int { return self.a } } @@ -737,38 +737,38 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { + access(all) contract Test { - pub var x: UsedStruct + access(all) var x: UsedStruct init() { self.x = UsedStruct() } - pub struct UsedStruct { - pub let a: Int + access(all) struct UsedStruct { + access(all) let a: Int init() { self.a = 123 } - pub fun getA() : String { + access(all) fun getA() : String { return "hello_123" } - pub fun getA_new() : Int { + access(all) fun getA_new() : Int { return self.a } } - pub struct UnusedStruct { - pub let a: String + access(all) struct UnusedStruct { + access(all) let a: String init() { self.a = "string_456" } - pub fun getA() : String { + access(all) fun getA() : String { return self.a } } @@ -790,33 +790,33 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { - pub var x: Foo + access(all) var x: Foo init() { self.x = Foo.up } - pub enum Foo: UInt8 { - pub case up - pub case down + access(all) enum Foo: UInt8 { + access(all) case up + access(all) case down } } ` const newCode = ` - pub contract Test { + access(all) contract Test { - pub var x: Foo + access(all) var x: Foo init() { self.x = Foo.up } - pub enum Foo: UInt128 { - pub case up - pub case down + access(all) enum Foo: UInt128 { + access(all) case up + access(all) case down } } ` @@ -833,33 +833,33 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { - pub var x: AnyStruct{TestStruct}? + access(all) var x: AnyStruct{TestStruct}? init() { self.x = nil } - pub struct interface TestStruct { - pub let a: String - pub var b: Int + access(all) struct interface TestStruct { + access(all) let a: String + access(all) var b: Int } } ` const newCode = ` - pub contract Test { + access(all) contract Test { - pub var x: AnyStruct{TestStruct}? + access(all) var x: AnyStruct{TestStruct}? init() { self.x = nil } - pub struct interface TestStruct { - pub let a: Int - pub var b: Int + access(all) struct interface TestStruct { + access(all) let a: Int + access(all) var b: Int } } ` @@ -876,17 +876,17 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub struct interface TestStruct { - pub var a: Int + access(all) contract Test { + access(all) struct interface TestStruct { + access(all) var a: Int } } ` const newCode = ` - pub contract Test { - pub struct TestStruct { - pub let a: Int + access(all) contract Test { + access(all) struct TestStruct { + access(all) let a: Int init() { self.a = 123 @@ -913,14 +913,14 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { } ` const newCode = ` - pub contract Test { - pub struct TestStruct { - pub let a: Int + access(all) contract Test { + access(all) struct TestStruct { + access(all) let a: Int init() { self.a = 123 @@ -938,9 +938,9 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub struct TestStruct { - pub let a: Int + access(all) contract Test { + access(all) struct TestStruct { + access(all) let a: Int init() { self.a = 123 @@ -950,7 +950,7 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { + access(all) contract Test { } ` @@ -966,8 +966,8 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub var a: String + access(all) contract Test { + access(all) var a: String init() { self.a = "hello" } @@ -975,8 +975,8 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { - pub var b: Int + access(all) contract Test { + access(all) var b: Int init() { self.b = 0 } @@ -995,31 +995,31 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub var a: String + access(all) contract Test { + access(all) var a: String init() { self.a = "hello" } - pub struct interface TestStruct { - pub var a: Int + access(all) struct interface TestStruct { + access(all) var a: Int } } ` const newCode = ` - pub contract Test { - pub var a: Int - pub var b: String + access(all) contract Test { + access(all) var a: Int + access(all) var b: String init() { self.a = 0 self.b = "hello" } - pub struct TestStruct { - pub let a: Int + access(all) struct TestStruct { + access(all) let a: Int init() { self.a = 123 @@ -1053,31 +1053,31 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub var a: String + access(all) contract Test { + access(all) var a: String init() { self.a = "hello" } - pub struct interface TestStruct { - pub var a: Int + access(all) struct interface TestStruct { + access(all) var a: Int } } ` const newCode = ` - pub contract Test { - pub var a: Int - pub var b: String + access(all) contract Test { + access(all) var a: Int + access(all) var b: String init() { self.a = 0 self.b = "hello" } - pub struct TestStruct { - pub let a: Int + access(all) struct TestStruct { + access(all) let a: Int init() { self.a = 123 @@ -1090,22 +1090,22 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { RequireError(t, err) const expectedError = "error: mismatching field `a` in `Test`\n" + - " --> 0000000000000042.Test:3:27\n" + + " --> 0000000000000042.Test:3:35\n" + " |\n" + - "3 | pub var a: Int\n" + - " | ^^^ incompatible type annotations. expected `String`, found `Int`\n" + + "3 | access(all) var a: Int\n" + + " | ^^^ incompatible type annotations. expected `String`, found `Int`\n" + "\n" + "error: found new field `b` in `Test`\n" + - " --> 0000000000000042.Test:4:24\n" + + " --> 0000000000000042.Test:4:32\n" + " |\n" + - "4 | pub var b: String\n" + - " | ^\n" + + "4 | access(all) var b: String\n" + + " | ^\n" + "\n" + "error: trying to convert structure interface `TestStruct` to a structure\n" + - " --> 0000000000000042.Test:11:27\n" + + " --> 0000000000000042.Test:11:35\n" + " |\n" + - "11 | pub struct TestStruct {\n" + - " | ^^^^^^^^^^" + "11 | access(all) struct TestStruct {\n" + + " | ^^^^^^^^^^" require.Contains(t, err.Error(), expectedError) }) @@ -1115,16 +1115,16 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { - pub var vault: Capability<&TestStruct>? + access(all) var vault: Capability<&TestStruct>? init() { self.vault = nil } - pub struct TestStruct { - pub let a: Int + access(all) struct TestStruct { + access(all) let a: Int init() { self.a = 123 @@ -1134,16 +1134,16 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { + access(all) contract Test { - pub var vault: Capability<&TestStruct>? + access(all) var vault: Capability<&TestStruct>? init() { self.vault = nil } - pub struct TestStruct { - pub let a: Int + access(all) struct TestStruct { + access(all) let a: Int init() { self.a = 123 @@ -1161,10 +1161,10 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { - pub struct TestStruct { - pub let a: Int + access(all) struct TestStruct { + access(all) let a: Int init() { self.a = 123 @@ -1174,9 +1174,9 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { + access(all) contract Test { - pub var add: fun(Int, Int): Int + access(all) var add: fun(Int, Int): Int init() { self.add = fun (a: Int, b: Int): Int { @@ -1184,8 +1184,8 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { } } - pub struct TestStruct { - pub let a: Int + access(all) struct TestStruct { + access(all) let a: Int init() { self.a = 123 @@ -1205,9 +1205,9 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const importCode = ` - pub contract TestImport { - pub struct interface AnInterface { - pub a: Int + access(all) contract TestImport { + access(all) struct interface AnInterface { + access(all) a: Int } } ` @@ -1219,16 +1219,16 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { const oldCode = ` import TestImport from 0x42 - pub contract Test { - pub struct TestStruct1 { - pub let a: Int + access(all) contract Test { + access(all) struct TestStruct1 { + access(all) let a: Int init() { self.a = 123 } } - pub struct TestStruct2: TestImport.AnInterface { - pub let a: Int + access(all) struct TestStruct2: TestImport.AnInterface { + access(all) let a: Int init() { self.a = 123 @@ -1240,18 +1240,18 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { const newCode = ` import TestImport from 0x42 - pub contract Test { + access(all) contract Test { - pub struct TestStruct2: TestImport.AnInterface { - pub let a: Int + access(all) struct TestStruct2: TestImport.AnInterface { + access(all) let a: Int init() { self.a = 123 } } - pub struct TestStruct1 { - pub let a: Int + access(all) struct TestStruct1 { + access(all) let a: Int init() { self.a = 123 } @@ -1271,33 +1271,33 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { // simple nominal type - pub var a: TestStruct + access(all) var a: TestStruct // qualified nominal type - pub var b: Test.TestStruct + access(all) var b: Test.TestStruct // optional type - pub var c: Int? + access(all) var c: Int? // variable sized type - pub var d: [Int] + access(all) var d: [Int] // constant sized type - pub var e: [Int; 2] + access(all) var e: [Int; 2] // dictionary type - pub var f: {Int: String} + access(all) var f: {Int: String} // restricted type - pub var g: {TestInterface} + access(all) var g: {TestInterface} // instantiation and reference types - pub var h: Capability<&TestStruct>? + access(all) var h: Capability<&TestStruct>? // function type - pub var i: Capability<&fun(Int, Int): Int>? + access(all) var i: Capability<&fun(Int, Int): Int>? init() { var count: Int = 567 @@ -1312,49 +1312,49 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { self.i = nil } - pub struct TestStruct:TestInterface { - pub let a: Int + access(all) struct TestStruct:TestInterface { + access(all) let a: Int init() { self.a = 123 } } - pub struct interface TestInterface { - pub let a: Int + access(all) struct interface TestInterface { + access(all) let a: Int } } ` const newCode = ` - pub contract Test { + access(all) contract Test { // function type - pub var i: Capability<&fun(Int, Int): Int>? + access(all) var i: Capability<&fun(Int, Int): Int>? // instantiation and reference types - pub var h: Capability<&TestStruct>? + access(all) var h: Capability<&TestStruct>? // restricted type - pub var g: {TestInterface} + access(all) var g: {TestInterface} // dictionary type - pub var f: {Int: String} + access(all) var f: {Int: String} // constant sized type - pub var e: [Int; 2] + access(all) var e: [Int; 2] // variable sized type - pub var d: [Int] + access(all) var d: [Int] // optional type - pub var c: Int? + access(all) var c: Int? // qualified nominal type - pub var b: Test.TestStruct + access(all) var b: Test.TestStruct // simple nominal type - pub var a: TestStruct + access(all) var a: TestStruct init() { var count: Int = 567 @@ -1369,15 +1369,15 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { self.i = nil } - pub struct TestStruct:TestInterface { - pub let a: Int + access(all) struct TestStruct:TestInterface { + access(all) let a: Int init() { self.a = 123 } } - pub struct interface TestInterface { - pub let a: Int + access(all) struct interface TestInterface { + access(all) let a: Int } } ` @@ -1391,13 +1391,13 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { // restricted type - pub var a: {TestInterface} - pub var b: {TestInterface} - pub var c: AnyStruct{TestInterface} - pub var d: AnyStruct{TestInterface} + access(all) var a: {TestInterface} + access(all) var b: {TestInterface} + access(all) var c: AnyStruct{TestInterface} + access(all) var d: AnyStruct{TestInterface} init() { var count: Int = 567 @@ -1407,25 +1407,25 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { self.d = TestStruct() } - pub struct TestStruct:TestInterface { - pub let a: Int + access(all) struct TestStruct:TestInterface { + access(all) let a: Int init() { self.a = 123 } } - pub struct interface TestInterface { - pub let a: Int + access(all) struct interface TestInterface { + access(all) let a: Int } } ` const newCode = ` - pub contract Test { - pub var a: {TestInterface} - pub var b: AnyStruct{TestInterface} - pub var c: {TestInterface} - pub var d: AnyStruct{TestInterface} + access(all) contract Test { + access(all) var a: {TestInterface} + access(all) var b: AnyStruct{TestInterface} + access(all) var c: {TestInterface} + access(all) var d: AnyStruct{TestInterface} init() { var count: Int = 567 @@ -1435,15 +1435,15 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { self.d = TestStruct() } - pub struct TestStruct:TestInterface { - pub let a: Int + access(all) struct TestStruct:TestInterface { + access(all) let a: Int init() { self.a = 123 } } - pub struct interface TestInterface { - pub let a: Int + access(all) struct interface TestInterface { + access(all) let a: Int } } ` @@ -1457,11 +1457,11 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { // restricted type - pub var a: TestStruct{TestInterface} - pub var b: {TestInterface} + access(all) var a: TestStruct{TestInterface} + access(all) var b: {TestInterface} init() { var count: Int = 567 @@ -1469,23 +1469,23 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { self.b = TestStruct() } - pub struct TestStruct:TestInterface { - pub let a: Int + access(all) struct TestStruct:TestInterface { + access(all) let a: Int init() { self.a = 123 } } - pub struct interface TestInterface { - pub let a: Int + access(all) struct interface TestInterface { + access(all) let a: Int } } ` const newCode = ` - pub contract Test { - pub var a: {TestInterface} - pub var b: TestStruct{TestInterface} + access(all) contract Test { + access(all) var a: {TestInterface} + access(all) var b: TestStruct{TestInterface} init() { var count: Int = 567 @@ -1493,15 +1493,15 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { self.b = TestStruct() } - pub struct TestStruct:TestInterface { - pub let a: Int + access(all) struct TestStruct:TestInterface { + access(all) let a: Int init() { self.a = 123 } } - pub struct interface TestInterface { - pub let a: Int + access(all) struct interface TestInterface { + access(all) let a: Int } } ` @@ -1509,12 +1509,12 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { err := testDeployAndUpdate(t, "Test", oldCode, newCode) RequireError(t, err) - assert.Contains(t, err.Error(), "pub var a: {TestInterface}"+ - "\n | ^^^^^^^^^^^^^^^ "+ + assert.Contains(t, err.Error(), "access(all) var a: {TestInterface}"+ + "\n | ^^^^^^^^^^^^^^^ "+ "incompatible type annotations. expected `TestStruct{TestInterface}`, found `{TestInterface}`") - assert.Contains(t, err.Error(), "pub var b: TestStruct{TestInterface}"+ - "\n | ^^^^^^^^^^^^^^^^^^^^^^^^^ "+ + assert.Contains(t, err.Error(), "access(all) var b: TestStruct{TestInterface}"+ + "\n | ^^^^^^^^^^^^^^^^^^^^^^^^^ "+ "incompatible type annotations. expected `{TestInterface}`, found `TestStruct{TestInterface}`") }) @@ -1523,19 +1523,19 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub enum Foo: UInt8 { - pub case up - pub case down + access(all) contract Test { + access(all) enum Foo: UInt8 { + access(all) case up + access(all) case down } } ` const newCode = ` - pub contract Test { - pub enum Foo: UInt8 { - pub case up - pub case down + access(all) contract Test { + access(all) enum Foo: UInt8 { + access(all) case up + access(all) case down } } ` @@ -1549,18 +1549,18 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub enum Foo: UInt8 { - pub case up - pub case down + access(all) contract Test { + access(all) enum Foo: UInt8 { + access(all) case up + access(all) case down } } ` const newCode = ` - pub contract Test { - pub enum Foo: UInt8 { - pub case up + access(all) contract Test { + access(all) enum Foo: UInt8 { + access(all) case up } } ` @@ -1577,20 +1577,20 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub enum Foo: UInt8 { - pub case up - pub case down + access(all) contract Test { + access(all) enum Foo: UInt8 { + access(all) case up + access(all) case down } } ` const newCode = ` - pub contract Test { - pub enum Foo: UInt8 { - pub case up - pub case down - pub case left + access(all) contract Test { + access(all) enum Foo: UInt8 { + access(all) case up + access(all) case down + access(all) case left } } ` @@ -1604,21 +1604,21 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub enum Foo: UInt8 { - pub case up - pub case down - pub case left + access(all) contract Test { + access(all) enum Foo: UInt8 { + access(all) case up + access(all) case down + access(all) case left } } ` const newCode = ` - pub contract Test { - pub enum Foo: UInt8 { - pub case down - pub case left - pub case up + access(all) contract Test { + access(all) enum Foo: UInt8 { + access(all) case down + access(all) case left + access(all) case up } } ` @@ -1642,11 +1642,11 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { - pub struct TestStruct { - pub let a: Int - pub var b: Int + access(all) struct TestStruct { + access(all) let a: Int + access(all) var b: Int init() { self.a = 123 @@ -1657,7 +1657,7 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const updateCode1 = ` - pub contract Test { + access(all) contract Test { } ` @@ -1673,10 +1673,10 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { assertMissingDeclarationError(t, cause, "TestStruct") const updateCode2 = ` - pub contract Test { + access(all) contract Test { - pub struct TestStruct { - pub let a: String + access(all) struct TestStruct { + access(all) let a: String init() { self.a = "hello123" @@ -1697,11 +1697,11 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { + access(all) contract Test { - pub struct TestStruct { - pub let a: Int - pub var b: Int + access(all) struct TestStruct { + access(all) let a: Int + access(all) var b: Int init() { self.a = 123 @@ -1712,11 +1712,11 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { ` const newCode = ` - pub contract Test { + access(all) contract Test { - pub struct TestStructRenamed { - pub let a: Int - pub var b: Int + access(all) struct TestStructRenamed { + access(all) let a: Int + access(all) var b: Int init() { self.a = 123 @@ -1738,8 +1738,8 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const code = ` - pub contract Test { - pub enum TestEnum: Int { + access(all) contract Test { + access(all) enum TestEnum: Int { } } ` @@ -1753,8 +1753,8 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Run("Remove contract interface with enum", func(t *testing.T) { const code = ` - pub contract interface Test { - pub enum TestEnum: Int { + access(all) contract interface Test { + access(all) enum TestEnum: Int { } } ` @@ -1770,9 +1770,9 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const code = ` - pub contract Test { - pub struct TestStruct { - pub let a: Int + access(all) contract Test { + access(all) struct TestStruct { + access(all) let a: Int init() { self.a = 123 @@ -1790,14 +1790,14 @@ func TestRuntimeContractUpdateValidation(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub struct A {} - pub struct B {} + access(all) contract Test { + access(all) struct A {} + access(all) struct B {} } ` const newCode = ` - pub contract Test {} + access(all) contract Test {} ` // Errors reporting was previously non-deterministic, @@ -1948,36 +1948,36 @@ func TestRuntimeContractUpdateConformanceChanges(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub var a: Foo + access(all) contract Test { + access(all) var a: Foo init() { self.a = Foo() } - pub struct Foo { + access(all) struct Foo { init() {} } } ` const newCode = ` - pub contract Test { - pub var a: Foo + access(all) contract Test { + access(all) var a: Foo init() { self.a = Foo() } - pub struct Foo: Bar { + access(all) struct Foo: Bar { init() { } - pub fun getName(): String { + access(all) fun getName(): String { return "John" } } - pub struct interface Bar { - pub fun getName(): String + access(all) struct interface Bar { + access(all) fun getName(): String } } ` @@ -1991,35 +1991,35 @@ func TestRuntimeContractUpdateConformanceChanges(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub var a: Foo + access(all) contract Test { + access(all) var a: Foo init() { self.a = Foo() } - pub struct Foo { + access(all) struct Foo { init() {} } } ` const newCode = ` - pub contract Test { - pub var a: Foo + access(all) contract Test { + access(all) var a: Foo init() { self.a = Foo() } - pub struct Foo: Bar { - pub var name: String + access(all) struct Foo: Bar { + access(all) var name: String init() { self.name = "John" } } - pub struct interface Bar { - pub var name: String + access(all) struct interface Bar { + access(all) var name: String } } ` @@ -2037,33 +2037,33 @@ func TestRuntimeContractUpdateConformanceChanges(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub var a: Foo + access(all) contract Test { + access(all) var a: Foo init() { self.a = Foo() } - pub struct Foo: Bar { + access(all) struct Foo: Bar { init() {} } - pub struct interface Bar { + access(all) struct interface Bar { } } ` const newCode = ` - pub contract Test { - pub var a: Foo + access(all) contract Test { + access(all) var a: Foo init() { self.a = Foo() } - pub struct Foo { + access(all) struct Foo { init() {} } - pub struct interface Bar { + access(all) struct interface Bar { } } ` @@ -2081,39 +2081,39 @@ func TestRuntimeContractUpdateConformanceChanges(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub var a: Foo + access(all) contract Test { + access(all) var a: Foo init() { self.a = Foo() } - pub struct Foo: First, Second { + access(all) struct Foo: First, Second { init() {} } - pub struct interface First { + access(all) struct interface First { } - pub struct interface Second { + access(all) struct interface Second { } } ` const newCode = ` - pub contract Test { - pub var a: Foo + access(all) contract Test { + access(all) var a: Foo init() { self.a = Foo() } - pub struct Foo: Second, First { + access(all) struct Foo: Second, First { init() {} } - pub struct interface First { + access(all) struct interface First { } - pub struct interface Second { + access(all) struct interface Second { } } ` @@ -2127,10 +2127,10 @@ func TestRuntimeContractUpdateConformanceChanges(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub entitlement X - pub entitlement Y - pub attachment Foo for AnyStruct { + access(all) contract Test { + access(all) entitlement X + access(all) entitlement Y + access(all) attachment Foo for AnyStruct { require entitlement X require entitlement Y } @@ -2138,10 +2138,10 @@ func TestRuntimeContractUpdateConformanceChanges(t *testing.T) { ` const newCode = ` - pub contract Test { - pub entitlement X - pub entitlement Y - pub attachment Foo for AnyStruct { + access(all) contract Test { + access(all) entitlement X + access(all) entitlement Y + access(all) attachment Foo for AnyStruct { require entitlement X } } @@ -2156,10 +2156,10 @@ func TestRuntimeContractUpdateConformanceChanges(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub entitlement X - pub entitlement Y - pub attachment Foo for AnyStruct { + access(all) contract Test { + access(all) entitlement X + access(all) entitlement Y + access(all) attachment Foo for AnyStruct { require entitlement X require entitlement Y } @@ -2167,10 +2167,10 @@ func TestRuntimeContractUpdateConformanceChanges(t *testing.T) { ` const newCode = ` - pub contract Test { - pub entitlement X - pub entitlement Y - pub attachment Foo for AnyStruct { + access(all) contract Test { + access(all) entitlement X + access(all) entitlement Y + access(all) attachment Foo for AnyStruct { require entitlement Y require entitlement X } @@ -2186,20 +2186,20 @@ func TestRuntimeContractUpdateConformanceChanges(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub entitlement X - pub entitlement Y - pub attachment Foo for AnyStruct { + access(all) contract Test { + access(all) entitlement X + access(all) entitlement Y + access(all) attachment Foo for AnyStruct { require entitlement Y } } ` const newCode = ` - pub contract Test { - pub entitlement X - pub entitlement Y - pub attachment Foo for AnyStruct { + access(all) contract Test { + access(all) entitlement X + access(all) entitlement Y + access(all) attachment Foo for AnyStruct { require entitlement X } } @@ -2218,20 +2218,20 @@ func TestRuntimeContractUpdateConformanceChanges(t *testing.T) { t.Parallel() const oldCode = ` - pub contract Test { - pub entitlement X - pub entitlement Y - pub attachment Foo for AnyStruct { + access(all) contract Test { + access(all) entitlement X + access(all) entitlement Y + access(all) attachment Foo for AnyStruct { require entitlement X } } ` const newCode = ` - pub contract Test { - pub entitlement X - pub entitlement Y - pub attachment Foo for AnyStruct { + access(all) contract Test { + access(all) entitlement X + access(all) entitlement Y + access(all) attachment Foo for AnyStruct { require entitlement X require entitlement Y } @@ -2255,14 +2255,14 @@ func TestRuntimeContractUpdateConformanceChanges(t *testing.T) { const contractName = "Test" const oldCode = ` - pub contract Test { - pub fun test(a: Int b: Int) {} + access(all) contract Test { + access(all) fun test(a: Int b: Int) {} } ` const newCode = ` - pub contract Test { - pub fun test(a: Int, b: Int) {} + access(all) contract Test { + access(all) fun test(a: Int, b: Int) {} } ` @@ -2323,10 +2323,10 @@ func TestRuntimeContractUpdateProgramCaching(t *testing.T) { const name = "Test" const oldCode = ` - pub contract Test { init() { 1 } } + access(all) contract Test { init() { 1 } } ` const newCode = ` - pub contract Test { init() { 2 } } + access(all) contract Test { init() { 2 } } ` address := common.MustBytesToAddress([]byte{0x42}) diff --git a/runtime/convertValues_test.go b/runtime/convertValues_test.go index fdd524471f..9b584041ee 100644 --- a/runtime/convertValues_test.go +++ b/runtime/convertValues_test.go @@ -1413,7 +1413,7 @@ func TestExportIntegerValuesFromScript(t *testing.T) { script := fmt.Sprintf( ` - pub fun main(): %s { + access(all) fun main(): %s { return 42 } `, @@ -1443,7 +1443,7 @@ func TestExportFixedPointValuesFromScript(t *testing.T) { script := fmt.Sprintf( ` - pub fun main(): %s { + access(all) fun main(): %s { return %s } `, @@ -1475,7 +1475,7 @@ func TestExportAddressValue(t *testing.T) { t.Parallel() script := ` - pub fun main(): Address { + access(all) fun main(): Address { return 0x42 } ` @@ -1493,15 +1493,15 @@ func TestExportStructValue(t *testing.T) { t.Parallel() script := ` - pub struct Foo { - pub let bar: Int + access(all) struct Foo { + access(all) let bar: Int init(bar: Int) { self.bar = bar } } - pub fun main(): Foo { + access(all) fun main(): Foo { return Foo(bar: 42) } ` @@ -1527,15 +1527,15 @@ func TestExportResourceValue(t *testing.T) { t.Parallel() script := ` - pub resource Foo { - pub let bar: Int + access(all) resource Foo { + access(all) let bar: Int init(bar: Int) { self.bar = bar } } - pub fun main(): @Foo { + access(all) fun main(): @Foo { return <- create Foo(bar: 42) } ` @@ -1556,15 +1556,15 @@ func TestExportResourceArrayValue(t *testing.T) { t.Parallel() script := ` - pub resource Foo { - pub let bar: Int + access(all) resource Foo { + access(all) let bar: Int init(bar: Int) { self.bar = bar } } - pub fun main(): @[Foo] { + access(all) fun main(): @[Foo] { return <- [<- create Foo(bar: 1), <- create Foo(bar: 2)] } ` @@ -1611,15 +1611,15 @@ func TestExportResourceDictionaryValue(t *testing.T) { t.Parallel() script := ` - pub resource Foo { - pub let bar: Int + access(all) resource Foo { + access(all) let bar: Int init(bar: Int) { self.bar = bar } } - pub fun main(): @{String: Foo} { + access(all) fun main(): @{String: Foo} { return <- { "a": <- create Foo(bar: 1), "b": <- create Foo(bar: 2) @@ -1706,16 +1706,16 @@ func TestExportNestedResourceValueFromScript(t *testing.T) { } script := ` - pub resource Bar { - pub let x: Int + access(all) resource Bar { + access(all) let x: Int init(x: Int) { self.x = x } } - pub resource Foo { - pub let bar: @Bar + access(all) resource Foo { + access(all) let bar: @Bar init(bar: @Bar) { self.bar <- bar @@ -1726,7 +1726,7 @@ func TestExportNestedResourceValueFromScript(t *testing.T) { } } - pub fun main(): @Foo { + access(all) fun main(): @Foo { return <- create Foo(bar: <- create Bar(x: 42)) } ` @@ -1752,9 +1752,9 @@ func TestExportEventValue(t *testing.T) { t.Parallel() script := ` - pub event Foo(bar: Int) + access(all) event Foo(bar: Int) - pub fun main() { + access(all) fun main() { emit Foo(bar: 42) } ` @@ -1829,7 +1829,7 @@ func TestExportReferenceValue(t *testing.T) { t.Parallel() script := ` - pub fun main(): &Int { + access(all) fun main(): &Int { return &1 as &Int } ` @@ -1845,7 +1845,7 @@ func TestExportReferenceValue(t *testing.T) { t.Parallel() script := ` - pub fun main(): [&AnyStruct] { + access(all) fun main(): [&AnyStruct] { let refs: [&AnyStruct] = [] refs.append(&refs as &AnyStruct) return refs @@ -1918,7 +1918,7 @@ func TestExportReferenceValue(t *testing.T) { require.NoError(t, err) script := ` - pub fun main(): &AnyStruct { + access(all) fun main(): &AnyStruct { return getAccount(0x1).getCapability(/public/test).borrow<&AnyStruct>()! } ` @@ -1944,7 +1944,7 @@ func TestExportReferenceValue(t *testing.T) { t.Parallel() script := ` - pub fun main(): &AnyStruct { + access(all) fun main(): &AnyStruct { var acct = getAuthAccount(0x01) var v:[AnyStruct] = [] acct.save(v, to: /storage/x) @@ -1979,7 +1979,7 @@ func TestExportReferenceValue(t *testing.T) { t.Parallel() script := ` - pub fun main(): &AnyStruct { + access(all) fun main(): &AnyStruct { var acct = getAuthAccount(0x01) var v:[AnyStruct] = [] acct.save(v, to: /storage/x) @@ -2021,7 +2021,7 @@ func TestExportTypeValue(t *testing.T) { t.Parallel() script := ` - pub fun main(): Type { + access(all) fun main(): Type { return Type() } ` @@ -2039,9 +2039,9 @@ func TestExportTypeValue(t *testing.T) { t.Parallel() script := ` - pub struct S {} + access(all) struct S {} - pub fun main(): Type { + access(all) fun main(): Type { return Type() } ` @@ -2063,7 +2063,7 @@ func TestExportTypeValue(t *testing.T) { t.Parallel() script := ` - pub fun main(): Type { + access(all) fun main(): Type { return CompositeType("PublicKey")! } ` @@ -2101,9 +2101,9 @@ func TestExportTypeValue(t *testing.T) { t.Parallel() const code = ` - pub struct interface SI {} + access(all) struct interface SI {} - pub struct S: SI {} + access(all) struct S: SI {} ` program, err := parser.ParseProgram(nil, []byte(code), parser.Config{}) @@ -2479,9 +2479,9 @@ func TestExportCompositeValueWithFunctionValueField(t *testing.T) { t.Parallel() script := ` - pub struct Foo { - pub let answer: Int - pub let f: fun(): Void + access(all) struct Foo { + access(all) let answer: Int + access(all) let f: fun(): Void init() { self.answer = 42 @@ -2489,7 +2489,7 @@ func TestExportCompositeValueWithFunctionValueField(t *testing.T) { } } - pub fun main(): Foo { + access(all) fun main(): Foo { return Foo() } ` @@ -2634,15 +2634,15 @@ func TestRuntimeEnumValue(t *testing.T) { t.Parallel() script := ` - pub fun main(): Direction { + access(all) fun main(): Direction { return Direction.RIGHT } - pub enum Direction: Int { - pub case UP - pub case DOWN - pub case LEFT - pub case RIGHT + access(all) enum Direction: Int { + access(all) case UP + access(all) case DOWN + access(all) case LEFT + access(all) case RIGHT } ` @@ -2659,7 +2659,7 @@ func TestRuntimeEnumValue(t *testing.T) { t.Parallel() script := ` - pub fun main(dir: Direction): Direction { + access(all) fun main(dir: Direction): Direction { if !dir.isInstance(Type()) { panic("Not a Direction value") } @@ -2667,11 +2667,11 @@ func TestRuntimeEnumValue(t *testing.T) { return dir } - pub enum Direction: Int { - pub case UP - pub case DOWN - pub case LEFT - pub case RIGHT + access(all) enum Direction: Int { + access(all) case UP + access(all) case DOWN + access(all) case LEFT + access(all) case RIGHT } ` @@ -2948,7 +2948,7 @@ func TestRuntimeArgumentPassing(t *testing.T) { } script := fmt.Sprintf( - `pub fun main(arg: %[1]s)%[2]s { + `access(all) fun main(arg: %[1]s)%[2]s { if !arg.isInstance(Type<%[1]s>()) { panic("Not a %[1]s value") @@ -3085,7 +3085,7 @@ func TestRuntimeComplexStructArgumentPassing(t *testing.T) { script := fmt.Sprintf( ` - pub fun main(arg: %[1]s): %[1]s { + access(all) fun main(arg: %[1]s): %[1]s { if !arg.isInstance(Type<%[1]s>()) { panic("Not a %[1]s value") @@ -3094,17 +3094,17 @@ func TestRuntimeComplexStructArgumentPassing(t *testing.T) { return arg } - 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 + access(all) struct Foo { + access(all) var a: String? + access(all) var b: {String: String} + access(all) var c: [String] + access(all) var d: [String; 2] + access(all) var e: Address + access(all) var f: Bool + access(all) var g: StoragePath + access(all) var h: PublicPath + access(all) var i: PrivatePath + access(all) var j: AnyStruct init() { self.a = "Hello" @@ -3207,7 +3207,7 @@ func TestRuntimeComplexStructWithAnyStructFields(t *testing.T) { script := fmt.Sprintf( ` - pub fun main(arg: %[1]s): %[1]s { + access(all) fun main(arg: %[1]s): %[1]s { if !arg.isInstance(Type<%[1]s>()) { panic("Not a %[1]s value") @@ -3216,12 +3216,12 @@ func TestRuntimeComplexStructWithAnyStructFields(t *testing.T) { return arg } - pub struct Foo { - pub var a: AnyStruct? - pub var b: {String: AnyStruct} - pub var c: [AnyStruct] - pub var d: [AnyStruct; 2] - pub var e: AnyStruct + access(all) struct Foo { + access(all) var a: AnyStruct? + access(all) var b: {String: AnyStruct} + access(all) var c: [AnyStruct] + access(all) var d: [AnyStruct; 2] + access(all) var e: AnyStruct init() { self.a = "Hello" @@ -3478,7 +3478,7 @@ func TestRuntimeMalformedArgumentPassing(t *testing.T) { t.Parallel() script := fmt.Sprintf( - `pub fun main(arg: %[1]s): %[1]s { + `access(all) fun main(arg: %[1]s): %[1]s { if !arg.isInstance(Type<%[1]s>()) { panic("Not a %[1]s value") @@ -3487,24 +3487,24 @@ func TestRuntimeMalformedArgumentPassing(t *testing.T) { return arg } - pub struct Foo { - pub var a: String + access(all) struct Foo { + access(all) var a: String init() { self.a = "Hello" } } - pub struct Bar { - pub var a: [Foo] + access(all) struct Bar { + access(all) var a: [Foo] init() { self.a = [] } } - pub struct Baz { - pub var a: {String: Foo} + access(all) struct Baz { + access(all) var a: {String: Foo} init() { self.a = {} @@ -3999,11 +3999,11 @@ func TestRuntimeImportExportDictionaryValue(t *testing.T) { t.Parallel() script := - `pub fun main(arg: Foo) { + `access(all) fun main(arg: Foo) { } - pub struct Foo { - pub var a: AnyStruct + access(all) struct Foo { + access(all) var a: AnyStruct init() { self.a = nil @@ -4050,7 +4050,7 @@ func TestRuntimeImportExportDictionaryValue(t *testing.T) { t.Parallel() script := - `pub fun main(arg: {String: {String: String}}) { + `access(all) fun main(arg: {String: {String: String}}) { } ` @@ -4094,7 +4094,7 @@ func TestRuntimeStringValueImport(t *testing.T) { stringValue := cadence.String(nonUTF8String) script := ` - pub fun main(s: String) { + access(all) fun main(s: String) { log(s) } ` @@ -4147,7 +4147,7 @@ func TestTypeValueImport(t *testing.T) { typeValue := cadence.NewTypeValue(cadence.IntType{}) script := ` - pub fun main(s: Type) { + access(all) fun main(s: Type) { log(s.identifier) } ` @@ -4199,7 +4199,7 @@ func TestTypeValueImport(t *testing.T) { }) script := ` - pub fun main(s: Type) { + access(all) fun main(s: Type) { } ` @@ -4252,7 +4252,7 @@ func TestPathCapabilityValueImport(t *testing.T) { ) script := ` - pub fun main(s: Capability<&Int>) { + access(all) fun main(s: Capability<&Int>) { log(s) } ` @@ -4306,7 +4306,7 @@ func TestPathCapabilityValueImport(t *testing.T) { ) script := ` - pub fun main(s: Capability) { + access(all) fun main(s: Capability) { } ` @@ -4353,7 +4353,7 @@ func TestPathCapabilityValueImport(t *testing.T) { ) script := ` - pub fun main(s: Capability<&Int>) { + access(all) fun main(s: Capability<&Int>) { } ` @@ -4400,7 +4400,7 @@ func TestPathCapabilityValueImport(t *testing.T) { ) script := ` - pub fun main(s: Capability<&Int>) { + access(all) fun main(s: Capability<&Int>) { } ` @@ -4454,7 +4454,7 @@ func TestPathCapabilityValueImport(t *testing.T) { ) script := ` - pub fun main(s: Capability) { + access(all) fun main(s: Capability) { } ` @@ -4503,7 +4503,7 @@ func TestIDCapabilityValueImport(t *testing.T) { ) script := ` - pub fun main(s: Capability<&Int>) { + access(all) fun main(s: Capability<&Int>) { } ` @@ -4547,7 +4547,7 @@ func TestIDCapabilityValueImport(t *testing.T) { ) script := ` - pub fun main(s: Capability) { + access(all) fun main(s: Capability) { } ` @@ -4598,7 +4598,7 @@ func TestIDCapabilityValueImport(t *testing.T) { ) script := ` - pub fun main(s: Capability) { + access(all) fun main(s: Capability) { } ` @@ -4676,7 +4676,7 @@ func TestRuntimePublicKeyImport(t *testing.T) { t.Parallel() script := ` - pub fun main(key: PublicKey) { + access(all) fun main(key: PublicKey) { } ` @@ -4741,7 +4741,7 @@ func TestRuntimePublicKeyImport(t *testing.T) { t.Parallel() script := ` - pub fun main(key: PublicKey): Bool { + access(all) fun main(key: PublicKey): Bool { return key.verify( signature: [], signedData: [], @@ -4800,7 +4800,7 @@ func TestRuntimePublicKeyImport(t *testing.T) { t.Run("Invalid raw public key", func(t *testing.T) { script := ` - pub fun main(key: PublicKey) { + access(all) fun main(key: PublicKey) { } ` @@ -4839,7 +4839,7 @@ func TestRuntimePublicKeyImport(t *testing.T) { t.Run("Invalid content in public key", func(t *testing.T) { script := ` - pub fun main(key: PublicKey) { + access(all) fun main(key: PublicKey) { } ` @@ -4881,7 +4881,7 @@ func TestRuntimePublicKeyImport(t *testing.T) { t.Run("Invalid sign algo", func(t *testing.T) { script := ` - pub fun main(key: PublicKey) { + access(all) fun main(key: PublicKey) { } ` @@ -4916,7 +4916,7 @@ func TestRuntimePublicKeyImport(t *testing.T) { t.Run("Invalid sign algo fields", func(t *testing.T) { script := ` - pub fun main(key: PublicKey) { + access(all) fun main(key: PublicKey) { } ` @@ -4955,7 +4955,7 @@ func TestRuntimePublicKeyImport(t *testing.T) { t.Run("Extra field", func(t *testing.T) { script := ` - pub fun main(key: PublicKey) { + access(all) fun main(key: PublicKey) { } ` @@ -5046,7 +5046,7 @@ func TestRuntimePublicKeyImport(t *testing.T) { t.Run("Missing raw public key", func(t *testing.T) { script := ` - pub fun main(key: PublicKey): PublicKey { + access(all) fun main(key: PublicKey): PublicKey { return key } ` @@ -5113,7 +5113,7 @@ func TestRuntimePublicKeyImport(t *testing.T) { t.Run("Missing publicKey", func(t *testing.T) { script := ` - pub fun main(key: PublicKey): [UInt8] { + access(all) fun main(key: PublicKey): [UInt8] { return key.publicKey } ` @@ -5188,7 +5188,7 @@ func TestRuntimePublicKeyImport(t *testing.T) { t.Run("Missing signatureAlgorithm", func(t *testing.T) { script := ` - pub fun main(key: PublicKey): SignatureAlgorithm { + access(all) fun main(key: PublicKey): SignatureAlgorithm { return key.signatureAlgorithm } ` @@ -5456,11 +5456,11 @@ func TestRuntimeStaticTypeAvailability(t *testing.T) { t.Run("inner array", func(t *testing.T) { script := ` - pub fun main(arg: Foo) { + access(all) fun main(arg: Foo) { } - pub struct Foo { - pub var a: AnyStruct + access(all) struct Foo { + access(all) var a: AnyStruct init() { self.a = nil @@ -5494,11 +5494,11 @@ func TestRuntimeStaticTypeAvailability(t *testing.T) { t.Run("inner dictionary", func(t *testing.T) { script := ` - pub fun main(arg: Foo) { + access(all) fun main(arg: Foo) { } - pub struct Foo { - pub var a: AnyStruct + access(all) struct Foo { + access(all) var a: AnyStruct init() { self.a = nil @@ -5562,12 +5562,12 @@ func TestNestedStructArgPassing(t *testing.T) { t.Parallel() script := ` - pub fun main(v: AnyStruct): UInt8 { + access(all) fun main(v: AnyStruct): UInt8 { return (v as! Foo).bytes[0] } - pub struct Foo { - pub let bytes: [UInt8] + access(all) struct Foo { + access(all) let bytes: [UInt8] init(_ bytes: [UInt8]) { self.bytes = bytes @@ -5634,10 +5634,10 @@ func TestNestedStructArgPassing(t *testing.T) { t.Parallel() script := ` - pub fun main(v: AnyStruct) { + access(all) fun main(v: AnyStruct) { } - pub struct interface Foo { + access(all) struct interface Foo { } ` @@ -5704,9 +5704,9 @@ func TestDestroyedResourceReferenceExport(t *testing.T) { rt := newTestInterpreterRuntimeWithAttachments() script := []byte(` - pub resource S {} + access(all) resource S {} - pub fun main(): &S { + access(all) fun main(): &S { var s <- create S() var ref = &s as &S @@ -5718,7 +5718,7 @@ func TestDestroyedResourceReferenceExport(t *testing.T) { return ref2! } - pub fun getRef(_ ref: &S): &S { + access(all) fun getRef(_ ref: &S): &S { return ref } `) diff --git a/runtime/coverage_test.go b/runtime/coverage_test.go index 951aa16033..e46cba7c6e 100644 --- a/runtime/coverage_test.go +++ b/runtime/coverage_test.go @@ -172,7 +172,7 @@ func TestCoverageReportInspectProgram(t *testing.T) { t.Parallel() script := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { var i = 0 while i < 42 { i = i + 1 @@ -199,7 +199,7 @@ func TestCoverageReportInspectProgramForExcludedLocation(t *testing.T) { t.Parallel() script := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { var i = 0 while i < 42 { i = i + 1 @@ -258,7 +258,7 @@ func TestCoverageReportAddLineHit(t *testing.T) { t.Parallel() script := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { var i = 0 while i < 42 { i = i + 1 @@ -301,7 +301,7 @@ func TestCoverageReportWithFlowLocation(t *testing.T) { t.Parallel() script := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { var i = 0 while i < 42 { i = i + 1 @@ -347,7 +347,7 @@ func TestCoverageReportWithREPLLocation(t *testing.T) { t.Parallel() script := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { var i = 0 while i < 42 { i = i + 1 @@ -393,7 +393,7 @@ func TestCoverageReportWithScriptLocation(t *testing.T) { t.Parallel() script := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { var i = 0 while i < 42 { i = i + 1 @@ -439,7 +439,7 @@ func TestCoverageReportWithStringLocation(t *testing.T) { t.Parallel() script := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { var i = 0 while i < 42 { i = i + 1 @@ -485,7 +485,7 @@ func TestCoverageReportWithIdentifierLocation(t *testing.T) { t.Parallel() script := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { var i = 0 while i < 42 { i = i + 1 @@ -531,7 +531,7 @@ func TestCoverageReportWithTransactionLocation(t *testing.T) { t.Parallel() script := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { var i = 0 while i < 42 { i = i + 1 @@ -577,7 +577,7 @@ func TestCoverageReportWithAddressLocation(t *testing.T) { t.Parallel() script := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { var i = 0 while i < 42 { i = i + 1 @@ -626,7 +626,7 @@ func TestCoverageReportReset(t *testing.T) { t.Parallel() script := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { var i = 0 while i < 42 { i = i + 1 @@ -723,7 +723,7 @@ func TestCoverageReportPercentage(t *testing.T) { t.Parallel() script := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { var i = 0 while i < 42 { i = i + 1 @@ -773,7 +773,7 @@ func TestCoverageReportString(t *testing.T) { t.Parallel() script := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { var i = 0 while i < 42 { i = i + 1 @@ -828,7 +828,7 @@ func TestCoverageReportDiff(t *testing.T) { t.Parallel() script := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { var i = 0 while i < 42 { i = i + 1 @@ -893,17 +893,17 @@ func TestCoverageReportMerge(t *testing.T) { t.Parallel() integerTraitsScript := []byte(` - pub let specialNumbers: {Int: String} = { + access(all) let specialNumbers: {Int: String} = { 1729: "Harshad", 8128: "Harmonic", 41041: "Carmichael" } - pub fun addSpecialNumber(_ n: Int, _ trait: String) { + access(all) fun addSpecialNumber(_ n: Int, _ trait: String) { specialNumbers[n] = trait } - pub fun getIntegerTrait(_ n: Int): String { + access(all) fun getIntegerTrait(_ n: Int): String { if n < 0 { return "Negative" } else if n == 0 { @@ -933,7 +933,7 @@ func TestCoverageReportMerge(t *testing.T) { coverageReport.InspectProgram(location, program) factorialScript := []byte(` - pub fun factorial(_ n: Int): Int { + access(all) fun factorial(_ n: Int): Int { pre { n >= 0: "factorial is only defined for integers greater than or equal to zero" @@ -1203,17 +1203,17 @@ func TestRuntimeCoverage(t *testing.T) { t.Parallel() importedScript := []byte(` - pub let specialNumbers: {Int: String} = { + access(all) let specialNumbers: {Int: String} = { 1729: "Harshad", 8128: "Harmonic", 41041: "Carmichael" } - pub fun addSpecialNumber(_ n: Int, _ trait: String) { + access(all) fun addSpecialNumber(_ n: Int, _ trait: String) { specialNumbers[n] = trait } - pub fun getIntegerTrait(_ n: Int): String { + access(all) fun getIntegerTrait(_ n: Int): String { if n < 0 { return "Negative" } else if n == 0 { @@ -1233,7 +1233,7 @@ func TestRuntimeCoverage(t *testing.T) { return "Enormous" } - pub fun factorial(_ n: Int): Int { + access(all) fun factorial(_ n: Int): Int { pre { n >= 0: "factorial is only defined for integers greater than or equal to zero" @@ -1254,7 +1254,7 @@ func TestRuntimeCoverage(t *testing.T) { script := []byte(` import "imported" - pub fun main(): Int { + access(all) fun main(): Int { let testInputs: {Int: String} = { -1: "Negative", 0: "Zero", @@ -1377,17 +1377,17 @@ func TestRuntimeCoverageWithExcludedLocation(t *testing.T) { t.Parallel() importedScript := []byte(` - pub let specialNumbers: {Int: String} = { + access(all) let specialNumbers: {Int: String} = { 1729: "Harshad", 8128: "Harmonic", 41041: "Carmichael" } - pub fun addSpecialNumber(_ n: Int, _ trait: String) { + access(all) fun addSpecialNumber(_ n: Int, _ trait: String) { specialNumbers[n] = trait } - pub fun getIntegerTrait(_ n: Int): String { + access(all) fun getIntegerTrait(_ n: Int): String { if n < 0 { return "Negative" } else if n == 0 { @@ -1411,7 +1411,7 @@ func TestRuntimeCoverageWithExcludedLocation(t *testing.T) { script := []byte(` import "imported" - pub fun main(): Int { + access(all) fun main(): Int { let testInputs: {Int: String} = { -1: "Negative", 0: "Zero", @@ -1513,17 +1513,17 @@ func TestRuntimeCoverageWithLocationFilter(t *testing.T) { t.Parallel() importedScript := []byte(` - pub let specialNumbers: {Int: String} = { + access(all) let specialNumbers: {Int: String} = { 1729: "Harshad", 8128: "Harmonic", 41041: "Carmichael" } - pub fun addSpecialNumber(_ n: Int, _ trait: String) { + access(all) fun addSpecialNumber(_ n: Int, _ trait: String) { specialNumbers[n] = trait } - pub fun getIntegerTrait(_ n: Int): String { + access(all) fun getIntegerTrait(_ n: Int): String { if n < 0 { return "Negative" } else if n == 0 { @@ -1547,7 +1547,7 @@ func TestRuntimeCoverageWithLocationFilter(t *testing.T) { script := []byte(` import "imported" - pub fun main(): Int { + access(all) fun main(): Int { let testInputs: {Int: String} = { -1: "Negative", 0: "Zero", diff --git a/runtime/crypto_test.go b/runtime/crypto_test.go index 0076b435be..82b42ce50c 100644 --- a/runtime/crypto_test.go +++ b/runtime/crypto_test.go @@ -44,7 +44,7 @@ func TestRuntimeCrypto_verify(t *testing.T) { script := []byte(` import Crypto - pub fun main(): Bool { + access(all) fun main(): Bool { let publicKey = PublicKey( publicKey: "0102".decodeHex(), signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 @@ -137,7 +137,7 @@ func TestRuntimeHashAlgorithm_hash(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { log(HashAlgorithm.SHA3_256.hash("01020304".decodeHex())) } ` @@ -182,7 +182,7 @@ func TestRuntimeHashAlgorithm_hash(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { HashAlgorithm.SHA3_256.hash("01020304".decodeHex()) } ` @@ -212,7 +212,7 @@ func TestRuntimeHashAlgorithm_hash(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { HashAlgorithm.SHA3_256.hashWithTag( "01020304".decodeHex(), tag: "some-tag" @@ -252,7 +252,7 @@ func TestRuntimeHashingAlgorithmExport(t *testing.T) { testHashAlgorithm := func(algo sema.CryptoAlgorithm) { script := fmt.Sprintf(` - pub fun main(): HashAlgorithm { + access(all) fun main(): HashAlgorithm { return HashAlgorithm.%s } `, @@ -293,7 +293,7 @@ func TestRuntimeSignatureAlgorithmExport(t *testing.T) { testSignatureAlgorithm := func(algo sema.CryptoAlgorithm) { script := fmt.Sprintf(` - pub fun main(): SignatureAlgorithm { + access(all) fun main(): SignatureAlgorithm { return SignatureAlgorithm.%s } `, @@ -339,7 +339,7 @@ func TestRuntimeSignatureAlgorithmImport(t *testing.T) { } const script = ` - pub fun main(algo: SignatureAlgorithm): UInt8 { + access(all) fun main(algo: SignatureAlgorithm): UInt8 { return algo.rawValue } ` @@ -390,7 +390,7 @@ func TestRuntimeHashAlgorithmImport(t *testing.T) { t.Parallel() const script = ` - pub fun main(algo: HashAlgorithm): UInt8 { + access(all) fun main(algo: HashAlgorithm): UInt8 { let data: [UInt8] = [1, 2, 3] log(algo.hash(data)) log(algo.hashWithTag(data, tag: "some-tag")) @@ -483,7 +483,7 @@ func TestBLSVerifyPoP(t *testing.T) { script := []byte(` - pub fun main(): Bool { + access(all) fun main(): Bool { let publicKey = PublicKey( publicKey: "0102".decodeHex(), signatureAlgorithm: SignatureAlgorithm.BLS_BLS12_381 @@ -542,7 +542,7 @@ func TestBLSAggregateSignatures(t *testing.T) { script := []byte(` - pub fun main(): [UInt8] { + access(all) fun main(): [UInt8] { return BLS.aggregateSignatures([ [1, 1, 1, 1, 1], [2, 2, 2, 2, 2], @@ -607,7 +607,7 @@ func TestBLSAggregatePublicKeys(t *testing.T) { script := []byte(` - pub fun main(): PublicKey? { + access(all) fun main(): PublicKey? { let k1 = PublicKey( publicKey: "0102".decodeHex(), signatureAlgorithm: SignatureAlgorithm.BLS_BLS12_381 @@ -700,7 +700,7 @@ func TestTraversingMerkleProof(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub fun main(rootHash: [UInt8], address: [UInt8], accountProof: [[UInt8]]){ + access(all) fun main(rootHash: [UInt8], address: [UInt8], accountProof: [[UInt8]]){ let path = HashAlgorithm.KECCAK_256.hash(address) diff --git a/runtime/deployedcontract_test.go b/runtime/deployedcontract_test.go index e97b07b383..49166bd53c 100644 --- a/runtime/deployedcontract_test.go +++ b/runtime/deployedcontract_test.go @@ -32,10 +32,10 @@ func TestDeployedContracts(t *testing.T) { t.Parallel() contractCode := ` - pub contract Test { - pub struct A {} - pub resource B {} - pub event C() + access(all) contract Test { + access(all) struct A {} + access(all) resource B {} + access(all) event C() init() {} } diff --git a/runtime/deployment_test.go b/runtime/deployment_test.go index 92687f3a49..8e9202905a 100644 --- a/runtime/deployment_test.go +++ b/runtime/deployment_test.go @@ -202,7 +202,7 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) { t.Run("no arguments", func(t *testing.T) { test(t, testCase{ contract: ` - pub contract Test {} + access(all) contract Test {} `, arguments: []argument{}, check: expectSuccess, @@ -212,7 +212,7 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) { t.Run("with argument", func(t *testing.T) { test(t, testCase{ contract: ` - pub contract Test { + access(all) contract Test { init(_ x: Int) {} } `, @@ -226,7 +226,7 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) { t.Run("with incorrect argument", func(t *testing.T) { test(t, testCase{ contract: ` - pub contract Test { + access(all) contract Test { init(_ x: Int) {} } `, @@ -238,8 +238,8 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) { "error: invalid argument at index 0: expected type `Int`, got `Bool`\n"+ " --> 0000000000000000000000000000000000000000000000000000000000000000:5:22\n"+ " |\n"+ - "5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202070756220636f6e74726163742054657374207b0a202020202020202020202020202020202020696e6974285f20783a20496e7429207b7d0a20202020202020202020202020207d0a202020202020202020202020\".decodeHex(), true)\n"+ - " | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202061636365737328616c6c2920636f6e74726163742054657374207b0a202020202020202020202020202020202020696e6974285f20783a20496e7429207b7d0a20202020202020202020202020207d0a202020202020202020202020\".decodeHex(), true)\n"+ + " | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", 2, ), }) @@ -248,7 +248,7 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) { t.Run("additional argument", func(t *testing.T) { test(t, testCase{ contract: ` - pub contract Test {} + access(all) contract Test {} `, arguments: []argument{ interpreter.NewUnmeteredIntValueFromInt64(1), @@ -258,8 +258,8 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) { "error: invalid argument count, too many arguments: expected 0, got 1\n"+ " --> 0000000000000000000000000000000000000000000000000000000000000000:5:22\n"+ " |\n"+ - "5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202070756220636f6e74726163742054657374207b7d0a202020202020202020202020\".decodeHex(), 1)\n"+ - " | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202061636365737328616c6c2920636f6e74726163742054657374207b7d0a202020202020202020202020\".decodeHex(), 1)\n"+ + " | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", 2, ), }) @@ -268,7 +268,7 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) { t.Run("additional code which is invalid at top-level", func(t *testing.T) { test(t, testCase{ contract: ` - pub contract Test {} + access(all) contract Test {} fun testCase() {} `, @@ -278,8 +278,8 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) { "error: cannot deploy invalid contract\n"+ " --> 0000000000000000000000000000000000000000000000000000000000000000:5:22\n"+ " |\n"+ - "5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202070756220636f6e74726163742054657374207b7d0a0a202020202020202020202020202066756e2074657374436173652829207b7d0a202020202020202020202020\".decodeHex())\n"+ - " | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"+ + "5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202061636365737328616c6c2920636f6e74726163742054657374207b7d0a0a202020202020202020202020202066756e2074657374436173652829207b7d0a202020202020202020202020\".decodeHex())\n"+ + " | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"+ "\n"+ "error: function declarations are not valid at the top-level\n"+ " --> 2a00000000000000.Test:4:18\n"+ @@ -324,8 +324,8 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) { t.Run("invalid contract, checking error", func(t *testing.T) { test(t, testCase{ contract: ` - pub contract Test { - pub fun test() { X } + access(all) contract Test { + access(all) fun test() { X } } `, arguments: []argument{}, @@ -334,14 +334,14 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) { "error: cannot deploy invalid contract\n"+ " --> 0000000000000000000000000000000000000000000000000000000000000000:5:22\n"+ " |\n"+ - "5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202070756220636f6e74726163742054657374207b0a2020202020202020202020202020202020207075622066756e20746573742829207b2058207d0a20202020202020202020202020207d0a202020202020202020202020\".decodeHex())\n"+ - " | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"+ + "5 | signer.contracts.add(name: \"Test\", code: \"0a202020202020202020202020202061636365737328616c6c2920636f6e74726163742054657374207b0a20202020202020202020202020202020202061636365737328616c6c292066756e20746573742829207b2058207d0a20202020202020202020202020207d0a202020202020202020202020\".decodeHex())\n"+ + " | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"+ "\n"+ "error: cannot find variable in this scope: `X`\n"+ - " --> 2a00000000000000.Test:3:35\n"+ + " --> 2a00000000000000.Test:3:43\n"+ " |\n"+ - "3 | pub fun test() { X }\n"+ - " | ^ not found in this scope\n", + "3 | access(all) fun test() { X }\n"+ + " | ^ not found in this scope\n", 2, ), }) @@ -350,7 +350,7 @@ func TestRuntimeTransactionWithContractDeployment(t *testing.T) { t.Run("Path subtype", func(t *testing.T) { test(t, testCase{ contract: ` - pub contract Test { + access(all) contract Test { init(_ path: StoragePath) {} } `, diff --git a/runtime/entitlements_test.go b/runtime/entitlements_test.go index 18cc9388b9..6729fee0ab 100644 --- a/runtime/entitlements_test.go +++ b/runtime/entitlements_test.go @@ -39,9 +39,9 @@ func TestAccountEntitlementSaveAndLoadSuccess(t *testing.T) { accountCodes := map[Location][]byte{} deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub entitlement X - pub entitlement Y + access(all) contract Test { + access(all) entitlement X + access(all) entitlement Y } `)) @@ -131,9 +131,9 @@ func TestAccountEntitlementSaveAndLoadFail(t *testing.T) { accountCodes := map[Location][]byte{} deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub entitlement X - pub entitlement Y + access(all) contract Test { + access(all) entitlement X + access(all) entitlement Y } `)) @@ -223,21 +223,21 @@ func TestAccountEntitlementAttachmentMap(t *testing.T) { accountCodes := map[Location][]byte{} deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub entitlement X - pub entitlement Y + access(all) contract Test { + access(all) entitlement X + access(all) entitlement Y - pub entitlement mapping M { + access(all) entitlement mapping M { X -> Y } - pub resource R {} + access(all) resource R {} access(M) attachment A for R { access(Y) fun foo() {} } - pub fun createRWithA(): @R { + access(all) fun createRWithA(): @R { return <-attach A() to <-create R() } } @@ -330,12 +330,12 @@ func TestAccountExportEntitledRef(t *testing.T) { accountCodes := map[Location][]byte{} deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub entitlement X + access(all) contract Test { + access(all) entitlement X - pub resource R {} + access(all) resource R {} - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } @@ -343,7 +343,7 @@ func TestAccountExportEntitledRef(t *testing.T) { script := []byte(` import Test from 0x1 - pub fun main(): &Test.R { + access(all) fun main(): &Test.R { let r <- Test.createR() let authAccount = getAuthAccount(0x1) authAccount.save(<-r, to: /storage/foo) @@ -407,22 +407,22 @@ func TestAccountEntitlementNamingConflict(t *testing.T) { accountCodes := map[Location][]byte{} deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub entitlement X + access(all) contract Test { + access(all) entitlement X - pub resource R { + access(all) resource R { access(X) fun foo() {} } - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } `)) otherDeployTx := DeploymentTransaction("OtherTest", []byte(` - pub contract OtherTest { - pub entitlement X + access(all) contract OtherTest { + access(all) entitlement X } `)) @@ -430,7 +430,7 @@ func TestAccountEntitlementNamingConflict(t *testing.T) { import Test from 0x1 import OtherTest from 0x1 - pub fun main(){ + access(all) fun main(){ let r <- Test.createR() let ref = &r as auth(OtherTest.X) &Test.R ref.foo() @@ -510,13 +510,13 @@ func TestAccountEntitlementCapabilityCasting(t *testing.T) { accountCodes := map[Location][]byte{} deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub entitlement X - pub entitlement Y + access(all) contract Test { + access(all) entitlement X + access(all) entitlement Y - pub resource R {} + access(all) resource R {} - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } @@ -609,13 +609,13 @@ func TestAccountEntitlementCapabilityDictionary(t *testing.T) { accountCodes := map[Location][]byte{} deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub entitlement X - pub entitlement Y + access(all) contract Test { + access(all) entitlement X + access(all) entitlement Y - pub resource R {} + access(all) resource R {} - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } @@ -719,13 +719,13 @@ func TestAccountEntitlementGenericCapabilityDictionary(t *testing.T) { accountCodes := map[Location][]byte{} deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub entitlement X - pub entitlement Y + access(all) contract Test { + access(all) entitlement X + access(all) entitlement Y - pub resource R {} + access(all) resource R {} - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } diff --git a/runtime/error_test.go b/runtime/error_test.go index 4b3eacd749..671dd1395d 100644 --- a/runtime/error_test.go +++ b/runtime/error_test.go @@ -107,7 +107,7 @@ func TestRuntimeError(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub fun main() { + access(all) fun main() { let a: UInt8 = 255 let b: UInt8 = 1 // overflow @@ -147,7 +147,7 @@ func TestRuntimeError(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub fun main() { + access(all) fun main() { let x: AnyStruct? = nil let y = x! } @@ -185,19 +185,19 @@ func TestRuntimeError(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub resource Resource { + access(all) resource Resource { init(s:String){ panic("42") } } - pub fun createResource(): @Resource{ + access(all) fun createResource(): @Resource{ return <- create Resource( s: "argument" ) } - pub fun main() { + access(all) fun main() { destroy createResource() } `) @@ -332,7 +332,7 @@ func TestRuntimeError(t *testing.T) { runtime := newTestInterpreterRuntime() importedScript := []byte(` - pub fun add() { + access(all) fun add() { let a: UInt8 = 255 let b: UInt8 = 1 // overflow @@ -343,7 +343,7 @@ func TestRuntimeError(t *testing.T) { script := []byte(` import add from "imported" - pub fun main() { + access(all) fun main() { add() } `) @@ -416,7 +416,7 @@ func TestRuntimeError(t *testing.T) { // program itself has more errors: // invalid top-level declaration - pub fun foo() { + access(all) fun foo() { // invalid reference to undeclared variable Y } @@ -426,7 +426,7 @@ func TestRuntimeError(t *testing.T) { Name: "B", }: ` // invalid top-level declaration - pub fun bar() { + access(all) fun bar() { // invalid reference to undeclared variable X } @@ -467,10 +467,10 @@ func TestRuntimeError(t *testing.T) { require.EqualError(t, err, "Execution failed:\n"+ "error: function declarations are not valid at the top-level\n"+ - " --> 0000000000000002.B:3:22\n"+ + " --> 0000000000000002.B:3:30\n"+ " |\n"+ - "3 | pub fun bar() {\n"+ - " | ^^^\n"+ + "3 | access(all) fun bar() {\n"+ + " | ^^^\n"+ "\n"+ "error: cannot find variable in this scope: `X`\n"+ " --> 0000000000000002.B:5:18\n"+ @@ -479,10 +479,10 @@ func TestRuntimeError(t *testing.T) { " | ^ not found in this scope\n"+ "\n"+ "error: function declarations are not valid at the top-level\n"+ - " --> 0000000000000001.A:8:22\n"+ + " --> 0000000000000001.A:8:30\n"+ " |\n"+ - "8 | pub fun foo() {\n"+ - " | ^^^\n"+ + "8 | access(all) fun foo() {\n"+ + " | ^^^\n"+ "\n"+ "error: cannot find variable in this scope: `Y`\n"+ " --> 0000000000000001.A:10:18\n"+ diff --git a/runtime/ft_test.go b/runtime/ft_test.go index f1d574017c..0118029de3 100644 --- a/runtime/ft_test.go +++ b/runtime/ft_test.go @@ -37,31 +37,31 @@ const realFungibleTokenContractInterface = ` /// /// The interface that fungible token contracts implement. /// -pub contract interface FungibleToken { +access(all) contract interface FungibleToken { /// The total number of tokens in existence. /// It is up to the implementer to ensure that the total supply /// stays accurate and up to date /// - pub var totalSupply: UFix64 + access(all) var totalSupply: UFix64 /// TokensInitialized /// /// The event that is emitted when the contract is created /// - pub event TokensInitialized(initialSupply: UFix64) + access(all) event TokensInitialized(initialSupply: UFix64) /// TokensWithdrawn /// /// The event that is emitted when tokens are withdrawn from a Vault /// - pub event TokensWithdrawn(amount: UFix64, from: Address?) + access(all) event TokensWithdrawn(amount: UFix64, from: Address?) /// TokensDeposited /// /// The event that is emitted when tokens are deposited into a Vault /// - pub event TokensDeposited(amount: UFix64, to: Address?) + access(all) event TokensDeposited(amount: UFix64, to: Address?) /// Provider /// @@ -72,7 +72,7 @@ pub contract interface FungibleToken { /// because it leaves open the possibility of creating custom providers /// that do not necessarily need their own balance. /// - pub resource interface Provider { + access(all) resource interface Provider { /// withdraw subtracts tokens from the owner's Vault /// and returns a Vault with the removed tokens. @@ -89,7 +89,7 @@ pub contract interface FungibleToken { /// capability that allows all users to access the provider /// resource through a reference. /// - pub fun withdraw(amount: UFix64): @Vault { + access(all) fun withdraw(amount: UFix64): @Vault { post { // 'result' refers to the return value result.balance == amount: @@ -108,11 +108,11 @@ pub contract interface FungibleToken { /// can do custom things with the tokens, like split them up and /// send them to different places. /// - pub resource interface Receiver { + access(all) resource interface Receiver { /// deposit takes a Vault and deposits it into the implementing resource type /// - pub fun deposit(from: @Vault) + access(all) fun deposit(from: @Vault) } /// Balance @@ -121,11 +121,11 @@ pub contract interface FungibleToken { /// and enforces that when new Vaults are created, the balance /// is initialized correctly. /// - pub resource interface Balance { + access(all) resource interface Balance { /// The total balance of a vault /// - pub var balance: UFix64 + access(all) var balance: UFix64 init(balance: UFix64) { post { @@ -139,7 +139,7 @@ pub contract interface FungibleToken { /// /// The resource that contains the functions to send and receive tokens. /// - pub resource Vault: Provider, Receiver, Balance { + access(all) resource Vault: Provider, Receiver, Balance { // The declaration of a concrete type in a contract interface means that // every Fungible Token contract that implements the FungibleToken interface @@ -148,7 +148,7 @@ pub contract interface FungibleToken { /// The total balance of the vault /// - pub var balance: UFix64 + access(all) var balance: UFix64 // The conforming type must declare an initializer // that allows prioviding the initial balance of the Vault @@ -158,7 +158,7 @@ pub contract interface FungibleToken { /// withdraw subtracts 'amount' from the Vault's balance /// and returns a new Vault with the subtracted balance /// - pub fun withdraw(amount: UFix64): @Vault { + access(all) fun withdraw(amount: UFix64): @Vault { pre { self.balance >= amount: "Amount withdrawn must be less than or equal than the balance of the Vault" @@ -174,7 +174,7 @@ pub contract interface FungibleToken { /// deposit takes a Vault and adds its balance to the balance of this Vault /// - pub fun deposit(from: @Vault) { + access(all) fun deposit(from: @Vault) { post { self.balance == before(self.balance) + before(from.balance): "New Vault balance must be the sum of the previous balance and the deposited Vault" @@ -184,7 +184,7 @@ pub contract interface FungibleToken { /// createEmptyVault allows any user to create a new Vault that has a zero balance /// - pub fun createEmptyVault(): @Vault { + access(all) fun createEmptyVault(): @Vault { post { result.balance == 0.0: "The newly created Vault must have zero balance" } @@ -195,31 +195,31 @@ pub contract interface FungibleToken { const realFlowContract = ` import FungibleToken from 0x1 -pub contract FlowToken: FungibleToken { +access(all) contract FlowToken: FungibleToken { // Total supply of Flow tokens in existence - pub var totalSupply: UFix64 + access(all) var totalSupply: UFix64 // Event that is emitted when the contract is created - pub event TokensInitialized(initialSupply: UFix64) + access(all) event TokensInitialized(initialSupply: UFix64) // Event that is emitted when tokens are withdrawn from a Vault - pub event TokensWithdrawn(amount: UFix64, from: Address?) + access(all) event TokensWithdrawn(amount: UFix64, from: Address?) // Event that is emitted when tokens are deposited to a Vault - pub event TokensDeposited(amount: UFix64, to: Address?) + access(all) event TokensDeposited(amount: UFix64, to: Address?) // Event that is emitted when new tokens are minted - pub event TokensMinted(amount: UFix64) + access(all) event TokensMinted(amount: UFix64) // Event that is emitted when tokens are destroyed - pub event TokensBurned(amount: UFix64) + access(all) event TokensBurned(amount: UFix64) // Event that is emitted when a new minter resource is created - pub event MinterCreated(allowedAmount: UFix64) + access(all) event MinterCreated(allowedAmount: UFix64) // Event that is emitted when a new burner resource is created - pub event BurnerCreated() + access(all) event BurnerCreated() // Vault // @@ -233,10 +233,10 @@ pub contract FlowToken: FungibleToken { // out of thin air. A special Minter resource needs to be defined to mint // new tokens. // - pub resource Vault: FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance { + access(all) resource Vault: FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance { // holds the balance of a users tokens - pub var balance: UFix64 + access(all) var balance: UFix64 // initialize the balance at resource creation time init(balance: UFix64) { @@ -252,7 +252,7 @@ pub contract FlowToken: FungibleToken { // created Vault to the context that called so it can be deposited // elsewhere. // - pub fun withdraw(amount: UFix64): @FungibleToken.Vault { + access(all) fun withdraw(amount: UFix64): @FungibleToken.Vault { self.balance = self.balance - amount emit TokensWithdrawn(amount: amount, from: self.owner?.address) return <-create Vault(balance: amount) @@ -265,7 +265,7 @@ pub contract FlowToken: FungibleToken { // It is allowed to destroy the sent Vault because the Vault // was a temporary holder of the tokens. The Vault's balance has // been consumed and therefore can be destroyed. - pub fun deposit(from: @FungibleToken.Vault) { + access(all) fun deposit(from: @FungibleToken.Vault) { let vault <- from as! @FlowToken.Vault self.balance = self.balance + vault.balance emit TokensDeposited(amount: vault.balance, to: self.owner?.address) @@ -285,16 +285,16 @@ pub contract FlowToken: FungibleToken { // and store the returned Vault in their storage in order to allow their // account to be able to receive deposits of this token type. // - pub fun createEmptyVault(): @FungibleToken.Vault { + access(all) fun createEmptyVault(): @FungibleToken.Vault { return <-create Vault(balance: 0.0) } - pub resource Administrator { + access(all) resource Administrator { // createNewMinter // // Function that creates and returns a new minter resource // - pub fun createNewMinter(allowedAmount: UFix64): @Minter { + access(all) fun createNewMinter(allowedAmount: UFix64): @Minter { emit MinterCreated(allowedAmount: allowedAmount) return <-create Minter(allowedAmount: allowedAmount) } @@ -303,7 +303,7 @@ pub contract FlowToken: FungibleToken { // // Function that creates and returns a new burner resource // - pub fun createNewBurner(): @Burner { + access(all) fun createNewBurner(): @Burner { emit BurnerCreated() return <-create Burner() } @@ -313,17 +313,17 @@ pub contract FlowToken: FungibleToken { // // Resource object that token admin accounts can hold to mint new tokens. // - pub resource Minter { + access(all) resource Minter { // the amount of tokens that the minter is allowed to mint - pub var allowedAmount: UFix64 + access(all) var allowedAmount: UFix64 // mintTokens // // Function that mints new tokens, adds them to the total supply, // and returns them to the calling context. // - pub fun mintTokens(amount: UFix64): @FlowToken.Vault { + access(all) fun mintTokens(amount: UFix64): @FlowToken.Vault { pre { amount > UFix64(0): "Amount minted must be greater than zero" amount <= self.allowedAmount: "Amount minted must be less than the allowed amount" @@ -343,7 +343,7 @@ pub contract FlowToken: FungibleToken { // // Resource object that token admin accounts can hold to burn tokens. // - pub resource Burner { + access(all) resource Burner { // burnTokens // @@ -352,7 +352,7 @@ pub contract FlowToken: FungibleToken { // Note: the burned tokens are automatically subtracted from the // total supply in the Vault destructor. // - pub fun burnTokens(from: @FungibleToken.Vault) { + access(all) fun burnTokens(from: @FungibleToken.Vault) { let vault <- from as! @FlowToken.Vault let amount = vault.balance destroy vault @@ -490,7 +490,7 @@ const realFlowTokenBalanceScript = ` import FungibleToken from 0x1 import FlowToken from 0x1 -pub fun main(account: Address): UFix64 { +access(all) fun main(account: Address): UFix64 { let vaultRef = getAccount(account) .getCapability(/public/flowTokenBalance) diff --git a/runtime/import_test.go b/runtime/import_test.go index 9364254cf6..a8ca56e56e 100644 --- a/runtime/import_test.go +++ b/runtime/import_test.go @@ -50,7 +50,7 @@ func TestRuntimeCyclicImport(t *testing.T) { script := []byte(` import p1 - pub fun main() {} + access(all) fun main() {} `) var checkCount int @@ -174,17 +174,17 @@ func TestCheckCyclicImports(t *testing.T) { } const fooContract = ` - pub contract Foo {} + access(all) contract Foo {} ` const barContract = ` import Foo from 0x0000000000000001 - pub contract Bar {} + access(all) contract Bar {} ` const updatedFooContract = ` import Bar from 0x0000000000000001 - pub contract Foo {} + access(all) contract Foo {} ` err := deploy("Foo", fooContract, false) diff --git a/runtime/imported_values_memory_metering_test.go b/runtime/imported_values_memory_metering_test.go index 8918ba39ac..763b8e9670 100644 --- a/runtime/imported_values_memory_metering_test.go +++ b/runtime/imported_values_memory_metering_test.go @@ -71,7 +71,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: String) {} + access(all) fun main(x: String) {} `) meter := make(map[common.MemoryKind]uint64) @@ -90,7 +90,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: String?) {} + access(all) fun main(x: String?) {} `) meter := make(map[common.MemoryKind]uint64) @@ -110,7 +110,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: UInt) {} + access(all) fun main(x: UInt) {} `) meter := make(map[common.MemoryKind]uint64) @@ -122,7 +122,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: UInt8) {} + access(all) fun main(x: UInt8) {} `) meter := make(map[common.MemoryKind]uint64) @@ -134,7 +134,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: UInt16) {} + access(all) fun main(x: UInt16) {} `) meter := make(map[common.MemoryKind]uint64) @@ -146,7 +146,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: UInt32) {} + access(all) fun main(x: UInt32) {} `) meter := make(map[common.MemoryKind]uint64) @@ -158,7 +158,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: UInt64) {} + access(all) fun main(x: UInt64) {} `) meter := make(map[common.MemoryKind]uint64) @@ -170,7 +170,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: UInt128) {} + access(all) fun main(x: UInt128) {} `) meter := make(map[common.MemoryKind]uint64) @@ -182,7 +182,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: UInt256) {} + access(all) fun main(x: UInt256) {} `) meter := make(map[common.MemoryKind]uint64) @@ -194,7 +194,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Int) {} + access(all) fun main(x: Int) {} `) meter := make(map[common.MemoryKind]uint64) @@ -206,7 +206,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Int8) {} + access(all) fun main(x: Int8) {} `) meter := make(map[common.MemoryKind]uint64) @@ -218,7 +218,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Int16) {} + access(all) fun main(x: Int16) {} `) meter := make(map[common.MemoryKind]uint64) @@ -230,7 +230,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Int32) {} + access(all) fun main(x: Int32) {} `) meter := make(map[common.MemoryKind]uint64) @@ -242,7 +242,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Int64) {} + access(all) fun main(x: Int64) {} `) meter := make(map[common.MemoryKind]uint64) @@ -254,7 +254,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Int128) {} + access(all) fun main(x: Int128) {} `) meter := make(map[common.MemoryKind]uint64) @@ -266,7 +266,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Int256) {} + access(all) fun main(x: Int256) {} `) meter := make(map[common.MemoryKind]uint64) @@ -278,7 +278,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Word8) {} + access(all) fun main(x: Word8) {} `) meter := make(map[common.MemoryKind]uint64) @@ -290,7 +290,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Word16) {} + access(all) fun main(x: Word16) {} `) meter := make(map[common.MemoryKind]uint64) @@ -302,7 +302,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Word32) {} + access(all) fun main(x: Word32) {} `) meter := make(map[common.MemoryKind]uint64) @@ -314,7 +314,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Word64) {} + access(all) fun main(x: Word64) {} `) meter := make(map[common.MemoryKind]uint64) @@ -326,7 +326,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Word128) {} + access(all) fun main(x: Word128) {} `) meter := make(map[common.MemoryKind]uint64) @@ -350,7 +350,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Fix64) {} + access(all) fun main(x: Fix64) {} `) meter := make(map[common.MemoryKind]uint64) @@ -366,7 +366,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: UFix64) {} + access(all) fun main(x: UFix64) {} `) meter := make(map[common.MemoryKind]uint64) @@ -381,9 +381,9 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Foo) {} + access(all) fun main(x: Foo) {} - pub struct Foo {} + access(all) struct Foo {} `) meter := make(map[common.MemoryKind]uint64) @@ -553,8 +553,8 @@ func TestImportedValueMemoryMeteringForSimpleTypes(t *testing.T) { script := []byte(fmt.Sprintf( ` - pub entitlement X - pub fun main(x: %s) {} + access(all) entitlement X + access(all) fun main(x: %s) {} `, test.TypeName, )) @@ -630,8 +630,8 @@ func TestScriptDecodedLocationMetering(t *testing.T) { }) script := []byte(` - pub struct S {} - pub fun main(x: S) {} + access(all) struct S {} + access(all) fun main(x: S) {} `) _, err := runtime.ExecuteScript( diff --git a/runtime/interpreter/interpreter.go b/runtime/interpreter/interpreter.go index dfb4a3c61f..c9da8ffb25 100644 --- a/runtime/interpreter/interpreter.go +++ b/runtime/interpreter/interpreter.go @@ -1290,7 +1290,7 @@ func (interpreter *Interpreter) declareNonEnumCompositeValue( attachmentType := interpreter.MustSemaTypeOfValue(value).(*sema.CompositeType) // Self's type in the constructor is codomain of the attachment's entitlement map, since // the constructor can only be called when in possession of the base resource - // if the attachment is declared with pub access, then self is unauthorized + // if the attachment is declared with access(all) access, then self is unauthorized if attachmentType.AttachmentEntitlementAccess != nil { auth = ConvertSemaAccesstoStaticAuthorization(interpreter, attachmentType.AttachmentEntitlementAccess.Codomain()) } diff --git a/runtime/interpreter/value_accountcapabilitycontroller.go b/runtime/interpreter/value_accountcapabilitycontroller.go index 3cbf569cce..70a39ed941 100644 --- a/runtime/interpreter/value_accountcapabilitycontroller.go +++ b/runtime/interpreter/value_accountcapabilitycontroller.go @@ -44,6 +44,7 @@ type AccountCapabilityControllerValue struct { GetTag func() *StringValue SetTag func(*StringValue) DeleteFunction FunctionValue + setTagFunction FunctionValue } func NewUnmeteredAccountCapabilityControllerValue( @@ -202,6 +203,11 @@ func (v *AccountCapabilityControllerValue) GetMember(inter *Interpreter, _ Locat } } return v.tag + case sema.AccountCapabilityControllerTypeSetTagFunctionName: + if v.setTagFunction == nil { + v.setTagFunction = v.newSetTagFunction(inter) + } + return v.setTagFunction case sema.AccountCapabilityControllerTypeCapabilityIDFieldName: return v.CapabilityID @@ -217,22 +223,12 @@ func (v *AccountCapabilityControllerValue) GetMember(inter *Interpreter, _ Locat } func (*AccountCapabilityControllerValue) RemoveMember(_ *Interpreter, _ LocationRange, _ string) Value { - // Storage capability controllers have no removable members (fields / functions) + // Account capability controllers have no removable members (fields / functions) panic(errors.NewUnreachableError()) } func (v *AccountCapabilityControllerValue) SetMember(_ *Interpreter, _ LocationRange, identifier string, value Value) bool { - switch identifier { - case sema.AccountCapabilityControllerTypeTagFieldName: - stringValue, ok := value.(*StringValue) - if !ok { - panic(errors.NewUnreachableError()) - } - v.tag = stringValue - v.SetTag(stringValue) - return true - } - + // Account capability controllers have no settable members (fields / functions) panic(errors.NewUnreachableError()) } @@ -276,3 +272,23 @@ func (v *AccountCapabilityControllerValue) SetDeleted(gauge common.MemoryGauge) panicHostFunction, ) } + +func (controller *AccountCapabilityControllerValue) newSetTagFunction( + inter *Interpreter, +) *HostFunctionValue { + return NewHostFunctionValue( + inter, + sema.AccountCapabilityControllerTypeSetTagFunctionType, + func(invocation Invocation) Value { + newTagValue, ok := invocation.Arguments[0].(*StringValue) + if !ok { + panic(errors.NewUnreachableError()) + } + + controller.tag = newTagValue + controller.SetTag(newTagValue) + + return Void + }, + ) +} diff --git a/runtime/interpreter/value_storagecapabilitycontroller.go b/runtime/interpreter/value_storagecapabilitycontroller.go index f36e92ce6e..3c7904e02e 100644 --- a/runtime/interpreter/value_storagecapabilitycontroller.go +++ b/runtime/interpreter/value_storagecapabilitycontroller.go @@ -58,6 +58,7 @@ type StorageCapabilityControllerValue struct { TargetFunction FunctionValue RetargetFunction FunctionValue DeleteFunction FunctionValue + setTagFunction FunctionValue } func NewUnmeteredStorageCapabilityControllerValue( @@ -227,6 +228,12 @@ func (v *StorageCapabilityControllerValue) GetMember(inter *Interpreter, _ Locat } return v.tag + case sema.StorageCapabilityControllerTypeSetTagFunctionName: + if v.setTagFunction == nil { + v.setTagFunction = v.newSetTagFunction(inter) + } + return v.setTagFunction + case sema.StorageCapabilityControllerTypeCapabilityIDFieldName: return v.CapabilityID @@ -252,17 +259,7 @@ func (*StorageCapabilityControllerValue) RemoveMember(_ *Interpreter, _ Location } func (v *StorageCapabilityControllerValue) SetMember(_ *Interpreter, _ LocationRange, identifier string, value Value) bool { - switch identifier { - case sema.StorageCapabilityControllerTypeTagFieldName: - stringValue, ok := value.(*StringValue) - if !ok { - panic(errors.NewUnreachableError()) - } - v.tag = stringValue - v.SetTag(stringValue) - return true - } - + // Storage capability controllers have no settable members (fields / functions) panic(errors.NewUnreachableError()) } @@ -316,3 +313,23 @@ func (v *StorageCapabilityControllerValue) SetDeleted(gauge common.MemoryGauge) panicHostFunction, ) } + +func (controller *StorageCapabilityControllerValue) newSetTagFunction( + inter *Interpreter, +) *HostFunctionValue { + return NewHostFunctionValue( + inter, + sema.StorageCapabilityControllerTypeSetTagFunctionType, + func(invocation Invocation) Value { + newTagValue, ok := invocation.Arguments[0].(*StringValue) + if !ok { + panic(errors.NewUnreachableError()) + } + + controller.tag = newTagValue + controller.SetTag(newTagValue) + + return Void + }, + ) +} diff --git a/runtime/interpreter/value_test.go b/runtime/interpreter/value_test.go index 5166d5c14f..b4b172f2d9 100644 --- a/runtime/interpreter/value_test.go +++ b/runtime/interpreter/value_test.go @@ -1698,19 +1698,23 @@ func TestEphemeralReferenceTypeConformance(t *testing.T) { // Obtain a self referencing (cyclic) ephemeral reference value. code := ` - pub fun getEphemeralRef(): &Foo { + access(all) fun getEphemeralRef(): &Foo { var foo = Foo() var fooRef = &foo as &Foo // Create the cyclic reference - fooRef.bar = fooRef + fooRef.setBar(fooRef) return fooRef } - pub struct Foo { + access(all) struct Foo { - pub(set) var bar: &Foo? + access(all) var bar: &Foo? + + access(all) fun setBar(_ bar: &Foo) { + self.bar = bar + } init() { self.bar = nil @@ -3721,7 +3725,7 @@ func TestNonStorable(t *testing.T) { storage := newUnmeteredInMemoryStorage() code := ` - pub struct Foo { + access(all) struct Foo { let bar: &Int? diff --git a/runtime/missingmember_test.go b/runtime/missingmember_test.go index c1a41dc477..a1b0882ce9 100644 --- a/runtime/missingmember_test.go +++ b/runtime/missingmember_test.go @@ -56,31 +56,31 @@ func TestRuntimeMissingMemberFabricant(t *testing.T) { const flowTokenContract = ` import FungibleToken from 0x9a0766d93b6608b7 -pub contract FlowToken: FungibleToken { +access(all) contract FlowToken: FungibleToken { // Total supply of Flow tokens in existence - pub var totalSupply: UFix64 + access(all) var totalSupply: UFix64 // Event that is emitted when the contract is created - pub event TokensInitialized(initialSupply: UFix64) + access(all) event TokensInitialized(initialSupply: UFix64) // Event that is emitted when tokens are withdrawn from a Vault - pub event TokensWithdrawn(amount: UFix64, from: Address?) + access(all) event TokensWithdrawn(amount: UFix64, from: Address?) // Event that is emitted when tokens are deposited to a Vault - pub event TokensDeposited(amount: UFix64, to: Address?) + access(all) event TokensDeposited(amount: UFix64, to: Address?) // Event that is emitted when new tokens are minted - pub event TokensMinted(amount: UFix64) + access(all) event TokensMinted(amount: UFix64) // Event that is emitted when tokens are destroyed - pub event TokensBurned(amount: UFix64) + access(all) event TokensBurned(amount: UFix64) // Event that is emitted when a new minter resource is created - pub event MinterCreated(allowedAmount: UFix64) + access(all) event MinterCreated(allowedAmount: UFix64) // Event that is emitted when a new burner resource is created - pub event BurnerCreated() + access(all) event BurnerCreated() // Vault // @@ -94,10 +94,10 @@ pub contract FlowToken: FungibleToken { // out of thin air. A special Minter resource needs to be defined to mint // new tokens. // - pub resource Vault: FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance { + access(all) resource Vault: FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance { // holds the balance of a users tokens - pub var balance: UFix64 + access(all) var balance: UFix64 // initialize the balance at resource creation time init(balance: UFix64) { @@ -113,7 +113,7 @@ pub contract FlowToken: FungibleToken { // created Vault to the context that called so it can be deposited // elsewhere. // - pub fun withdraw(amount: UFix64): @FungibleToken.Vault { + access(all) fun withdraw(amount: UFix64): @FungibleToken.Vault { self.balance = self.balance - amount emit TokensWithdrawn(amount: amount, from: self.owner?.address) return <-create Vault(balance: amount) @@ -126,7 +126,7 @@ pub contract FlowToken: FungibleToken { // It is allowed to destroy the sent Vault because the Vault // was a temporary holder of the tokens. The Vault's balance has // been consumed and therefore can be destroyed. - pub fun deposit(from: @FungibleToken.Vault) { + access(all) fun deposit(from: @FungibleToken.Vault) { let vault <- from as! @FlowToken.Vault self.balance = self.balance + vault.balance emit TokensDeposited(amount: vault.balance, to: self.owner?.address) @@ -146,16 +146,16 @@ pub contract FlowToken: FungibleToken { // and store the returned Vault in their storage in order to allow their // account to be able to receive deposits of this token type. // - pub fun createEmptyVault(): @FungibleToken.Vault { + access(all) fun createEmptyVault(): @FungibleToken.Vault { return <-create Vault(balance: 0.0) } - pub resource Administrator { + access(all) resource Administrator { // createNewMinter // // Function that creates and returns a new minter resource // - pub fun createNewMinter(allowedAmount: UFix64): @Minter { + access(all) fun createNewMinter(allowedAmount: UFix64): @Minter { emit MinterCreated(allowedAmount: allowedAmount) return <-create Minter(allowedAmount: allowedAmount) } @@ -164,7 +164,7 @@ pub contract FlowToken: FungibleToken { // // Function that creates and returns a new burner resource // - pub fun createNewBurner(): @Burner { + access(all) fun createNewBurner(): @Burner { emit BurnerCreated() return <-create Burner() } @@ -174,17 +174,17 @@ pub contract FlowToken: FungibleToken { // // Resource object that token admin accounts can hold to mint new tokens. // - pub resource Minter { + access(all) resource Minter { // the amount of tokens that the minter is allowed to mint - pub var allowedAmount: UFix64 + access(all) var allowedAmount: UFix64 // mintTokens // // Function that mints new tokens, adds them to the total supply, // and returns them to the calling context. // - pub fun mintTokens(amount: UFix64): @FlowToken.Vault { + access(all) fun mintTokens(amount: UFix64): @FlowToken.Vault { pre { amount > UFix64(0): "Amount minted must be greater than zero" amount <= self.allowedAmount: "Amount minted must be less than the allowed amount" @@ -204,7 +204,7 @@ pub contract FlowToken: FungibleToken { // // Resource object that token admin accounts can hold to burn tokens. // - pub resource Burner { + access(all) resource Burner { // burnTokens // @@ -213,7 +213,7 @@ pub contract FlowToken: FungibleToken { // Note: the burned tokens are automatically subtracted from the // total supply in the Vault destructor. // - pub fun burnTokens(from: @FungibleToken.Vault) { + access(all) fun burnTokens(from: @FungibleToken.Vault) { let vault <- from as! @FlowToken.Vault let amount = vault.balance destroy vault @@ -258,40 +258,40 @@ pub contract FlowToken: FungibleToken { const fbrcContract = ` import FungibleToken from 0x9a0766d93b6608b7 -pub contract FBRC: FungibleToken { +access(all) contract FBRC: FungibleToken { // Total supply of Flow tokens in existence - pub var totalSupply: UFix64 + access(all) var totalSupply: UFix64 // Event that is emitted when the contract is created - pub event TokensInitialized(initialSupply: UFix64) + access(all) event TokensInitialized(initialSupply: UFix64) // Event that is emitted when tokens are withdrawn from a Vault - pub event TokensWithdrawn(amount: UFix64, from: Address?) + access(all) event TokensWithdrawn(amount: UFix64, from: Address?) // Event that is emitted when tokens are deposited to a Vault - pub event TokensDeposited(amount: UFix64, to: Address?) + access(all) event TokensDeposited(amount: UFix64, to: Address?) // Event that is emitted when new tokens are minted - pub event TokensMinted(amount: UFix64) + access(all) event TokensMinted(amount: UFix64) // Event that is emitted when tokens are destroyed - pub event TokensBurned(amount: UFix64) + access(all) event TokensBurned(amount: UFix64) // Event that is emitted when a new minter resource is created - pub event MinterCreated(allowedAmount: UFix64) + access(all) event MinterCreated(allowedAmount: UFix64) // Event that is emitted when a new burner resource is created - pub event BurnerCreated() + access(all) event BurnerCreated() // Contains standard storage and public paths of resources - pub let CollectionStoragePath: StoragePath + access(all) let CollectionStoragePath: StoragePath - pub let CollectionReceiverPath: PublicPath + access(all) let CollectionReceiverPath: PublicPath - pub let CollectionBalancePath: PublicPath + access(all) let CollectionBalancePath: PublicPath - pub let AdminStoragePath: StoragePath + access(all) let AdminStoragePath: StoragePath // Vault // // Each user stores an instance of only the Vault in their storage @@ -304,10 +304,10 @@ pub contract FBRC: FungibleToken { // out of thin air. A special Minter resource needs to be defined to mint // new tokens. // - pub resource Vault: FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance { + access(all) resource Vault: FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance { // holds the balance of a users tokens - pub var balance: UFix64 + access(all) var balance: UFix64 // initialize the balance at resource creation time init(balance: UFix64) { @@ -323,7 +323,7 @@ pub contract FBRC: FungibleToken { // created Vault to the context that called so it can be deposited // elsewhere. // - pub fun withdraw(amount: UFix64): @FungibleToken.Vault { + access(all) fun withdraw(amount: UFix64): @FungibleToken.Vault { self.balance = self.balance - amount emit TokensWithdrawn(amount: amount, from: self.owner?.address) return <-create Vault(balance: amount) @@ -336,7 +336,7 @@ pub contract FBRC: FungibleToken { // It is allowed to destroy the sent Vault because the Vault // was a temporary holder of the tokens. The Vault's balance has // been consumed and therefore can be destroyed. - pub fun deposit(from: @FungibleToken.Vault) { + access(all) fun deposit(from: @FungibleToken.Vault) { let vault <- from as! @FBRC.Vault self.balance = self.balance + vault.balance emit TokensDeposited(amount: vault.balance, to: self.owner?.address) @@ -356,16 +356,16 @@ pub contract FBRC: FungibleToken { // and store the returned Vault in their storage in order to allow their // account to be able to receive deposits of this token type. // - pub fun createEmptyVault(): @FungibleToken.Vault { + access(all) fun createEmptyVault(): @FungibleToken.Vault { return <-create Vault(balance: 0.0) } - pub resource Administrator { + access(all) resource Administrator { // createNewMinter // // Function that creates and returns a new minter resource // - pub fun createNewMinter(allowedAmount: UFix64): @Minter { + access(all) fun createNewMinter(allowedAmount: UFix64): @Minter { emit MinterCreated(allowedAmount: allowedAmount) return <-create Minter(allowedAmount: allowedAmount) } @@ -374,7 +374,7 @@ pub contract FBRC: FungibleToken { // // Function that creates and returns a new burner resource // - pub fun createNewBurner(): @Burner { + access(all) fun createNewBurner(): @Burner { emit BurnerCreated() return <-create Burner() } @@ -384,17 +384,17 @@ pub contract FBRC: FungibleToken { // // Resource object that token admin accounts can hold to mint new tokens. // - pub resource Minter { + access(all) resource Minter { // the amount of tokens that the minter is allowed to mint - pub var allowedAmount: UFix64 + access(all) var allowedAmount: UFix64 // mintTokens // // Function that mints new tokens, adds them to the total supply, // and returns them to the calling context. // - pub fun mintTokens(amount: UFix64): @FBRC.Vault { + access(all) fun mintTokens(amount: UFix64): @FBRC.Vault { pre { amount > 0.0: "Amount minted must be greater than zero" amount <= self.allowedAmount: "Amount minted must be less than the allowed amount" @@ -414,7 +414,7 @@ pub contract FBRC: FungibleToken { // // Resource object that token admin accounts can hold to burn tokens. // - pub resource Burner { + access(all) resource Burner { // burnTokens // @@ -423,7 +423,7 @@ pub contract FBRC: FungibleToken { // Note: the burned tokens are automatically subtracted from the // total supply in the Vault destructor. // - pub fun burnTokens(from: @FungibleToken.Vault) { + access(all) fun burnTokens(from: @FungibleToken.Vault) { let vault <- from as! @FBRC.Vault let amount = vault.balance destroy vault @@ -474,36 +474,36 @@ import NonFungibleToken from 0x631e88ae7f1d7c20 import FungibleToken from 0x9a0766d93b6608b7 import FBRC from 0x5a76b4858ce34b2f -pub contract GarmentNFT: NonFungibleToken { +access(all) contract GarmentNFT: NonFungibleToken { // ----------------------------------------------------------------------- // GarmentNFT contract Events // ----------------------------------------------------------------------- // Emitted when the Garment contract is created - pub event ContractInitialized() + access(all) event ContractInitialized() // Emitted when a new GarmentData struct is created - pub event GarmentDataCreated(garmentDataID: UInt32, mainImage: String, images: [String], name: String, artist: String, description: String) + access(all) event GarmentDataCreated(garmentDataID: UInt32, mainImage: String, images: [String], name: String, artist: String, description: String) // Emitted when a Garment is minted - pub event GarmentMinted(garmentID: UInt64, garmentDataID: UInt32, serialNumber: UInt32) + access(all) event GarmentMinted(garmentID: UInt64, garmentDataID: UInt32, serialNumber: UInt32) // Emitted when the contract's royalty percentage is changed - pub event RoyaltyPercentageChanged(newRoyaltyPercentage: UFix64) + access(all) event RoyaltyPercentageChanged(newRoyaltyPercentage: UFix64) - pub event GarmentDataIDRetired(garmentDataID: UInt32) + access(all) event GarmentDataIDRetired(garmentDataID: UInt32) // Events for Collection-related actions // // Emitted when a Garment is withdrawn from a Collection - pub event Withdraw(id: UInt64, from: Address?) + access(all) event Withdraw(id: UInt64, from: Address?) // Emitted when a Garment is deposited into a Collection - pub event Deposit(id: UInt64, to: Address?) + access(all) event Deposit(id: UInt64, to: Address?) // Emitted when a Garment is destroyed - pub event GarmentDestroyed(id: UInt64) + access(all) event GarmentDestroyed(id: UInt64) // ----------------------------------------------------------------------- // contract-level fields. @@ -511,11 +511,11 @@ pub contract GarmentNFT: NonFungibleToken { // ----------------------------------------------------------------------- // Contains standard storage and public paths of resources - pub let CollectionStoragePath: StoragePath + access(all) let CollectionStoragePath: StoragePath - pub let CollectionPublicPath: PublicPath + access(all) let CollectionPublicPath: PublicPath - pub let AdminStoragePath: StoragePath + access(all) let AdminStoragePath: StoragePath // Variable size dictionary of Garment structs access(self) var garmentDatas: {UInt32: GarmentData} @@ -527,25 +527,25 @@ pub contract GarmentNFT: NonFungibleToken { access(self) var isGarmentDataRetired: {UInt32: Bool} // Keeps track of how many unique GarmentData's are created - pub var nextGarmentDataID: UInt32 + access(all) var nextGarmentDataID: UInt32 - pub var royaltyPercentage: UFix64 + access(all) var royaltyPercentage: UFix64 - pub var totalSupply: UInt64 + access(all) var totalSupply: UInt64 - pub struct GarmentData { + access(all) struct GarmentData { // The unique ID for the Garment Data - pub let garmentDataID: UInt32 + access(all) let garmentDataID: UInt32 //stores link to image - pub let mainImage: String + access(all) let mainImage: String //stores link to supporting images - pub let images: [String] - pub let name: String - pub let artist: String + access(all) let images: [String] + access(all) let name: String + access(all) let artist: String //description of design - pub let description: String + access(all) let description: String init( mainImage: String, @@ -570,13 +570,13 @@ pub contract GarmentNFT: NonFungibleToken { } } - pub struct Garment { + access(all) struct Garment { // The ID of the GarmentData that the Garment references - pub let garmentDataID: UInt32 + access(all) let garmentDataID: UInt32 // The N'th NFT with 'GarmentDataID' minted - pub let serialNumber: UInt32 + access(all) let serialNumber: UInt32 init(garmentDataID: UInt32) { self.garmentDataID = garmentDataID @@ -590,16 +590,16 @@ pub contract GarmentNFT: NonFungibleToken { // The resource that represents the Garment NFTs // - pub resource NFT: NonFungibleToken.INFT { + access(all) resource NFT: NonFungibleToken.INFT { // Global unique Garment ID - pub let id: UInt64 + access(all) let id: UInt64 // struct of Garment - pub let garment: Garment + access(all) let garment: Garment // Royalty capability which NFT will use - pub let royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}> + access(all) let royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}> init(serialNumber: UInt32, garmentDataID: UInt32, royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}>) { GarmentNFT.totalSupply = GarmentNFT.totalSupply + 1 as UInt64 @@ -624,9 +624,9 @@ pub contract GarmentNFT: NonFungibleToken { // allows the owner to perform important functions to modify the // various aspects of the Garment and NFTs // - pub resource Admin { + access(all) resource Admin { - pub fun createGarmentData( + access(all) fun createGarmentData( mainImage: String, images: [String], name: String, @@ -654,12 +654,12 @@ pub contract GarmentNFT: NonFungibleToken { // createNewAdmin creates a new Admin resource // - pub fun createNewAdmin(): @Admin { + access(all) fun createNewAdmin(): @Admin { return <-create Admin() } // Mint the new Garment - pub fun mintNFT(garmentDataID: UInt32, royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}>): @NFT { + access(all) fun mintNFT(garmentDataID: UInt32, royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}>): @NFT { pre { royaltyVault.check(): "Royalty capability is invalid!" @@ -681,7 +681,7 @@ pub contract GarmentNFT: NonFungibleToken { return <-newGarment } - pub fun batchMintNFT(garmentDataID: UInt32, royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}>, quantity: UInt64): @Collection { + access(all) fun batchMintNFT(garmentDataID: UInt32, royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}>, quantity: UInt64): @Collection { let newCollection <- create Collection() var i: UInt64 = 0 @@ -694,14 +694,14 @@ pub contract GarmentNFT: NonFungibleToken { } // Change the royalty percentage of the contract - pub fun changeRoyaltyPercentage(newRoyaltyPercentage: UFix64) { + access(all) fun changeRoyaltyPercentage(newRoyaltyPercentage: UFix64) { GarmentNFT.royaltyPercentage = newRoyaltyPercentage emit RoyaltyPercentageChanged(newRoyaltyPercentage: newRoyaltyPercentage) } // Retire garmentData so that it cannot be used to mint anymore - pub fun retireGarmentData(garmentDataID: UInt32) { + access(all) fun retireGarmentData(garmentDataID: UInt32) { pre { GarmentNFT.isGarmentDataRetired[garmentDataID] != nil: "Cannot retire Garment: Garment doesn't exist!" } @@ -717,12 +717,12 @@ pub contract GarmentNFT: NonFungibleToken { // This is the interface users can cast their Garment Collection as // to allow others to deposit into their Collection. It also allows for reading // the IDs of Garment in the Collection. - pub resource interface GarmentCollectionPublic { - pub fun deposit(token: @NonFungibleToken.NFT) - pub fun batchDeposit(tokens: @NonFungibleToken.Collection) - pub fun getIDs(): [UInt64] - pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT - pub fun borrowGarment(id: UInt64): &GarmentNFT.NFT? { + access(all) resource interface GarmentCollectionPublic { + access(all) fun deposit(token: @NonFungibleToken.NFT) + access(all) fun batchDeposit(tokens: @NonFungibleToken.Collection) + access(all) fun getIDs(): [UInt64] + access(all) fun borrowNFT(id: UInt64): &NonFungibleToken.NFT + access(all) fun borrowGarment(id: UInt64): &GarmentNFT.NFT? { // If the result isn't nil, the id of the returned reference // should be the same as the argument to the function post { @@ -735,10 +735,10 @@ pub contract GarmentNFT: NonFungibleToken { // Collection is a resource that every user who owns NFTs // will store in their account to manage their NFTS // - pub resource Collection: GarmentCollectionPublic, NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic { + access(all) resource Collection: GarmentCollectionPublic, NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic { // Dictionary of Garment conforming tokens // NFT is a resource type with a UInt64 ID field - pub var ownedNFTs: @{UInt64: NonFungibleToken.NFT} + access(all) var ownedNFTs: @{UInt64: NonFungibleToken.NFT} init() { self.ownedNFTs <- {} @@ -750,7 +750,7 @@ pub contract GarmentNFT: NonFungibleToken { // that is to be removed from the Collection // // returns: @NonFungibleToken.NFT the token that was withdrawn - pub fun withdraw(withdrawID: UInt64): @NonFungibleToken.NFT { + access(all) fun withdraw(withdrawID: UInt64): @NonFungibleToken.NFT { // Remove the nft from the Collection let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("Cannot withdraw: Garment does not exist in the collection") @@ -768,7 +768,7 @@ pub contract GarmentNFT: NonFungibleToken { // Returns: @NonFungibleToken.Collection: A collection that contains // the withdrawn Garment // - pub fun batchWithdraw(ids: [UInt64]): @NonFungibleToken.Collection { + access(all) fun batchWithdraw(ids: [UInt64]): @NonFungibleToken.Collection { // Create a new empty Collection var batchCollection <- create Collection() @@ -785,7 +785,7 @@ pub contract GarmentNFT: NonFungibleToken { // // Parameters: token: the NFT to be deposited in the collection // - pub fun deposit(token: @NonFungibleToken.NFT) { + access(all) fun deposit(token: @NonFungibleToken.NFT) { // Cast the deposited token as NFT to make sure // it is the correct type let token <- token as! @GarmentNFT.NFT @@ -808,7 +808,7 @@ pub contract GarmentNFT: NonFungibleToken { // batchDeposit takes a Collection object as an argument // and deposits each contained NFT into this Collection - pub fun batchDeposit(tokens: @NonFungibleToken.Collection) { + access(all) fun batchDeposit(tokens: @NonFungibleToken.Collection) { // Get an array of the IDs to be deposited let keys = tokens.getIDs() @@ -822,7 +822,7 @@ pub contract GarmentNFT: NonFungibleToken { } // getIDs returns an array of the IDs that are in the Collection - pub fun getIDs(): [UInt64] { + access(all) fun getIDs(): [UInt64] { return self.ownedNFTs.keys } @@ -837,14 +837,14 @@ pub contract GarmentNFT: NonFungibleToken { // not an specific data. Please use borrowGarment to // read Garment data. // - pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT { + access(all) fun borrowNFT(id: UInt64): &NonFungibleToken.NFT { return (&self.ownedNFTs[id] as &NonFungibleToken.NFT?)! } // Parameters: id: The ID of the NFT to get the reference for // // Returns: A reference to the NFT - pub fun borrowGarment(id: UInt64): &GarmentNFT.NFT? { + access(all) fun borrowGarment(id: UInt64): &GarmentNFT.NFT? { if self.ownedNFTs[id] != nil { let ref = &self.ownedNFTs[id] as &NonFungibleToken.NFT? return ref as! &GarmentNFT.NFT? @@ -870,39 +870,39 @@ pub contract GarmentNFT: NonFungibleToken { // Once they have a Collection in their storage, they are able to receive // Garment in transactions. // - pub fun createEmptyCollection(): @NonFungibleToken.Collection { + access(all) fun createEmptyCollection(): @NonFungibleToken.Collection { return <-create GarmentNFT.Collection() } // get dictionary of numberMintedPerGarment - pub fun getNumberMintedPerGarment(): {UInt32: UInt32} { + access(all) fun getNumberMintedPerGarment(): {UInt32: UInt32} { return GarmentNFT.numberMintedPerGarment } // get how many Garments with garmentDataID are minted - pub fun getGarmentNumberMinted(id: UInt32): UInt32 { + access(all) fun getGarmentNumberMinted(id: UInt32): UInt32 { let numberMinted = GarmentNFT.numberMintedPerGarment[id]?? panic("garmentDataID not found") return numberMinted } // get the garmentData of a specific id - pub fun getGarmentData(id: UInt32): GarmentData { + access(all) fun getGarmentData(id: UInt32): GarmentData { let garmentData = GarmentNFT.garmentDatas[id]?? panic("garmentDataID not found") return garmentData } // get all garmentDatas created - pub fun getGarmentDatas(): {UInt32: GarmentData} { + access(all) fun getGarmentDatas(): {UInt32: GarmentData} { return GarmentNFT.garmentDatas } - pub fun getGarmentDatasRetired(): {UInt32: Bool} { + access(all) fun getGarmentDatasRetired(): {UInt32: Bool} { return GarmentNFT.isGarmentDataRetired } - pub fun getGarmentDataRetired(garmentDataID: UInt32): Bool { + access(all) fun getGarmentDataRetired(garmentDataID: UInt32): Bool { let isGarmentDataRetired = GarmentNFT.isGarmentDataRetired[garmentDataID]?? panic("garmentDataID not found") return isGarmentDataRetired @@ -943,36 +943,36 @@ import NonFungibleToken from 0x631e88ae7f1d7c20 import FungibleToken from 0x9a0766d93b6608b7 import FBRC from 0x5a76b4858ce34b2f -pub contract MaterialNFT: NonFungibleToken { +access(all) contract MaterialNFT: NonFungibleToken { // ----------------------------------------------------------------------- // MaterialNFT contract Events // ----------------------------------------------------------------------- // Emitted when the Material contract is created - pub event ContractInitialized() + access(all) event ContractInitialized() // Emitted when a new MaterialData struct is created - pub event MaterialDataCreated(materialDataID: UInt32, mainImage: String, secondImage: String, name: String, description: String) + access(all) event MaterialDataCreated(materialDataID: UInt32, mainImage: String, secondImage: String, name: String, description: String) // Emitted when a Material is minted - pub event MaterialMinted(materialID: UInt64, materialDataID: UInt32, serialNumber: UInt32) + access(all) event MaterialMinted(materialID: UInt64, materialDataID: UInt32, serialNumber: UInt32) // Emitted when the contract's royalty percentage is changed - pub event RoyaltyPercentageChanged(newRoyaltyPercentage: UFix64) + access(all) event RoyaltyPercentageChanged(newRoyaltyPercentage: UFix64) - pub event MaterialDataIDRetired(materialDataID: UInt32) + access(all) event MaterialDataIDRetired(materialDataID: UInt32) // Events for Collection-related actions // // Emitted when a Material is withdrawn from a Collection - pub event Withdraw(id: UInt64, from: Address?) + access(all) event Withdraw(id: UInt64, from: Address?) // Emitted when a Material is deposited into a Collection - pub event Deposit(id: UInt64, to: Address?) + access(all) event Deposit(id: UInt64, to: Address?) // Emitted when a Material is destroyed - pub event MaterialDestroyed(id: UInt64) + access(all) event MaterialDestroyed(id: UInt64) // ----------------------------------------------------------------------- // contract-level fields. @@ -980,11 +980,11 @@ pub contract MaterialNFT: NonFungibleToken { // ----------------------------------------------------------------------- // Contains standard storage and public paths of resources - pub let CollectionStoragePath: StoragePath + access(all) let CollectionStoragePath: StoragePath - pub let CollectionPublicPath: PublicPath + access(all) let CollectionPublicPath: PublicPath - pub let AdminStoragePath: StoragePath + access(all) let AdminStoragePath: StoragePath // Variable size dictionary of Material structs access(self) var materialDatas: {UInt32: MaterialData} @@ -996,22 +996,22 @@ pub contract MaterialNFT: NonFungibleToken { access(self) var isMaterialDataRetired: {UInt32: Bool} // Keeps track of how many unique MaterialData's are created - pub var nextMaterialDataID: UInt32 + access(all) var nextMaterialDataID: UInt32 - pub var royaltyPercentage: UFix64 + access(all) var royaltyPercentage: UFix64 - pub var totalSupply: UInt64 + access(all) var totalSupply: UInt64 - pub struct MaterialData { + access(all) struct MaterialData { // The unique ID for the Material Data - pub let materialDataID: UInt32 + access(all) let materialDataID: UInt32 //stores link to image - pub let mainImage: String - pub let secondImage: String - pub let name: String - pub let description: String + access(all) let mainImage: String + access(all) let secondImage: String + access(all) let name: String + access(all) let description: String init( mainImage: String, @@ -1034,13 +1034,13 @@ pub contract MaterialNFT: NonFungibleToken { } } - pub struct Material { + access(all) struct Material { // The ID of the MaterialData that the Material references - pub let materialDataID: UInt32 + access(all) let materialDataID: UInt32 // The N'th NFT with 'MaterialDataID' minted - pub let serialNumber: UInt32 + access(all) let serialNumber: UInt32 init(materialDataID: UInt32) { self.materialDataID = materialDataID @@ -1054,16 +1054,16 @@ pub contract MaterialNFT: NonFungibleToken { // The resource that represents the Material NFTs // - pub resource NFT: NonFungibleToken.INFT { + access(all) resource NFT: NonFungibleToken.INFT { // Global unique Material ID - pub let id: UInt64 + access(all) let id: UInt64 // struct of Material - pub let material: Material + access(all) let material: Material // Royalty capability which NFT will use - pub let royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}> + access(all) let royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}> init(serialNumber: UInt32, materialDataID: UInt32, royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}>) { MaterialNFT.totalSupply = MaterialNFT.totalSupply + 1 as UInt64 @@ -1088,9 +1088,9 @@ pub contract MaterialNFT: NonFungibleToken { // allows the owner to perform important functions to modify the // various aspects of the Material and NFTs // - pub resource Admin { + access(all) resource Admin { - pub fun createMaterialData( + access(all) fun createMaterialData( mainImage: String, secondImage: String, name: String, @@ -1116,12 +1116,12 @@ pub contract MaterialNFT: NonFungibleToken { // createNewAdmin creates a new Admin resource // - pub fun createNewAdmin(): @Admin { + access(all) fun createNewAdmin(): @Admin { return <-create Admin() } // Mint the new Material - pub fun mintNFT(materialDataID: UInt32, royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}>): @NFT { + access(all) fun mintNFT(materialDataID: UInt32, royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}>): @NFT { pre { royaltyVault.check(): "Royalty capability is invalid!" @@ -1143,7 +1143,7 @@ pub contract MaterialNFT: NonFungibleToken { return <-newMaterial } - pub fun batchMintNFT(materialDataID: UInt32, royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}>, quantity: UInt64): @Collection { + access(all) fun batchMintNFT(materialDataID: UInt32, royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}>, quantity: UInt64): @Collection { let newCollection <- create Collection() var i: UInt64 = 0 @@ -1156,14 +1156,14 @@ pub contract MaterialNFT: NonFungibleToken { } // Change the royalty percentage of the contract - pub fun changeRoyaltyPercentage(newRoyaltyPercentage: UFix64) { + access(all) fun changeRoyaltyPercentage(newRoyaltyPercentage: UFix64) { MaterialNFT.royaltyPercentage = newRoyaltyPercentage emit RoyaltyPercentageChanged(newRoyaltyPercentage: newRoyaltyPercentage) } // Retire materialData so that it cannot be used to mint anymore - pub fun retireMaterialData(materialDataID: UInt32) { + access(all) fun retireMaterialData(materialDataID: UInt32) { pre { MaterialNFT.isMaterialDataRetired[materialDataID] != nil: "Cannot retire Material: Material doesn't exist!" } @@ -1179,12 +1179,12 @@ pub contract MaterialNFT: NonFungibleToken { // This is the interface users can cast their Material Collection as // to allow others to deposit into their Collection. It also allows for reading // the IDs of Material in the Collection. - pub resource interface MaterialCollectionPublic { - pub fun deposit(token: @NonFungibleToken.NFT) - pub fun batchDeposit(tokens: @NonFungibleToken.Collection) - pub fun getIDs(): [UInt64] - pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT - pub fun borrowMaterial(id: UInt64): &MaterialNFT.NFT? { + access(all) resource interface MaterialCollectionPublic { + access(all) fun deposit(token: @NonFungibleToken.NFT) + access(all) fun batchDeposit(tokens: @NonFungibleToken.Collection) + access(all) fun getIDs(): [UInt64] + access(all) fun borrowNFT(id: UInt64): &NonFungibleToken.NFT + access(all) fun borrowMaterial(id: UInt64): &MaterialNFT.NFT? { // If the result isn't nil, the id of the returned reference // should be the same as the argument to the function post { @@ -1197,10 +1197,10 @@ pub contract MaterialNFT: NonFungibleToken { // Collection is a resource that every user who owns NFTs // will store in their account to manage their NFTS // - pub resource Collection: MaterialCollectionPublic, NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic { + access(all) resource Collection: MaterialCollectionPublic, NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic { // Dictionary of Material conforming tokens // NFT is a resource type with a UInt64 ID field - pub var ownedNFTs: @{UInt64: NonFungibleToken.NFT} + access(all) var ownedNFTs: @{UInt64: NonFungibleToken.NFT} init() { self.ownedNFTs <- {} @@ -1212,7 +1212,7 @@ pub contract MaterialNFT: NonFungibleToken { // that is to be removed from the Collection // // returns: @NonFungibleToken.NFT the token that was withdrawn - pub fun withdraw(withdrawID: UInt64): @NonFungibleToken.NFT { + access(all) fun withdraw(withdrawID: UInt64): @NonFungibleToken.NFT { // Remove the nft from the Collection let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("Cannot withdraw: Material does not exist in the collection") @@ -1230,7 +1230,7 @@ pub contract MaterialNFT: NonFungibleToken { // Returns: @NonFungibleToken.Collection: A collection that contains // the withdrawn Material // - pub fun batchWithdraw(ids: [UInt64]): @NonFungibleToken.Collection { + access(all) fun batchWithdraw(ids: [UInt64]): @NonFungibleToken.Collection { // Create a new empty Collection var batchCollection <- create Collection() @@ -1247,7 +1247,7 @@ pub contract MaterialNFT: NonFungibleToken { // // Parameters: token: the NFT to be deposited in the collection // - pub fun deposit(token: @NonFungibleToken.NFT) { + access(all) fun deposit(token: @NonFungibleToken.NFT) { // Cast the deposited token as NFT to make sure // it is the correct type let token <- token as! @MaterialNFT.NFT @@ -1270,7 +1270,7 @@ pub contract MaterialNFT: NonFungibleToken { // batchDeposit takes a Collection object as an argument // and deposits each contained NFT into this Collection - pub fun batchDeposit(tokens: @NonFungibleToken.Collection) { + access(all) fun batchDeposit(tokens: @NonFungibleToken.Collection) { // Get an array of the IDs to be deposited let keys = tokens.getIDs() @@ -1284,7 +1284,7 @@ pub contract MaterialNFT: NonFungibleToken { } // getIDs returns an array of the IDs that are in the Collection - pub fun getIDs(): [UInt64] { + access(all) fun getIDs(): [UInt64] { return self.ownedNFTs.keys } @@ -1299,14 +1299,14 @@ pub contract MaterialNFT: NonFungibleToken { // not an specific data. Please use borrowMaterial to // read Material data. // - pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT { + access(all) fun borrowNFT(id: UInt64): &NonFungibleToken.NFT { return (&self.ownedNFTs[id] as &NonFungibleToken.NFT?)! } // Parameters: id: The ID of the NFT to get the reference for // // Returns: A reference to the NFT - pub fun borrowMaterial(id: UInt64): &MaterialNFT.NFT? { + access(all) fun borrowMaterial(id: UInt64): &MaterialNFT.NFT? { if self.ownedNFTs[id] != nil { let ref = (&self.ownedNFTs[id] as &NonFungibleToken.NFT?)! return ref as! &MaterialNFT.NFT @@ -1332,39 +1332,39 @@ pub contract MaterialNFT: NonFungibleToken { // Once they have a Collection in their storage, they are able to receive // Material in transactions. // - pub fun createEmptyCollection(): @NonFungibleToken.Collection { + access(all) fun createEmptyCollection(): @NonFungibleToken.Collection { return <-create MaterialNFT.Collection() } // get dictionary of numberMintedPerMaterial - pub fun getNumberMintedPerMaterial(): {UInt32: UInt32} { + access(all) fun getNumberMintedPerMaterial(): {UInt32: UInt32} { return MaterialNFT.numberMintedPerMaterial } // get how many Materials with materialDataID are minted - pub fun getMaterialNumberMinted(id: UInt32): UInt32 { + access(all) fun getMaterialNumberMinted(id: UInt32): UInt32 { let numberMinted = MaterialNFT.numberMintedPerMaterial[id]?? panic("materialDataID not found") return numberMinted } // get the materialData of a specific id - pub fun getMaterialData(id: UInt32): MaterialData { + access(all) fun getMaterialData(id: UInt32): MaterialData { let materialData = MaterialNFT.materialDatas[id]?? panic("materialDataID not found") return materialData } // get all materialDatas created - pub fun getMaterialDatas(): {UInt32: MaterialData} { + access(all) fun getMaterialDatas(): {UInt32: MaterialData} { return MaterialNFT.materialDatas } - pub fun getMaterialDatasRetired(): {UInt32: Bool} { + access(all) fun getMaterialDatasRetired(): {UInt32: Bool} { return MaterialNFT.isMaterialDataRetired } - pub fun getMaterialDataRetired(materialDataID: UInt32): Bool { + access(all) fun getMaterialDataRetired(materialDataID: UInt32): Bool { let isMaterialDataRetired = MaterialNFT.isMaterialDataRetired[materialDataID]?? panic("materialDataID not found") return isMaterialDataRetired @@ -1407,57 +1407,57 @@ import GarmentNFT from 0x5a76b4858ce34b2f import MaterialNFT from 0x5a76b4858ce34b2f import FBRC from 0x5a76b4858ce34b2f -pub contract ItemNFT: NonFungibleToken { +access(all) contract ItemNFT: NonFungibleToken { // ----------------------------------------------------------------------- // ItemNFT contract Events // ----------------------------------------------------------------------- // Emitted when the Item contract is created - pub event ContractInitialized() + access(all) event ContractInitialized() // Emitted when a new ItemData struct is created - pub event ItemDataCreated(itemDataID: UInt32, mainImage: String, images: [String]) + access(all) event ItemDataCreated(itemDataID: UInt32, mainImage: String, images: [String]) // Emitted when a Item is mintee - pub event ItemMinted(itemID: UInt64, itemDataID: UInt32, serialNumber: UInt32) + access(all) event ItemMinted(itemID: UInt64, itemDataID: UInt32, serialNumber: UInt32) // Emitted when a Item' name is changed - pub event ItemNameChanged(id: UInt64, name: String) + access(all) event ItemNameChanged(id: UInt64, name: String) // Emitted when the contract's royalty percentage is changed - pub event RoyaltyPercentageChanged(newRoyaltyPercentage: UFix64) + access(all) event RoyaltyPercentageChanged(newRoyaltyPercentage: UFix64) - pub event ItemDataAllocated(garmentDataID: UInt32, materialDataID: UInt32, itemDataID: UInt32) + access(all) event ItemDataAllocated(garmentDataID: UInt32, materialDataID: UInt32, itemDataID: UInt32) // Emitted when the items are set to be splittable - pub event ItemNFTNowSplittable() + access(all) event ItemNFTNowSplittable() - pub event numberItemDataMintableChanged(number: UInt32) + access(all) event numberItemDataMintableChanged(number: UInt32) - pub event ItemDataIDRetired(itemDataID: UInt32) + access(all) event ItemDataIDRetired(itemDataID: UInt32) // Events for Collection-related actions // // Emitted when a Item is withdrawn from a Collection - pub event Withdraw(id: UInt64, from: Address?) + access(all) event Withdraw(id: UInt64, from: Address?) // Emitted when a Item is deposited into a Collection - pub event Deposit(id: UInt64, to: Address?) + access(all) event Deposit(id: UInt64, to: Address?) // Emitted when a Item is destroyed - pub event ItemDestroyed(id: UInt64) + access(all) event ItemDestroyed(id: UInt64) // ----------------------------------------------------------------------- // contract-level fields. // These contain actual values that are stored in the smart contract. // ----------------------------------------------------------------------- - pub let CollectionStoragePath: StoragePath + access(all) let CollectionStoragePath: StoragePath - pub let CollectionPublicPath: PublicPath + access(all) let CollectionPublicPath: PublicPath - pub let AdminStoragePath: StoragePath + access(all) let AdminStoragePath: StoragePath // Dictionary with ItemDataID as key and number of NFTs with that ItemDataID are minted access(self) var numberMintedPerItem: {UInt32: UInt32} @@ -1472,28 +1472,28 @@ pub contract ItemNFT: NonFungibleToken { access(self) var isItemDataRetired: {UInt32: Bool} // Keeps track of how many unique ItemData's are created - pub var nextItemDataID: UInt32 + access(all) var nextItemDataID: UInt32 - pub var nextItemDataAllocation: UInt32 + access(all) var nextItemDataAllocation: UInt32 // Are garment and material removable from item - pub var isSplittable: Bool + access(all) var isSplittable: Bool // The maximum number of items with itemDataID mintable - pub var numberItemDataMintable: UInt32 + access(all) var numberItemDataMintable: UInt32 - pub var royaltyPercentage: UFix64 + access(all) var royaltyPercentage: UFix64 - pub var totalSupply: UInt64 + access(all) var totalSupply: UInt64 - pub struct ItemData { + access(all) struct ItemData { // The unique ID for the Item Data - pub let itemDataID: UInt32 + access(all) let itemDataID: UInt32 //stores link to image - pub let mainImage: String + access(all) let mainImage: String //stores link to supporting images - pub let images: [String] + access(all) let images: [String] init( mainImage: String, @@ -1512,13 +1512,13 @@ pub contract ItemNFT: NonFungibleToken { } } - pub struct Item { + access(all) struct Item { // The ID of the itemData that the item references - pub let itemDataID: UInt32 + access(all) let itemDataID: UInt32 // The N'th NFT with 'ItemDataID' minted - pub let serialNumber: UInt32 + access(all) let serialNumber: UInt32 init(itemDataID: UInt32) { pre { @@ -1538,23 +1538,23 @@ pub contract ItemNFT: NonFungibleToken { // The resource that represents the Item NFTs // - pub resource NFT: NonFungibleToken.INFT { + access(all) resource NFT: NonFungibleToken.INFT { // Global unique Item ID - pub let id: UInt64 + access(all) let id: UInt64 // struct of Item - pub let item: Item + access(all) let item: Item // name of nft, can be changed - pub var name: String + access(all) var name: String // Royalty capability which NFT will use - pub let royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}> + access(all) let royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}> // after you remove the garment and material from the item, the ItemNFT will be considered "dead". // accounts will be unable to deposit, withdraw or call functions of the nft. - pub var isDead : Bool + access(all) var isDead : Bool // this is where the garment nft is stored, it cannot be moved out access(self) var garment: @GarmentNFT.NFT? @@ -1594,7 +1594,7 @@ pub contract ItemNFT: NonFungibleToken { } //Make Item considered dead. Deposit garment and material to respective vaults - pub fun split(garmentCap: Capability<&{GarmentNFT.GarmentCollectionPublic}>, materialCap: Capability<&{MaterialNFT.MaterialCollectionPublic}>) { + access(all) fun split(garmentCap: Capability<&{GarmentNFT.GarmentCollectionPublic}>, materialCap: Capability<&{MaterialNFT.MaterialCollectionPublic}>) { pre { !self.isDead: "Cannot split. Item is dead" @@ -1620,17 +1620,17 @@ pub contract ItemNFT: NonFungibleToken { } // get a reference to the garment that item stores - pub fun borrowGarment(): &GarmentNFT.NFT? { + access(all) fun borrowGarment(): &GarmentNFT.NFT? { return &self.garment as &GarmentNFT.NFT? } // get a reference to the material that item stores - pub fun borrowMaterial(): &MaterialNFT.NFT? { + access(all) fun borrowMaterial(): &MaterialNFT.NFT? { return &self.material as &MaterialNFT.NFT? } // change name of item nft - pub fun changeName(name: String) { + access(all) fun changeName(name: String) { pre { !self.isDead: "Cannot change garment name. Item is dead" @@ -1642,7 +1642,7 @@ pub contract ItemNFT: NonFungibleToken { } //destroy item if it is considered dead - pub fun cleanDeadItems(item: @ItemNFT.NFT) { + access(all) fun cleanDeadItems(item: @ItemNFT.NFT) { pre { item.isDead: "Cannot destroy, item not dead" @@ -1652,7 +1652,7 @@ pub contract ItemNFT: NonFungibleToken { // mint the NFT, combining a garment and boot. // The itemData that is used to mint the Item is based on the garment and material' garmentDataID and materialDataID - pub fun mintNFT(name: String, royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}>, garment: @GarmentNFT.NFT, material: @MaterialNFT.NFT): @NFT { + access(all) fun mintNFT(name: String, royaltyVault: Capability<&FBRC.Vault{FungibleToken.Receiver}>, garment: @GarmentNFT.NFT, material: @MaterialNFT.NFT): @NFT { pre { royaltyVault.check(): "Royalty capability is invalid!" @@ -1688,12 +1688,12 @@ pub contract ItemNFT: NonFungibleToken { // This is the interface that users can cast their Item Collection as // to allow others to deposit Items into their Collection. It also allows for reading // the IDs of Items in the Collection. - pub resource interface ItemCollectionPublic { - pub fun deposit(token: @NonFungibleToken.NFT) - pub fun batchDeposit(tokens: @NonFungibleToken.Collection) - pub fun getIDs(): [UInt64] - pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT - pub fun borrowItem(id: UInt64): &ItemNFT.NFT? { + access(all) resource interface ItemCollectionPublic { + access(all) fun deposit(token: @NonFungibleToken.NFT) + access(all) fun batchDeposit(tokens: @NonFungibleToken.Collection) + access(all) fun getIDs(): [UInt64] + access(all) fun borrowNFT(id: UInt64): &NonFungibleToken.NFT + access(all) fun borrowItem(id: UInt64): &ItemNFT.NFT? { // If the result isn't nil, the id of the returned reference // should be the same as the argument to the function post { @@ -1706,10 +1706,10 @@ pub contract ItemNFT: NonFungibleToken { // Collection is a resource that every user who owns NFTs // will store in their account to manage their NFTS // - pub resource Collection: ItemCollectionPublic, NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic { + access(all) resource Collection: ItemCollectionPublic, NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic { // Dictionary of Item conforming tokens // NFT is a resource type with a UInt64 ID field - pub var ownedNFTs: @{UInt64: NonFungibleToken.NFT} + access(all) var ownedNFTs: @{UInt64: NonFungibleToken.NFT} init() { self.ownedNFTs <- {} @@ -1721,7 +1721,7 @@ pub contract ItemNFT: NonFungibleToken { // that is to be removed from the Collection // // returns: @NonFungibleToken.NFT the token that was withdrawn - pub fun withdraw(withdrawID: UInt64): @NonFungibleToken.NFT { + access(all) fun withdraw(withdrawID: UInt64): @NonFungibleToken.NFT { // Remove the nft from the Collection let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("Cannot withdraw: Item does not exist in the collection") @@ -1739,7 +1739,7 @@ pub contract ItemNFT: NonFungibleToken { // Returns: @NonFungibleToken.Collection: A collection that contains // the withdrawn Items // - pub fun batchWithdraw(ids: [UInt64]): @NonFungibleToken.Collection { + access(all) fun batchWithdraw(ids: [UInt64]): @NonFungibleToken.Collection { // Create a new empty Collection var batchCollection <- create Collection() @@ -1756,7 +1756,7 @@ pub contract ItemNFT: NonFungibleToken { // // Parameters: token: the NFT to be deposited in the collection // - pub fun deposit(token: @NonFungibleToken.NFT) { + access(all) fun deposit(token: @NonFungibleToken.NFT) { //todo: someFunction that transfers royalty // Cast the deposited token as NFT to make sure // it is the correct type @@ -1780,7 +1780,7 @@ pub contract ItemNFT: NonFungibleToken { // batchDeposit takes a Collection object as an argument // and deposits each contained NFT into this Collection - pub fun batchDeposit(tokens: @NonFungibleToken.Collection) { + access(all) fun batchDeposit(tokens: @NonFungibleToken.Collection) { // Get an array of the IDs to be deposited let keys = tokens.getIDs() @@ -1794,7 +1794,7 @@ pub contract ItemNFT: NonFungibleToken { } // getIDs returns an array of the IDs that are in the Collection - pub fun getIDs(): [UInt64] { + access(all) fun getIDs(): [UInt64] { return self.ownedNFTs.keys } @@ -1809,14 +1809,14 @@ pub contract ItemNFT: NonFungibleToken { // not an specific data. Please use borrowItem to // read Item data. // - pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT { + access(all) fun borrowNFT(id: UInt64): &NonFungibleToken.NFT { return (&self.ownedNFTs[id] as &NonFungibleToken.NFT?)! } // Parameters: id: The ID of the NFT to get the reference for // // Returns: A reference to the NFT - pub fun borrowItem(id: UInt64): &ItemNFT.NFT? { + access(all) fun borrowItem(id: UInt64): &ItemNFT.NFT? { if self.ownedNFTs[id] != nil { let ref = (&self.ownedNFTs[id] as &NonFungibleToken.NFT?)! return ref as! &ItemNFT.NFT @@ -1837,10 +1837,10 @@ pub contract ItemNFT: NonFungibleToken { // allows the owner to perform important functions to modify the // various aspects of the Items and NFTs // - pub resource Admin { + access(all) resource Admin { // create itemdataid allocation from the garmentdataid and materialdataid - pub fun createItemDataAllocation(garmentDataID: UInt32, materialDataID: UInt32){ + access(all) fun createItemDataAllocation(garmentDataID: UInt32, materialDataID: UInt32){ if(ItemNFT.itemDataAllocation[garmentDataID] != nil) { if(ItemNFT.itemDataAllocation[garmentDataID]![materialDataID] != nil){ @@ -1860,7 +1860,7 @@ pub contract ItemNFT: NonFungibleToken { } - pub fun createItemData(mainImage: String, images: [String]): UInt32 { + access(all) fun createItemData(mainImage: String, images: [String]): UInt32 { // Create the new Item var newItem = ItemData(mainImage: mainImage, images: images) @@ -1875,33 +1875,33 @@ pub contract ItemNFT: NonFungibleToken { // createNewAdmin creates a new Admin resource // - pub fun createNewAdmin(): @Admin { + access(all) fun createNewAdmin(): @Admin { return <-create Admin() } // Change the royalty percentage of the contract - pub fun changeRoyaltyPercentage(newRoyaltyPercentage: UFix64) { + access(all) fun changeRoyaltyPercentage(newRoyaltyPercentage: UFix64) { ItemNFT.royaltyPercentage = newRoyaltyPercentage emit RoyaltyPercentageChanged(newRoyaltyPercentage: newRoyaltyPercentage) } // Change the royalty percentage of the contract - pub fun makeSplittable() { + access(all) fun makeSplittable() { ItemNFT.isSplittable = true emit ItemNFTNowSplittable() } // Change the royalty percentage of the contract - pub fun changeItemDataNumberMintable(number: UInt32) { + access(all) fun changeItemDataNumberMintable(number: UInt32) { ItemNFT.numberItemDataMintable = number emit numberItemDataMintableChanged(number: number) } // Retire itemData so that it cannot be used to mint anymore - pub fun retireItemData(itemDataID: UInt32) { + access(all) fun retireItemData(itemDataID: UInt32) { pre { ItemNFT.isItemDataRetired[itemDataID] != nil: "Cannot retire item: Item doesn't exist!" } @@ -1924,37 +1924,37 @@ pub contract ItemNFT: NonFungibleToken { // Once they have a Collection in their storage, they are able to receive // Items in transactions. // - pub fun createEmptyCollection(): @NonFungibleToken.Collection { + access(all) fun createEmptyCollection(): @NonFungibleToken.Collection { return <-create ItemNFT.Collection() } // get dictionary of numberMintedPerItem - pub fun getNumberMintedPerItem(): {UInt32: UInt32} { + access(all) fun getNumberMintedPerItem(): {UInt32: UInt32} { return ItemNFT.numberMintedPerItem } // get how many Items with itemDataID are minted - pub fun getItemNumberMinted(id: UInt32): UInt32 { + access(all) fun getItemNumberMinted(id: UInt32): UInt32 { let numberMinted = ItemNFT.numberMintedPerItem[id]?? panic("itemDataID not found") return numberMinted } // get the ItemData of a specific id - pub fun getItemData(id: UInt32): ItemData { + access(all) fun getItemData(id: UInt32): ItemData { let itemData = ItemNFT.itemDatas[id]?? panic("itemDataID not found") return itemData } // get the map of item data allocations - pub fun getItemDataAllocations(): {UInt32: {UInt32: UInt32}} { + access(all) fun getItemDataAllocations(): {UInt32: {UInt32: UInt32}} { let itemDataAllocation = ItemNFT.itemDataAllocation return itemDataAllocation } // get the itemData allocation from the garment and material dataID - pub fun getItemDataAllocation(garmentDataID: UInt32, materialDataID: UInt32): UInt32 { + access(all) fun getItemDataAllocation(garmentDataID: UInt32, materialDataID: UInt32): UInt32 { let isValidGarmentMaterialPair = ItemNFT.itemDataAllocation[garmentDataID]?? panic("garment and material dataID pair not allocated") @@ -1965,17 +1965,17 @@ pub contract ItemNFT: NonFungibleToken { return itemDataAllocation } // get all ItemDatas created - pub fun getItemDatas(): {UInt32: ItemData} { + access(all) fun getItemDatas(): {UInt32: ItemData} { return ItemNFT.itemDatas } // get dictionary of itemdataids and whether they are retired - pub fun getItemDatasRetired(): {UInt32: Bool} { + access(all) fun getItemDatasRetired(): {UInt32: Bool} { return ItemNFT.isItemDataRetired } // get bool of if itemdataid is retired - pub fun getItemDataRetired(itemDataID: UInt32): Bool? { + access(all) fun getItemDataRetired(itemDataID: UInt32): Bool? { return ItemNFT.isItemDataRetired[itemDataID]! } @@ -2125,7 +2125,7 @@ import FBRC from 0x5a76b4858ce34b2f import FlowToken from 0x7e60df042a9c0868 import FungibleToken from 0x9a0766d93b6608b7 -pub fun hasFBRC(_ address: Address): Bool { +access(all) fun hasFBRC(_ address: Address): Bool { let receiver = getAccount(address) .getCapability<&FBRC.Vault{FungibleToken.Receiver}>(FBRC.CollectionReceiverPath) .check() @@ -2135,7 +2135,7 @@ pub fun hasFBRC(_ address: Address): Bool { return receiver && balance } -pub fun hasFlowToken(_ address: Address): Bool { +access(all) fun hasFlowToken(_ address: Address): Bool { let receiver = getAccount(address) .getCapability<&FlowToken.Vault{FungibleToken.Receiver}>(/public/flowTokenReceiver) .check() @@ -2145,19 +2145,19 @@ pub fun hasFlowToken(_ address: Address): Bool { return receiver && balance } -pub fun hasGarmentNFT(_ address: Address): Bool { +access(all) fun hasGarmentNFT(_ address: Address): Bool { return getAccount(address) .getCapability<&{GarmentNFT.GarmentCollectionPublic}>(GarmentNFT.CollectionPublicPath) .check() } -pub fun hasMaterialNFT(_ address: Address): Bool { +access(all) fun hasMaterialNFT(_ address: Address): Bool { return getAccount(address) .getCapability<&{MaterialNFT.MaterialCollectionPublic}>(MaterialNFT.CollectionPublicPath) .check() } -pub fun hasItemNFT(_ address: Address): Bool { +access(all) fun hasItemNFT(_ address: Address): Bool { return getAccount(address) .getCapability<&{ItemNFT.ItemCollectionPublic}>(ItemNFT.CollectionPublicPath) .check() @@ -2596,15 +2596,15 @@ transaction(recipientAddr: Address, name: String, garmentWithdrawID: UInt64, mat import GarmentNFT from 0x5a76b4858ce34b2f import MaterialNFT from 0x5a76b4858ce34b2f - pub struct ItemDetails { - pub let name: String - pub let serialNumber: UInt32 - pub let numberMintedPerItemDataID: UInt32 - pub let itemDataID: UInt32 - pub let mainImage: String - pub let images: [String] - pub let garment: GarmentDetails - pub let material: MaterialDetails + access(all) struct ItemDetails { + access(all) let name: String + access(all) let serialNumber: UInt32 + access(all) let numberMintedPerItemDataID: UInt32 + access(all) let itemDataID: UInt32 + access(all) let mainImage: String + access(all) let images: [String] + access(all) let garment: GarmentDetails + access(all) let material: MaterialDetails init( name: String, @@ -2627,16 +2627,16 @@ transaction(recipientAddr: Address, name: String, garmentWithdrawID: UInt64, mat } } - pub struct GarmentDetails { - pub let id: UInt64 - pub let serialNumber: UInt32 - pub let numberMintedPerGarmentDataID: UInt32 - pub let garmentDataID: UInt32 - pub let mainImage: String - pub let images: [String] - pub let name: String - pub let artist: String - pub let description: String + access(all) struct GarmentDetails { + access(all) let id: UInt64 + access(all) let serialNumber: UInt32 + access(all) let numberMintedPerGarmentDataID: UInt32 + access(all) let garmentDataID: UInt32 + access(all) let mainImage: String + access(all) let images: [String] + access(all) let name: String + access(all) let artist: String + access(all) let description: String init( id: UInt64, @@ -2661,15 +2661,15 @@ transaction(recipientAddr: Address, name: String, garmentWithdrawID: UInt64, mat } } - pub struct MaterialDetails { - pub let id: UInt64 - pub let serialNumber: UInt32 - pub let numberMintedPerMaterialDataID: UInt32 - pub let materialDataID: UInt32 - pub let mainImage: String - pub let secondImage: String - pub let name: String - pub let description: String + access(all) struct MaterialDetails { + access(all) let id: UInt64 + access(all) let serialNumber: UInt32 + access(all) let numberMintedPerMaterialDataID: UInt32 + access(all) let materialDataID: UInt32 + access(all) let mainImage: String + access(all) let secondImage: String + access(all) let name: String + access(all) let description: String init( id: UInt64, @@ -2692,7 +2692,7 @@ transaction(recipientAddr: Address, name: String, garmentWithdrawID: UInt64, mat } } - pub fun main(account: Address, id: UInt64): ItemDetails { + access(all) fun main(account: Address, id: UInt64): ItemDetails { let acct = getAccount(account) @@ -2793,31 +2793,31 @@ func TestRuntimeMissingMemberVersus(t *testing.T) { const flowTokenContract = ` import FungibleToken from 0x9a0766d93b6608b7 -pub contract FlowToken: FungibleToken { +access(all) contract FlowToken: FungibleToken { // Total supply of Flow tokens in existence - pub var totalSupply: UFix64 + access(all) var totalSupply: UFix64 // Event that is emitted when the contract is created - pub event TokensInitialized(initialSupply: UFix64) + access(all) event TokensInitialized(initialSupply: UFix64) // Event that is emitted when tokens are withdrawn from a Vault - pub event TokensWithdrawn(amount: UFix64, from: Address?) + access(all) event TokensWithdrawn(amount: UFix64, from: Address?) // Event that is emitted when tokens are deposited to a Vault - pub event TokensDeposited(amount: UFix64, to: Address?) + access(all) event TokensDeposited(amount: UFix64, to: Address?) // Event that is emitted when new tokens are minted - pub event TokensMinted(amount: UFix64) + access(all) event TokensMinted(amount: UFix64) // Event that is emitted when tokens are destroyed - pub event TokensBurned(amount: UFix64) + access(all) event TokensBurned(amount: UFix64) // Event that is emitted when a new minter resource is created - pub event MinterCreated(allowedAmount: UFix64) + access(all) event MinterCreated(allowedAmount: UFix64) // Event that is emitted when a new burner resource is created - pub event BurnerCreated() + access(all) event BurnerCreated() // Vault // @@ -2831,10 +2831,10 @@ pub contract FlowToken: FungibleToken { // out of thin air. A special Minter resource needs to be defined to mint // new tokens. // - pub resource Vault: FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance { + access(all) resource Vault: FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance { // holds the balance of a users tokens - pub var balance: UFix64 + access(all) var balance: UFix64 // initialize the balance at resource creation time init(balance: UFix64) { @@ -2850,7 +2850,7 @@ pub contract FlowToken: FungibleToken { // created Vault to the context that called so it can be deposited // elsewhere. // - pub fun withdraw(amount: UFix64): @FungibleToken.Vault { + access(all) fun withdraw(amount: UFix64): @FungibleToken.Vault { self.balance = self.balance - amount emit TokensWithdrawn(amount: amount, from: self.owner?.address) return <-create Vault(balance: amount) @@ -2863,7 +2863,7 @@ pub contract FlowToken: FungibleToken { // It is allowed to destroy the sent Vault because the Vault // was a temporary holder of the tokens. The Vault's balance has // been consumed and therefore can be destroyed. - pub fun deposit(from: @FungibleToken.Vault) { + access(all) fun deposit(from: @FungibleToken.Vault) { let vault <- from as! @FlowToken.Vault self.balance = self.balance + vault.balance emit TokensDeposited(amount: vault.balance, to: self.owner?.address) @@ -2883,16 +2883,16 @@ pub contract FlowToken: FungibleToken { // and store the returned Vault in their storage in order to allow their // account to be able to receive deposits of this token type. // - pub fun createEmptyVault(): @FungibleToken.Vault { + access(all) fun createEmptyVault(): @FungibleToken.Vault { return <-create Vault(balance: 0.0) } - pub resource Administrator { + access(all) resource Administrator { // createNewMinter // // Function that creates and returns a new minter resource // - pub fun createNewMinter(allowedAmount: UFix64): @Minter { + access(all) fun createNewMinter(allowedAmount: UFix64): @Minter { emit MinterCreated(allowedAmount: allowedAmount) return <-create Minter(allowedAmount: allowedAmount) } @@ -2901,7 +2901,7 @@ pub contract FlowToken: FungibleToken { // // Function that creates and returns a new burner resource // - pub fun createNewBurner(): @Burner { + access(all) fun createNewBurner(): @Burner { emit BurnerCreated() return <-create Burner() } @@ -2911,17 +2911,17 @@ pub contract FlowToken: FungibleToken { // // Resource object that token admin accounts can hold to mint new tokens. // - pub resource Minter { + access(all) resource Minter { // the amount of tokens that the minter is allowed to mint - pub var allowedAmount: UFix64 + access(all) var allowedAmount: UFix64 // mintTokens // // Function that mints new tokens, adds them to the total supply, // and returns them to the calling context. // - pub fun mintTokens(amount: UFix64): @FlowToken.Vault { + access(all) fun mintTokens(amount: UFix64): @FlowToken.Vault { pre { amount > UFix64(0): "Amount minted must be greater than zero" amount <= self.allowedAmount: "Amount minted must be less than the allowed amount" @@ -2941,7 +2941,7 @@ pub contract FlowToken: FungibleToken { // // Resource object that token admin accounts can hold to burn tokens. // - pub resource Burner { + access(all) resource Burner { // burnTokens // @@ -2950,7 +2950,7 @@ pub contract FlowToken: FungibleToken { // Note: the burned tokens are automatically subtracted from the // total supply in the Vault destructor. // - pub fun burnTokens(from: @FungibleToken.Vault) { + access(all) fun burnTokens(from: @FungibleToken.Vault) { let vault <- from as! @FlowToken.Vault let amount = vault.balance destroy vault @@ -2999,25 +2999,25 @@ import FlowToken from 0x7e60df042a9c0868 // import Debug from 0x99ca04281098b33d // import Clock from 0x99ca04281098b33d -pub contract AuctionDutch { +access(all) contract AuctionDutch { - pub let CollectionStoragePath: StoragePath - pub let CollectionPublicPath: PublicPath + access(all) let CollectionStoragePath: StoragePath + access(all) let CollectionPublicPath: PublicPath - pub let BidCollectionStoragePath: StoragePath - pub let BidCollectionPublicPath: PublicPath + access(all) let BidCollectionStoragePath: StoragePath + access(all) let BidCollectionPublicPath: PublicPath - pub event AuctionDutchBidRejected(bidder: Address) - pub event AuctionDutchCreated(name: String, artist: String, number: Int, owner:Address, id: UInt64) + access(all) event AuctionDutchBidRejected(bidder: Address) + access(all) event AuctionDutchCreated(name: String, artist: String, number: Int, owner:Address, id: UInt64) - pub event AuctionDutchBid(amount: UFix64, bidder: Address, auction: UInt64, bid: UInt64) - pub event AuctionDutchBidIncreased(amount: UFix64, bidder: Address, auction: UInt64, bid: UInt64) - pub event AuctionDutchTick(tickPrice: UFix64, acceptedBids: Int, totalItems: Int, tickTime: UFix64, auction: UInt64) - pub event AuctionDutchSettle(price: UFix64, auction: UInt64) + access(all) event AuctionDutchBid(amount: UFix64, bidder: Address, auction: UInt64, bid: UInt64) + access(all) event AuctionDutchBidIncreased(amount: UFix64, bidder: Address, auction: UInt64, bid: UInt64) + access(all) event AuctionDutchTick(tickPrice: UFix64, acceptedBids: Int, totalItems: Int, tickTime: UFix64, auction: UInt64) + access(all) event AuctionDutchSettle(price: UFix64, auction: UInt64) - pub struct Bids { - pub let bids: [BidReport] - pub let winningPrice: UFix64? + access(all) struct Bids { + access(all) let bids: [BidReport] + access(all) let winningPrice: UFix64? init(bids: [BidReport], winningPrice: UFix64?) { self.bids =bids @@ -3025,13 +3025,13 @@ pub contract AuctionDutch { } } - pub struct BidReport { - pub let id: UInt64 - pub let time: UFix64 - pub let amount: UFix64 - pub let bidder: Address - pub let winning: Bool - pub let confirmed: Bool + access(all) struct BidReport { + access(all) let id: UInt64 + access(all) let time: UFix64 + access(all) let amount: UFix64 + access(all) let bidder: Address + access(all) let winning: Bool + access(all) let confirmed: Bool init(id: UInt64, time: UFix64, amount: UFix64, bidder: Address, winning: Bool, confirmed: Bool) { self.id=id @@ -3043,7 +3043,7 @@ pub contract AuctionDutch { } } - pub struct BidInfo { + access(all) struct BidInfo { access(contract) let id: UInt64 access(contract) let vaultCap: Capability<&{FungibleToken.Receiver}> access(contract) let nftCap: Capability<&{NonFungibleToken.Receiver}> @@ -3061,7 +3061,7 @@ pub contract AuctionDutch { self.winning=false } - pub fun increaseBid(_ amount:UFix64) { + access(all) fun increaseBid(_ amount:UFix64) { self.balance=self.balance+amount self.time = 42.0 // Clock.time() } @@ -3070,14 +3070,14 @@ pub contract AuctionDutch { self.balance=self.balance - amount } - pub fun setWinning(_ value: Bool) { + access(all) fun setWinning(_ value: Bool) { self.winning=value } } - pub struct Tick { - pub let price: UFix64 - pub let startedAt: UFix64 + access(all) struct Tick { + access(all) let price: UFix64 + access(all) let startedAt: UFix64 init(price: UFix64, startedAt: UFix64) { self.price=price @@ -3085,11 +3085,11 @@ pub contract AuctionDutch { } } - pub struct TickStatus{ - pub let price: UFix64 - pub let startedAt: UFix64 - pub let acceptedBids: Int - pub let cumulativeAcceptedBids: Int + access(all) struct TickStatus{ + access(all) let price: UFix64 + access(all) let startedAt: UFix64 + access(all) let acceptedBids: Int + access(all) let cumulativeAcceptedBids: Int init(price: UFix64, startedAt: UFix64, acceptedBids:Int, cumulativeAcceptedBids:Int) { self.price=price @@ -3099,7 +3099,7 @@ pub contract AuctionDutch { } } - pub resource Auction { + access(all) resource Auction { access(contract) let nfts: @{UInt64:NonFungibleToken.NFT} access(contract) let metadata: {String:String} @@ -3165,7 +3165,7 @@ pub contract AuctionDutch { self.royaltyPercentage=royaltyPercentage } - pub fun startAt() : UFix64 { + access(all) fun startAt() : UFix64 { return self.ticks[0].startedAt } @@ -3215,7 +3215,7 @@ pub contract AuctionDutch { emit AuctionDutchSettle(price: self.winningBid!, auction: self.uuid) } - pub fun getBids() : Bids { + access(all) fun getBids() : Bids { var bids: [BidReport] =[] var numberWinning=0 var winningBid=self.winningBid @@ -3238,7 +3238,7 @@ pub contract AuctionDutch { return Bids(bids: bids, winningPrice: winningBid) } - pub fun findWinners() : [UInt64] { + access(all) fun findWinners() : [UInt64] { var bids: [UInt64] =[] for tick in self.ticks { @@ -3259,12 +3259,12 @@ pub contract AuctionDutch { return bids } - pub fun getTick() : Tick { + access(all) fun getTick() : Tick { return self.ticks[self.currentTickIndex] } //this should be called something else - pub fun isAuctionFinished() : Bool { + access(all) fun isAuctionFinished() : Bool { if !self.isLastTick() { //if the startedAt of the next tick is larger then current time not time to tick yet @@ -3325,13 +3325,13 @@ pub contract AuctionDutch { return false } - pub fun isLastTick() : Bool { + access(all) fun isLastTick() : Bool { let tickLength = UInt64(self.ticks.length-1) return self.currentTickIndex==tickLength } // taken from bisect_right in pthon https://stackoverflow.com/questions/2945017/javas-equivalent-to-bisect-in-python - pub fun bisect(items: [UInt64], new: BidInfo) : Int { + access(all) fun bisect(items: [UInt64], new: BidInfo) : Int { var high=items.length var low=0 while low < high { @@ -3347,7 +3347,7 @@ pub contract AuctionDutch { return low } - priv fun insertBid(_ bid: BidInfo) { + access(self) fun insertBid(_ bid: BidInfo) { for tick in self.ticks { if tick.price > bid.balance { continue @@ -3369,7 +3369,7 @@ pub contract AuctionDutch { } } - pub fun findTickForBid(_ id:UInt64) : Tick { + access(all) fun findTickForBid(_ id:UInt64) : Tick { for tick in self.ticks { let bucket= self.bids[tick.startedAt]! if bucket.contains(id) { @@ -3379,7 +3379,7 @@ pub contract AuctionDutch { panic("Could not find bid") } - pub fun removeBidFromTick(_ id:UInt64, tick: UFix64) { + access(all) fun removeBidFromTick(_ id:UInt64, tick: UFix64) { var index=0 let bids= self.bids[tick]! while index < bids.length { @@ -3499,7 +3499,7 @@ pub contract AuctionDutch { //emit event } - pub fun addBid(vault: @FlowToken.Vault, nftCap: Capability<&{NonFungibleToken.Receiver}>, vaultCap: Capability<&{FungibleToken.Receiver}>, time: UFix64) : UInt64{ + access(all) fun addBid(vault: @FlowToken.Vault, nftCap: Capability<&{NonFungibleToken.Receiver}>, vaultCap: Capability<&{FungibleToken.Receiver}>, time: UFix64) : UInt64{ let bidId=self.totalBids @@ -3511,7 +3511,7 @@ pub contract AuctionDutch { return bid.id } - pub fun calculatePrice() : UFix64{ + access(all) fun calculatePrice() : UFix64{ return self.ticks[self.currentTickIndex].price } @@ -3523,27 +3523,27 @@ pub contract AuctionDutch { } } - pub resource interface Public { - pub fun getIds() : [UInt64] + access(all) resource interface Public { + access(all) fun getIds() : [UInt64] //TODO: can we just join these two? - pub fun getStatus(_ id: UInt64) : AuctionDutchStatus - pub fun getBids(_ id: UInt64) : Bids + access(all) fun getStatus(_ id: UInt64) : AuctionDutchStatus + access(all) fun getBids(_ id: UInt64) : Bids //these methods are only allowed to be called from within this contract, but we want to call them on another users resource access(contract) fun getAuction(_ id:UInt64) : &Auction - pub fun bid(id: UInt64, vault: @FungibleToken.Vault, vaultCap: Capability<&{FungibleToken.Receiver}>, nftCap: Capability<&{NonFungibleToken.Receiver}>) : @Bid + access(all) fun bid(id: UInt64, vault: @FungibleToken.Vault, vaultCap: Capability<&{FungibleToken.Receiver}>, nftCap: Capability<&{NonFungibleToken.Receiver}>) : @Bid } - pub struct AuctionDutchStatus { + access(all) struct AuctionDutchStatus { - pub let status: String - pub let startTime: UFix64 - pub let currentTime: UFix64 - pub let currentPrice: UFix64 - pub let totalItems: Int - pub let acceptedBids: Int - pub let tickStatus: {UFix64:TickStatus} - pub let metadata: {String:String} + access(all) let status: String + access(all) let startTime: UFix64 + access(all) let currentTime: UFix64 + access(all) let currentPrice: UFix64 + access(all) let totalItems: Int + access(all) let acceptedBids: Int + access(all) let tickStatus: {UFix64:TickStatus} + access(all) let metadata: {String:String} init(status:String, currentPrice: UFix64, totalItems: Int, acceptedBids:Int, startTime: UFix64, tickStatus: {UFix64:TickStatus}, metadata: {String:String}){ self.status=status @@ -3557,22 +3557,22 @@ pub contract AuctionDutch { } } - pub resource Collection: Public { + access(all) resource Collection: Public { //TODO: what to do with ended auctions? put them in another collection? //NFTS are gone but we might want to keep some information about it? - pub let auctions: @{UInt64: Auction} + access(all) let auctions: @{UInt64: Auction} init() { self.auctions <- {} } - pub fun getIds() : [UInt64] { + access(all) fun getIds() : [UInt64] { return self.auctions.keys } - pub fun getStatus(_ id: UInt64) : AuctionDutchStatus{ + access(all) fun getStatus(_ id: UInt64) : AuctionDutchStatus{ let item= self.getAuction(id) let currentTime= 42.0 // Clock.time() @@ -3595,7 +3595,7 @@ pub contract AuctionDutch { metadata:item.metadata) } - pub fun getBids(_ id:UInt64) : Bids { + access(all) fun getBids(_ id:UInt64) : Bids { pre { self.auctions[id] != nil: "auction doesn't exist" } @@ -3611,7 +3611,7 @@ pub contract AuctionDutch { return (&self.auctions[id] as &Auction?)! } - pub fun bid(id: UInt64, vault: @FungibleToken.Vault, vaultCap: Capability<&{FungibleToken.Receiver}>, nftCap: Capability<&{NonFungibleToken.Receiver}>) : @Bid{ + access(all) fun bid(id: UInt64, vault: @FungibleToken.Vault, vaultCap: Capability<&{FungibleToken.Receiver}>, nftCap: Capability<&{NonFungibleToken.Receiver}>) : @Bid{ //TODO: pre id should exist let time= 42.0 // Clock.time() @@ -3636,7 +3636,7 @@ pub contract AuctionDutch { return <- create Bid(capability: AuctionDutch.account.getCapability<&Collection{Public}>(AuctionDutch.CollectionPublicPath), auctionId: id, bidId: bidId) } - pub fun tickOrFulfill(_ id:UInt64) { + access(all) fun tickOrFulfill(_ id:UInt64) { let time= 42.0 // Clock.time() let auction=self.getAuction(id) @@ -3651,7 +3651,7 @@ pub contract AuctionDutch { } - pub fun createAuction( nfts: @{UInt64: NonFungibleToken.NFT}, metadata: {String: String}, startAt: UFix64, startPrice: UFix64, floorPrice: UFix64, decreasePriceFactor: UFix64, decreasePriceAmount: UFix64, tickDuration: UFix64, ownerVaultCap: Capability<&{FungibleToken.Receiver}>, ownerNFTCap: Capability<&{NonFungibleToken.Receiver}>, royaltyVaultCap: Capability<&{FungibleToken.Receiver}>, royaltyPercentage: UFix64) { + access(all) fun createAuction( nfts: @{UInt64: NonFungibleToken.NFT}, metadata: {String: String}, startAt: UFix64, startPrice: UFix64, floorPrice: UFix64, decreasePriceFactor: UFix64, decreasePriceAmount: UFix64, tickDuration: UFix64, ownerVaultCap: Capability<&{FungibleToken.Receiver}>, ownerNFTCap: Capability<&{NonFungibleToken.Receiver}>, royaltyVaultCap: Capability<&{FungibleToken.Receiver}>, royaltyPercentage: UFix64) { let ticks: [Tick] = [Tick(price: startPrice, startedAt: startAt)] var currentPrice=startPrice @@ -3681,7 +3681,7 @@ pub contract AuctionDutch { } - pub fun getBids(_ id: UInt64) : Bids { + access(all) fun getBids(_ id: UInt64) : Bids { let account = AuctionDutch.account let cap=account.getCapability<&Collection{Public}>(self.CollectionPublicPath) if let collection = cap.borrow() { @@ -3690,7 +3690,7 @@ pub contract AuctionDutch { panic("Could not find auction capability") } - pub fun getAuctionDutch(_ id: UInt64) : AuctionDutchStatus? { + access(all) fun getAuctionDutch(_ id: UInt64) : AuctionDutchStatus? { let account = AuctionDutch.account let cap=account.getCapability<&Collection{Public}>(self.CollectionPublicPath) if let collection = cap.borrow() { @@ -3699,11 +3699,11 @@ pub contract AuctionDutch { return nil } - pub resource Bid { + access(all) resource Bid { - pub let capability:Capability<&Collection{Public}> - pub let auctionId: UInt64 - pub let bidId: UInt64 + access(all) let capability:Capability<&Collection{Public}> + access(all) let auctionId: UInt64 + access(all) let bidId: UInt64 init(capability:Capability<&Collection{Public}>, auctionId: UInt64, bidId:UInt64) { self.capability=capability @@ -3711,31 +3711,31 @@ pub contract AuctionDutch { self.bidId=bidId } - pub fun getBidInfo() : BidInfo { + access(all) fun getBidInfo() : BidInfo { return self.capability.borrow()!.getAuction(self.auctionId).getBidInfo(id: self.bidId) } - pub fun getExcessBalance() : UFix64 { + access(all) fun getExcessBalance() : UFix64 { return self.capability.borrow()!.getAuction(self.auctionId).getExcessBalance(self.bidId) } - pub fun increaseBid(vault: @FlowToken.Vault) { + access(all) fun increaseBid(vault: @FlowToken.Vault) { self.capability.borrow()!.getAuction(self.auctionId).increaseBid(id: self.bidId, vault: <- vault) } - pub fun cancelBid() { + access(all) fun cancelBid() { self.capability.borrow()!.getAuction(self.auctionId).cancelBid(id: self.bidId) } - pub fun withdrawExcessFlow(_ cap: Capability<&{FungibleToken.Receiver}>) { + access(all) fun withdrawExcessFlow(_ cap: Capability<&{FungibleToken.Receiver}>) { self.capability.borrow()!.getAuction(self.auctionId).withdrawExcessFlow(id: self.bidId, cap:cap) } } - pub struct ExcessFlowReport { - pub let id: UInt64 - pub let winning: Bool //TODO: should this be confirmed winning? - pub let excessAmount: UFix64 + access(all) struct ExcessFlowReport { + access(all) let id: UInt64 + access(all) let winning: Bool //TODO: should this be confirmed winning? + access(all) let excessAmount: UFix64 init(id: UInt64, report: BidInfo, excessAmount: UFix64) { self.id=id @@ -3744,14 +3744,14 @@ pub contract AuctionDutch { } } - pub resource interface BidCollectionPublic { - pub fun bid(marketplace: Address, id: UInt64, vault: @FungibleToken.Vault, vaultCap: Capability<&{FungibleToken.Receiver}>, nftCap: Capability<&{NonFungibleToken.Receiver}>) - pub fun getIds() :[UInt64] - pub fun getReport(_ id: UInt64) : ExcessFlowReport + access(all) resource interface BidCollectionPublic { + access(all) fun bid(marketplace: Address, id: UInt64, vault: @FungibleToken.Vault, vaultCap: Capability<&{FungibleToken.Receiver}>, nftCap: Capability<&{NonFungibleToken.Receiver}>) + access(all) fun getIds() :[UInt64] + access(all) fun getReport(_ id: UInt64) : ExcessFlowReport } - pub resource BidCollection:BidCollectionPublic { + access(all) resource BidCollection:BidCollectionPublic { access(contract) let bids : @{UInt64: Bid} @@ -3759,34 +3759,34 @@ pub contract AuctionDutch { self.bids <- {} } - pub fun getIds() : [UInt64] { + access(all) fun getIds() : [UInt64] { return self.bids.keys } - pub fun getReport(_ id: UInt64) : ExcessFlowReport { + access(all) fun getReport(_ id: UInt64) : ExcessFlowReport { let bid=self.getBid(id) return ExcessFlowReport(id:id, report: bid.getBidInfo(), excessAmount: bid.getExcessBalance()) } - pub fun bid(marketplace: Address, id: UInt64, vault: @FungibleToken.Vault, vaultCap: Capability<&{FungibleToken.Receiver}>, nftCap: Capability<&{NonFungibleToken.Receiver}>) { + access(all) fun bid(marketplace: Address, id: UInt64, vault: @FungibleToken.Vault, vaultCap: Capability<&{FungibleToken.Receiver}>, nftCap: Capability<&{NonFungibleToken.Receiver}>) { let dutchAuctionCap=getAccount(marketplace).getCapability<&AuctionDutch.Collection{AuctionDutch.Public}>(AuctionDutch.CollectionPublicPath) let bid <- dutchAuctionCap.borrow()!.bid(id: id, vault: <- vault, vaultCap: vaultCap, nftCap: nftCap) self.bids[bid.uuid] <-! bid } - pub fun withdrawExcessFlow(id: UInt64, vaultCap: Capability<&{FungibleToken.Receiver}>) { + access(all) fun withdrawExcessFlow(id: UInt64, vaultCap: Capability<&{FungibleToken.Receiver}>) { let bid = self.getBid(id) bid.withdrawExcessFlow(vaultCap) } - pub fun cancelBid(_ id: UInt64) { + access(all) fun cancelBid(_ id: UInt64) { let bid = self.getBid(id) bid.cancelBid() destroy <- self.bids.remove(key: bid.uuid) } - pub fun increaseBid(_ id: UInt64, vault: @FungibleToken.Vault) { + access(all) fun increaseBid(_ id: UInt64, vault: @FungibleToken.Vault) { let vault <- vault as! @FlowToken.Vault let bid = self.getBid(id) bid.increaseBid(vault: <- vault) @@ -3806,7 +3806,7 @@ pub contract AuctionDutch { } - pub fun createEmptyBidCollection() : @BidCollection { + access(all) fun createEmptyBidCollection() : @BidCollection { return <- create BidCollection() } @@ -4177,10 +4177,10 @@ func TestRuntimeMissingMemberExampleMarketplace(t *testing.T) { // This is a basic implementation of a Fungible Token and is NOT meant to be used in production // See the Flow Fungible Token standard for real examples: https://github.com/onflow/flow-ft -pub contract ExampleToken { +access(all) contract ExampleToken { // Total supply of all tokens in existence. - pub var totalSupply: UFix64 + access(all) var totalSupply: UFix64 // Provider // @@ -4191,7 +4191,7 @@ pub contract ExampleToken { // it leaves open the possibility of creating custom providers // that don't necessarily need their own balance. // - pub resource interface Provider { + access(all) resource interface Provider { // withdraw // @@ -4204,7 +4204,7 @@ pub contract ExampleToken { // them access by publishing a resource that exposes the withdraw // function. // - pub fun withdraw(amount: UFix64): @Vault { + access(all) fun withdraw(amount: UFix64): @Vault { post { // result refers to the return value of the function result.balance == UFix64(amount): @@ -4223,13 +4223,13 @@ pub contract ExampleToken { // can do custom things with the tokens, like split them up and // send them to different places. // - pub resource interface Receiver { + access(all) resource interface Receiver { // deposit // // Function that can be called to deposit tokens // into the implementing resource type // - pub fun deposit(from: @Vault) { + access(all) fun deposit(from: @Vault) { pre { from.balance > 0.0: "Deposit balance must be positive" @@ -4241,8 +4241,8 @@ pub contract ExampleToken { // // Interface that specifies a public balance field for the vault // - pub resource interface Balance { - pub var balance: UFix64 + access(all) resource interface Balance { + access(all) var balance: UFix64 } // Vault @@ -4257,10 +4257,10 @@ pub contract ExampleToken { // out of thin air. A special Minter resource needs to be defined to mint // new tokens. // - pub resource Vault: Provider, Receiver, Balance { + access(all) resource Vault: Provider, Receiver, Balance { // keeps track of the total balance of the account's tokens - pub var balance: UFix64 + access(all) var balance: UFix64 // initialize the balance at resource creation time init(balance: UFix64) { @@ -4277,7 +4277,7 @@ pub contract ExampleToken { // created Vault to the context that called so it can be deposited // elsewhere. // - pub fun withdraw(amount: UFix64): @Vault { + access(all) fun withdraw(amount: UFix64): @Vault { self.balance = self.balance - amount return <-create Vault(balance: amount) } @@ -4290,7 +4290,7 @@ pub contract ExampleToken { // It is allowed to destroy the sent Vault because the Vault // was a temporary holder of the tokens. The Vault's balance has // been consumed and therefore can be destroyed. - pub fun deposit(from: @Vault) { + access(all) fun deposit(from: @Vault) { self.balance = self.balance + from.balance destroy from } @@ -4303,18 +4303,18 @@ pub contract ExampleToken { // and store the returned Vault in their storage in order to allow their // account to be able to receive deposits of this token type. // - pub fun createEmptyVault(): @Vault { + access(all) fun createEmptyVault(): @Vault { return <-create Vault(balance: 0.0) } // VaultMinter // // Resource object that an admin can control to mint new tokens - pub resource VaultMinter { + access(all) resource VaultMinter { // Function that mints new tokens and deposits into an account's vault // using their Receiver reference. - pub fun mintTokens(amount: UFix64, recipient: Capability<&AnyResource{Receiver}>) { + access(all) fun mintTokens(amount: UFix64, recipient: Capability<&AnyResource{Receiver}>) { let recipientRef = recipient.borrow() ?? panic("Could not borrow a receiver reference to the vault") @@ -4359,19 +4359,19 @@ pub contract ExampleToken { // // Learn more about non-fungible tokens in this tutorial: https://docs.onflow.org/docs/non-fungible-tokens -pub contract ExampleNFT { +access(all) contract ExampleNFT { // Declare Path constants so paths do not have to be hardcoded // in transactions and scripts - pub let CollectionStoragePath: StoragePath - pub let CollectionPublicPath: PublicPath - pub let MinterStoragePath: StoragePath + access(all) let CollectionStoragePath: StoragePath + access(all) let CollectionPublicPath: PublicPath + access(all) let MinterStoragePath: StoragePath // Declare the NFT resource type - pub resource NFT { + access(all) resource NFT { // The unique ID that differentiates each NFT - pub let id: UInt64 + access(all) let id: UInt64 // Initialize both fields in the init function init(initID: UInt64) { @@ -4383,20 +4383,20 @@ pub contract ExampleNFT { // to create public, restricted references to their NFT Collection. // They would use this to publicly expose only the deposit, getIDs, // and idExists fields in their Collection - pub resource interface NFTReceiver { + access(all) resource interface NFTReceiver { - pub fun deposit(token: @NFT) + access(all) fun deposit(token: @NFT) - pub fun getIDs(): [UInt64] + access(all) fun getIDs(): [UInt64] - pub view fun idExists(id: UInt64): Bool + access(all) view fun idExists(id: UInt64): Bool } // The definition of the Collection resource that // holds the NFTs that a user owns - pub resource Collection: NFTReceiver { + access(all) resource Collection: NFTReceiver { // dictionary of NFT conforming tokens - pub var ownedNFTs: @{UInt64: NFT} + access(all) var ownedNFTs: @{UInt64: NFT} // Initialize the NFTs field to an empty collection init () { @@ -4407,14 +4407,14 @@ pub contract ExampleNFT { // // Function that removes an NFT from the collection // and moves it to the calling context - pub fun withdraw(withdrawID: UInt64): @NFT { + access(all) fun withdraw(withdrawID: UInt64): @NFT { // If the NFT isn't found, the transaction panics and reverts let token <- self.ownedNFTs.remove(key: withdrawID)! return <-token } - pub fun getReference(id: UInt64): &NFT { + access(all) fun getReference(id: UInt64): &NFT { return (&self.ownedNFTs[id] as &NFT?)! } @@ -4422,7 +4422,7 @@ pub contract ExampleNFT { // // Function that takes a NFT as an argument and // adds it to the collections dictionary - pub fun deposit(token: @NFT) { + access(all) fun deposit(token: @NFT) { // add the new token to the dictionary with a force assignment // if there is already a value at that key, it will fail and revert self.ownedNFTs[token.id] <-! token @@ -4430,12 +4430,12 @@ pub contract ExampleNFT { // idExists checks to see if a NFT // with the given ID exists in the collection - pub view fun idExists(id: UInt64): Bool { + access(all) view fun idExists(id: UInt64): Bool { return self.ownedNFTs[id] != nil } // getIDs returns an array of the IDs that are in the collection - pub fun getIDs(): [UInt64] { + access(all) fun getIDs(): [UInt64] { return self.ownedNFTs.keys } @@ -4445,7 +4445,7 @@ pub contract ExampleNFT { } // creates a new empty Collection resource and returns it - pub fun createEmptyCollection(): @Collection { + access(all) fun createEmptyCollection(): @Collection { return <- create Collection() } @@ -4453,13 +4453,13 @@ pub contract ExampleNFT { // // Resource that would be owned by an admin or by a smart contract // that allows them to mint new NFTs when needed - pub resource NFTMinter { + access(all) resource NFTMinter { // the ID that is used to mint NFTs // it is only incremented so that NFT ids remain // unique. It also keeps track of the total number of NFTs // in existence - pub var idCount: UInt64 + access(all) var idCount: UInt64 init() { self.idCount = 1 @@ -4469,7 +4469,7 @@ pub contract ExampleNFT { // // Function that mints a new NFT with a new ID // and returns it to the caller - pub fun mintNFT(): @NFT { + access(all) fun mintNFT(): @NFT { // create a new NFT var newNFT <- create NFT(initID: self.idCount) @@ -4518,27 +4518,27 @@ import ExampleNFT from 0x02 // // https://github.com/onflow/nft-storefront -pub contract ExampleMarketplace { +access(all) contract ExampleMarketplace { // Event that is emitted when a new NFT is put up for sale - pub event ForSale(id: UInt64, price: UFix64, owner: Address?) + access(all) event ForSale(id: UInt64, price: UFix64, owner: Address?) // Event that is emitted when the price of an NFT changes - pub event PriceChanged(id: UInt64, newPrice: UFix64, owner: Address?) + access(all) event PriceChanged(id: UInt64, newPrice: UFix64, owner: Address?) // Event that is emitted when a token is purchased - pub event TokenPurchased(id: UInt64, price: UFix64, seller: Address?, buyer: Address?) + access(all) event TokenPurchased(id: UInt64, price: UFix64, seller: Address?, buyer: Address?) // Event that is emitted when a seller withdraws their NFT from the sale - pub event SaleCanceled(id: UInt64, seller: Address?) + access(all) event SaleCanceled(id: UInt64, seller: Address?) // Interface that users will publish for their Sale collection // that only exposes the methods that are supposed to be public // - pub resource interface SalePublic { - pub fun purchase(tokenID: UInt64, recipient: Capability<&AnyResource{ExampleNFT.NFTReceiver}>, buyTokens: @ExampleToken.Vault) - pub fun idPrice(tokenID: UInt64): UFix64? - pub fun getIDs(): [UInt64] + access(all) resource interface SalePublic { + access(all) fun purchase(tokenID: UInt64, recipient: Capability<&AnyResource{ExampleNFT.NFTReceiver}>, buyTokens: @ExampleToken.Vault) + access(all) fun idPrice(tokenID: UInt64): UFix64? + access(all) fun getIDs(): [UInt64] } // SaleCollection @@ -4546,7 +4546,7 @@ pub contract ExampleMarketplace { // NFT Collection object that allows a user to put their NFT up for sale // where others can send fungible tokens to purchase it // - pub resource SaleCollection: SalePublic { + access(all) resource SaleCollection: SalePublic { /// A capability for the owner's collection access(self) var ownerCollection: Capability<&ExampleNFT.Collection> @@ -4577,7 +4577,7 @@ pub contract ExampleMarketplace { } // cancelSale gives the owner the opportunity to cancel a sale in the collection - pub fun cancelSale(tokenID: UInt64) { + access(all) fun cancelSale(tokenID: UInt64) { // remove the price self.prices.remove(key: tokenID) self.prices[tokenID] = nil @@ -4586,7 +4586,7 @@ pub contract ExampleMarketplace { } // listForSale lists an NFT for sale in this collection - pub fun listForSale(tokenID: UInt64, price: UFix64) { + access(all) fun listForSale(tokenID: UInt64, price: UFix64) { pre { self.ownerCollection.borrow()!.idExists(id: tokenID): "NFT to be listed does not exist in the owner's collection" @@ -4598,14 +4598,14 @@ pub contract ExampleMarketplace { } // changePrice changes the price of a token that is currently for sale - pub fun changePrice(tokenID: UInt64, newPrice: UFix64) { + access(all) fun changePrice(tokenID: UInt64, newPrice: UFix64) { self.prices[tokenID] = newPrice emit PriceChanged(id: tokenID, newPrice: newPrice, owner: self.owner?.address) } // purchase lets a user send tokens to purchase an NFT that is for sale - pub fun purchase(tokenID: UInt64, recipient: Capability<&AnyResource{ExampleNFT.NFTReceiver}>, buyTokens: @ExampleToken.Vault) { + access(all) fun purchase(tokenID: UInt64, recipient: Capability<&AnyResource{ExampleNFT.NFTReceiver}>, buyTokens: @ExampleToken.Vault) { pre { self.prices[tokenID] != nil: "No token matching this ID for sale!" @@ -4641,18 +4641,18 @@ pub contract ExampleMarketplace { } // idPrice returns the price of a specific token in the sale - pub fun idPrice(tokenID: UInt64): UFix64? { + access(all) fun idPrice(tokenID: UInt64): UFix64? { return self.prices[tokenID] } // getIDs returns an array of token IDs that are for sale - pub fun getIDs(): [UInt64] { + access(all) fun getIDs(): [UInt64] { return self.prices.keys } } // createCollection returns a new collection resource to the caller - pub fun createSaleCollection(ownerCollection: Capability<&ExampleNFT.Collection>, + access(all) fun createSaleCollection(ownerCollection: Capability<&ExampleNFT.Collection>, ownerVault: Capability<&AnyResource{ExampleToken.Receiver}>): @SaleCollection { return <- create SaleCollection(ownerCollection: ownerCollection, ownerVault: ownerVault) } diff --git a/runtime/nft_test.go b/runtime/nft_test.go index 7895295c88..298bb33ab6 100644 --- a/runtime/nft_test.go +++ b/runtime/nft_test.go @@ -20,44 +20,44 @@ package runtime const realNonFungibleTokenInterface = ` -pub contract interface NonFungibleToken { +access(all) contract interface NonFungibleToken { // The total number of tokens of this type in existence - pub var totalSupply: UInt64 + access(all) var totalSupply: UInt64 // Event that emitted when the NFT contract is initialized // - pub event ContractInitialized() + access(all) event ContractInitialized() // Event that is emitted when a token is withdrawn, // indicating the owner of the collection that it was withdrawn from. // - pub event Withdraw(id: UInt64, from: Address?) + access(all) event Withdraw(id: UInt64, from: Address?) // Event that emitted when a token is deposited to a collection. // // It indicates the owner of the collection that it was deposited to. // - pub event Deposit(id: UInt64, to: Address?) + access(all) event Deposit(id: UInt64, to: Address?) // Interface that the NFTs have to conform to // - pub resource interface INFT { + access(all) resource interface INFT { // The unique ID that each NFT has - pub let id: UInt64 + access(all) let id: UInt64 } // Requirement that all conforming NFT smart contracts have // to define a resource called NFT that conforms to INFT - pub resource NFT: INFT { - pub let id: UInt64 + access(all) resource NFT: INFT { + access(all) let id: UInt64 } // Interface to mediate withdraws from the Collection // - pub resource interface Provider { + access(all) resource interface Provider { // withdraw removes an NFT from the collection and moves it to the caller - pub fun withdraw(withdrawID: UInt64): @NFT { + access(all) fun withdraw(withdrawID: UInt64): @NFT { post { result.id == withdrawID: "The ID of the withdrawn token must be the same as the requested ID" } @@ -66,42 +66,42 @@ pub contract interface NonFungibleToken { // Interface to mediate deposits to the Collection // - pub resource interface Receiver { + access(all) resource interface Receiver { // deposit takes an NFT as an argument and adds it to the Collection // - pub fun deposit(token: @NFT) + access(all) fun deposit(token: @NFT) } // Interface that an account would commonly // publish for their collection - pub resource interface CollectionPublic { - pub fun deposit(token: @NFT) - pub fun getIDs(): [UInt64] - pub fun borrowNFT(id: UInt64): &NFT + access(all) resource interface CollectionPublic { + access(all) fun deposit(token: @NFT) + access(all) fun getIDs(): [UInt64] + access(all) fun borrowNFT(id: UInt64): &NFT } // Requirement for the the concrete resource type // to be declared in the implementing contract // - pub resource Collection: Provider, Receiver, CollectionPublic { + access(all) resource Collection: Provider, Receiver, CollectionPublic { // Dictionary to hold the NFTs in the Collection - pub var ownedNFTs: @{UInt64: NFT} + access(all) var ownedNFTs: @{UInt64: NFT} // withdraw removes an NFT from the collection and moves it to the caller - pub fun withdraw(withdrawID: UInt64): @NFT + access(all) fun withdraw(withdrawID: UInt64): @NFT // deposit takes a NFT and adds it to the collections dictionary // and adds the ID to the id array - pub fun deposit(token: @NFT) + access(all) fun deposit(token: @NFT) // getIDs returns an array of the IDs that are in the collection - pub fun getIDs(): [UInt64] + access(all) fun getIDs(): [UInt64] // Returns a borrowed reference to an NFT in the collection // so that the caller can read data and call methods from it - pub fun borrowNFT(id: UInt64): &NFT { + access(all) fun borrowNFT(id: UInt64): &NFT { pre { self.ownedNFTs[id] != nil: "NFT does not exist in the collection!" } @@ -110,7 +110,7 @@ pub contract interface NonFungibleToken { // createEmptyCollection creates an empty Collection // and returns it to the caller so that they can own NFTs - pub fun createEmptyCollection(): @Collection { + access(all) fun createEmptyCollection(): @Collection { post { result.ownedNFTs.length == 0: "The created collection must be empty!" } @@ -120,42 +120,42 @@ pub contract interface NonFungibleToken { const realTopShotContract = ` import NonFungibleToken from 0x1d7e57aa55817448 -pub contract TopShot: NonFungibleToken { +access(all) contract TopShot: NonFungibleToken { // ----------------------------------------------------------------------- // TopShot contract Event definitions // ----------------------------------------------------------------------- // emitted when the TopShot contract is created - pub event ContractInitialized() + access(all) event ContractInitialized() // emitted when a new Play struct is created - pub event PlayCreated(id: UInt32, metadata: {String:String}) + access(all) event PlayCreated(id: UInt32, metadata: {String:String}) // emitted when a new series has been triggered by an admin - pub event NewSeriesStarted(newCurrentSeries: UInt32) + access(all) event NewSeriesStarted(newCurrentSeries: UInt32) // Events for Set-Related actions // // emitted when a new Set is created - pub event SetCreated(setID: UInt32, series: UInt32) + access(all) event SetCreated(setID: UInt32, series: UInt32) // emitted when a new play is added to a set - pub event PlayAddedToSet(setID: UInt32, playID: UInt32) + access(all) event PlayAddedToSet(setID: UInt32, playID: UInt32) // emitted when a play is retired from a set and cannot be used to mint - pub event PlayRetiredFromSet(setID: UInt32, playID: UInt32, numMoments: UInt32) + access(all) event PlayRetiredFromSet(setID: UInt32, playID: UInt32, numMoments: UInt32) // emitted when a set is locked, meaning plays cannot be added - pub event SetLocked(setID: UInt32) + access(all) event SetLocked(setID: UInt32) // emitted when a moment is minted from a set - pub event MomentMinted(momentID: UInt64, playID: UInt32, setID: UInt32, serialNumber: UInt32) + access(all) event MomentMinted(momentID: UInt64, playID: UInt32, setID: UInt32, serialNumber: UInt32) // events for Collection-related actions // // emitted when a moment is withdrawn from a collection - pub event Withdraw(id: UInt64, from: Address?) + access(all) event Withdraw(id: UInt64, from: Address?) // emitted when a moment is deposited into a collection - pub event Deposit(id: UInt64, to: Address?) + access(all) event Deposit(id: UInt64, to: Address?) // emitted when a moment is destroyed - pub event MomentDestroyed(id: UInt64) + access(all) event MomentDestroyed(id: UInt64) // ----------------------------------------------------------------------- // TopShot contract-level fields @@ -165,7 +165,7 @@ pub contract TopShot: NonFungibleToken { // Series that this set belongs to // Series is a concept that indicates a group of sets through time // Many sets can exist at a time, but only one series - pub var currentSeries: UInt32 + access(all) var currentSeries: UInt32 // variable size dictionary of Play structs access(self) var playDatas: {UInt32: Play} @@ -179,18 +179,18 @@ pub contract TopShot: NonFungibleToken { // the ID that is used to create Plays. // Every time a Play is created, playID is assigned // to the new Play's ID and then is incremented by 1. - pub var nextPlayID: UInt32 + access(all) var nextPlayID: UInt32 // the ID that is used to create Sets. Every time a Set is created // setID is assigned to the new set's ID and then is incremented by 1. - pub var nextSetID: UInt32 + access(all) var nextSetID: UInt32 // the total number of Top shot moment NFTs that have been created // Because NFTs can be destroyed, it doesn't necessarily mean that this // reflects the total number of NFTs in existence, just the number that // have been minted to date. // Is also used as global moment IDs for minting - pub var totalSupply: UInt64 + access(all) var totalSupply: UInt64 // ----------------------------------------------------------------------- // TopShot contract-level Composite Type DEFINITIONS @@ -210,16 +210,16 @@ pub contract TopShot: NonFungibleToken { // its metadata. The Plays are publicly accessible, so anyone can // read the metadata associated with a specific play ID // - pub struct Play { + access(all) struct Play { // the unique ID that the Play has - pub let playID: UInt32 + access(all) let playID: UInt32 // Stores all the metadata about the Play as a string mapping // This is not the long term way we will do metadata. Just a temporary // construct while we figure out a better way to do metadata // - pub let metadata: {String: String} + access(all) let metadata: {String: String} init(metadata: {String: String}) { pre { @@ -244,19 +244,19 @@ pub contract TopShot: NonFungibleToken { // about a set but not have the ability to modify any data in the // private set resource // - pub struct SetData { + access(all) struct SetData { // unique ID for the set - pub let setID: UInt32 + access(all) let setID: UInt32 // Name of the Set // ex. "Times when the Toronto Raptors choked in the playoffs" - pub let name: String + access(all) let name: String // Series that this set belongs to // Series is a concept that indicates a group of sets through time // Many sets can exist at a time, but only one series - pub let series: UInt32 + access(all) let series: UInt32 init(name: String) { pre { @@ -293,21 +293,21 @@ pub contract TopShot: NonFungibleToken { // // If retireAll() and lock() are called back to back, // the Set is closed off forever and nothing more can be done with it - pub resource Set { + access(all) resource Set { // unique ID for the set - pub let setID: UInt32 + access(all) let setID: UInt32 // Array of plays that are a part of this set // When a play is added to the set, its ID gets appended here // The ID does not get removed from this array when a play is retired - pub var plays: [UInt32] + access(all) var plays: [UInt32] // Indicates if a play in this set can be minted // A play is set to false when it is added to a set // to indicate that it is still active // When the play is retired, this is set to true and cannot be changed - pub var retired: {UInt32: Bool} + access(all) var retired: {UInt32: Bool} // Indicates if the set is currently locked // When a set is created, it is unlocked @@ -318,13 +318,13 @@ pub contract TopShot: NonFungibleToken { // If a set is locked, plays cannot be added, but // moments can still be minted from plays // that already had been added to it. - pub var locked: Bool + access(all) var locked: Bool // Indicates the number of moments // that have been minted per play in this set // When a moment is minted, this value is stored in the moment to // show where in the play set it is so far. ex. 13 of 60 - pub var numberMintedPerPlay: {UInt32: UInt32} + access(all) var numberMintedPerPlay: {UInt32: UInt32} init(name: String) { self.setID = TopShot.nextSetID @@ -346,7 +346,7 @@ pub contract TopShot: NonFungibleToken { // The set needs to be not locked // The play can't have already been added to the set // - pub fun addPlay(playID: UInt32) { + access(all) fun addPlay(playID: UInt32) { pre { TopShot.playDatas[playID] != nil: "Cannot add the Play to Set: Play doesn't exist" !self.locked: "Cannot add the play to the Set after the set has been locked" @@ -370,7 +370,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: playIDs: The IDs of the plays that are being added // as an array // - pub fun addPlays(playIDs: [UInt32]) { + access(all) fun addPlays(playIDs: [UInt32]) { for play in playIDs { self.addPlay(playID: play) } @@ -383,7 +383,7 @@ pub contract TopShot: NonFungibleToken { // Pre-Conditions: // The play needs to be an existing play that is currently open for minting // - pub fun retirePlay(playID: UInt32) { + access(all) fun retirePlay(playID: UInt32) { pre { self.retired[playID] != nil: "Cannot retire the Play: Play doesn't exist in this set!" } @@ -398,7 +398,7 @@ pub contract TopShot: NonFungibleToken { // retireAll retires all the plays in the set // Afterwards, none of the retired plays will be able to mint new moments // - pub fun retireAll() { + access(all) fun retireAll() { for play in self.plays { self.retirePlay(playID: play) } @@ -408,7 +408,7 @@ pub contract TopShot: NonFungibleToken { // // Pre-Conditions: // The set cannot already have been locked - pub fun lock() { + access(all) fun lock() { if !self.locked { self.locked = true emit SetLocked(setID: self.setID) @@ -424,7 +424,7 @@ pub contract TopShot: NonFungibleToken { // // Returns: The NFT that was minted // - pub fun mintMoment(playID: UInt32): @NFT { + access(all) fun mintMoment(playID: UInt32): @NFT { pre { self.retired[playID] != nil: "Cannot mint the moment: This play doesn't exist" !self.retired[playID]!: "Cannot mint the moment from this play: This play has been retired" @@ -453,7 +453,7 @@ pub contract TopShot: NonFungibleToken { // // Returns: Collection object that contains all the moments that were minted // - pub fun batchMintMoment(playID: UInt32, quantity: UInt64): @Collection { + access(all) fun batchMintMoment(playID: UInt32, quantity: UInt64): @Collection { let newCollection <- create Collection() var i: UInt64 = 0 @@ -466,17 +466,17 @@ pub contract TopShot: NonFungibleToken { } } - pub struct MomentData { + access(all) struct MomentData { // the ID of the Set that the Moment comes from - pub let setID: UInt32 + access(all) let setID: UInt32 // the ID of the Play that the moment references - pub let playID: UInt32 + access(all) let playID: UInt32 // the place in the play that this moment was minted // Otherwise know as the serial number - pub let serialNumber: UInt32 + access(all) let serialNumber: UInt32 init(setID: UInt32, playID: UInt32, serialNumber: UInt32) { self.setID = setID @@ -488,13 +488,13 @@ pub contract TopShot: NonFungibleToken { // The resource that represents the Moment NFTs // - pub resource NFT: NonFungibleToken.INFT { + access(all) resource NFT: NonFungibleToken.INFT { // global unique moment ID - pub let id: UInt64 + access(all) let id: UInt64 // struct of moment metadata - pub let data: MomentData + access(all) let data: MomentData init(serialNumber: UInt32, playID: UInt32, setID: UInt32) { // Increment the global moment IDs @@ -517,7 +517,7 @@ pub contract TopShot: NonFungibleToken { // allows the owner to perform important functions to modify the // various aspects of the plays, sets, and moments // - pub resource Admin { + access(all) resource Admin { // createPlay creates a new Play struct // and stores it in the plays dictionary in the TopShot smart contract @@ -527,7 +527,7 @@ pub contract TopShot: NonFungibleToken { // (because we all know Kevin Durant is not 6'9") // // Returns: the ID of the new Play object - pub fun createPlay(metadata: {String: String}): UInt32 { + access(all) fun createPlay(metadata: {String: String}): UInt32 { // Create the new Play var newPlay = Play(metadata: metadata) let newID = newPlay.playID @@ -544,7 +544,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: name: The name of the set // series: The series that the set belongs to // - pub fun createSet(name: String) { + access(all) fun createSet(name: String) { // Create the new Set var newSet <- create Set(name: name) @@ -560,7 +560,7 @@ pub contract TopShot: NonFungibleToken { // Returns: A reference to the set with all of the fields // and methods exposed // - pub fun borrowSet(setID: UInt32): &Set { + access(all) fun borrowSet(setID: UInt32): &Set { pre { TopShot.sets[setID] != nil: "Cannot borrow Set: The Set doesn't exist" } @@ -573,7 +573,7 @@ pub contract TopShot: NonFungibleToken { // // Returns: The new series number // - pub fun startNewSeries(): UInt32 { + access(all) fun startNewSeries(): UInt32 { // end the current series and start a new one // by incrementing the TopShot series number TopShot.currentSeries = TopShot.currentSeries + UInt32(1) @@ -585,19 +585,19 @@ pub contract TopShot: NonFungibleToken { // createNewAdmin creates a new Admin Resource // - pub fun createNewAdmin(): @Admin { + access(all) fun createNewAdmin(): @Admin { return <-create Admin() } } // This is the interface that users can cast their moment Collection as // to allow others to deposit moments into their collection - pub resource interface MomentCollectionPublic { - pub fun deposit(token: @NonFungibleToken.NFT) - pub fun batchDeposit(tokens: @NonFungibleToken.Collection) - pub fun getIDs(): [UInt64] - pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT - pub fun borrowMoment(id: UInt64): &TopShot.NFT? { + access(all) resource interface MomentCollectionPublic { + access(all) fun deposit(token: @NonFungibleToken.NFT) + access(all) fun batchDeposit(tokens: @NonFungibleToken.Collection) + access(all) fun getIDs(): [UInt64] + access(all) fun borrowNFT(id: UInt64): &NonFungibleToken.NFT + access(all) fun borrowMoment(id: UInt64): &TopShot.NFT? { // If the result isn't nil, the id of the returned reference // should be the same as the argument to the function post { @@ -610,17 +610,17 @@ pub contract TopShot: NonFungibleToken { // Collection is a resource that every user who owns NFTs // will store in their account to manage their NFTS // - pub resource Collection: MomentCollectionPublic, NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic { + access(all) resource Collection: MomentCollectionPublic, NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic { // Dictionary of Moment conforming tokens // NFT is a resource type with a UInt64 ID field - pub var ownedNFTs: @{UInt64: NonFungibleToken.NFT} + access(all) var ownedNFTs: @{UInt64: NonFungibleToken.NFT} init() { self.ownedNFTs <- {} } // withdraw removes an Moment from the collection and moves it to the caller - pub fun withdraw(withdrawID: UInt64): @NonFungibleToken.NFT { + access(all) fun withdraw(withdrawID: UInt64): @NonFungibleToken.NFT { let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("Cannot withdraw: Moment does not exist in the collection") @@ -630,7 +630,7 @@ pub contract TopShot: NonFungibleToken { } // batchWithdraw withdraws multiple tokens and returns them as a Collection - pub fun batchWithdraw(ids: [UInt64]): @NonFungibleToken.Collection { + access(all) fun batchWithdraw(ids: [UInt64]): @NonFungibleToken.Collection { var batchCollection <- create Collection() // iterate through the ids and withdraw them from the collection @@ -641,7 +641,7 @@ pub contract TopShot: NonFungibleToken { } // deposit takes a Moment and adds it to the collections dictionary - pub fun deposit(token: @NonFungibleToken.NFT) { + access(all) fun deposit(token: @NonFungibleToken.NFT) { let token <- token as! @TopShot.NFT let id = token.id @@ -657,7 +657,7 @@ pub contract TopShot: NonFungibleToken { // batchDeposit takes a Collection object as an argument // and deposits each contained NFT into this collection - pub fun batchDeposit(tokens: @NonFungibleToken.Collection) { + access(all) fun batchDeposit(tokens: @NonFungibleToken.Collection) { let keys = tokens.getIDs() // iterate through the keys in the collection and deposit each one @@ -668,7 +668,7 @@ pub contract TopShot: NonFungibleToken { } // getIDs returns an array of the IDs that are in the collection - pub fun getIDs(): [UInt64] { + access(all) fun getIDs(): [UInt64] { return self.ownedNFTs.keys } @@ -678,7 +678,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: id: The ID of the NFT to get the reference for // // Returns: A reference to the NFT - pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT { + access(all) fun borrowNFT(id: UInt64): &NonFungibleToken.NFT { return (&self.ownedNFTs[id] as &NonFungibleToken.NFT?)! } @@ -692,7 +692,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: id: The ID of the NFT to get the reference for // // Returns: A reference to the NFT - pub fun borrowMoment(id: UInt64): &TopShot.NFT? { + access(all) fun borrowMoment(id: UInt64): &TopShot.NFT? { if self.ownedNFTs[id] != nil { let ref = (&self.ownedNFTs[id] as &NonFungibleToken.NFT?)! return ref as! &TopShot.NFT @@ -720,14 +720,14 @@ pub contract TopShot: NonFungibleToken { // Once they have a Collection in their storage, they are able to receive // Moments in transactions // - pub fun createEmptyCollection(): @NonFungibleToken.Collection { + access(all) fun createEmptyCollection(): @NonFungibleToken.Collection { return <-create TopShot.Collection() } // getAllPlays returns all the plays in topshot // // Returns: An array of all the plays that have been created - pub fun getAllPlays(): [TopShot.Play] { + access(all) fun getAllPlays(): [TopShot.Play] { return TopShot.playDatas.values } @@ -736,7 +736,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: playID: The id of the play that is being searched // // Returns: The metadata as a String to String mapping optional - pub fun getPlayMetaData(playID: UInt32): {String: String}? { + access(all) fun getPlayMetaData(playID: UInt32): {String: String}? { return self.playDatas[playID]?.metadata } @@ -749,7 +749,7 @@ pub contract TopShot: NonFungibleToken { // field: The field to search for // // Returns: The metadata field as a String Optional - pub fun getPlayMetaDataByField(playID: UInt32, field: String): String? { + access(all) fun getPlayMetaDataByField(playID: UInt32, field: String): String? { // Don't force a revert if the playID or field is invalid if let play = TopShot.playDatas[playID] { return play.metadata[field] @@ -764,7 +764,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: setID: The id of the set that is being searched // // Returns: The name of the set - pub fun getSetName(setID: UInt32): String? { + access(all) fun getSetName(setID: UInt32): String? { // Don't force a revert if the setID is invalid return TopShot.setDatas[setID]?.name } @@ -775,7 +775,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: setID: The id of the set that is being searched // // Returns: The series that the set belongs to - pub fun getSetSeries(setID: UInt32): UInt32? { + access(all) fun getSetSeries(setID: UInt32): UInt32? { // Don't force a revert if the setID is invalid return TopShot.setDatas[setID]?.series } @@ -786,7 +786,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: setName: The name of the set that is being searched // // Returns: An array of the IDs of the set if it exists, or nil if doesn't - pub fun getSetIDsByName(setName: String): [UInt32]? { + access(all) fun getSetIDsByName(setName: String): [UInt32]? { var setIDs: [UInt32] = [] // iterate through all the setDatas and search for the name @@ -811,7 +811,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: setID: The id of the set that is being searched // // Returns: An array of play IDs - pub fun getPlaysInSet(setID: UInt32): [UInt32]? { + access(all) fun getPlaysInSet(setID: UInt32): [UInt32]? { // Don't force a revert if the setID is invalid return TopShot.sets[setID]?.plays } @@ -825,7 +825,7 @@ pub contract TopShot: NonFungibleToken { // playID: The id of the play that is being searched // // Returns: Boolean indicating if the edition is retired or not - pub fun isEditionRetired(setID: UInt32, playID: UInt32): Bool? { + access(all) fun isEditionRetired(setID: UInt32, playID: UInt32): Bool? { // Don't force a revert if the set or play ID is invalid // remove the set from the dictionary to ket its field if let setToRead <- TopShot.sets.remove(key: setID) { @@ -849,7 +849,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: setID: The id of the set that is being searched // // Returns: Boolean indicating if the set is locked or not - pub fun isSetLocked(setID: UInt32): Bool? { + access(all) fun isSetLocked(setID: UInt32): Bool? { // Don't force a revert if the setID is invalid return TopShot.sets[setID]?.locked } @@ -862,7 +862,7 @@ pub contract TopShot: NonFungibleToken { // // Returns: The total number of moments // that have been minted from an edition - pub fun getNumMomentsInEdition(setID: UInt32, playID: UInt32): UInt32? { + access(all) fun getNumMomentsInEdition(setID: UInt32, playID: UInt32): UInt32? { // Don't force a revert if the set or play ID is invalid // remove the set from the dictionary to get its field if let setToRead <- TopShot.sets.remove(key: setID) { @@ -912,18 +912,18 @@ const realTopShotShardedCollectionContract = ` import NonFungibleToken from 0x1d7e57aa55817448 import TopShot from 0x0b2a3299cc857e29 -pub contract TopShotShardedCollection { +access(all) contract TopShotShardedCollection { // ShardedCollection stores a dictionary of TopShot Collections // A Moment is stored in the field that corresponds to its id % numBuckets - pub resource ShardedCollection: TopShot.MomentCollectionPublic, NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic { + access(all) resource ShardedCollection: TopShot.MomentCollectionPublic, NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic { // Dictionary of topshot collections - pub var collections: @{UInt64: TopShot.Collection} + access(all) var collections: @{UInt64: TopShot.Collection} // The number of buckets to split Moments into // This makes storage more efficient and performant - pub let numBuckets: UInt64 + access(all) let numBuckets: UInt64 init(numBuckets: UInt64) { self.collections <- {} @@ -941,7 +941,7 @@ pub contract TopShotShardedCollection { // withdraw removes a Moment from one of the Collections // and moves it to the caller - pub fun withdraw(withdrawID: UInt64): @NonFungibleToken.NFT { + access(all) fun withdraw(withdrawID: UInt64): @NonFungibleToken.NFT { post { result.id == withdrawID: "The ID of the withdrawn NFT is incorrect" } @@ -960,7 +960,7 @@ pub contract TopShotShardedCollection { // // Returns: @NonFungibleToken.Collection a Collection containing the moments // that were withdrawn - pub fun batchWithdraw(ids: [UInt64]): @NonFungibleToken.Collection { + access(all) fun batchWithdraw(ids: [UInt64]): @NonFungibleToken.Collection { var batchCollection <- TopShot.createEmptyCollection() // Iterate through the ids and withdraw them from the Collection @@ -971,7 +971,7 @@ pub contract TopShotShardedCollection { } // deposit takes a Moment and adds it to the Collections dictionary - pub fun deposit(token: @NonFungibleToken.NFT) { + access(all) fun deposit(token: @NonFungibleToken.NFT) { // Find the bucket this corresponds to let bucket = token.id % self.numBuckets @@ -988,7 +988,7 @@ pub contract TopShotShardedCollection { // batchDeposit takes a Collection object as an argument // and deposits each contained NFT into this Collection - pub fun batchDeposit(tokens: @NonFungibleToken.Collection) { + access(all) fun batchDeposit(tokens: @NonFungibleToken.Collection) { let keys = tokens.getIDs() // Iterate through the keys in the Collection and deposit each one @@ -999,7 +999,7 @@ pub contract TopShotShardedCollection { } // getIDs returns an array of the IDs that are in the Collection - pub fun getIDs(): [UInt64] { + access(all) fun getIDs(): [UInt64] { var ids: [UInt64] = [] // Concatenate IDs in all the Collections @@ -1013,7 +1013,7 @@ pub contract TopShotShardedCollection { // borrowNFT Returns a borrowed reference to a Moment in the Collection // so that the caller can read data and call methods from it - pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT { + access(all) fun borrowNFT(id: UInt64): &NonFungibleToken.NFT { post { result.id == id: "The ID of the reference is incorrect" } @@ -1035,7 +1035,7 @@ pub contract TopShotShardedCollection { // Parameters: id: The ID of the NFT to get the reference for // // Returns: A reference to the NFT - pub fun borrowMoment(id: UInt64): &TopShot.NFT? { + access(all) fun borrowMoment(id: UInt64): &TopShot.NFT? { // Get the bucket of the nft to be borrowed let bucket = id % self.numBuckets @@ -1051,7 +1051,7 @@ pub contract TopShotShardedCollection { } // Creates an empty ShardedCollection and returns it to the caller - pub fun createEmptyCollection(numBuckets: UInt64): @ShardedCollection { + access(all) fun createEmptyCollection(numBuckets: UInt64): @ShardedCollection { return <-create ShardedCollection(numBuckets: numBuckets) } } @@ -1061,12 +1061,12 @@ const realTopshotAdminReceiverContract = ` import TopShot from 0x0b2a3299cc857e29 import TopShotShardedCollection from 0x0b2a3299cc857e29 -pub contract TopshotAdminReceiver { +access(all) contract TopshotAdminReceiver { // storeAdmin takes a TopShot Admin resource and // saves it to the account storage of the account // where the contract is deployed - pub fun storeAdmin(newAdmin: @TopShot.Admin) { + access(all) fun storeAdmin(newAdmin: @TopShot.Admin) { self.account.save(<-newAdmin, to: /storage/TopShotAdmin) } diff --git a/runtime/parser/benchmark_test.go b/runtime/parser/benchmark_test.go index 3cb32aecc4..13ee5d8689 100644 --- a/runtime/parser/benchmark_test.go +++ b/runtime/parser/benchmark_test.go @@ -90,10 +90,10 @@ func BenchmarkParseDeploy(b *testing.B) { } const fungibleTokenContract = ` -pub contract FungibleToken { +access(all) contract FungibleToken { - pub resource interface Provider { - pub fun withdraw(amount: Int): @Vault { + access(all) resource interface Provider { + access(all) fun withdraw(amount: Int): @Vault { pre { amount > 0: "Withdrawal amount must be positive" @@ -105,8 +105,8 @@ pub contract FungibleToken { } } - pub resource interface Receiver { - pub balance: Int + access(all) resource interface Receiver { + access(all) balance: Int init(balance: Int) { pre { @@ -119,7 +119,7 @@ pub contract FungibleToken { } } - pub fun deposit(from: @Receiver) { + access(all) fun deposit(from: @Receiver) { pre { from.balance > 0: "Deposit balance needs to be positive!" @@ -131,21 +131,21 @@ pub contract FungibleToken { } } - pub resource Vault: Provider, Receiver { + access(all) resource Vault: Provider, Receiver { - pub var balance: Int + access(all) var balance: Int init(balance: Int) { self.balance = balance } - pub fun withdraw(amount: Int): @Vault { + access(all) fun withdraw(amount: Int): @Vault { self.balance = self.balance - amount return <-create Vault(balance: amount) } // transfer combines withdraw and deposit into one function call - pub fun transfer(to: &Receiver, amount: Int) { + access(all) fun transfer(to: &Receiver, amount: Int) { pre { amount <= self.balance: "Insufficient funds" @@ -157,22 +157,22 @@ pub contract FungibleToken { to.deposit(from: <-self.withdraw(amount: amount)) } - pub fun deposit(from: @Receiver) { + access(all) fun deposit(from: @Receiver) { self.balance = self.balance + from.balance destroy from } - pub fun createEmptyVault(): @Vault { + access(all) fun createEmptyVault(): @Vault { return <-create Vault(balance: 0) } } - pub fun createEmptyVault(): @Vault { + access(all) fun createEmptyVault(): @Vault { return <-create Vault(balance: 0) } - pub resource VaultMinter { - pub fun mintTokens(amount: Int, recipient: &Receiver) { + access(all) resource VaultMinter { + access(all) fun mintTokens(amount: Int, recipient: &Receiver) { recipient.deposit(from: <-create Vault(balance: amount)) } } diff --git a/runtime/parser/declaration.go b/runtime/parser/declaration.go index 8fe34f37a0..62f435c1f1 100644 --- a/runtime/parser/declaration.go +++ b/runtime/parser/declaration.go @@ -214,7 +214,10 @@ func parseDeclaration(p *parser, docString string) (ast.Declaration, error) { purity = parsePurityAnnotation(p) continue - case KeywordPriv, KeywordPub, KeywordAccess: + case KeywordPub, KeywordPriv: + return nil, p.syntaxError(fmt.Sprintf("`%s` is no longer a valid access keyword", p.currentTokenSource())) + + case KeywordAccess: if access != ast.AccessNotSpecified { return nil, p.syntaxError("invalid second access modifier") } @@ -345,54 +348,12 @@ func parseEntitlementList(p *parser) (ast.EntitlementSet, error) { // parseAccess parses an access modifier // // access -// : 'priv' -// | 'pub' ( '(' 'set' ')' )? +// : 'access(self)' +// | 'access(all)' ( '(' 'set' ')' )? // | 'access' '(' ( 'self' | 'contract' | 'account' | 'all' | entitlementList ) ')' func parseAccess(p *parser) (ast.Access, error) { switch string(p.currentTokenSource()) { - case KeywordPriv: - // Skip the `priv` keyword - p.next() - return ast.AccessPrivate, nil - - case KeywordPub: - // Skip the `pub` keyword - p.nextSemanticToken() - if !p.current.Is(lexer.TokenParenOpen) { - return ast.AccessPublic, nil - } - - // Skip the opening paren - p.nextSemanticToken() - - if !p.current.Is(lexer.TokenIdentifier) { - return ast.AccessNotSpecified, p.syntaxError( - "expected keyword %q, got %s", - KeywordSet, - p.current.Type, - ) - } - - keyword := p.currentTokenSource() - if string(keyword) != KeywordSet { - return ast.AccessNotSpecified, p.syntaxError( - "expected keyword %q, got %q", - KeywordSet, - keyword, - ) - } - - // Skip the `set` keyword - p.nextSemanticToken() - - _, err := p.mustOne(lexer.TokenParenClose) - if err != nil { - return ast.AccessNotSpecified, err - } - - return ast.AccessPublicSettable, nil - case KeywordAccess: // Skip the `access` keyword p.nextSemanticToken() @@ -417,7 +378,7 @@ func parseAccess(p *parser) (ast.Access, error) { keyword := p.currentTokenSource() switch string(keyword) { case KeywordAll: - access = ast.AccessPublic + access = ast.AccessAll // Skip the keyword p.nextSemanticToken() @@ -432,7 +393,7 @@ func parseAccess(p *parser) (ast.Access, error) { p.nextSemanticToken() case KeywordSelf: - access = ast.AccessPrivate + access = ast.AccessSelf // Skip the keyword p.nextSemanticToken() @@ -1682,7 +1643,10 @@ func parseMemberOrNestedDeclaration(p *parser, docString string) (ast.Declaratio purity = parsePurityAnnotation(p) continue - case KeywordPriv, KeywordPub, KeywordAccess: + case KeywordPub, KeywordPriv: + return nil, p.syntaxError(fmt.Sprintf("`%s` is no longer a valid access keyword", p.currentTokenSource())) + + case KeywordAccess: if access != ast.AccessNotSpecified { return nil, p.syntaxError("invalid second access modifier") } diff --git a/runtime/parser/declaration_test.go b/runtime/parser/declaration_test.go index 257c78d2fb..e92ca29a6a 100644 --- a/runtime/parser/declaration_test.go +++ b/runtime/parser/declaration_test.go @@ -72,36 +72,57 @@ func TestParseVariableDeclaration(t *testing.T) { ) }) - t.Run("var, no type annotation, copy, one value, pub", func(t *testing.T) { + t.Run("var, no type annotation, copy, one value, access(all)", func(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations(" pub var x = 1") + result, errs := testParseDeclarations(" access(all) var x = 1") require.Empty(t, errs) utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.VariableDeclaration{ - Access: ast.AccessPublic, - IsConstant: false, - Identifier: ast.Identifier{ - Identifier: "x", - Pos: ast.Position{Line: 1, Column: 9, Offset: 9}, - }, Value: &ast.IntegerExpression{ - PositiveLiteral: []byte("1"), - Value: big.NewInt(1), - Base: 10, + Value: big.NewInt(1), + PositiveLiteral: []uint8{ + 0x31, + }, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 13, Offset: 13}, - EndPos: ast.Position{Line: 1, Column: 13, Offset: 13}, + StartPos: ast.Position{ + Offset: 21, + Line: 1, + Column: 21, + }, + EndPos: ast.Position{ + Offset: 21, + Line: 1, + Column: 21, + }, }, + Base: 10, }, Transfer: &ast.Transfer{ - Operation: ast.TransferOperationCopy, - Pos: ast.Position{Line: 1, Column: 11, Offset: 11}, + Operation: 0x1, + Pos: ast.Position{ + Offset: 19, + Line: 1, + Column: 19, + }, }, - StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, + Identifier: ast.Identifier{ + Identifier: "x", + Pos: ast.Position{ + Offset: 17, + Line: 1, + Column: 17, + }, + }, + StartPos: ast.Position{ + Offset: 1, + Line: 1, + Column: 1, + }, + Access: ast.AccessAll, }, }, result, @@ -598,37 +619,60 @@ func TestParseFunctionDeclaration(t *testing.T) { ) }) - t.Run("without return type, pub", func(t *testing.T) { + t.Run("without return type, access(all)", func(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations("pub fun foo () { }") + result, errs := testParseDeclarations("access(all) fun foo () { }") require.Empty(t, errs) utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ - Access: ast.AccessPublic, - Identifier: ast.Identifier{ - Identifier: "foo", - Pos: ast.Position{Line: 1, Column: 8, Offset: 8}, - }, ParameterList: &ast.ParameterList{ - Parameters: nil, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 12, Offset: 12}, - EndPos: ast.Position{Line: 1, Column: 13, Offset: 13}, + StartPos: ast.Position{ + Offset: 20, + Line: 1, + Column: 20, + }, + EndPos: ast.Position{ + Offset: 21, + Line: 1, + Column: 21, + }, }, }, FunctionBlock: &ast.FunctionBlock{ Block: &ast.Block{ Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 15, Offset: 15}, - EndPos: ast.Position{Line: 1, Column: 17, Offset: 17}, + StartPos: ast.Position{ + Offset: 23, + Line: 1, + Column: 23, + }, + EndPos: ast.Position{ + Offset: 25, + Line: 1, + Column: 25, + }, }, }, }, - StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, + Identifier: ast.Identifier{ + Identifier: "foo", + Pos: ast.Position{ + Offset: 16, + Line: 1, + Column: 16, + }, + }, + StartPos: ast.Position{ + Offset: 0, + Line: 1, + Column: 0, + }, + Access: ast.AccessAll, }, }, result, @@ -1273,13 +1317,13 @@ func TestParseFunctionDeclaration(t *testing.T) { ) }) - t.Run("pub static native, enabled", func(t *testing.T) { + t.Run("access(all) static native, enabled", func(t *testing.T) { t.Parallel() result, errs := ParseDeclarations( nil, - []byte("pub static native fun foo() {}"), + []byte("access(all) static native fun foo() {}"), Config{ StaticModifierEnabled: true, NativeModifierEnabled: true, @@ -1290,45 +1334,78 @@ func TestParseFunctionDeclaration(t *testing.T) { utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ - Access: ast.AccessPublic, - Flags: ast.FunctionDeclarationFlagsIsStatic | ast.FunctionDeclarationFlagsIsNative, - Identifier: ast.Identifier{ - Identifier: "foo", - Pos: ast.Position{Line: 1, Column: 22, Offset: 22}, - }, + Purity: 0, + TypeParameterList: (*ast.TypeParameterList)(nil), ParameterList: &ast.ParameterList{ - Parameters: nil, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 25, Offset: 25}, - EndPos: ast.Position{Line: 1, Column: 26, Offset: 26}, + StartPos: ast.Position{ + Offset: 33, + Line: 1, + Column: 33, + }, + EndPos: ast.Position{ + Offset: 34, + Line: 1, + Column: 34, + }, }, }, + ReturnTypeAnnotation: (*ast.TypeAnnotation)(nil), FunctionBlock: &ast.FunctionBlock{ Block: &ast.Block{ Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 28, Offset: 28}, - EndPos: ast.Position{Line: 1, Column: 29, Offset: 29}, + StartPos: ast.Position{ + Offset: 36, + Line: 1, + Column: 36, + }, + EndPos: ast.Position{ + Offset: 37, + Line: 1, + Column: 37, + }, }, }, + PreConditions: (*ast.Conditions)(nil), + PostConditions: (*ast.Conditions)(nil), }, - StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, + DocString: "", + Identifier: ast.Identifier{ + Identifier: "foo", + Pos: ast.Position{ + Offset: 30, + Line: 1, + Column: 30, + }, + }, + StartPos: ast.Position{ + Offset: 0, + Line: 1, + Column: 0, + }, + Access: ast.AccessAll, + Flags: 0x03, }, }, result, ) }) - t.Run("pub static native, disabled", func(t *testing.T) { + t.Run("access(all) static native, disabled", func(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations("pub static native fun foo() {}") + _, errs := testParseDeclarations("access(all) static native fun foo() {}") utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", - Pos: ast.Position{Offset: 4, Line: 1, Column: 4}, + Pos: ast.Position{ + Offset: 12, + Line: 1, + Column: 12, + }, }, }, errs, @@ -1591,108 +1668,6 @@ func TestParseAccess(t *testing.T) { ) } - t.Run("pub", func(t *testing.T) { - - t.Parallel() - - result, errs := parse("pub") - require.Empty(t, errs) - - utils.AssertEqualWithDiff(t, - ast.AccessPublic, - result, - ) - }) - - t.Run("pub(set)", func(t *testing.T) { - - t.Parallel() - - result, errs := parse("pub ( set )") - require.Empty(t, errs) - - utils.AssertEqualWithDiff(t, - ast.AccessPublicSettable, - result, - ) - }) - - t.Run("pub, missing set keyword", func(t *testing.T) { - - t.Parallel() - - result, errs := parse("pub ( ") - utils.AssertEqualWithDiff(t, - []error{ - &SyntaxError{ - Message: "expected keyword \"set\", got EOF", - Pos: ast.Position{Offset: 6, Line: 1, Column: 6}, - }, - }, - errs, - ) - - utils.AssertEqualWithDiff(t, - ast.AccessNotSpecified, - result, - ) - }) - - t.Run("pub, missing closing paren", func(t *testing.T) { - - t.Parallel() - - result, errs := parse("pub ( set ") - utils.AssertEqualWithDiff(t, - []error{ - &SyntaxError{ - Message: "expected token ')'", - Pos: ast.Position{Offset: 10, Line: 1, Column: 10}, - }, - }, - errs, - ) - - utils.AssertEqualWithDiff(t, - ast.AccessNotSpecified, - result, - ) - }) - - t.Run("pub, invalid inner keyword", func(t *testing.T) { - - t.Parallel() - - result, errs := parse("pub ( foo )") - utils.AssertEqualWithDiff(t, - []error{ - &SyntaxError{ - Message: "expected keyword \"set\", got \"foo\"", - Pos: ast.Position{Offset: 6, Line: 1, Column: 6}, - }, - }, - errs, - ) - - utils.AssertEqualWithDiff(t, - ast.AccessNotSpecified, - result, - ) - }) - - t.Run("priv", func(t *testing.T) { - - t.Parallel() - - result, errs := parse("priv") - require.Empty(t, errs) - - utils.AssertEqualWithDiff(t, - ast.AccessPrivate, - result, - ) - }) - t.Run("access(all)", func(t *testing.T) { t.Parallel() @@ -1701,7 +1676,7 @@ func TestParseAccess(t *testing.T) { require.Empty(t, errs) utils.AssertEqualWithDiff(t, - ast.AccessPublic, + ast.AccessAll, result, ) }) @@ -1740,7 +1715,7 @@ func TestParseAccess(t *testing.T) { require.Empty(t, errs) utils.AssertEqualWithDiff(t, - ast.AccessPrivate, + ast.AccessSelf, result, ) }) @@ -2456,78 +2431,129 @@ func TestParseEvent(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations(" priv event E2 ( a : Int , b : String )") + result, errs := testParseDeclarations(" access(self) event E2 ( a : Int , b : String )") require.Empty(t, errs) utils.AssertEqualWithDiff(t, []ast.Declaration{ - &ast.CompositeDeclaration{ - Access: ast.AccessPrivate, - CompositeKind: common.CompositeKindEvent, - Identifier: ast.Identifier{ - Identifier: "E2", - Pos: ast.Position{Offset: 12, Line: 1, Column: 12}, - }, Members: ast.NewUnmeteredMembers( []ast.Declaration{ &ast.SpecialFunctionDeclaration{ - Kind: common.DeclarationKindInitializer, FunctionDeclaration: &ast.FunctionDeclaration{ - Access: ast.AccessNotSpecified, ParameterList: &ast.ParameterList{ Parameters: []*ast.Parameter{ { - Label: "", - Identifier: ast.Identifier{ - Identifier: "a", - Pos: ast.Position{Offset: 17, Line: 1, Column: 17}, - }, TypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", - Pos: ast.Position{Offset: 21, Line: 1, Column: 21}, + Pos: ast.Position{ + Offset: 29, + Line: 1, + Column: 29, + }, }, }, - StartPos: ast.Position{Offset: 21, Line: 1, Column: 21}, + StartPos: ast.Position{ + Offset: 29, + Line: 1, + Column: 29, + }, }, - StartPos: ast.Position{Offset: 17, Line: 1, Column: 17}, - }, - { - Label: "", Identifier: ast.Identifier{ - Identifier: "b", - Pos: ast.Position{Offset: 27, Line: 1, Column: 27}, + Identifier: "a", + Pos: ast.Position{ + Offset: 25, + Line: 1, + Column: 25, + }, }, + StartPos: ast.Position{ + Offset: 25, + Line: 1, + Column: 25, + }, + }, + { TypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "String", - Pos: ast.Position{Offset: 31, Line: 1, Column: 31}, + Pos: ast.Position{ + Offset: 39, + Line: 1, + Column: 39, + }, }, }, - StartPos: ast.Position{Offset: 31, Line: 1, Column: 31}, + StartPos: ast.Position{ + Offset: 39, + Line: 1, + Column: 39, + }, + }, + Identifier: ast.Identifier{ + Identifier: "b", + Pos: ast.Position{ + Offset: 35, + Line: 1, + Column: 35, + }, + }, + StartPos: ast.Position{ + Offset: 35, + Line: 1, + Column: 35, }, - StartPos: ast.Position{Offset: 27, Line: 1, Column: 27}, }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 15, Line: 1, Column: 15}, - EndPos: ast.Position{Offset: 38, Line: 1, Column: 38}, + StartPos: ast.Position{ + Offset: 23, + Line: 1, + Column: 23, + }, + EndPos: ast.Position{ + Offset: 46, + Line: 1, + Column: 46, + }, }, }, - StartPos: ast.Position{Offset: 15, Line: 1, Column: 15}, + StartPos: ast.Position{ + Offset: 23, + Line: 1, + Column: 23, + }, + Access: ast.AccessNotSpecified, }, + Kind: common.DeclarationKindInitializer, }, }, ), + Identifier: ast.Identifier{ + Identifier: "E2", + Pos: ast.Position{ + Offset: 20, + Line: 1, + Column: 20, + }, + }, Range: ast.Range{ - StartPos: ast.Position{Offset: 1, Line: 1, Column: 1}, - EndPos: ast.Position{Offset: 38, Line: 1, Column: 38}, + StartPos: ast.Position{ + Offset: 1, + Line: 1, + Column: 1, + }, + EndPos: ast.Position{ + Offset: 46, + Line: 1, + Column: 46, + }, }, + Access: ast.AccessSelf, + CompositeKind: common.CompositeKindEvent, }, }, result, @@ -2850,12 +2876,12 @@ func TestParseField(t *testing.T) { ) }) - t.Run("pub static native, enabled", func(t *testing.T) { + t.Run("access(all) static native, enabled", func(t *testing.T) { t.Parallel() result, errs := parse( - "pub static native let foo: Int", + "access(all) static native let foo: Int", Config{ StaticModifierEnabled: true, NativeModifierEnabled: true, @@ -2865,42 +2891,63 @@ func TestParseField(t *testing.T) { utils.AssertEqualWithDiff(t, &ast.FieldDeclaration{ - Access: ast.AccessPublic, - Flags: ast.FieldDeclarationFlagsIsStatic | ast.FieldDeclarationFlagsIsNative, - VariableKind: ast.VariableKindConstant, - Identifier: ast.Identifier{ - Identifier: "foo", - Pos: ast.Position{Line: 1, Column: 22, Offset: 22}, - }, TypeAnnotation: &ast.TypeAnnotation{ Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", - Pos: ast.Position{Line: 1, Column: 27, Offset: 27}, + Pos: ast.Position{ + Offset: 35, + Line: 1, + Column: 35, + }, }, }, - StartPos: ast.Position{Line: 1, Column: 27, Offset: 27}, + StartPos: ast.Position{ + Offset: 35, + Line: 1, + Column: 35, + }, + IsResource: false, + }, + Identifier: ast.Identifier{ + Identifier: "foo", + Pos: ast.Position{ + Offset: 30, + Line: 1, + Column: 30, + }, }, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, - EndPos: ast.Position{Line: 1, Column: 29, Offset: 29}, + StartPos: ast.Position{ + Offset: 0, + Line: 1, + Column: 0, + }, + EndPos: ast.Position{ + Offset: 37, + Line: 1, + Column: 37, + }, }, + Access: ast.AccessAll, + VariableKind: 0x2, + Flags: 0x03, }, result, ) }) - t.Run("pub static native, disabled", func(t *testing.T) { + t.Run("access(all) static native, disabled", func(t *testing.T) { t.Parallel() - _, errs := parse("pub static native let foo: Int", Config{}) + _, errs := parse("access(all) static native let foo: Int", Config{}) utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", - Pos: ast.Position{Offset: 4, Line: 1, Column: 4}, + Pos: ast.Position{Offset: 12, Line: 1, Column: 12}, }, }, errs, @@ -2917,23 +2964,35 @@ func TestParseCompositeDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations(" pub struct S { }") + result, errs := testParseDeclarations(" access(all) struct S { }") require.Empty(t, errs) utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ - Access: ast.AccessPublic, - CompositeKind: common.CompositeKindStructure, + Members: ast.NewUnmeteredMembers(nil), Identifier: ast.Identifier{ Identifier: "S", - Pos: ast.Position{Line: 1, Column: 12, Offset: 12}, + Pos: ast.Position{ + Offset: 20, + Line: 1, + Column: 20, + }, }, - Members: &ast.Members{}, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, - EndPos: ast.Position{Line: 1, Column: 16, Offset: 16}, + StartPos: ast.Position{ + Offset: 1, + Line: 1, + Column: 1, + }, + EndPos: ast.Position{ + Offset: 24, + Line: 1, + Column: 24, + }, }, + Access: ast.AccessAll, + CompositeKind: 0x1, }, }, result, @@ -2944,30 +3003,30 @@ func TestParseCompositeDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations(" pub resource R : RI { }") + result, errs := testParseDeclarations(" access(all) resource R : RI { }") require.Empty(t, errs) utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, CompositeKind: common.CompositeKindResource, Identifier: ast.Identifier{ Identifier: "R", - Pos: ast.Position{Line: 1, Column: 14, Offset: 14}, + Pos: ast.Position{Line: 1, Column: 22, Offset: 22}, }, Conformances: []*ast.NominalType{ { Identifier: ast.Identifier{ Identifier: "RI", - Pos: ast.Position{Line: 1, Column: 18, Offset: 18}, + Pos: ast.Position{Line: 1, Column: 26, Offset: 26}, }, }, }, Members: &ast.Members{}, Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, - EndPos: ast.Position{Line: 1, Column: 23, Offset: 23}, + EndPos: ast.Position{Line: 1, Column: 31, Offset: 31}, }, }, }, @@ -2981,13 +3040,13 @@ func TestParseCompositeDeclaration(t *testing.T) { result, errs := testParseDeclarations(` struct Test { - pub(set) var foo: Int + access(all) var foo: Int init(foo: Int) { self.foo = foo } - pub fun getFoo(): Int { + access(all) fun getFoo(): Int { return self.foo } } @@ -2998,68 +3057,100 @@ func TestParseCompositeDeclaration(t *testing.T) { utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ - Access: ast.AccessNotSpecified, - CompositeKind: common.CompositeKindStructure, - Identifier: ast.Identifier{ - Identifier: "Test", - Pos: ast.Position{Offset: 18, Line: 2, Column: 17}, - }, Members: ast.NewUnmeteredMembers( []ast.Declaration{ &ast.FieldDeclaration{ - Access: ast.AccessPublicSettable, - VariableKind: ast.VariableKindVariable, - Identifier: ast.Identifier{ - Identifier: "foo", - Pos: ast.Position{Offset: 52, Line: 3, Column: 27}, - }, TypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", - Pos: ast.Position{Offset: 57, Line: 3, Column: 32}, + Pos: ast.Position{ + Offset: 60, + Line: 3, + Column: 35, + }, }, }, - StartPos: ast.Position{Offset: 57, Line: 3, Column: 32}, + StartPos: ast.Position{ + Offset: 60, + Line: 3, + Column: 35, + }, + IsResource: false, + }, + Identifier: ast.Identifier{ + Identifier: "foo", + Pos: ast.Position{ + Offset: 55, + Line: 3, + Column: 30, + }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 39, Line: 3, Column: 14}, - EndPos: ast.Position{Offset: 59, Line: 3, Column: 34}, + StartPos: ast.Position{ + Offset: 39, + Line: 3, + Column: 14, + }, + EndPos: ast.Position{ + Offset: 62, + Line: 3, + Column: 37, + }, }, + Access: ast.AccessAll, + VariableKind: 0x1, + Flags: 0x00, }, &ast.SpecialFunctionDeclaration{ - Kind: common.DeclarationKindInitializer, FunctionDeclaration: &ast.FunctionDeclaration{ - Access: ast.AccessNotSpecified, - Identifier: ast.Identifier{ - Identifier: "init", - Pos: ast.Position{Offset: 76, Line: 5, Column: 14}, - }, ParameterList: &ast.ParameterList{ Parameters: []*ast.Parameter{ { - Label: "", - Identifier: ast.Identifier{ - Identifier: "foo", - Pos: ast.Position{Offset: 81, Line: 5, Column: 19}, - }, TypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", - Pos: ast.Position{Offset: 86, Line: 5, Column: 24}, + Pos: ast.Position{ + Offset: 89, + Line: 5, + Column: 24, + }, }, }, - StartPos: ast.Position{Offset: 86, Line: 5, Column: 24}, + StartPos: ast.Position{ + Offset: 89, + Line: 5, + Column: 24, + }, + IsResource: false, + }, + Identifier: ast.Identifier{ + Identifier: "foo", + Pos: ast.Position{ + Offset: 84, + Line: 5, + Column: 19, + }, + }, + StartPos: ast.Position{ + Offset: 84, + Line: 5, + Column: 19, }, - StartPos: ast.Position{Offset: 81, Line: 5, Column: 19}, }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 80, Line: 5, Column: 18}, - EndPos: ast.Position{Offset: 89, Line: 5, Column: 27}, + StartPos: ast.Position{ + Offset: 83, + Line: 5, + Column: 18, + }, + EndPos: ast.Position{ + Offset: 92, + Line: 5, + Column: 27, + }, }, }, FunctionBlock: &ast.FunctionBlock{ @@ -3070,57 +3161,112 @@ func TestParseCompositeDeclaration(t *testing.T) { Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ Identifier: "self", - Pos: ast.Position{Offset: 111, Line: 6, Column: 18}, + Pos: ast.Position{ + Offset: 114, + Line: 6, + Column: 18, + }, }, }, - AccessPos: ast.Position{Offset: 115, Line: 6, Column: 22}, Identifier: ast.Identifier{ Identifier: "foo", - Pos: ast.Position{Offset: 116, Line: 6, Column: 23}, + Pos: ast.Position{ + Offset: 119, + Line: 6, + Column: 23, + }, }, + AccessPos: ast.Position{ + Offset: 118, + Line: 6, + Column: 22, + }, + Optional: false, }, Transfer: &ast.Transfer{ - Operation: ast.TransferOperationCopy, - Pos: ast.Position{Offset: 120, Line: 6, Column: 27}, + Operation: 0x1, + Pos: ast.Position{ + Offset: 123, + Line: 6, + Column: 27, + }, }, Value: &ast.IdentifierExpression{ Identifier: ast.Identifier{ Identifier: "foo", - Pos: ast.Position{Offset: 122, Line: 6, Column: 29}, + Pos: ast.Position{ + Offset: 125, + Line: 6, + Column: 29, + }, }, }, }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 91, Line: 5, Column: 29}, - EndPos: ast.Position{Offset: 140, Line: 7, Column: 14}, + StartPos: ast.Position{ + Offset: 94, + Line: 5, + Column: 29, + }, + EndPos: ast.Position{ + Offset: 143, + Line: 7, + Column: 14, + }, }, }, }, - StartPos: ast.Position{Offset: 76, Line: 5, Column: 14}, + Identifier: ast.Identifier{ + Identifier: "init", + Pos: ast.Position{ + Offset: 79, + Line: 5, + Column: 14, + }, + }, + StartPos: ast.Position{ + Offset: 79, + Line: 5, + Column: 14, + }, + Access: ast.AccessNotSpecified, + Flags: 0x00, }, + Kind: 0xd, }, &ast.FunctionDeclaration{ - Access: ast.AccessPublic, - Identifier: ast.Identifier{ - Identifier: "getFoo", - Pos: ast.Position{Offset: 165, Line: 9, Column: 22}, - }, ParameterList: &ast.ParameterList{ Range: ast.Range{ - StartPos: ast.Position{Offset: 171, Line: 9, Column: 28}, - EndPos: ast.Position{Offset: 172, Line: 9, Column: 29}, + StartPos: ast.Position{ + Offset: 182, + Line: 9, + Column: 36, + }, + EndPos: ast.Position{ + Offset: 183, + Line: 9, + Column: 37, + }, }, }, ReturnTypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", - Pos: ast.Position{Offset: 175, Line: 9, Column: 32}, + Pos: ast.Position{ + Offset: 186, + Line: 9, + Column: 40, + }, }, }, - StartPos: ast.Position{Offset: 175, Line: 9, Column: 32}, + StartPos: ast.Position{ + Offset: 186, + Line: 9, + Column: 40, + }, + IsResource: false, }, FunctionBlock: &ast.FunctionBlock{ Block: &ast.Block{ @@ -3130,35 +3276,97 @@ func TestParseCompositeDeclaration(t *testing.T) { Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ Identifier: "self", - Pos: ast.Position{Offset: 206, Line: 10, Column: 25}, + Pos: ast.Position{ + Offset: 217, + Line: 10, + Column: 25, + }, }, }, - AccessPos: ast.Position{Offset: 210, Line: 10, Column: 29}, Identifier: ast.Identifier{ Identifier: "foo", - Pos: ast.Position{Offset: 211, Line: 10, Column: 30}, + Pos: ast.Position{ + Offset: 222, + Line: 10, + Column: 30, + }, + }, + AccessPos: ast.Position{ + Offset: 221, + Line: 10, + Column: 29, }, + Optional: false, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 199, Line: 10, Column: 18}, - EndPos: ast.Position{Offset: 213, Line: 10, Column: 32}, + StartPos: ast.Position{ + Offset: 210, + Line: 10, + Column: 18, + }, + EndPos: ast.Position{ + Offset: 224, + Line: 10, + Column: 32, + }, }, }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 179, Line: 9, Column: 36}, - EndPos: ast.Position{Offset: 229, Line: 11, Column: 14}, + StartPos: ast.Position{ + Offset: 190, + Line: 9, + Column: 44, + }, + EndPos: ast.Position{ + Offset: 240, + Line: 11, + Column: 14, + }, }, }, }, - StartPos: ast.Position{Offset: 157, Line: 9, Column: 14}, + DocString: "", + Identifier: ast.Identifier{ + Identifier: "getFoo", + Pos: ast.Position{ + Offset: 176, + Line: 9, + Column: 30, + }, + }, + StartPos: ast.Position{ + Offset: 160, + Line: 9, + Column: 14, + }, + Access: ast.AccessAll, + Flags: 0x00, }, }, ), + Identifier: ast.Identifier{ + Identifier: "Test", + Pos: ast.Position{ + Offset: 18, + Line: 2, + Column: 17, + }, + }, Range: ast.Range{ - StartPos: ast.Position{Offset: 11, Line: 2, Column: 10}, - EndPos: ast.Position{Offset: 241, Line: 12, Column: 10}, + StartPos: ast.Position{ + Offset: 11, + Line: 2, + Column: 10, + }, + EndPos: ast.Position{ + Offset: 252, + Line: 12, + Column: 10, + }, }, + Access: ast.AccessNotSpecified, + CompositeKind: 0x1, }, }, result, @@ -3351,11 +3559,11 @@ func TestParseInvalidCompositeFunctionWithSelfParameter(t *testing.T) { func TestParseInvalidParameterWithoutLabel(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(`pub fun foo(continue: Int) {}`) + _, errs := testParseDeclarations(`access(all) fun foo(continue: Int) {}`) utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ - Pos: ast.Position{Line: 1, Column: 12, Offset: 12}, + Pos: ast.Position{Line: 1, Column: 20, Offset: 20}, Message: "expected identifier for argument label or parameter name, got keyword continue", }, }, errs) @@ -3364,11 +3572,11 @@ func TestParseInvalidParameterWithoutLabel(t *testing.T) { func TestParseParametersWithExtraLabels(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(`pub fun foo(_ foo: String, label fable table: Int) {}`) + _, errs := testParseDeclarations(`access(all) fun foo(_ foo: String, label fable table: Int) {}`) utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ - Pos: ast.Position{Line: 1, Column: 39, Offset: 39}, + Pos: ast.Position{Line: 1, Column: 47, Offset: 47}, Message: "expected ':' after parameter name, got identifier", }, }, errs) @@ -3382,27 +3590,27 @@ func TestParseAttachmentDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations("pub attachment E for S {} ") + result, errs := testParseDeclarations("access(all) attachment E for S {} ") require.Empty(t, errs) utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, Identifier: ast.Identifier{ Identifier: "E", - Pos: ast.Position{Line: 1, Column: 15, Offset: 15}, + Pos: ast.Position{Line: 1, Column: 23, Offset: 23}, }, BaseType: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "S", - Pos: ast.Position{Line: 1, Column: 21, Offset: 21}, + Pos: ast.Position{Line: 1, Column: 29, Offset: 29}, }, }, Members: &ast.Members{}, Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, - EndPos: ast.Position{Line: 1, Column: 24, Offset: 24}, + EndPos: ast.Position{Line: 1, Column: 32, Offset: 32}, }, }, }, @@ -3416,7 +3624,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { result, errs := testParseDeclarations(` contract Test { - pub attachment E for S {} + access(all) attachment E for S {} }`) require.Empty(t, errs) @@ -3431,26 +3639,26 @@ func TestParseAttachmentDeclaration(t *testing.T) { }, Range: ast.Range{ StartPos: ast.Position{Line: 2, Column: 2, Offset: 3}, - EndPos: ast.Position{Line: 4, Column: 2, Offset: 50}, + EndPos: ast.Position{Line: 4, Column: 2, Offset: 58}, }, Members: ast.NewUnmeteredMembers( []ast.Declaration{ &ast.AttachmentDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, Identifier: ast.Identifier{ Identifier: "E", - Pos: ast.Position{Line: 3, Column: 18, Offset: 37}, + Pos: ast.Position{Line: 3, Column: 26, Offset: 45}, }, BaseType: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "S", - Pos: ast.Position{Line: 3, Column: 24, Offset: 43}, + Pos: ast.Position{Line: 3, Column: 32, Offset: 51}, }, }, Members: &ast.Members{}, Range: ast.Range{ StartPos: ast.Position{Line: 3, Column: 3, Offset: 22}, - EndPos: ast.Position{Line: 3, Column: 27, Offset: 46}, + EndPos: ast.Position{Line: 3, Column: 35, Offset: 54}, }, }, }, @@ -3481,21 +3689,21 @@ func TestParseAttachmentDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations("pub attachment E for S: I {} ") + result, errs := testParseDeclarations("access(all) attachment E for S: I {} ") require.Empty(t, errs) utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, Identifier: ast.Identifier{ Identifier: "E", - Pos: ast.Position{Line: 1, Column: 15, Offset: 15}, + Pos: ast.Position{Line: 1, Column: 23, Offset: 23}, }, BaseType: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "S", - Pos: ast.Position{Line: 1, Column: 21, Offset: 21}, + Pos: ast.Position{Line: 1, Column: 29, Offset: 29}, }, }, Members: &ast.Members{}, @@ -3504,14 +3712,14 @@ func TestParseAttachmentDeclaration(t *testing.T) { nil, ast.Identifier{ Identifier: "I", - Pos: ast.Position{Line: 1, Column: 24, Offset: 24}, + Pos: ast.Position{Line: 1, Column: 32, Offset: 32}, }, nil, ), }, Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, - EndPos: ast.Position{Line: 1, Column: 27, Offset: 27}, + EndPos: ast.Position{Line: 1, Column: 35, Offset: 35}, }, }, }, @@ -3523,45 +3731,65 @@ func TestParseAttachmentDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations("pub attachment E for S: I1, I2 {} ") + result, errs := testParseDeclarations("access(all) attachment E for S: I1, I2 {} ") require.Empty(t, errs) utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, Identifier: ast.Identifier{ Identifier: "E", - Pos: ast.Position{Line: 1, Column: 15, Offset: 15}, + Pos: ast.Position{ + Offset: 23, + Line: 1, + Column: 23, + }, }, BaseType: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "S", - Pos: ast.Position{Line: 1, Column: 21, Offset: 21}, + Pos: ast.Position{ + Offset: 29, + Line: 1, + Column: 29, + }, }, }, - Members: &ast.Members{}, Conformances: []*ast.NominalType{ - ast.NewNominalType( - nil, - ast.Identifier{ + { + Identifier: ast.Identifier{ Identifier: "I1", - Pos: ast.Position{Line: 1, Column: 24, Offset: 24}, + Pos: ast.Position{ + Offset: 32, + Line: 1, + Column: 32, + }, }, - nil, - ), - ast.NewNominalType( - nil, - ast.Identifier{ + }, + { + Identifier: ast.Identifier{ Identifier: "I2", - Pos: ast.Position{Line: 1, Column: 28, Offset: 28}, + Pos: ast.Position{ + Offset: 36, + Line: 1, + Column: 36, + }, }, - nil, - ), + }, }, + Members: ast.NewUnmeteredMembers(nil), Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, - EndPos: ast.Position{Line: 1, Column: 32, Offset: 32}, + StartPos: ast.Position{ + Offset: 0, + Line: 1, + Column: 0, + }, + EndPos: ast.Position{ + Offset: 40, + Line: 1, + Column: 40, + }, }, }, }, @@ -3573,139 +3801,257 @@ func TestParseAttachmentDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations(`pub attachment E for S { - pub(set) var foo: Int + result, errs := testParseDeclarations(`access(all) attachment E for S { + access(all) var foo: Int init() {} destroy() {} - pub fun getFoo(): Int {} + access(all) fun getFoo(): Int {} }`) require.Empty(t, errs) utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, Identifier: ast.Identifier{ Identifier: "E", - Pos: ast.Position{Line: 1, Column: 15, Offset: 15}, + Pos: ast.Position{ + Offset: 23, + Line: 1, + Column: 23, + }, }, BaseType: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "S", - Pos: ast.Position{Line: 1, Column: 21, Offset: 21}, + Pos: ast.Position{ + Offset: 29, + Line: 1, + Column: 29, + }, }, }, Members: ast.NewUnmeteredMembers( []ast.Declaration{ &ast.FieldDeclaration{ - Access: ast.AccessPublicSettable, - VariableKind: ast.VariableKindVariable, - Identifier: ast.Identifier{ - Identifier: "foo", - Pos: ast.Position{Offset: 41, Line: 2, Column: 16}, - }, TypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", - Pos: ast.Position{Offset: 46, Line: 2, Column: 21}, + Pos: ast.Position{ + Offset: 57, + Line: 2, + Column: 24, + }, }, }, - StartPos: ast.Position{Offset: 46, Line: 2, Column: 21}, + StartPos: ast.Position{ + Offset: 57, + Line: 2, + Column: 24, + }, + IsResource: false, + }, + Identifier: ast.Identifier{ + Identifier: "foo", + Pos: ast.Position{ + Offset: 52, + Line: 2, + Column: 19, + }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 28, Line: 2, Column: 3}, - EndPos: ast.Position{Offset: 48, Line: 2, Column: 23}, + StartPos: ast.Position{ + Offset: 36, + Line: 2, + Column: 3, + }, + EndPos: ast.Position{ + Offset: 59, + Line: 2, + Column: 26, + }, }, + Access: ast.AccessAll, + VariableKind: 0x1, + Flags: 0x00, }, &ast.SpecialFunctionDeclaration{ - Kind: common.DeclarationKindInitializer, FunctionDeclaration: &ast.FunctionDeclaration{ - Access: ast.AccessNotSpecified, - Identifier: ast.Identifier{ - Identifier: "init", - Pos: ast.Position{Offset: 53, Line: 3, Column: 3}, - }, ParameterList: &ast.ParameterList{ Range: ast.Range{ - StartPos: ast.Position{Offset: 57, Line: 3, Column: 7}, - EndPos: ast.Position{Offset: 58, Line: 3, Column: 8}, + StartPos: ast.Position{ + Offset: 68, + Line: 3, + Column: 7, + }, + EndPos: ast.Position{ + Offset: 69, + Line: 3, + Column: 8, + }, }, }, FunctionBlock: &ast.FunctionBlock{ Block: &ast.Block{ Range: ast.Range{ - StartPos: ast.Position{Offset: 60, Line: 3, Column: 10}, - EndPos: ast.Position{Offset: 61, Line: 3, Column: 11}, + StartPos: ast.Position{ + Offset: 71, + Line: 3, + Column: 10, + }, + EndPos: ast.Position{ + Offset: 72, + Line: 3, + Column: 11, + }, }, }, }, - StartPos: ast.Position{Offset: 53, Line: 3, Column: 3}, + Identifier: ast.Identifier{ + Identifier: "init", + Pos: ast.Position{ + Offset: 64, + Line: 3, + Column: 3, + }, + }, + StartPos: ast.Position{ + Offset: 64, + Line: 3, + Column: 3, + }, + Access: ast.AccessNotSpecified, }, + Kind: 0xd, }, &ast.SpecialFunctionDeclaration{ - Kind: common.DeclarationKindDestructor, FunctionDeclaration: &ast.FunctionDeclaration{ - Access: ast.AccessNotSpecified, - Identifier: ast.Identifier{ - Identifier: "destroy", - Pos: ast.Position{Offset: 66, Line: 4, Column: 3}, - }, ParameterList: &ast.ParameterList{ Range: ast.Range{ - StartPos: ast.Position{Offset: 73, Line: 4, Column: 10}, - EndPos: ast.Position{Offset: 74, Line: 4, Column: 11}, + StartPos: ast.Position{ + Offset: 84, + Line: 4, + Column: 10, + }, + EndPos: ast.Position{ + Offset: 85, + Line: 4, + Column: 11, + }, }, }, FunctionBlock: &ast.FunctionBlock{ Block: &ast.Block{ Range: ast.Range{ - StartPos: ast.Position{Offset: 76, Line: 4, Column: 13}, - EndPos: ast.Position{Offset: 77, Line: 4, Column: 14}, + StartPos: ast.Position{ + Offset: 87, + Line: 4, + Column: 13, + }, + EndPos: ast.Position{ + Offset: 88, + Line: 4, + Column: 14, + }, }, }, }, - StartPos: ast.Position{Offset: 66, Line: 4, Column: 3}, + Identifier: ast.Identifier{ + Identifier: "destroy", + Pos: ast.Position{ + Offset: 77, + Line: 4, + Column: 3, + }, + }, + StartPos: ast.Position{ + Offset: 77, + Line: 4, + Column: 3, + }, + Access: ast.AccessNotSpecified, + Flags: 0x00, }, + Kind: 0xe, }, &ast.FunctionDeclaration{ - Access: ast.AccessPublic, - Identifier: ast.Identifier{ - Identifier: "getFoo", - Pos: ast.Position{Offset: 90, Line: 5, Column: 11}, - }, ParameterList: &ast.ParameterList{ Range: ast.Range{ - StartPos: ast.Position{Offset: 96, Line: 5, Column: 17}, - EndPos: ast.Position{Offset: 97, Line: 5, Column: 18}, + StartPos: ast.Position{ + Offset: 115, + Line: 5, + Column: 25, + }, + EndPos: ast.Position{ + Offset: 116, + Line: 5, + Column: 26, + }, }, }, ReturnTypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", - Pos: ast.Position{Offset: 100, Line: 5, Column: 21}, + Pos: ast.Position{ + Offset: 119, + Line: 5, + Column: 29, + }, }, }, - StartPos: ast.Position{Offset: 100, Line: 5, Column: 21}, + StartPos: ast.Position{ + Offset: 119, + Line: 5, + Column: 29, + }, + IsResource: false, }, FunctionBlock: &ast.FunctionBlock{ Block: &ast.Block{ Range: ast.Range{ - StartPos: ast.Position{Offset: 104, Line: 5, Column: 25}, - EndPos: ast.Position{Offset: 105, Line: 5, Column: 26}, + StartPos: ast.Position{ + Offset: 123, + Line: 5, + Column: 33, + }, + EndPos: ast.Position{ + Offset: 124, + Line: 5, + Column: 34, + }, }, }, }, - StartPos: ast.Position{Offset: 82, Line: 5, Column: 3}, + Identifier: ast.Identifier{ + Identifier: "getFoo", + Pos: ast.Position{ + Offset: 109, + Line: 5, + Column: 19, + }, + }, + StartPos: ast.Position{ + Offset: 93, + Line: 5, + Column: 3, + }, + Access: ast.AccessAll, }, }, ), Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, - EndPos: ast.Position{Line: 6, Column: 2, Offset: 109}, + StartPos: ast.Position{ + Offset: 0, + Line: 1, + Column: 0, + }, + EndPos: ast.Position{ + Offset: 128, + Line: 6, + Column: 2, + }, }, }, }, @@ -3717,7 +4063,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations(`pub attachment E for S { + result, errs := testParseDeclarations(`access(all) attachment E for S { require entitlement X require entitlement Y destroy() {} @@ -3727,67 +4073,111 @@ func TestParseAttachmentDeclaration(t *testing.T) { utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, Identifier: ast.Identifier{ Identifier: "E", - Pos: ast.Position{Line: 1, Column: 15, Offset: 15}, + Pos: ast.Position{ + Offset: 23, + Line: 1, + Column: 23, + }, }, BaseType: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "S", - Pos: ast.Position{Line: 1, Column: 21, Offset: 21}, + Pos: ast.Position{ + Offset: 29, + Line: 1, + Column: 29, + }, + }, + }, + RequiredEntitlements: []*ast.NominalType{ + { + Identifier: ast.Identifier{ + Identifier: "X", + Pos: ast.Position{ + Offset: 56, + Line: 2, + Column: 23, + }, + }, + }, + { + Identifier: ast.Identifier{ + Identifier: "Y", + Pos: ast.Position{ + Offset: 81, + Line: 3, + Column: 23, + }, + }, }, }, Members: ast.NewUnmeteredMembers( []ast.Declaration{ &ast.SpecialFunctionDeclaration{ - Kind: common.DeclarationKindDestructor, FunctionDeclaration: &ast.FunctionDeclaration{ - Access: ast.AccessNotSpecified, - Identifier: ast.Identifier{ - Identifier: "destroy", - Pos: ast.Position{Offset: 78, Line: 4, Column: 3}, - }, ParameterList: &ast.ParameterList{ Range: ast.Range{ - StartPos: ast.Position{Offset: 85, Line: 4, Column: 10}, - EndPos: ast.Position{Offset: 86, Line: 4, Column: 11}, + StartPos: ast.Position{ + Offset: 93, + Line: 4, + Column: 10, + }, + EndPos: ast.Position{ + Offset: 94, + Line: 4, + Column: 11, + }, }, }, FunctionBlock: &ast.FunctionBlock{ Block: &ast.Block{ Range: ast.Range{ - StartPos: ast.Position{Offset: 88, Line: 4, Column: 13}, - EndPos: ast.Position{Offset: 89, Line: 4, Column: 14}, + StartPos: ast.Position{ + Offset: 96, + Line: 4, + Column: 13, + }, + EndPos: ast.Position{ + Offset: 97, + Line: 4, + Column: 14, + }, }, }, }, - StartPos: ast.Position{Offset: 78, Line: 4, Column: 3}, + Identifier: ast.Identifier{ + Identifier: "destroy", + Pos: ast.Position{ + Offset: 86, + Line: 4, + Column: 3, + }, + }, + StartPos: ast.Position{ + Offset: 86, + Line: 4, + Column: 3, + }, + Access: ast.AccessNotSpecified, }, + Kind: 0xe, }, }, ), - RequiredEntitlements: []*ast.NominalType{ - ast.NewNominalType( - nil, - ast.Identifier{ - Identifier: "X", - Pos: ast.Position{Line: 2, Column: 23, Offset: 48}, - }, - nil, - ), - ast.NewNominalType( - nil, - ast.Identifier{ - Identifier: "Y", - Pos: ast.Position{Line: 3, Column: 23, Offset: 73}, - }, - nil, - ), - }, Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, - EndPos: ast.Position{Line: 5, Column: 2, Offset: 93}, + StartPos: ast.Position{ + Offset: 0, + Line: 1, + Column: 0, + }, + EndPos: ast.Position{ + Offset: 101, + Line: 5, + Column: 2, + }, }, }, }, @@ -3799,13 +4189,13 @@ func TestParseAttachmentDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(`pub attachment E for S { + _, errs := testParseDeclarations(`access(all) attachment E for S { require entitlement destroy() {} }`) utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ - Pos: ast.Position{Line: 3, Column: 10, Offset: 59}, + Pos: ast.Position{Line: 3, Column: 10, Offset: 67}, Message: "unexpected '('", }, }, errs) @@ -3815,13 +4205,13 @@ func TestParseAttachmentDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(`pub attachment E for S { + _, errs := testParseDeclarations(`access(all) attachment E for S { require X destroy() {} }`) utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ - Pos: ast.Position{Line: 2, Column: 11, Offset: 36}, + Pos: ast.Position{Line: 2, Column: 11, Offset: 44}, Message: "expected 'entitlement', got identifier", }, }, errs) @@ -3831,13 +4221,13 @@ func TestParseAttachmentDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(`pub attachment E for S { + _, errs := testParseDeclarations(`access(all) attachment E for S { require entitlement [X] destroy() {} }`) utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ - Pos: ast.Position{Line: 2, Column: 26, Offset: 51}, + Pos: ast.Position{Line: 2, Column: 26, Offset: 59}, Message: "unexpected non-nominal type: [X]", }, }, errs) @@ -3847,7 +4237,7 @@ func TestParseAttachmentDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations(`pub attachment E for S { + result, errs := testParseDeclarations(`access(all) attachment E for S { access(X) var foo: Int }`) require.Empty(t, errs) @@ -3855,57 +4245,97 @@ func TestParseAttachmentDeclaration(t *testing.T) { utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.AttachmentDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, Identifier: ast.Identifier{ Identifier: "E", - Pos: ast.Position{Line: 1, Column: 15, Offset: 15}, + Pos: ast.Position{ + Offset: 23, + Line: 1, + Column: 23, + }, }, BaseType: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "S", - Pos: ast.Position{Line: 1, Column: 21, Offset: 21}, + Pos: ast.Position{ + Offset: 29, + Line: 1, + Column: 29, + }, }, }, Members: ast.NewUnmeteredMembers( []ast.Declaration{ &ast.FieldDeclaration{ + TypeAnnotation: &ast.TypeAnnotation{ + Type: &ast.NominalType{ + Identifier: ast.Identifier{ + Identifier: "Int", + Pos: ast.Position{ + Offset: 55, + Line: 2, + Column: 22, + }, + }, + }, + StartPos: ast.Position{ + Offset: 55, + Line: 2, + Column: 22, + }, + IsResource: false, + }, + Identifier: ast.Identifier{ + Identifier: "foo", + Pos: ast.Position{ + Offset: 50, + Line: 2, + Column: 17, + }, + }, + Range: ast.Range{ + StartPos: ast.Position{ + Offset: 36, + Line: 2, + Column: 3, + }, + EndPos: ast.Position{ + Offset: 57, + Line: 2, + Column: 24, + }, + }, Access: ast.EntitlementAccess{ EntitlementSet: &ast.ConjunctiveEntitlementSet{ Elements: []*ast.NominalType{ { Identifier: ast.Identifier{ Identifier: "X", - Pos: ast.Position{Offset: 35, Line: 2, Column: 10}, + Pos: ast.Position{ + Offset: 43, + Line: 2, + Column: 10, + }, }, }, }, }, }, - VariableKind: ast.VariableKindVariable, - Identifier: ast.Identifier{ - Identifier: "foo", - Pos: ast.Position{Offset: 42, Line: 2, Column: 17}, - }, - TypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, - Type: &ast.NominalType{ - Identifier: ast.Identifier{ - Identifier: "Int", - Pos: ast.Position{Offset: 47, Line: 2, Column: 22}, - }, - }, - StartPos: ast.Position{Offset: 47, Line: 2, Column: 22}, - }, - Range: ast.Range{ - StartPos: ast.Position{Offset: 28, Line: 2, Column: 3}, - EndPos: ast.Position{Offset: 49, Line: 2, Column: 24}, - }, + VariableKind: 0x1, }, }, ), Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 0, Offset: 0}, - EndPos: ast.Position{Line: 3, Column: 2, Offset: 53}, + StartPos: ast.Position{ + Offset: 0, + Line: 1, + Column: 0, + }, + EndPos: ast.Position{ + Offset: 61, + Line: 3, + Column: 2, + }, }, }, }, @@ -3922,22 +4352,22 @@ func TestParseInterfaceDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations(" pub struct interface S { }") + result, errs := testParseDeclarations(" access(all) struct interface S { }") require.Empty(t, errs) utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.InterfaceDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, CompositeKind: common.CompositeKindStructure, Identifier: ast.Identifier{ Identifier: "S", - Pos: ast.Position{Line: 1, Column: 22, Offset: 22}, + Pos: ast.Position{Line: 1, Column: 30, Offset: 30}, }, Members: &ast.Members{}, Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, - EndPos: ast.Position{Line: 1, Column: 26, Offset: 26}, + EndPos: ast.Position{Line: 1, Column: 34, Offset: 34}, }, }, }, @@ -3949,12 +4379,12 @@ func TestParseInterfaceDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations(" pub struct interface interface { }") + result, errs := testParseDeclarations(" access(all) struct interface interface { }") utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected interface name, got keyword \"interface\"", - Pos: ast.Position{Offset: 22, Line: 1, Column: 22}, + Pos: ast.Position{Offset: 30, Line: 1, Column: 30}, }, }, errs, @@ -3974,13 +4404,13 @@ func TestParseInterfaceDeclaration(t *testing.T) { result, errs := testParseDeclarations(` struct interface Test { - pub(set) var foo: Int + access(all) var foo: Int init(foo: Int) - pub fun getFoo(): Int + access(all) fun getFoo(): Int - pub fun getBar(): Int {} + access(all) fun getBar(): Int {} destroy() {} } @@ -3991,160 +4421,307 @@ func TestParseInterfaceDeclaration(t *testing.T) { utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.InterfaceDeclaration{ - Access: ast.AccessNotSpecified, - CompositeKind: common.CompositeKindStructure, - Identifier: ast.Identifier{ - Identifier: "Test", - Pos: ast.Position{Offset: 28, Line: 2, Column: 27}, - }, Members: ast.NewUnmeteredMembers( []ast.Declaration{ &ast.FieldDeclaration{ - Access: ast.AccessPublicSettable, - VariableKind: ast.VariableKindVariable, - Identifier: ast.Identifier{ - Identifier: "foo", - Pos: ast.Position{Offset: 62, Line: 3, Column: 27}, - }, TypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", - Pos: ast.Position{Offset: 67, Line: 3, Column: 32}, + Pos: ast.Position{ + Offset: 70, + Line: 3, + Column: 35, + }, }, }, - StartPos: ast.Position{Offset: 67, Line: 3, Column: 32}, + StartPos: ast.Position{ + Offset: 70, + Line: 3, + Column: 35, + }, + IsResource: false, + }, + Identifier: ast.Identifier{ + Identifier: "foo", + Pos: ast.Position{ + Offset: 65, + Line: 3, + Column: 30, + }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 49, Line: 3, Column: 14}, - EndPos: ast.Position{Offset: 69, Line: 3, Column: 34}, + StartPos: ast.Position{ + Offset: 49, + Line: 3, + Column: 14, + }, + EndPos: ast.Position{ + Offset: 72, + Line: 3, + Column: 37, + }, }, + Access: ast.AccessAll, + VariableKind: 0x1, + Flags: 0x00, }, &ast.SpecialFunctionDeclaration{ - Kind: common.DeclarationKindInitializer, FunctionDeclaration: &ast.FunctionDeclaration{ - Access: ast.AccessNotSpecified, - Identifier: ast.Identifier{ - Identifier: "init", - Pos: ast.Position{Offset: 86, Line: 5, Column: 14}, - }, ParameterList: &ast.ParameterList{ Parameters: []*ast.Parameter{ { - Label: "", - Identifier: ast.Identifier{ - Identifier: "foo", - Pos: ast.Position{Offset: 91, Line: 5, Column: 19}, - }, TypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", - Pos: ast.Position{Offset: 96, Line: 5, Column: 24}, + Pos: ast.Position{ + Offset: 99, + Line: 5, + Column: 24, + }, }, }, - StartPos: ast.Position{Offset: 96, Line: 5, Column: 24}, + StartPos: ast.Position{ + Offset: 99, + Line: 5, + Column: 24, + }, + IsResource: false, + }, + Identifier: ast.Identifier{ + Identifier: "foo", + Pos: ast.Position{ + Offset: 94, + Line: 5, + Column: 19, + }, + }, + StartPos: ast.Position{ + Offset: 94, + Line: 5, + Column: 19, }, - StartPos: ast.Position{Offset: 91, Line: 5, Column: 19}, }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 90, Line: 5, Column: 18}, - EndPos: ast.Position{Offset: 99, Line: 5, Column: 27}, + StartPos: ast.Position{ + Offset: 93, + Line: 5, + Column: 18, + }, + EndPos: ast.Position{ + Offset: 102, + Line: 5, + Column: 27, + }, }, }, - StartPos: ast.Position{Offset: 86, Line: 5, Column: 14}, + Identifier: ast.Identifier{ + Identifier: "init", + Pos: ast.Position{ + Offset: 89, + Line: 5, + Column: 14, + }, + }, + StartPos: ast.Position{ + Offset: 89, + Line: 5, + Column: 14, + }, + Access: ast.AccessNotSpecified, + Flags: 0x00, }, + Kind: 0xd, }, &ast.FunctionDeclaration{ - Access: ast.AccessPublic, - Identifier: ast.Identifier{ - Identifier: "getFoo", - Pos: ast.Position{Offset: 124, Line: 7, Column: 22}, - }, ParameterList: &ast.ParameterList{ Range: ast.Range{ - StartPos: ast.Position{Offset: 130, Line: 7, Column: 28}, - EndPos: ast.Position{Offset: 131, Line: 7, Column: 29}, + StartPos: ast.Position{ + Offset: 141, + Line: 7, + Column: 36, + }, + EndPos: ast.Position{ + Offset: 142, + Line: 7, + Column: 37, + }, }, }, ReturnTypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", - Pos: ast.Position{Offset: 134, Line: 7, Column: 32}, + Pos: ast.Position{ + Offset: 145, + Line: 7, + Column: 40, + }, }, }, - StartPos: ast.Position{Offset: 134, Line: 7, Column: 32}, + StartPos: ast.Position{ + Offset: 145, + Line: 7, + Column: 40, + }, + IsResource: false, }, - StartPos: ast.Position{Offset: 116, Line: 7, Column: 14}, - }, - &ast.FunctionDeclaration{ - Access: ast.AccessPublic, Identifier: ast.Identifier{ - Identifier: "getBar", - Pos: ast.Position{Offset: 161, Line: 9, Column: 22}, + Identifier: "getFoo", + Pos: ast.Position{ + Offset: 135, + Line: 7, + Column: 30, + }, }, + StartPos: ast.Position{ + Offset: 119, + Line: 7, + Column: 14, + }, + Access: ast.AccessAll, + Flags: 0x00, + }, + &ast.FunctionDeclaration{ ParameterList: &ast.ParameterList{ Range: ast.Range{ - StartPos: ast.Position{Offset: 167, Line: 9, Column: 28}, - EndPos: ast.Position{Offset: 168, Line: 9, Column: 29}, + StartPos: ast.Position{ + Offset: 186, + Line: 9, + Column: 36, + }, + EndPos: ast.Position{ + Offset: 187, + Line: 9, + Column: 37, + }, }, }, ReturnTypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", - Pos: ast.Position{Offset: 171, Line: 9, Column: 32}, + Pos: ast.Position{ + Offset: 190, + Line: 9, + Column: 40, + }, }, }, - StartPos: ast.Position{Offset: 171, Line: 9, Column: 32}, + StartPos: ast.Position{ + Offset: 190, + Line: 9, + Column: 40, + }, + IsResource: false, }, FunctionBlock: &ast.FunctionBlock{ Block: &ast.Block{ Range: ast.Range{ - StartPos: ast.Position{Offset: 175, Line: 9, Column: 36}, - EndPos: ast.Position{Offset: 176, Line: 9, Column: 37}, + StartPos: ast.Position{ + Offset: 194, + Line: 9, + Column: 44, + }, + EndPos: ast.Position{ + Offset: 195, + Line: 9, + Column: 45, + }, }, }, }, - StartPos: ast.Position{Offset: 153, Line: 9, Column: 14}, + Identifier: ast.Identifier{ + Identifier: "getBar", + Pos: ast.Position{ + Offset: 180, + Line: 9, + Column: 30, + }, + }, + StartPos: ast.Position{ + Offset: 164, + Line: 9, + Column: 14, + }, + Access: ast.AccessAll, }, &ast.SpecialFunctionDeclaration{ - Kind: common.DeclarationKindDestructor, FunctionDeclaration: &ast.FunctionDeclaration{ - Access: ast.AccessNotSpecified, - Identifier: ast.Identifier{ - Identifier: "destroy", - Pos: ast.Position{Offset: 193, Line: 11, Column: 14}, - }, ParameterList: &ast.ParameterList{ Range: ast.Range{ - StartPos: ast.Position{Offset: 200, Line: 11, Column: 21}, - EndPos: ast.Position{Offset: 201, Line: 11, Column: 22}, + StartPos: ast.Position{ + Offset: 219, + Line: 11, + Column: 21, + }, + EndPos: ast.Position{ + Offset: 220, + Line: 11, + Column: 22, + }, }, }, FunctionBlock: &ast.FunctionBlock{ Block: &ast.Block{ Range: ast.Range{ - StartPos: ast.Position{Offset: 203, Line: 11, Column: 24}, - EndPos: ast.Position{Offset: 204, Line: 11, Column: 25}, + StartPos: ast.Position{ + Offset: 222, + Line: 11, + Column: 24, + }, + EndPos: ast.Position{ + Offset: 223, + Line: 11, + Column: 25, + }, }, }, }, - StartPos: ast.Position{Offset: 193, Line: 11, Column: 14}, + DocString: "", + Identifier: ast.Identifier{ + Identifier: "destroy", + Pos: ast.Position{ + Offset: 212, + Line: 11, + Column: 14, + }, + }, + StartPos: ast.Position{ + Offset: 212, + Line: 11, + Column: 14, + }, + Access: ast.AccessNotSpecified, }, + Kind: 0xe, }, }, ), + Identifier: ast.Identifier{ + Identifier: "Test", + Pos: ast.Position{ + Offset: 28, + Line: 2, + Column: 27, + }, + }, Range: ast.Range{ - StartPos: ast.Position{Offset: 11, Line: 2, Column: 10}, - EndPos: ast.Position{Offset: 216, Line: 12, Column: 10}, + StartPos: ast.Position{ + Offset: 11, + Line: 2, + Column: 10, + }, + EndPos: ast.Position{ + Offset: 235, + Line: 12, + Column: 10, + }, }, + Access: ast.AccessNotSpecified, + CompositeKind: 0x1, }, }, result, @@ -4152,11 +4729,11 @@ func TestParseInterfaceDeclaration(t *testing.T) { }) t.Run("invalid interface name", func(t *testing.T) { - _, errs := testParseDeclarations(`pub struct interface continue {}`) + _, errs := testParseDeclarations(`access(all) struct interface continue {}`) utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ - Pos: ast.Position{Line: 1, Column: 21, Offset: 21}, + Pos: ast.Position{Line: 1, Column: 29, Offset: 29}, Message: "expected identifier following struct declaration, got keyword continue", }, }, errs) @@ -4224,17 +4801,17 @@ func TestParseEnumDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations(" pub enum E { case c ; pub case d }") + result, errs := testParseDeclarations(" access(all) enum E { case c ; access(all) case d }") require.Empty(t, errs) utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, CompositeKind: common.CompositeKindEnum, Identifier: ast.Identifier{ Identifier: "E", - Pos: ast.Position{Line: 1, Column: 10, Offset: 10}, + Pos: ast.Position{Line: 1, Column: 18, Offset: 18}, }, Members: ast.NewUnmeteredMembers( []ast.Declaration{ @@ -4242,23 +4819,23 @@ func TestParseEnumDeclaration(t *testing.T) { Access: ast.AccessNotSpecified, Identifier: ast.Identifier{ Identifier: "c", - Pos: ast.Position{Line: 1, Column: 19, Offset: 19}, + Pos: ast.Position{Line: 1, Column: 27, Offset: 27}, }, - StartPos: ast.Position{Line: 1, Column: 14, Offset: 14}, + StartPos: ast.Position{Line: 1, Column: 22, Offset: 22}, }, &ast.EnumCaseDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, Identifier: ast.Identifier{ Identifier: "d", - Pos: ast.Position{Line: 1, Column: 32, Offset: 32}, + Pos: ast.Position{Line: 1, Column: 48, Offset: 48}, }, - StartPos: ast.Position{Line: 1, Column: 23, Offset: 23}, + StartPos: ast.Position{Line: 1, Column: 31, Offset: 31}, }, }, ), Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, - EndPos: ast.Position{Line: 1, Column: 34, Offset: 34}, + EndPos: ast.Position{Line: 1, Column: 50, Offset: 50}, }, }, }, @@ -5283,13 +5860,13 @@ func TestParseStructure(t *testing.T) { const code = ` struct Test { - pub(set) var foo: Int + access(all) var foo: Int init(foo: Int) { self.foo = foo } - pub fun getFoo(): Int { + access(all) fun getFoo(): Int { return self.foo } } @@ -5300,68 +5877,100 @@ func TestParseStructure(t *testing.T) { utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ - Access: ast.AccessNotSpecified, - CompositeKind: common.CompositeKindStructure, - Identifier: ast.Identifier{ - Identifier: "Test", - Pos: ast.Position{Offset: 16, Line: 2, Column: 15}, - }, Members: ast.NewUnmeteredMembers( []ast.Declaration{ &ast.FieldDeclaration{ - Access: ast.AccessPublicSettable, - VariableKind: ast.VariableKindVariable, - Identifier: ast.Identifier{ - Identifier: "foo", - Pos: ast.Position{Offset: 48, Line: 3, Column: 25}, - }, TypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", - Pos: ast.Position{Offset: 53, Line: 3, Column: 30}, + Pos: ast.Position{ + Offset: 56, + Line: 3, + Column: 33, + }, }, }, - StartPos: ast.Position{Offset: 53, Line: 3, Column: 30}, + StartPos: ast.Position{ + Offset: 56, + Line: 3, + Column: 33, + }, + IsResource: false, + }, + DocString: "", + Identifier: ast.Identifier{ + Identifier: "foo", + Pos: ast.Position{ + Offset: 51, + Line: 3, + Column: 28, + }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 35, Line: 3, Column: 12}, - EndPos: ast.Position{Offset: 55, Line: 3, Column: 32}, + StartPos: ast.Position{ + Offset: 35, + Line: 3, + Column: 12, + }, + EndPos: ast.Position{ + Offset: 58, + Line: 3, + Column: 35, + }, }, + Access: ast.AccessAll, + VariableKind: 0x1, }, &ast.SpecialFunctionDeclaration{ - Kind: common.DeclarationKindInitializer, FunctionDeclaration: &ast.FunctionDeclaration{ - Access: ast.AccessNotSpecified, - Identifier: ast.Identifier{ - Identifier: "init", - Pos: ast.Position{Offset: 70, Line: 5, Column: 12}, - }, ParameterList: &ast.ParameterList{ Parameters: []*ast.Parameter{ { - Label: "", - Identifier: ast.Identifier{ - Identifier: "foo", - Pos: ast.Position{Offset: 75, Line: 5, Column: 17}, - }, TypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", - Pos: ast.Position{Offset: 80, Line: 5, Column: 22}, + Pos: ast.Position{ + Offset: 83, + Line: 5, + Column: 22, + }, }, }, - StartPos: ast.Position{Offset: 80, Line: 5, Column: 22}, + StartPos: ast.Position{ + Offset: 83, + Line: 5, + Column: 22, + }, + IsResource: false, + }, + Identifier: ast.Identifier{ + Identifier: "foo", + Pos: ast.Position{ + Offset: 78, + Line: 5, + Column: 17, + }, + }, + StartPos: ast.Position{ + Offset: 78, + Line: 5, + Column: 17, }, - StartPos: ast.Position{Offset: 75, Line: 5, Column: 17}, }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 74, Line: 5, Column: 16}, - EndPos: ast.Position{Offset: 83, Line: 5, Column: 25}, + StartPos: ast.Position{ + Offset: 77, + Line: 5, + Column: 16, + }, + EndPos: ast.Position{ + Offset: 86, + Line: 5, + Column: 25, + }, }, }, FunctionBlock: &ast.FunctionBlock{ @@ -5372,57 +5981,111 @@ func TestParseStructure(t *testing.T) { Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ Identifier: "self", - Pos: ast.Position{Offset: 103, Line: 6, Column: 16}, + Pos: ast.Position{ + Offset: 106, + Line: 6, + Column: 16, + }, }, }, - AccessPos: ast.Position{Offset: 107, Line: 6, Column: 20}, Identifier: ast.Identifier{ Identifier: "foo", - Pos: ast.Position{Offset: 108, Line: 6, Column: 21}, + Pos: ast.Position{ + Offset: 111, + Line: 6, + Column: 21, + }, }, + AccessPos: ast.Position{ + Offset: 110, + Line: 6, + Column: 20, + }, + Optional: false, }, Transfer: &ast.Transfer{ - Operation: ast.TransferOperationCopy, - Pos: ast.Position{Offset: 112, Line: 6, Column: 25}, + Operation: 0x1, + Pos: ast.Position{ + Offset: 115, + Line: 6, + Column: 25, + }, }, Value: &ast.IdentifierExpression{ Identifier: ast.Identifier{ Identifier: "foo", - Pos: ast.Position{Offset: 114, Line: 6, Column: 27}, + Pos: ast.Position{ + Offset: 117, + Line: 6, + Column: 27, + }, }, }, }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 85, Line: 5, Column: 27}, - EndPos: ast.Position{Offset: 130, Line: 7, Column: 12}, + StartPos: ast.Position{ + Offset: 88, + Line: 5, + Column: 27, + }, + EndPos: ast.Position{ + Offset: 133, + Line: 7, + Column: 12, + }, }, }, }, - StartPos: ast.Position{Offset: 70, Line: 5, Column: 12}, + Identifier: ast.Identifier{ + Identifier: "init", + Pos: ast.Position{ + Offset: 73, + Line: 5, + Column: 12, + }, + }, + StartPos: ast.Position{ + Offset: 73, + Line: 5, + Column: 12, + }, + Access: ast.AccessNotSpecified, }, + Kind: 0xd, }, &ast.FunctionDeclaration{ - Access: ast.AccessPublic, - Identifier: ast.Identifier{ - Identifier: "getFoo", - Pos: ast.Position{Offset: 153, Line: 9, Column: 20}, - }, ParameterList: &ast.ParameterList{ Range: ast.Range{ - StartPos: ast.Position{Offset: 159, Line: 9, Column: 26}, - EndPos: ast.Position{Offset: 160, Line: 9, Column: 27}, + StartPos: ast.Position{ + Offset: 170, + Line: 9, + Column: 34, + }, + EndPos: ast.Position{ + Offset: 171, + Line: 9, + Column: 35, + }, }, }, ReturnTypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int", - Pos: ast.Position{Offset: 163, Line: 9, Column: 30}, + Pos: ast.Position{ + Offset: 174, + Line: 9, + Column: 38, + }, }, }, - StartPos: ast.Position{Offset: 163, Line: 9, Column: 30}, + StartPos: ast.Position{ + Offset: 174, + Line: 9, + Column: 38, + }, + IsResource: false, }, FunctionBlock: &ast.FunctionBlock{ Block: &ast.Block{ @@ -5432,35 +6095,96 @@ func TestParseStructure(t *testing.T) { Expression: &ast.IdentifierExpression{ Identifier: ast.Identifier{ Identifier: "self", - Pos: ast.Position{Offset: 192, Line: 10, Column: 23}, + Pos: ast.Position{ + Offset: 203, + Line: 10, + Column: 23, + }, }, }, - AccessPos: ast.Position{Offset: 196, Line: 10, Column: 27}, Identifier: ast.Identifier{ Identifier: "foo", - Pos: ast.Position{Offset: 197, Line: 10, Column: 28}, + Pos: ast.Position{ + Offset: 208, + Line: 10, + Column: 28, + }, + }, + AccessPos: ast.Position{ + Offset: 207, + Line: 10, + Column: 27, }, + Optional: false, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 185, Line: 10, Column: 16}, - EndPos: ast.Position{Offset: 199, Line: 10, Column: 30}, + StartPos: ast.Position{ + Offset: 196, + Line: 10, + Column: 16, + }, + EndPos: ast.Position{ + Offset: 210, + Line: 10, + Column: 30, + }, }, }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 167, Line: 9, Column: 34}, - EndPos: ast.Position{Offset: 213, Line: 11, Column: 12}, + StartPos: ast.Position{ + Offset: 178, + Line: 9, + Column: 42, + }, + EndPos: ast.Position{ + Offset: 224, + Line: 11, + Column: 12, + }, }, }, }, - StartPos: ast.Position{Offset: 145, Line: 9, Column: 12}, + Identifier: ast.Identifier{ + Identifier: "getFoo", + Pos: ast.Position{ + Offset: 164, + Line: 9, + Column: 28, + }, + }, + StartPos: ast.Position{ + Offset: 148, + Line: 9, + Column: 12, + }, + Access: ast.AccessAll, + Flags: 0x00, }, }, ), + Identifier: ast.Identifier{ + Identifier: "Test", + Pos: ast.Position{ + Offset: 16, + Line: 2, + Column: 15, + }, + }, Range: ast.Range{ - StartPos: ast.Position{Offset: 9, Line: 2, Column: 8}, - EndPos: ast.Position{Offset: 223, Line: 12, Column: 8}, + StartPos: ast.Position{ + Offset: 9, + Line: 2, + Column: 8, + }, + EndPos: ast.Position{ + Offset: 234, + Line: 12, + Column: 8, + }, }, + Access: ast.AccessNotSpecified, + CompositeKind: 0x1, }, }, result.Declarations(), @@ -7264,7 +7988,7 @@ func TestParseInvalidAccessModifiers(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations("pub #test") + _, errs := testParseDeclarations("access(all) #test") utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ @@ -7280,7 +8004,7 @@ func TestParseInvalidAccessModifiers(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations("pub transaction {}") + _, errs := testParseDeclarations("access(all) transaction {}") utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ @@ -7296,12 +8020,12 @@ func TestParseInvalidAccessModifiers(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations("pub priv let x = 1") + _, errs := testParseDeclarations("access(all) access(self) let x = 1") utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid second access modifier", - Pos: ast.Position{Offset: 4, Line: 1, Column: 4}, + Pos: ast.Position{Offset: 12, Line: 1, Column: 12}, }, }, errs, @@ -7842,11 +8566,11 @@ func TestParseNestedPragma(t *testing.T) { ) }) - t.Run("pub", func(t *testing.T) { + t.Run("access(all)", func(t *testing.T) { t.Parallel() - _, errs := parse("pub #pragma", Config{}) + _, errs := parse("access(all) #pragma", Config{}) utils.AssertEqualWithDiff(t, []error{ @@ -7859,12 +8583,12 @@ func TestParseNestedPragma(t *testing.T) { ) }) - t.Run("pub static native, enabled", func(t *testing.T) { + t.Run("access(all) static native, enabled", func(t *testing.T) { t.Parallel() _, errs := parse( - "pub static native #pragma", + "access(all) static native #pragma", Config{ StaticModifierEnabled: true, NativeModifierEnabled: true, @@ -7881,17 +8605,17 @@ func TestParseNestedPragma(t *testing.T) { ) }) - t.Run("pub static native, disabled", func(t *testing.T) { + t.Run("access(all) static native, disabled", func(t *testing.T) { t.Parallel() - _, errs := parse("pub static native #pragma", Config{}) + _, errs := parse("access(all) static native #pragma", Config{}) utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected identifier", - Pos: ast.Position{Offset: 4, Line: 1, Column: 4}, + Pos: ast.Position{Offset: 12, Line: 1, Column: 12}, }, }, errs, @@ -7908,20 +8632,20 @@ func TestParseEntitlementDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations(" pub entitlement E ") + result, errs := testParseDeclarations(" access(all) entitlement E ") require.Empty(t, errs) utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.EntitlementDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, Identifier: ast.Identifier{ Identifier: "E", - Pos: ast.Position{Line: 1, Column: 17, Offset: 17}, + Pos: ast.Position{Line: 1, Column: 25, Offset: 25}, }, Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, - EndPos: ast.Position{Line: 1, Column: 17, Offset: 17}, + EndPos: ast.Position{Line: 1, Column: 25, Offset: 25}, }, }, }, @@ -7936,8 +8660,8 @@ func TestParseEntitlementDeclaration(t *testing.T) { // at static checking time, all entitlements nested inside non-contract-kinded composites // will be rejected result, errs := testParseDeclarations(` - pub contract C { - pub entitlement E + access(all) contract C { + access(all) entitlement E } `) require.Empty(t, errs) @@ -7945,31 +8669,55 @@ func TestParseEntitlementDeclaration(t *testing.T) { utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.CompositeDeclaration{ - Access: ast.AccessPublic, - CompositeKind: common.CompositeKindContract, - Identifier: ast.Identifier{ - Identifier: "C", - Pos: ast.Position{Line: 2, Column: 25, Offset: 26}, - }, - Range: ast.Range{ - StartPos: ast.Position{Line: 2, Column: 12, Offset: 13}, - EndPos: ast.Position{Line: 4, Column: 12, Offset: 77}, - }, Members: ast.NewUnmeteredMembers( []ast.Declaration{ &ast.EntitlementDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, Identifier: ast.Identifier{ Identifier: "E", - Pos: ast.Position{Line: 3, Column: 32, Offset: 63}, + Pos: ast.Position{ + Offset: 79, + Line: 3, + Column: 40, + }, }, Range: ast.Range{ - StartPos: ast.Position{Line: 3, Column: 16, Offset: 47}, - EndPos: ast.Position{Line: 3, Column: 32, Offset: 63}, + StartPos: ast.Position{ + Offset: 55, + Line: 3, + Column: 16, + }, + EndPos: ast.Position{ + Offset: 79, + Line: 3, + Column: 40, + }, }, }, }, ), + Identifier: ast.Identifier{ + Identifier: "C", + Pos: ast.Position{ + Offset: 34, + Line: 2, + Column: 33, + }, + }, + Range: ast.Range{ + StartPos: ast.Position{ + Offset: 13, + Line: 2, + Column: 12, + }, + EndPos: ast.Position{ + Offset: 93, + Line: 4, + Column: 12, + }, + }, + Access: ast.AccessAll, + CompositeKind: 0x3, }, }, result, @@ -7980,12 +8728,12 @@ func TestParseEntitlementDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(" pub entitlement") + _, errs := testParseDeclarations(" access(all) entitlement") utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected identifier, got EOF", - Pos: ast.Position{Offset: 16, Line: 1, Column: 16}, + Pos: ast.Position{Offset: 24, Line: 1, Column: 24}, }, }, errs, @@ -7996,12 +8744,12 @@ func TestParseEntitlementDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(" pub view entitlement E") + _, errs := testParseDeclarations(" access(all) view entitlement E") utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "invalid view modifier for entitlement", - Pos: ast.Position{Offset: 5, Line: 1, Column: 5}, + Pos: ast.Position{Offset: 13, Line: 1, Column: 13}, }, }, errs, @@ -8244,20 +8992,20 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations(" pub entitlement mapping M { } ") + result, errs := testParseDeclarations(" access(all) entitlement mapping M { } ") require.Empty(t, errs) utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.EntitlementMappingDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, Identifier: ast.Identifier{ Identifier: "M", - Pos: ast.Position{Line: 1, Column: 25, Offset: 25}, + Pos: ast.Position{Line: 1, Column: 33, Offset: 33}, }, Range: ast.Range{ StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, - EndPos: ast.Position{Line: 1, Column: 29, Offset: 29}, + EndPos: ast.Position{Line: 1, Column: 37, Offset: 37}, }, }, }, @@ -8269,7 +9017,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations(` pub entitlement mapping M { + result, errs := testParseDeclarations(` access(all) entitlement mapping M { A -> B C -> D } `) @@ -8278,45 +9026,73 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.EntitlementMappingDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, + DocString: "", Identifier: ast.Identifier{ Identifier: "M", - Pos: ast.Position{Line: 1, Column: 25, Offset: 25}, - }, - Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, - EndPos: ast.Position{Line: 4, Column: 2, Offset: 52}, + Pos: ast.Position{ + Offset: 33, + Line: 1, + Column: 33, + }, }, Associations: []*ast.EntitlementMapElement{ { Input: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "A", - Pos: ast.Position{Line: 2, Column: 3, Offset: 33}, + Pos: ast.Position{ + Offset: 41, + Line: 2, + Column: 3, + }, }, }, Output: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "B", - Pos: ast.Position{Line: 2, Column: 8, Offset: 38}, + Pos: ast.Position{ + Offset: 46, + Line: 2, + Column: 8, + }, }, }, - }, - { + }, { Input: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "C", - Pos: ast.Position{Line: 3, Column: 3, Offset: 43}, + Pos: ast.Position{ + Offset: 51, + Line: 3, + Column: 3, + }, }, }, Output: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "D", - Pos: ast.Position{Line: 3, Column: 8, Offset: 48}, + Pos: ast.Position{ + Offset: 56, + Line: 3, + Column: 8, + }, }, }, }, }, + Range: ast.Range{ + StartPos: ast.Position{ + Offset: 1, + Line: 1, + Column: 1, + }, + EndPos: ast.Position{ + Offset: 60, + Line: 4, + Column: 2, + }, + }, }, }, result, @@ -8327,7 +9103,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() - result, errs := testParseDeclarations(` pub entitlement mapping M { + result, errs := testParseDeclarations(` access(all) entitlement mapping M { A -> B C -> D } `) require.Empty(t, errs) @@ -8335,27 +9111,35 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.EntitlementMappingDeclaration{ - Access: ast.AccessPublic, + Access: ast.AccessAll, Identifier: ast.Identifier{ Identifier: "M", - Pos: ast.Position{Line: 1, Column: 25, Offset: 25}, - }, - Range: ast.Range{ - StartPos: ast.Position{Line: 1, Column: 1, Offset: 1}, - EndPos: ast.Position{Line: 3, Column: 2, Offset: 49}, + Pos: ast.Position{ + Offset: 33, + Line: 1, + Column: 33, + }, }, Associations: []*ast.EntitlementMapElement{ { Input: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "A", - Pos: ast.Position{Line: 2, Column: 3, Offset: 33}, + Pos: ast.Position{ + Offset: 41, + Line: 2, + Column: 3, + }, }, }, Output: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "B", - Pos: ast.Position{Line: 2, Column: 8, Offset: 38}, + Pos: ast.Position{ + Offset: 46, + Line: 2, + Column: 8, + }, }, }, }, @@ -8363,17 +9147,37 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { Input: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "C", - Pos: ast.Position{Line: 2, Column: 10, Offset: 40}, + Pos: ast.Position{ + Offset: 48, + Line: 2, + Column: 10, + }, }, }, Output: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "D", - Pos: ast.Position{Line: 2, Column: 15, Offset: 45}, + Pos: ast.Position{ + Offset: 53, + Line: 2, + Column: 15, + }, }, }, }, }, + Range: ast.Range{ + StartPos: ast.Position{ + Offset: 1, + Line: 1, + Column: 1, + }, + EndPos: ast.Position{ + Offset: 57, + Line: 3, + Column: 2, + }, + }, }, }, result, @@ -8384,12 +9188,12 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(" pub mapping M {} ") + _, errs := testParseDeclarations(" access(all) mapping M {} ") utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: identifier", - Pos: ast.Position{Offset: 5, Line: 1, Column: 5}, + Pos: ast.Position{Offset: 13, Line: 1, Column: 13}, }, }, errs, @@ -8400,12 +9204,12 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(" pub entitlement M {} ") + _, errs := testParseDeclarations(" access(all) entitlement M {} ") utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "unexpected token: '{'", - Pos: ast.Position{Offset: 19, Line: 1, Column: 19}, + Pos: ast.Position{Offset: 27, Line: 1, Column: 27}, }, }, errs, @@ -8416,12 +9220,12 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(" pub entitlement mapping M ") + _, errs := testParseDeclarations(" access(all) entitlement mapping M ") utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token '{'", - Pos: ast.Position{Offset: 27, Line: 1, Column: 27}, + Pos: ast.Position{Offset: 35, Line: 1, Column: 35}, }, }, errs, @@ -8432,12 +9236,12 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(" pub entitlement mapping M {") + _, errs := testParseDeclarations(" access(all) entitlement mapping M {") utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token '}'", - Pos: ast.Position{Offset: 28, Line: 1, Column: 28}, + Pos: ast.Position{Offset: 36, Line: 1, Column: 36}, }, }, errs, @@ -8448,12 +9252,12 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(" pub entitlement mapping M }") + _, errs := testParseDeclarations(" access(all) entitlement mapping M }") utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected token '{'", - Pos: ast.Position{Offset: 27, Line: 1, Column: 27}, + Pos: ast.Position{Offset: 35, Line: 1, Column: 35}, }, }, errs, @@ -8464,12 +9268,12 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(" pub entitlement mapping {}") + _, errs := testParseDeclarations(" access(all) entitlement mapping {}") utils.AssertEqualWithDiff(t, []error{ &SyntaxError{ Message: "expected identifier following entitlement mapping declaration, got '{'", - Pos: ast.Position{Offset: 25, Line: 1, Column: 25}, + Pos: ast.Position{Offset: 33, Line: 1, Column: 33}, }, }, errs, @@ -8480,7 +9284,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(` pub entitlement mapping M { + _, errs := testParseDeclarations(` access(all) entitlement mapping M { &A -> B } `) @@ -8488,7 +9292,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { []error{ &SyntaxError{ Message: "expected nominal type, got &A", - Pos: ast.Position{Offset: 35, Line: 2, Column: 5}, + Pos: ast.Position{Offset: 43, Line: 2, Column: 5}, }, }, errs, @@ -8499,7 +9303,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(` pub entitlement mapping M { + _, errs := testParseDeclarations(` access(all) entitlement mapping M { A -> [B] } `) @@ -8507,7 +9311,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { []error{ &SyntaxError{ Message: "expected nominal type, got [B]", - Pos: ast.Position{Offset: 41, Line: 2, Column: 11}, + Pos: ast.Position{Offset: 49, Line: 2, Column: 11}, }, }, errs, @@ -8518,7 +9322,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(` pub entitlement mapping M { + _, errs := testParseDeclarations(` access(all) entitlement mapping M { A B } `) @@ -8526,7 +9330,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { []error{ &SyntaxError{ Message: "expected token '->'", - Pos: ast.Position{Offset: 35, Line: 2, Column: 5}, + Pos: ast.Position{Offset: 43, Line: 2, Column: 5}, }, }, errs, @@ -8537,7 +9341,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { t.Parallel() - _, errs := testParseDeclarations(` pub entitlement mapping M { + _, errs := testParseDeclarations(` access(all) entitlement mapping M { A - B } `) @@ -8545,7 +9349,7 @@ func TestParseEntitlementMappingDeclaration(t *testing.T) { []error{ &SyntaxError{ Message: "expected token '->'", - Pos: ast.Position{Offset: 35, Line: 2, Column: 5}, + Pos: ast.Position{Offset: 43, Line: 2, Column: 5}, }, }, errs, @@ -8628,3 +9432,59 @@ func TestSoftKeywordsInFunctionDeclaration(t *testing.T) { testSoftKeyword(keyword) } } + +func TestParseDeprecatedAccessModifiers(t *testing.T) { + + t.Parallel() + + t.Run("pub", func(t *testing.T) { + + t.Parallel() + + _, errs := testParseDeclarations(" pub fun foo ( ) { }") + utils.AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "`pub` is no longer a valid access keyword", + Pos: ast.Position{Offset: 1, Line: 1, Column: 1}, + }, + }, + errs, + ) + + }) + + t.Run("priv", func(t *testing.T) { + + t.Parallel() + + _, errs := testParseDeclarations(" priv fun foo ( ) { }") + utils.AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "`priv` is no longer a valid access keyword", + Pos: ast.Position{Offset: 1, Line: 1, Column: 1}, + }, + }, + errs, + ) + + }) + + t.Run("pub(set)", func(t *testing.T) { + + t.Parallel() + + _, errs := testParseDeclarations(" pub(set) fun foo ( ) { }") + utils.AssertEqualWithDiff(t, + []error{ + &SyntaxError{ + Message: "`pub` is no longer a valid access keyword", + Pos: ast.Position{Offset: 1, Line: 1, Column: 1}, + }, + }, + errs, + ) + + }) +} diff --git a/runtime/parser/keyword.go b/runtime/parser/keyword.go index e42499f7f7..bb89e6a8fa 100644 --- a/runtime/parser/keyword.go +++ b/runtime/parser/keyword.go @@ -41,10 +41,7 @@ const ( KeywordIn = "in" KeywordEmit = "emit" KeywordAuth = "auth" - KeywordPriv = "priv" - KeywordPub = "pub" KeywordAccess = "access" - KeywordSet = "set" KeywordAll = "all" KeywordSelf = "self" KeywordInit = "init" @@ -76,6 +73,8 @@ const ( KeywordRequire = "require" KeywordStatic = "static" KeywordNative = "native" + KeywordPub = "pub" + KeywordPriv = "priv" // NOTE: ensure to update allKeywords when adding a new keyword ) @@ -99,10 +98,7 @@ var allKeywords = []string{ KeywordIn, KeywordEmit, KeywordAuth, - KeywordPriv, - KeywordPub, KeywordAccess, - KeywordSet, KeywordAll, KeywordSelf, KeywordInit, @@ -138,7 +134,6 @@ var allKeywords = []string{ var softKeywords = []string{ KeywordFrom, KeywordAccount, - KeywordSet, KeywordAll, KeywordView, keywordAttach, diff --git a/runtime/parser/parser_test.go b/runtime/parser/parser_test.go index 4ebb853610..7e0799e3e1 100644 --- a/runtime/parser/parser_test.go +++ b/runtime/parser/parser_test.go @@ -552,9 +552,9 @@ func TestParseBuffering(t *testing.T) { t.Parallel() src := ` - pub struct interface Y {} - pub struct X : Y {} - pub fun main():String { + access(all) struct interface Y {} + access(all) struct X : Y {} + access(all) fun main():String { fun f(a:Bool, _:String):String { return _; } let S = 1 if false { @@ -576,7 +576,7 @@ func TestParseBuffering(t *testing.T) { src := ` transaction { } - pub fun main():String { + access(all) fun main():String { let A = 1 let B = 2 let C = 3 diff --git a/runtime/parser/type_test.go b/runtime/parser/type_test.go index 18dcacd86f..eea4ad234e 100644 --- a/runtime/parser/type_test.go +++ b/runtime/parser/type_test.go @@ -1509,7 +1509,7 @@ func TestParseParametersAndArrayTypes(t *testing.T) { t.Parallel() const code = ` - pub fun test(a: Int32, b: [Int32; 2], c: [[Int32; 3]]): [[Int64]] {} + access(all) fun test(a: Int32, b: [Int32; 2], c: [[Int32; 3]]): [[Int64]] {} ` result, errs := testParseProgram(code) require.Empty(t, errs) @@ -1517,136 +1517,279 @@ func TestParseParametersAndArrayTypes(t *testing.T) { utils.AssertEqualWithDiff(t, []ast.Declaration{ &ast.FunctionDeclaration{ - Access: ast.AccessPublic, - Identifier: ast.Identifier{ - Identifier: "test", - Pos: ast.Position{Offset: 11, Line: 2, Column: 10}, - }, ParameterList: &ast.ParameterList{ Parameters: []*ast.Parameter{ { - Identifier: ast.Identifier{ - Identifier: "a", - Pos: ast.Position{Offset: 16, Line: 2, Column: 15}, - }, TypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int32", - Pos: ast.Position{Offset: 19, Line: 2, Column: 18}, + Pos: ast.Position{ + Offset: 27, + Line: 2, + Column: 26, + }, }, }, - StartPos: ast.Position{Offset: 19, Line: 2, Column: 18}, + StartPos: ast.Position{ + Offset: 27, + Line: 2, + Column: 26, + }, + IsResource: false, }, - StartPos: ast.Position{Offset: 16, Line: 2, Column: 15}, - }, - { + Label: "", Identifier: ast.Identifier{ - Identifier: "b", - Pos: ast.Position{Offset: 26, Line: 2, Column: 25}, + Identifier: "a", + Pos: ast.Position{ + Offset: 24, + Line: 2, + Column: 23, + }, + }, + StartPos: ast.Position{ + Offset: 24, + Line: 2, + Column: 23, }, + }, + { TypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.ConstantSizedType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int32", - Pos: ast.Position{Offset: 30, Line: 2, Column: 29}, + Pos: ast.Position{ + Offset: 38, + Line: 2, + Column: 37, + }, }, }, Size: &ast.IntegerExpression{ - PositiveLiteral: []byte("2"), - Value: big.NewInt(2), - Base: 10, + Value: big.NewInt(2), + PositiveLiteral: []uint8{ + 0x32, + }, Range: ast.Range{ - StartPos: ast.Position{Offset: 37, Line: 2, Column: 36}, - EndPos: ast.Position{Offset: 37, Line: 2, Column: 36}, + StartPos: ast.Position{ + Offset: 45, + Line: 2, + Column: 44, + }, + EndPos: ast.Position{ + Offset: 45, + Line: 2, + Column: 44, + }, }, + Base: 10, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 29, Line: 2, Column: 28}, - EndPos: ast.Position{Offset: 38, Line: 2, Column: 37}, + StartPos: ast.Position{ + Offset: 37, + Line: 2, + Column: 36, + }, + EndPos: ast.Position{ + Offset: 46, + Line: 2, + Column: 45, + }, }, }, - StartPos: ast.Position{Offset: 29, Line: 2, Column: 28}, + StartPos: ast.Position{ + Offset: 37, + Line: 2, + Column: 36, + }, + IsResource: false, }, - StartPos: ast.Position{Offset: 26, Line: 2, Column: 25}, - }, - { Identifier: ast.Identifier{ - Identifier: "c", - Pos: ast.Position{Offset: 41, Line: 2, Column: 40}, + Identifier: "b", + Pos: ast.Position{ + Offset: 34, + Line: 2, + Column: 33, + }, + }, + StartPos: ast.Position{ + Offset: 34, + Line: 2, + Column: 33, }, + }, + { TypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.VariableSizedType{ Type: &ast.ConstantSizedType{ Type: &ast.NominalType{ Identifier: ast.Identifier{ Identifier: "Int32", - Pos: ast.Position{Offset: 46, Line: 2, Column: 45}, + Pos: ast.Position{ + Offset: 54, + Line: 2, + Column: 53, + }, }, }, Size: &ast.IntegerExpression{ - PositiveLiteral: []byte("3"), - Value: big.NewInt(3), - Base: 10, + Value: big.NewInt(3), + PositiveLiteral: []uint8{ + 0x33, + }, Range: ast.Range{ - StartPos: ast.Position{Offset: 53, Line: 2, Column: 52}, - EndPos: ast.Position{Offset: 53, Line: 2, Column: 52}, + StartPos: ast.Position{ + Offset: 61, + Line: 2, + Column: 60, + }, + EndPos: ast.Position{ + Offset: 61, + Line: 2, + Column: 60, + }, }, + Base: 10, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 45, Line: 2, Column: 44}, - EndPos: ast.Position{Offset: 54, Line: 2, Column: 53}, + StartPos: ast.Position{ + Offset: 53, + Line: 2, + Column: 52, + }, + EndPos: ast.Position{ + Offset: 62, + Line: 2, + Column: 61, + }, }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 44, Line: 2, Column: 43}, - EndPos: ast.Position{Offset: 55, Line: 2, Column: 54}, + StartPos: ast.Position{ + Offset: 52, + Line: 2, + Column: 51, + }, + EndPos: ast.Position{ + Offset: 63, + Line: 2, + Column: 62, + }, }, }, - StartPos: ast.Position{Offset: 44, Line: 2, Column: 43}, + StartPos: ast.Position{ + Offset: 52, + Line: 2, + Column: 51, + }, + IsResource: false, + }, + Identifier: ast.Identifier{ + Identifier: "c", + Pos: ast.Position{ + Offset: 49, + Line: 2, + Column: 48, + }, + }, + StartPos: ast.Position{ + Offset: 49, + Line: 2, + Column: 48, }, - StartPos: ast.Position{Offset: 41, Line: 2, Column: 40}, }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 15, Line: 2, Column: 14}, - EndPos: ast.Position{Offset: 56, Line: 2, Column: 55}, + StartPos: ast.Position{ + Offset: 23, + Line: 2, + Column: 22, + }, + EndPos: ast.Position{ + Offset: 64, + Line: 2, + Column: 63, + }, }, }, ReturnTypeAnnotation: &ast.TypeAnnotation{ - IsResource: false, Type: &ast.VariableSizedType{ Type: &ast.VariableSizedType{ Type: &ast.NominalType{ - Identifier: ast.Identifier{Identifier: "Int64", - Pos: ast.Position{Offset: 61, Line: 2, Column: 60}, + Identifier: ast.Identifier{ + Identifier: "Int64", + Pos: ast.Position{ + Offset: 69, + Line: 2, + Column: 68, + }, }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 60, Line: 2, Column: 59}, - EndPos: ast.Position{Offset: 66, Line: 2, Column: 65}, + StartPos: ast.Position{ + Offset: 68, + Line: 2, + Column: 67, + }, + EndPos: ast.Position{ + Offset: 74, + Line: 2, + Column: 73, + }, }, }, Range: ast.Range{ - StartPos: ast.Position{Offset: 59, Line: 2, Column: 58}, - EndPos: ast.Position{Offset: 67, Line: 2, Column: 66}, + StartPos: ast.Position{ + Offset: 67, + Line: 2, + Column: 66, + }, + EndPos: ast.Position{ + Offset: 75, + Line: 2, + Column: 74, + }, }, }, - StartPos: ast.Position{Offset: 59, Line: 2, Column: 58}, + StartPos: ast.Position{ + Offset: 67, + Line: 2, + Column: 66, + }, + IsResource: false, }, FunctionBlock: &ast.FunctionBlock{ Block: &ast.Block{ Range: ast.Range{ - StartPos: ast.Position{Offset: 69, Line: 2, Column: 68}, - EndPos: ast.Position{Offset: 70, Line: 2, Column: 69}, + StartPos: ast.Position{ + Offset: 77, + Line: 2, + Column: 76, + }, + EndPos: ast.Position{ + Offset: 78, + Line: 2, + Column: 77, + }, }, }, }, - StartPos: ast.Position{Offset: 3, Line: 2, Column: 2}, + Identifier: ast.Identifier{ + Identifier: "test", + Pos: ast.Position{ + Offset: 19, + Line: 2, + Column: 18, + }, + }, + StartPos: ast.Position{ + Offset: 3, + Line: 2, + Column: 2, + }, + Access: ast.AccessAll, + Flags: 0x00, }, }, result.Declarations(), diff --git a/runtime/predeclaredvalues_test.go b/runtime/predeclaredvalues_test.go index 069838164b..6a237de985 100644 --- a/runtime/predeclaredvalues_test.go +++ b/runtime/predeclaredvalues_test.go @@ -44,8 +44,8 @@ func TestRuntimePredeclaredValues(t *testing.T) { } contract := []byte(` - pub contract C { - pub fun foo(): Int { + access(all) contract C { + access(all) fun foo(): Int { return foo } } @@ -54,7 +54,7 @@ func TestRuntimePredeclaredValues(t *testing.T) { script := []byte(` import C from 0x1 - pub fun main(): Int { + access(all) fun main(): Int { return foo + C.foo() } `) diff --git a/runtime/pretty/print_test.go b/runtime/pretty/print_test.go index 5e826282de..256ff77c75 100644 --- a/runtime/pretty/print_test.go +++ b/runtime/pretty/print_test.go @@ -40,7 +40,7 @@ func TestPrintBrokenCode(t *testing.T) { t.Parallel() - const code = `pub resource R {}` + const code = `access(all) resource R {}` lineCount := len(strings.Split(code, "\n")) location := common.StringLocation("test") diff --git a/runtime/program_params_validation_test.go b/runtime/program_params_validation_test.go index 0ba6e4e0c4..39662283c5 100644 --- a/runtime/program_params_validation_test.go +++ b/runtime/program_params_validation_test.go @@ -113,10 +113,10 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: Foo) { + access(all) fun main(arg: Foo) { } - pub struct Foo { + access(all) struct Foo { } ` @@ -128,11 +128,11 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: Foo?) { + access(all) fun main(arg: Foo?) { } - pub struct Foo { - pub var funcTypedField: fun(): Void + access(all) struct Foo { + access(all) var funcTypedField: fun(): Void init() { self.funcTypedField = fun() {} @@ -148,7 +148,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: AnyStruct?) { + access(all) fun main(arg: AnyStruct?) { } ` @@ -160,13 +160,13 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: {Bar}) { + access(all) fun main(arg: {Bar}) { } - pub struct Foo: Bar { + access(all) struct Foo: Bar { } - pub struct interface Bar { + access(all) struct interface Bar { } ` @@ -178,11 +178,11 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: {Bar}?) { + access(all) fun main(arg: {Bar}?) { } - pub struct interface Bar { - pub var funcTypedField: fun():Void + access(all) struct interface Bar { + access(all) var funcTypedField: fun():Void } ` @@ -194,11 +194,11 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: @Baz?) { + access(all) fun main(arg: @Baz?) { destroy arg } - pub resource Baz { + access(all) resource Baz { } ` @@ -210,7 +210,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: @AnyResource?) { + access(all) fun main(arg: @AnyResource?) { destroy arg } ` @@ -223,10 +223,10 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: Foo?) { + access(all) fun main(arg: Foo?) { } - pub contract Foo { + access(all) contract Foo { } ` @@ -238,7 +238,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: [String]) { + access(all) fun main(arg: [String]) { } ` @@ -255,7 +255,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: [fun():Void]) { + access(all) fun main(arg: [fun():Void]) { } ` @@ -272,7 +272,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: {String: Bool}) { + access(all) fun main(arg: {String: Bool}) { } ` @@ -289,7 +289,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: Capability<&Int>?) { + access(all) fun main(arg: Capability<&Int>?) { } ` @@ -301,7 +301,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: {String: fun():Void}) { + access(all) fun main(arg: {String: fun():Void}) { } ` @@ -324,7 +324,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := fmt.Sprintf(` - pub fun main(arg: %s?) { + access(all) fun main(arg: %s?) { } `, typString, @@ -406,7 +406,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := fmt.Sprintf(` - pub fun main(arg: %s) { + access(all) fun main(arg: %s) { }`, test.typeSignature, ) @@ -430,10 +430,10 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: AnyStruct?) { + access(all) fun main(arg: AnyStruct?) { } - pub struct Foo { - pub var nonImportableField: PublicAccount.Keys? + access(all) struct Foo { + access(all) var nonImportableField: PublicAccount.Keys? init() { self.nonImportableField = nil } @@ -448,15 +448,15 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: {Bar}?) { + access(all) fun main(arg: {Bar}?) { } - pub struct Foo: Bar { - pub var nonImportableField: PublicAccount.Keys? + access(all) struct Foo: Bar { + access(all) var nonImportableField: PublicAccount.Keys? init() { self.nonImportableField = nil } } - pub struct interface Bar { + access(all) struct interface Bar { } ` @@ -468,7 +468,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: AnyStruct) { + access(all) fun main(arg: AnyStruct) { } ` @@ -482,7 +482,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() script := ` - pub fun main(arg: [AnyStruct]) { + access(all) fun main(arg: [AnyStruct]) { } ` @@ -502,7 +502,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() err := executeScript(t, - `pub fun main(arg: HashAlgorithm) {}`, + `access(all) fun main(arg: HashAlgorithm) {}`, cadence.NewEnum( []cadence.Value{ cadence.NewUInt8(0), @@ -519,7 +519,7 @@ func TestRuntimeScriptParameterTypeValidation(t *testing.T) { t.Parallel() err := executeScript(t, - `pub fun main(arg: SignatureAlgorithm) {}`, + `access(all) fun main(arg: SignatureAlgorithm) {}`, cadence.NewEnum( []cadence.Value{ cadence.NewUInt8(0), @@ -637,8 +637,8 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { Address: common.MustBytesToAddress([]byte{0x1}), Name: "C", }: []byte(` - pub contract C { - pub struct Foo {} + access(all) contract C { + access(all) struct Foo {} } `), } @@ -661,9 +661,9 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { Address: common.MustBytesToAddress([]byte{0x1}), Name: "C", }: []byte(` - pub contract C { - pub struct Foo { - pub var funcTypedField: fun (): Void + access(all) contract C { + access(all) struct Foo { + access(all) var funcTypedField: fun (): Void init() { self.funcTypedField = fun () {} @@ -706,10 +706,10 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { Address: common.MustBytesToAddress([]byte{0x1}), Name: "C", }: []byte(` - pub contract C { - pub struct Foo: Bar {} + access(all) contract C { + access(all) struct Foo: Bar {} - pub struct interface Bar {} + access(all) struct interface Bar {} } `), } @@ -731,9 +731,9 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { Address: common.MustBytesToAddress([]byte{0x1}), Name: "C", }: []byte(` - pub contract C { - pub struct interface Bar { - pub var funcTypedField: fun (): Void + access(all) contract C { + access(all) struct interface Bar { + access(all) var funcTypedField: fun (): Void } } `), @@ -762,8 +762,8 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { Address: common.MustBytesToAddress([]byte{0x1}), Name: "C", }: []byte(` - pub contract C { - pub resource Baz {} + access(all) contract C { + access(all) resource Baz {} } `), } @@ -809,7 +809,7 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { Address: common.MustBytesToAddress([]byte{0x1}), Name: "C", }: []byte(` - pub contract C {} + access(all) contract C {} `), } script := ` @@ -1016,9 +1016,9 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { Address: common.MustBytesToAddress([]byte{0x1}), Name: "C", }: []byte(` - pub contract C { - pub struct Foo { - pub var nonImportableField: PublicAccount.Keys? + access(all) contract C { + access(all) struct Foo { + access(all) var nonImportableField: PublicAccount.Keys? init() { self.nonImportableField = nil @@ -1046,15 +1046,15 @@ func TestRuntimeTransactionParameterTypeValidation(t *testing.T) { Address: common.MustBytesToAddress([]byte{0x1}), Name: "C", }: []byte(` - pub contract C { - pub struct Foo: Bar { - pub var nonImportableField: PublicAccount.Keys? + access(all) contract C { + access(all) struct Foo: Bar { + access(all) var nonImportableField: PublicAccount.Keys? init() { self.nonImportableField = nil } } - pub struct interface Bar {} + access(all) struct interface Bar {} } `), } diff --git a/runtime/resource_duplicate_test.go b/runtime/resource_duplicate_test.go index b6cc4a1966..2c43aec4b4 100644 --- a/runtime/resource_duplicate_test.go +++ b/runtime/resource_duplicate_test.go @@ -549,13 +549,23 @@ func TestRuntimeResourceDuplicationWithContractTransfer(t *testing.T) { const holderContract = ` import FlowToken from 0x1 - pub contract Holder { + access(all) contract Holder { - pub (set) var content: @FlowToken.Vault? + access(all) var content: @FlowToken.Vault? init() { self.content <- nil } + + access(all) fun setContent(_ vault: @FlowToken.Vault?) { + self.content <-! vault + } + + access(all) fun swapContent(_ vault: @FlowToken.Vault?): @FlowToken.Vault? { + let oldVault <- self.content <- vault + return <-oldVault + } + } ` err = runtime.ExecuteTransaction( @@ -587,20 +597,20 @@ func TestRuntimeResourceDuplicationWithContractTransfer(t *testing.T) { let vault <- FlowToken.createEmptyVault() as! @FlowToken.Vault? // Move vault into the contract - Holder.content <-! vault + Holder.setContent(<-vault) // Save the contract into storage (invalid, even if same account) acct.save(Holder as AnyStruct, to: /storage/holder) // Move vault back out of the contract - let vault2 <- Holder.content <- nil + let vault2 <- Holder.swapContent(nil) let unwrappedVault2 <- vault2! // Load the contract back from storage let dupeContract = acct.load(from: /storage/holder)! as! Holder // Move the vault of of the duplicated contract - let dupeVault <- dupeContract.content <- nil + let dupeVault <- dupeContract.swapContent(nil) let unwrappedDupeVault <- dupeVault! // Deposit the duplicated vault into the original vault diff --git a/runtime/resourcedictionary_test.go b/runtime/resourcedictionary_test.go index e43d231db1..b511bceb9c 100644 --- a/runtime/resourcedictionary_test.go +++ b/runtime/resourcedictionary_test.go @@ -32,17 +32,17 @@ import ( ) const resourceDictionaryContract = ` - pub contract Test { + access(all) contract Test { - pub resource R { + access(all) resource R { - pub var value: Int + access(all) var value: Int init(_ value: Int) { self.value = value } - pub fun increment() { + access(all) fun increment() { self.value = self.value + 1 } @@ -52,34 +52,38 @@ const resourceDictionaryContract = ` } } - pub fun createR(_ value: Int): @R { + access(all) fun createR(_ value: Int): @R { return <-create R(value) } - pub resource C { + access(all) resource C { - pub(set) var rs: @{String: R} + access(all) var rs: @{String: R} init() { self.rs <- {} } - pub fun remove(_ id: String): @R { + access(all) fun remove(_ id: String): @R { let r <- self.rs.remove(key: id) ?? panic("missing") return <-r } - pub fun insert(_ id: String, _ r: @R): @R? { + access(all) fun insert(_ id: String, _ r: @R): @R? { let old <- self.rs.insert(key: id, <-r) return <- old } + access(all) fun forceInsert(_ id: String, _ r: @R) { + self.rs[id] <-! r + } + destroy() { destroy self.rs } } - pub fun createC(): @C { + access(all) fun createC(): @C { return <-create C() } } @@ -167,8 +171,8 @@ func TestRuntimeResourceDictionaryValues(t *testing.T) { prepare(signer: AuthAccount) { let c = signer.borrow<&Test.C>(from: /storage/c)! - c.rs["a"] <-! Test.createR(1) - c.rs["b"] <-! Test.createR(2) + c.forceInsert("a", <- Test.createR(1)) + c.forceInsert("b", <- Test.createR(2)) } } `) @@ -250,8 +254,8 @@ func TestRuntimeResourceDictionaryValues(t *testing.T) { prepare(signer: AuthAccount) { let c = signer.borrow<&Test.C>(from: /storage/c)! log(c.rs["b"]?.value) - let existing <- c.rs["b"] <- Test.createR(4) - destroy existing + destroy c.remove("b") + c.forceInsert("b", <- Test.createR(4)) log(c.rs["b"]?.value) } } @@ -290,8 +294,7 @@ func TestRuntimeResourceDictionaryValues(t *testing.T) { prepare(signer: AuthAccount) { let c = signer.borrow<&Test.C>(from: /storage/c)! log(c.rs["b"]?.value) - let existing <- c.rs["b"] <- nil - destroy existing + destroy c.remove("b") log(c.rs["b"]?.value) } } @@ -351,7 +354,7 @@ func TestRuntimeResourceDictionaryValues(t *testing.T) { } let c2 <- Test.createC() - c2.rs["x"] <-! Test.createR(10) + c2.forceInsert("x", <-Test.createR(10)) signer.save(<-c2, to: /storage/c) } } @@ -389,49 +392,57 @@ func TestRuntimeResourceDictionaryValues_Nested(t *testing.T) { addressValue := cadence.BytesToAddress([]byte{0xCA, 0xDE}) contract := []byte(` - pub contract Test { + access(all) contract Test { - pub resource R { + access(all) resource R { - pub var value: Int + access(all) var value: Int init(_ value: Int) { self.value = value } - pub fun increment() { + access(all) fun increment() { self.value = self.value + 1 } } - pub fun createR(_ value: Int): @R { + access(all) fun createR(_ value: Int): @R { return <-create R(value) } - pub resource C2 { + access(all) resource C2 { - pub(set) var rs: @{String: R} + access(all) var rs: @{String: R} init() { self.rs <- {} } - pub fun value(key: String): Int? { + access(all) fun value(key: String): Int? { return self.rs[key]?.value } + access(all) fun forceInsert(_ id: String, _ r: @R) { + self.rs[id] <-! r + } + destroy() { destroy self.rs } } - pub fun createC2(): @C2 { + access(all) fun createC2(): @C2 { return <-create C2() } - pub resource C { + access(all) resource C { - pub(set) var c2s: @{String: C2} + access(all) var c2s: @{String: C2} + + access(all) fun forceInsert(_ id: String, _ c: @C2) { + self.c2s[id] <-! c + } init() { self.c2s <- {} @@ -442,7 +453,7 @@ func TestRuntimeResourceDictionaryValues_Nested(t *testing.T) { } } - pub fun createC(): @C { + access(all) fun createC(): @C { return <-create C() } } @@ -524,9 +535,9 @@ func TestRuntimeResourceDictionaryValues_Nested(t *testing.T) { prepare(signer: AuthAccount) { let c = signer.borrow<&Test.C>(from: /storage/c)! let c2 <- Test.createC2() - c2.rs["a"] <-! Test.createR(1) - c2.rs["b"] <-! Test.createR(2) - c.c2s["x"] <-! c2 + c2.forceInsert("a", <- Test.createR(1)) + c2.forceInsert("b", <- Test.createR(2)) + c.forceInsert("x", <- c2) } } `) @@ -581,28 +592,32 @@ func TestRuntimeResourceDictionaryValues_DictionaryTransfer(t *testing.T) { runtime := newTestInterpreterRuntime() contract := []byte(` - pub contract Test { + access(all) contract Test { - pub resource R { + access(all) resource R { - pub var value: Int + access(all) var value: Int init(_ value: Int) { self.value = value } - pub fun increment() { + access(all) fun increment() { self.value = self.value + 1 } } - pub fun createR(_ value: Int): @R { + access(all) fun createR(_ value: Int): @R { return <-create R(value) } - pub resource C { + access(all) resource C { + + access(all) var rs: @{String: R} - pub(set) var rs: @{String: R} + access(all) fun setRs(key s: String, r: @R) { + self.rs[s] <-! r + } init() { self.rs <- {} @@ -613,7 +628,7 @@ func TestRuntimeResourceDictionaryValues_DictionaryTransfer(t *testing.T) { } } - pub fun createC(): @C { + access(all) fun createC(): @C { return <-create C() } } @@ -638,8 +653,8 @@ func TestRuntimeResourceDictionaryValues_DictionaryTransfer(t *testing.T) { prepare(signer1: AuthAccount, signer2: AuthAccount) { let c <- Test.createC() - c.rs["a"] <-! Test.createR(1) - c.rs["b"] <-! Test.createR(2) + c.setRs(key: "a", r: <- Test.createR(1)) + c.setRs(key: "b", r: <- Test.createR(2)) signer1.save(<-c, to: /storage/c) } } @@ -712,7 +727,7 @@ func TestRuntimeResourceDictionaryValues_DictionaryTransfer(t *testing.T) { prepare(signer1: AuthAccount, signer2: AuthAccount) { let c <- signer1.load<@Test.C>(from: /storage/c) ?? panic("missing C") - c.rs["x"] <-! Test.createR(42) + c.setRs(key: "x", r: <- Test.createR(42)) signer2.save(<-c, to: /storage/c2) } } @@ -749,8 +764,8 @@ func TestRuntimeResourceDictionaryValues_Removal(t *testing.T) { prepare(signer: AuthAccount) { let c <- Test.createC() - c.rs["a"] <-! Test.createR(1) - c.rs["b"] <-! Test.createR(2) + c.forceInsert("a", <- Test.createR(1)) + c.forceInsert("b", <- Test.createR(2)) signer.save(<-c, to: /storage/c) } } @@ -878,8 +893,8 @@ func TestRuntimeSResourceDictionaryValues_Destruction(t *testing.T) { prepare(signer: AuthAccount) { let c <- Test.createC() - c.rs["a"] <-! Test.createR(1) - c.rs["b"] <-! Test.createR(2) + c.forceInsert("a", <- Test.createR(1)) + c.forceInsert("b", <- Test.createR(2)) signer.save(<-c, to: /storage/c) } } @@ -992,8 +1007,8 @@ func TestRuntimeResourceDictionaryValues_Insertion(t *testing.T) { prepare(signer: AuthAccount) { let c <- Test.createC() - c.rs["a"] <-! Test.createR(1) - c.rs["b"] <-! Test.createR(2) + c.forceInsert("a", <- Test.createR(1)) + c.forceInsert("b", <- Test.createR(2)) signer.save(<-c, to: /storage/c) } } @@ -1304,11 +1319,11 @@ func BenchmarkRuntimeResourceDictionaryValues(b *testing.B) { addressValue := cadence.BytesToAddress([]byte{0xCA, 0xDE}) contract := []byte(` - pub contract Test { + access(all) contract Test { - pub resource R {} + access(all) resource R {} - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } diff --git a/runtime/rlp_test.go b/runtime/rlp_test.go index 5f4bb05a07..11cae14e66 100644 --- a/runtime/rlp_test.go +++ b/runtime/rlp_test.go @@ -38,7 +38,7 @@ func TestRLPDecodeString(t *testing.T) { script := []byte(` - pub fun main(_ data: [UInt8]): [UInt8] { + access(all) fun main(_ data: [UInt8]): [UInt8] { return RLP.decodeString(data) } `) @@ -181,7 +181,7 @@ func TestRLPDecodeList(t *testing.T) { script := []byte(` - pub fun main(_ data: [UInt8]): [[UInt8]] { + access(all) fun main(_ data: [UInt8]): [[UInt8]] { return RLP.decodeList(data) } `) diff --git a/runtime/runtime_memory_metering_test.go b/runtime/runtime_memory_metering_test.go index 196e4c0d77..96c0d43b38 100644 --- a/runtime/runtime_memory_metering_test.go +++ b/runtime/runtime_memory_metering_test.go @@ -61,9 +61,9 @@ func TestInterpreterAddressLocationMetering(t *testing.T) { t.Parallel() script := ` - pub struct S {} + access(all) struct S {} - pub fun main() { + access(all) fun main() { let s = CompositeType("A.0000000000000001.S") } ` @@ -107,10 +107,10 @@ func TestInterpreterElaborationImportMetering(t *testing.T) { t.Parallel() contracts := [...][]byte{ - []byte(`pub contract C0 {}`), - []byte(`pub contract C1 {}`), - []byte(`pub contract C2 {}`), - []byte(`pub contract C3 {}`), + []byte(`access(all) contract C0 {}`), + []byte(`access(all) contract C1 {}`), + []byte(`access(all) contract C2 {}`), + []byte(`access(all) contract C3 {}`), } importExpressions := [len(contracts)]string{} @@ -125,7 +125,7 @@ func TestInterpreterElaborationImportMetering(t *testing.T) { t.Parallel() - script := "pub fun main() {}" + script := "access(all) fun main() {}" for j := 0; j <= imports; j++ { script = importExpressions[j] + script } @@ -210,7 +210,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(a: Int) { + access(all) fun main(a: Int) { } ` meter := newTestMemoryGauge() @@ -246,7 +246,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(a: Int) { + access(all) fun main(a: Int) { } ` meter := newTestMemoryGauge() @@ -289,7 +289,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(a: Int8) { + access(all) fun main(a: Int8) { } ` meter := newTestMemoryGauge() @@ -325,7 +325,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(a: Int16) { + access(all) fun main(a: Int16) { } ` meter := newTestMemoryGauge() @@ -361,7 +361,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(a: Int32) { + access(all) fun main(a: Int32) { } ` meter := newTestMemoryGauge() @@ -397,7 +397,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(a: Int64) { + access(all) fun main(a: Int64) { } ` meter := newTestMemoryGauge() @@ -433,7 +433,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(a: Int128) { + access(all) fun main(a: Int128) { } ` meter := newTestMemoryGauge() @@ -469,7 +469,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(a: Int256) { + access(all) fun main(a: Int256) { } ` meter := newTestMemoryGauge() @@ -505,7 +505,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(): Int { + access(all) fun main(): Int { let a = Int(2) return a } @@ -540,7 +540,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(): Int { + access(all) fun main(): Int { let a = Int(1) let b = a << 64 return b @@ -576,7 +576,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(): Int8 { + access(all) fun main(): Int8 { return 12 } ` @@ -607,7 +607,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(): Int16 { + access(all) fun main(): Int16 { return 12 } ` @@ -638,7 +638,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(): Int32 { + access(all) fun main(): Int32 { return 12 } ` @@ -669,7 +669,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(): Int64 { + access(all) fun main(): Int64 { return 12 } ` @@ -700,7 +700,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(): Int128 { + access(all) fun main(): Int128 { return 12 } ` @@ -731,7 +731,7 @@ func TestCadenceValueAndTypeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(): Int256 { + access(all) fun main(): Int256 { return 12 } ` @@ -766,7 +766,7 @@ func TestLogFunctionStringConversionMetering(t *testing.T) { testMetering := func(strLiteral string) (meteredAmount, actualLen uint64) { script := fmt.Sprintf(` - pub fun main() { + access(all) fun main() { let s = "%s" log(s) } @@ -1004,7 +1004,7 @@ func TestMemoryMeteringErrors(t *testing.T) { t.Parallel() script := []byte(` - pub fun main() {} + access(all) fun main() {} `) err := executeScript(script, memoryMeter{}) @@ -1015,7 +1015,7 @@ func TestMemoryMeteringErrors(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: String) {} + access(all) fun main(x: String) {} `) err := executeScript( @@ -1032,7 +1032,7 @@ func TestMemoryMeteringErrors(t *testing.T) { t.Parallel() script := []byte(` - pub fun main() { + access(all) fun main() { 0b } `) @@ -1052,7 +1052,7 @@ func TestMemoryMeteringErrors(t *testing.T) { t.Parallel() script := []byte(` - pub fun main() { + access(all) fun main() { let x: [AnyStruct] = [] } `) @@ -1181,7 +1181,7 @@ func TestMeterEncoding(t *testing.T) { _, err := rt.ExecuteScript( Script{ Source: []byte(` - pub fun main() { + access(all) fun main() { let acc = getAuthAccount(0x02) var i = 0 var f = Foo() @@ -1192,8 +1192,8 @@ func TestMeterEncoding(t *testing.T) { } } - pub struct Foo { - priv var id: Int + access(all) struct Foo { + access(self) var id: Int init() { self.id = 123456789 } diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index e1ecb2f7af..b4a40ad00d 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -693,7 +693,7 @@ func TestRuntimeImport(t *testing.T) { runtime := newTestInterpreterRuntime() importedScript := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { return 42 } `) @@ -701,7 +701,7 @@ func TestRuntimeImport(t *testing.T) { script := []byte(` import "imported" - pub fun main(): Int { + access(all) fun main(): Int { let answer = answer() if answer != 42 { panic("?!") @@ -754,7 +754,7 @@ func TestRuntimeConcurrentImport(t *testing.T) { runtime := newTestInterpreterRuntime() importedScript := []byte(` - pub fun answer(): Int { + access(all) fun answer(): Int { return 42 } `) @@ -762,7 +762,7 @@ func TestRuntimeConcurrentImport(t *testing.T) { script := []byte(` import "imported" - pub fun main(): Int { + access(all) fun main(): Int { let answer = answer() if answer != 42 { panic("?!") @@ -1277,9 +1277,9 @@ func TestRuntimeTransactionWithArguments(t *testing.T) { Address: common.MustBytesToAddress([]byte{0x1}), Name: "C", }: []byte(` - pub contract C { - pub struct Foo { - pub var y: String + access(all) contract C { + access(all) struct Foo { + access(all) var y: String init() { self.y = "initial string" @@ -1325,9 +1325,9 @@ func TestRuntimeTransactionWithArguments(t *testing.T) { Address: common.MustBytesToAddress([]byte{0x1}), Name: "C", }: []byte(` - pub contract C { - pub struct Foo { - pub var y: String + access(all) contract C { + access(all) struct Foo { + access(all) var y: String init() { self.y = "initial string" @@ -1442,7 +1442,7 @@ func TestRuntimeScriptArguments(t *testing.T) { { name: "No arguments", script: ` - pub fun main() { + access(all) fun main() { log("t") } `, @@ -1452,7 +1452,7 @@ func TestRuntimeScriptArguments(t *testing.T) { { name: "Single argument", script: ` - pub fun main(x: Int) { + access(all) fun main(x: Int) { log(x) } `, @@ -1464,7 +1464,7 @@ func TestRuntimeScriptArguments(t *testing.T) { { name: "Multiple arguments", script: ` - pub fun main(x: Int, y: String) { + access(all) fun main(x: Int, y: String) { log(x) log(y) } @@ -1478,7 +1478,7 @@ func TestRuntimeScriptArguments(t *testing.T) { { name: "Invalid bytes", script: ` - pub fun main(x: Int) { } + access(all) fun main(x: Int) { } `, args: [][]byte{ {1, 2, 3, 4}, // not valid JSON-CDC @@ -1494,7 +1494,7 @@ func TestRuntimeScriptArguments(t *testing.T) { { name: "Type mismatch", script: ` - pub fun main(x: Int) { + access(all) fun main(x: Int) { log(x) } `, @@ -1513,7 +1513,7 @@ func TestRuntimeScriptArguments(t *testing.T) { { name: "Address", script: ` - pub fun main(x: Address) { + access(all) fun main(x: Address) { log(x) } `, @@ -1532,7 +1532,7 @@ func TestRuntimeScriptArguments(t *testing.T) { { name: "Array", script: ` - pub fun main(x: [Int]) { + access(all) fun main(x: [Int]) { log(x) } `, @@ -1552,7 +1552,7 @@ func TestRuntimeScriptArguments(t *testing.T) { { name: "Constant-sized array, too many elements", script: ` - pub fun main(x: [Int; 2]) { + access(all) fun main(x: [Int; 2]) { log(x) } `, @@ -1579,7 +1579,7 @@ func TestRuntimeScriptArguments(t *testing.T) { { name: "Constant-sized array, too few elements", script: ` - pub fun main(x: [Int; 2]) { + access(all) fun main(x: [Int; 2]) { log(x) } `, @@ -1604,7 +1604,7 @@ func TestRuntimeScriptArguments(t *testing.T) { { name: "Dictionary", script: ` - pub fun main(x: {String:Int}) { + access(all) fun main(x: {String:Int}) { log(x["y"]) } `, @@ -1625,7 +1625,7 @@ func TestRuntimeScriptArguments(t *testing.T) { { name: "Invalid dictionary", script: ` - pub fun main(x: {String:String}) { + access(all) fun main(x: {String:String}) { log(x["y"]) } `, @@ -1653,15 +1653,15 @@ func TestRuntimeScriptArguments(t *testing.T) { { name: "Struct", script: ` - pub struct Foo { - pub var y: String + access(all) struct Foo { + access(all) var y: String init() { self.y = "initial string" } } - pub fun main(x: Foo) { + access(all) fun main(x: Foo) { log(x.y) } `, @@ -1686,15 +1686,15 @@ func TestRuntimeScriptArguments(t *testing.T) { { name: "Struct in array", script: ` - pub struct Foo { - pub var y: String + access(all) struct Foo { + access(all) var y: String init() { self.y = "initial string" } } - pub fun main(f: [Foo]) { + access(all) fun main(f: [Foo]) { let x = f[0] log(x.y) } @@ -1722,7 +1722,7 @@ func TestRuntimeScriptArguments(t *testing.T) { { name: "Path subtype", script: ` - pub fun main(x: StoragePath) { + access(all) fun main(x: StoragePath) { log(x) } `, @@ -1795,7 +1795,7 @@ func TestRuntimeProgramWithNoTransaction(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub fun main() {} + access(all) fun main() {} `) runtimeInterface := &testRuntimeInterface{} @@ -1915,13 +1915,13 @@ func TestRuntimeStorage(t *testing.T) { runtime := newTestInterpreterRuntime() imported := []byte(` - pub resource R {} + access(all) resource R {} - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } - pub struct S {} + access(all) struct S {} `) script := []byte(fmt.Sprintf(` @@ -1981,15 +1981,19 @@ func TestRuntimeStorageMultipleTransactionsResourceWithArray(t *testing.T) { runtime := newTestInterpreterRuntime() container := []byte(` - pub resource Container { - pub(set) var values: [Int] + access(all) resource Container { + access(all) var values: [Int] init() { self.values = [] } + + access(all) fun appendValue(_ v: Int) { + self.values.append(v) + } } - pub fun createContainer(): @Container { + access(all) fun createContainer(): @Container { return <-create Container() } `) @@ -2016,7 +2020,7 @@ func TestRuntimeStorageMultipleTransactionsResourceWithArray(t *testing.T) { .borrow<&Container>()! let length = ref.values.length - ref.values.append(1) + ref.appendValue(1) let length2 = ref.values.length } } @@ -2033,7 +2037,7 @@ func TestRuntimeStorageMultipleTransactionsResourceWithArray(t *testing.T) { .borrow<&Container>()! let length = ref.values.length - ref.values.append(2) + ref.appendValue(2) let length2 = ref.values.length } } @@ -2104,14 +2108,14 @@ func TestRuntimeStorageMultipleTransactionsResourceFunction(t *testing.T) { runtime := newTestInterpreterRuntime() deepThought := []byte(` - pub resource DeepThought { + access(all) resource DeepThought { - pub fun answer(): Int { + access(all) fun answer(): Int { return 42 } } - pub fun createDeepThought(): @DeepThought { + access(all) fun createDeepThought(): @DeepThought { return <-create DeepThought() } `) @@ -2196,14 +2200,14 @@ func TestRuntimeStorageMultipleTransactionsResourceField(t *testing.T) { runtime := newTestInterpreterRuntime() imported := []byte(` - pub resource SomeNumber { - pub(set) var n: Int + access(all) resource SomeNumber { + access(all) var n: Int init(_ n: Int) { self.n = n } } - pub fun createNumber(_ n: Int): @SomeNumber { + access(all) fun createNumber(_ n: Int): @SomeNumber { return <-create SomeNumber(n) } `) @@ -2289,16 +2293,16 @@ func TestRuntimeCompositeFunctionInvocationFromImportingProgram(t *testing.T) { imported := []byte(` // function must have arguments - pub fun x(x: Int) {} + access(all) fun x(x: Int) {} // invocation must be in composite - pub resource Y { - pub fun x() { + access(all) resource Y { + access(all) fun x() { x(x: 1) } } - pub fun createY(): @Y { + access(all) fun createY(): @Y { return <-create Y() } `) @@ -2372,13 +2376,13 @@ func TestRuntimeResourceContractUseThroughReference(t *testing.T) { runtime := newTestInterpreterRuntime() imported := []byte(` - pub resource R { - pub fun x() { + access(all) resource R { + access(all) fun x() { log("x!") } } - pub fun createR(): @R { + access(all) fun createR(): @R { return <- create R() } `) @@ -2460,13 +2464,13 @@ func TestRuntimeResourceContractUseThroughLink(t *testing.T) { runtime := newTestInterpreterRuntime() imported := []byte(` - pub resource R { - pub fun x() { + access(all) resource R { + access(all) fun x() { log("x!") } } - pub fun createR(): @R { + access(all) fun createR(): @R { return <- create R() } `) @@ -2551,21 +2555,21 @@ func TestRuntimeResourceContractWithInterface(t *testing.T) { runtime := newTestInterpreterRuntime() imported1 := []byte(` - pub resource interface RI { - pub fun x() + access(all) resource interface RI { + access(all) fun x() } `) imported2 := []byte(` import RI from "imported1" - pub resource R: RI { - pub fun x() { + access(all) resource R: RI { + access(all) fun x() { log("x!") } } - pub fun createR(): @R { + access(all) fun createR(): @R { return <- create R() } `) @@ -2656,7 +2660,7 @@ func TestRuntimeParseAndCheckProgram(t *testing.T) { t.Run("ValidProgram", func(t *testing.T) { runtime := newTestInterpreterRuntime() - script := []byte("pub fun test(): Int { return 42 }") + script := []byte("access(all) fun test(): Int { return 42 }") runtimeInterface := &testRuntimeInterface{} nextTransactionLocation := newTransactionLocationGenerator() @@ -2692,7 +2696,7 @@ func TestRuntimeParseAndCheckProgram(t *testing.T) { t.Run("InvalidSemantics", func(t *testing.T) { runtime := newTestInterpreterRuntime() - script := []byte(`pub let a: Int = "b"`) + script := []byte(`access(all) let a: Int = "b"`) runtimeInterface := &testRuntimeInterface{} nextTransactionLocation := newTransactionLocationGenerator() @@ -2759,7 +2763,7 @@ func TestRuntimeScriptReturnSpecial(t *testing.T) { test(t, testCase{ code: ` - pub fun main(): AnyStruct { + access(all) fun main(): AnyStruct { return fun (): Int { return 0 } @@ -2783,7 +2787,7 @@ func TestRuntimeScriptReturnSpecial(t *testing.T) { test(t, testCase{ code: ` - pub fun main(): AnyStruct { + access(all) fun main(): AnyStruct { return panic } `, @@ -2813,11 +2817,11 @@ func TestRuntimeScriptReturnSpecial(t *testing.T) { test(t, testCase{ code: ` - pub struct S { - pub fun f() {} + access(all) struct S { + access(all) fun f() {} } - pub fun main(): AnyStruct { + access(all) fun main(): AnyStruct { let s = S() return s.f } @@ -2840,7 +2844,7 @@ func TestRuntimeScriptReturnSpecial(t *testing.T) { test(t, testCase{ code: ` - pub fun main(): AnyStruct { + access(all) fun main(): AnyStruct { let a: Address = 0x1 return &a as &Address } @@ -2857,7 +2861,7 @@ func TestRuntimeScriptReturnSpecial(t *testing.T) { test(t, testCase{ code: ` - pub fun main(): AnyStruct { + access(all) fun main(): AnyStruct { let refs: [&AnyStruct] = [] refs.append(&refs as &AnyStruct) return refs @@ -2890,7 +2894,7 @@ func TestRuntimeScriptParameterTypeNotImportableError(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub fun main(x: fun(): Int) { + access(all) fun main(x: fun(): Int) { return } `) @@ -2923,7 +2927,7 @@ func TestRuntimeSyntaxError(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub fun main(): String { + access(all) fun main(): String { return "Hello World! } `) @@ -2956,15 +2960,19 @@ func TestRuntimeStorageChanges(t *testing.T) { runtime := newTestInterpreterRuntime() imported := []byte(` - pub resource X { - pub(set) var x: Int + access(all) resource X { + access(all) var x: Int init() { self.x = 0 } + + access(all) fun setX(_ x: Int) { + self.x = x + } } - pub fun createX(): @X { + access(all) fun createX(): @X { return <-create X() } `) @@ -2977,7 +2985,7 @@ func TestRuntimeStorageChanges(t *testing.T) { signer.save(<-createX(), to: /storage/x) let ref = signer.borrow<&X>(from: /storage/x)! - ref.x = 1 + ref.setX(1) } } `) @@ -3138,13 +3146,13 @@ func TestRuntimeAccountPublishAndAccess(t *testing.T) { runtime := newTestInterpreterRuntime() imported := []byte(` - pub resource R { - pub fun test(): Int { + access(all) resource R { + access(all) fun test(): Int { return 42 } } - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } `) @@ -3285,8 +3293,8 @@ func TestRuntimeContractAccount(t *testing.T) { addressValue := cadence.BytesToAddress([]byte{0xCA, 0xDE}) contract := []byte(` - pub contract Test { - pub let address: Address + access(all) contract Test { + access(all) let address: Address init() { // field 'account' can be used, as it is considered initialized @@ -3296,7 +3304,7 @@ func TestRuntimeContractAccount(t *testing.T) { // test that both functions are linked back into restored composite values, // and also injected fields are injected back into restored composite values // - pub fun test(): Address { + access(all) fun test(): Address { return self.account.address } } @@ -3305,7 +3313,7 @@ func TestRuntimeContractAccount(t *testing.T) { script1 := []byte(` import Test from 0xCADE - pub fun main(): Address { + access(all) fun main(): Address { return Test.address } `) @@ -3313,7 +3321,7 @@ func TestRuntimeContractAccount(t *testing.T) { script2 := []byte(` import Test from 0xCADE - pub fun main(): Address { + access(all) fun main(): Address { return Test.test() } `) @@ -3403,25 +3411,25 @@ func TestRuntimeInvokeContractFunction(t *testing.T) { } contract := []byte(` - pub contract Test { - pub fun hello() { + access(all) contract Test { + access(all) fun hello() { log("Hello World!") } - pub fun helloArg(_ arg: String) { + access(all) fun helloArg(_ arg: String) { log("Hello ".concat(arg)) } - pub fun helloMultiArg(arg1: String, arg2: Int, arg3: Address) { + access(all) fun helloMultiArg(arg1: String, arg2: Int, arg3: Address) { log("Hello ".concat(arg1).concat(" ").concat(arg2.toString()).concat(" from ").concat(arg3.toString())) } - pub fun helloReturn(_ arg: String): String { + access(all) fun helloReturn(_ arg: String): String { log("Hello return!") return arg } - pub fun helloAuthAcc(account: AuthAccount) { + access(all) fun helloAuthAcc(account: AuthAccount) { log("Hello ".concat(account.address.toString())) } - pub fun helloPublicAcc(account: PublicAccount) { - log("Hello pub ".concat(account.address.toString())) + access(all) fun helloPublicAcc(account: PublicAccount) { + log("Hello access(all) ".concat(account.address.toString())) } } `) @@ -3713,7 +3721,7 @@ func TestRuntimeInvokeContractFunction(t *testing.T) { ) require.NoError(t, err) - assert.Equal(t, `"Hello pub 0x0000000000000001"`, loggedMessage) + assert.Equal(t, `"Hello access(all) 0x0000000000000001"`, loggedMessage) }) } @@ -3728,11 +3736,11 @@ func TestRuntimeContractNestedResource(t *testing.T) { } contract := []byte(` - pub contract Test { - pub resource R { + access(all) contract Test { + access(all) resource R { // test that the hello function is linked back into the nested resource // after being loaded from storage - pub fun hello(): String { + access(all) fun hello(): String { return "Hello World!" } } @@ -3824,8 +3832,8 @@ func TestRuntimeStorageLoadedDestructionConcreteType(t *testing.T) { } contract := []byte(` - pub contract Test { - pub resource R { + access(all) contract Test { + access(all) resource R { // test that the destructor is linked back into the nested resource // after being loaded from storage destroy() { @@ -3918,8 +3926,8 @@ func TestRuntimeStorageLoadedDestructionAnyResource(t *testing.T) { } contract := []byte(` - pub contract Test { - pub resource R { + access(all) contract Test { + access(all) resource R { // test that the destructor is linked back into the nested resource // after being loaded from storage destroy() { @@ -4014,8 +4022,8 @@ func TestRuntimeStorageLoadedDestructionAfterRemoval(t *testing.T) { } contract := []byte(` - pub contract Test { - pub resource R { + access(all) contract Test { + access(all) resource R { // test that the destructor is linked back into the nested resource // after being loaded from storage destroy() { @@ -4128,10 +4136,10 @@ func TestRuntimeStorageLoadedDestructionAfterRemoval(t *testing.T) { } const basicFungibleTokenContract = ` -pub contract FungibleToken { +access(all) contract FungibleToken { - pub resource interface Provider { - pub fun withdraw(amount: Int): @Vault { + access(all) resource interface Provider { + access(all) fun withdraw(amount: Int): @Vault { pre { amount > 0: "Withdrawal amount must be positive" @@ -4143,8 +4151,8 @@ pub contract FungibleToken { } } - pub resource interface Receiver { - pub balance: Int + access(all) resource interface Receiver { + access(all) balance: Int init(balance: Int) { pre { @@ -4157,7 +4165,7 @@ pub contract FungibleToken { } } - pub fun deposit(from: @AnyResource{Receiver}) { + access(all) fun deposit(from: @AnyResource{Receiver}) { pre { from.balance > 0: "Deposit balance needs to be positive!" @@ -4169,21 +4177,21 @@ pub contract FungibleToken { } } - pub resource Vault: Provider, Receiver { + access(all) resource Vault: Provider, Receiver { - pub var balance: Int + access(all) var balance: Int init(balance: Int) { self.balance = balance } - pub fun withdraw(amount: Int): @Vault { + access(all) fun withdraw(amount: Int): @Vault { self.balance = self.balance - amount return <-create Vault(balance: amount) } // transfer combines withdraw and deposit into one function call - pub fun transfer(to: &AnyResource{Receiver}, amount: Int) { + access(all) fun transfer(to: &AnyResource{Receiver}, amount: Int) { pre { amount <= self.balance: "Insufficient funds" @@ -4195,22 +4203,22 @@ pub contract FungibleToken { to.deposit(from: <-self.withdraw(amount: amount)) } - pub fun deposit(from: @AnyResource{Receiver}) { + access(all) fun deposit(from: @AnyResource{Receiver}) { self.balance = self.balance + from.balance destroy from } - pub fun createEmptyVault(): @Vault { + access(all) fun createEmptyVault(): @Vault { return <-create Vault(balance: 0) } } - pub fun createEmptyVault(): @Vault { + access(all) fun createEmptyVault(): @Vault { return <-create Vault(balance: 0) } - pub resource VaultMinter { - pub fun mintTokens(amount: Int, recipient: &AnyResource{Receiver}) { + access(all) resource VaultMinter { + access(all) fun mintTokens(amount: Int, recipient: &AnyResource{Receiver}) { recipient.deposit(from: <-create Vault(balance: amount)) } } @@ -4504,11 +4512,11 @@ func TestRuntimeInvokeStoredInterfaceFunction(t *testing.T) { } contractInterfaceCode := ` - pub contract interface TestContractInterface { + access(all) contract interface TestContractInterface { - pub resource interface RInterface { + access(all) resource interface RInterface { - pub fun check(a: Int, b: Int) { + access(all) fun check(a: Int, b: Int) { pre { a > 1 } post { b > 1 } } @@ -4519,17 +4527,17 @@ func TestRuntimeInvokeStoredInterfaceFunction(t *testing.T) { contractCode := ` import TestContractInterface from 0x2 - pub contract TestContract: TestContractInterface { + access(all) contract TestContract: TestContractInterface { - pub resource R: TestContractInterface.RInterface { + access(all) resource R: TestContractInterface.RInterface { - pub fun check(a: Int, b: Int) { + access(all) fun check(a: Int, b: Int) { pre { a < 3 } post { b < 3 } } } - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } @@ -4792,7 +4800,7 @@ func TestRuntimeTransactionTopLevelDeclarations(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub fun test() {} + access(all) fun test() {} transaction {} `) @@ -4821,7 +4829,7 @@ func TestRuntimeTransactionTopLevelDeclarations(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub resource R {} + access(all) resource R {} transaction {} `) @@ -4875,9 +4883,9 @@ func TestRuntimeStoreIntegerTypes(t *testing.T) { contract := []byte( fmt.Sprintf( ` - pub contract Test { + access(all) contract Test { - pub let n: %s + access(all) let n: %s init() { self.n = 42 @@ -4943,16 +4951,16 @@ func TestRuntimeResourceOwnerFieldUseComposite(t *testing.T) { } contract := []byte(` - pub contract Test { + access(all) contract Test { - pub resource R { + access(all) resource R { - pub fun logOwnerAddress() { + access(all) fun logOwnerAddress() { log(self.owner?.address) } } - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } @@ -5137,16 +5145,16 @@ func TestRuntimeResourceOwnerFieldUseArray(t *testing.T) { } contract := []byte(` - pub contract Test { + access(all) contract Test { - pub resource R { + access(all) resource R { - pub fun logOwnerAddress() { + access(all) fun logOwnerAddress() { log(self.owner?.address) } } - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } @@ -5310,16 +5318,16 @@ func TestRuntimeResourceOwnerFieldUseDictionary(t *testing.T) { } contract := []byte(` - pub contract Test { + access(all) contract Test { - pub resource R { + access(all) resource R { - pub fun logOwnerAddress() { + access(all) fun logOwnerAddress() { log(self.owner?.address) } } - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } @@ -5481,7 +5489,7 @@ func TestRuntimeMetrics(t *testing.T) { imported1Location := common.StringLocation("imported1") importedScript1 := []byte(` - pub fun generate(): [Int] { + access(all) fun generate(): [Int] { return [1, 2, 3] } `) @@ -5489,7 +5497,7 @@ func TestRuntimeMetrics(t *testing.T) { imported2Location := common.StringLocation("imported2") importedScript2 := []byte(` - pub fun getPath(): StoragePath { + access(all) fun getPath(): StoragePath { return /storage/foo } `) @@ -5652,13 +5660,17 @@ func TestRuntimeContractWriteback(t *testing.T) { addressValue := cadence.BytesToAddress([]byte{0xCA, 0xDE}) contract := []byte(` - pub contract Test { + access(all) contract Test { - pub(set) var test: Int + access(all) var test: Int init() { self.test = 1 } + + access(all) fun setTest(_ test: Int) { + self.test = test + } } `) @@ -5681,7 +5693,7 @@ func TestRuntimeContractWriteback(t *testing.T) { transaction { prepare(signer: AuthAccount) { - Test.test = 2 + Test.setTest(2) } } `) @@ -5808,19 +5820,23 @@ func TestRuntimeStorageWriteback(t *testing.T) { addressValue := cadence.BytesToAddress([]byte{0xCA, 0xDE}) contract := []byte(` - pub contract Test { + access(all) contract Test { - pub resource R { + access(all) resource R { - pub(set) var test: Int + access(all) var test: Int init() { self.test = 1 } + + access(all) fun setTest(_ test: Int) { + self.test = test + } } - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } @@ -5977,7 +5993,7 @@ func TestRuntimeStorageWriteback(t *testing.T) { prepare(signer: AuthAccount) { let r = signer.borrow<&Test.R>(from: /storage/r)! - r.test = 2 + r.setTest(2) } } `) @@ -6106,15 +6122,15 @@ func TestRuntimeDeployCodeCaching(t *testing.T) { t.Parallel() const helloWorldContract = ` - pub contract HelloWorld { + access(all) contract HelloWorld { - pub let greeting: String + access(all) let greeting: String init() { self.greeting = "Hello, World!" } - pub fun hello(): String { + access(all) fun hello(): String { return self.greeting } } @@ -6228,18 +6244,18 @@ func TestRuntimeUpdateCodeCaching(t *testing.T) { t.Parallel() const helloWorldContract1 = ` - pub contract HelloWorld { + access(all) contract HelloWorld { - pub fun hello(): String { + access(all) fun hello(): String { return "1" } } ` const helloWorldContract2 = ` - pub contract HelloWorld { + access(all) contract HelloWorld { - pub fun hello(): String { + access(all) fun hello(): String { return "2" } } @@ -6248,7 +6264,7 @@ func TestRuntimeUpdateCodeCaching(t *testing.T) { const callHelloScriptTemplate = ` import HelloWorld from 0x%s - pub fun main(): String { + access(all) fun main(): String { return HelloWorld.hello() } ` @@ -6450,15 +6466,15 @@ func TestRuntimeProgramsHitForToplevelPrograms(t *testing.T) { t.Parallel() const helloWorldContract = ` - pub contract HelloWorld { + access(all) contract HelloWorld { - pub let greeting: String + access(all) let greeting: String init() { self.greeting = "Hello, World!" } - pub fun hello(): String { + access(all) fun hello(): String { return self.greeting } } @@ -6626,24 +6642,24 @@ func TestRuntimeTransaction_ContractUpdate(t *testing.T) { runtime := newTestInterpreterRuntime() const contract1 = ` - pub contract Test { + access(all) contract Test { - pub resource R { + access(all) resource R { - pub let name: String + access(all) let name: String init(name: String) { self.name = name } - pub fun hello(): Int { + access(all) fun hello(): Int { return 1 } } - pub var rs: @{String: R} + access(all) var rs: @{String: R} - pub fun hello(): Int { + access(all) fun hello(): Int { return 1 } @@ -6655,24 +6671,24 @@ func TestRuntimeTransaction_ContractUpdate(t *testing.T) { ` const contract2 = ` - pub contract Test { + access(all) contract Test { - pub resource R { + access(all) resource R { - pub let name: String + access(all) let name: String init(name: String) { self.name = name } - pub fun hello(): Int { + access(all) fun hello(): Int { return 2 } } - pub var rs: @{String: R} + access(all) var rs: @{String: R} - pub fun hello(): Int { + access(all) fun hello(): Int { return 2 } @@ -6756,7 +6772,7 @@ func TestRuntimeTransaction_ContractUpdate(t *testing.T) { script1 := []byte(` import 0x42 - pub fun main() { + access(all) fun main() { // Check stored data assert(Test.rs.length == 1) @@ -6818,7 +6834,7 @@ func TestRuntimeTransaction_ContractUpdate(t *testing.T) { script2 := []byte(` import 0x42 - pub fun main() { + access(all) fun main() { // Existing data is still available and the same as before assert(Test.rs.length == 1) @@ -6851,7 +6867,7 @@ func TestRuntimeExecuteScriptArguments(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub fun main(num: Int) {} + access(all) fun main(num: Int) {} `) type testCase struct { @@ -6961,7 +6977,7 @@ func TestRuntimePanics(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub fun main() { + access(all) fun main() { [1][1] } `) @@ -7001,7 +7017,7 @@ func TestRuntimeGetCapability(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub fun main(): Capability { + access(all) fun main(): Capability { let dict: {Int: AuthAccount} = {} let ref = &dict as &{Int: AnyStruct} ref[0] = getAccount(0x01) as AnyStruct @@ -7036,7 +7052,7 @@ func TestRuntimeGetCapability(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub fun main(): Capability { + access(all) fun main(): Capability { let dict: {Int: AuthAccount} = {} let ref = &dict as &{Int: AnyStruct} ref[0] = getAccount(0x01) as AnyStruct @@ -7071,7 +7087,7 @@ func TestRuntimeGetCapability(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub fun main(): Capability { + access(all) fun main(): Capability { let dict: {Int: PublicAccount} = {} let ref = &dict as &{Int: AnyStruct} ref[0] = getAccount(0x01) as AnyStruct @@ -7120,9 +7136,9 @@ func TestRuntimeStackOverflow(t *testing.T) { const contract = ` - pub contract Recurse { + access(all) contract Recurse { - priv fun recurse() { + access(self) fun recurse() { self.recurse() } @@ -7198,7 +7214,7 @@ func TestRuntimeInternalErrors(t *testing.T) { t.Parallel() script := []byte(` - pub fun main() { + access(all) fun main() { log("hello") } `) @@ -7233,7 +7249,7 @@ func TestRuntimeInternalErrors(t *testing.T) { t.Parallel() script := []byte(` - pub fun main() { + access(all) fun main() { log("hello") } `) @@ -7309,8 +7325,8 @@ func TestRuntimeInternalErrors(t *testing.T) { } contract := []byte(` - pub contract Test { - pub fun hello() { + access(all) contract Test { + access(all) fun hello() { log("Hello World!") } } @@ -7384,7 +7400,7 @@ func TestRuntimeInternalErrors(t *testing.T) { t.Parallel() - script := []byte("pub fun test() {}") + script := []byte("access(all) fun test() {}") runtime := newTestInterpreterRuntime() @@ -7479,7 +7495,7 @@ func TestRuntimeInternalErrors(t *testing.T) { t.Parallel() - script := []byte(`pub fun main() {}`) + script := []byte(`access(all) fun main() {}`) runtime := newTestInterpreterRuntime() @@ -7727,7 +7743,7 @@ func BenchmarkRuntimeScriptNoop(b *testing.B) { } script := Script{ - Source: []byte("pub fun main() {}"), + Source: []byte("access(all) fun main() {}"), } environment := NewScriptInterpreterEnvironment(Config{}) @@ -7763,7 +7779,7 @@ func TestRuntimeImportTestStdlib(t *testing.T) { Source: []byte(` import Test - pub fun main() { + access(all) fun main() { Test.assert(true) } `), @@ -7794,7 +7810,7 @@ func TestRuntimeGetCurrentBlockScript(t *testing.T) { _, err := rt.ExecuteScript( Script{ Source: []byte(` - pub fun main(): AnyStruct { + access(all) fun main(): AnyStruct { return getCurrentBlock() } `), @@ -7821,8 +7837,8 @@ func TestRuntimeTypeMismatchErrorMessage(t *testing.T) { address2 := common.MustBytesToAddress([]byte{0x2}) contract := []byte(` - pub contract Foo { - pub struct Bar {} + access(all) contract Foo { + access(all) struct Bar {} } `) @@ -7911,7 +7927,7 @@ func TestRuntimeTypeMismatchErrorMessage(t *testing.T) { script := []byte(` import Foo from 0x2 - pub fun main() { + access(all) fun main() { getAuthAccount(0x1).borrow<&Foo.Bar>(from: /storage/bar) } `) @@ -7938,7 +7954,7 @@ func TestRuntimeErrorExcerpts(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main(): Int { + access(all) fun main(): Int { // fill lines so the error occurs on lines 9 and 10 // // @@ -7989,7 +8005,7 @@ func TestRuntimeErrorExcerptsMultiline(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main(): String { + access(all) fun main(): String { // fill lines so the error occurs on lines 9 and 10 // // @@ -8046,7 +8062,7 @@ func TestRuntimeAccountTypeEquality(t *testing.T) { script := []byte(` #allowAccountLinking - pub fun main(address: Address): AnyStruct { + access(all) fun main(address: Address): AnyStruct { let acct = getAuthAccount(address) let p = /private/tmp diff --git a/runtime/sema/access.go b/runtime/sema/access.go index 0ec9f1be07..af45f41028 100644 --- a/runtime/sema/access.go +++ b/runtime/sema/access.go @@ -117,7 +117,7 @@ func (e EntitlementSetAccess) Equal(other Access) bool { func (e EntitlementSetAccess) PermitsAccess(other Access) bool { switch otherAccess := other.(type) { case PrimitiveAccess: - return otherAccess == PrimitiveAccess(ast.AccessPrivate) + return otherAccess == PrimitiveAccess(ast.AccessSelf) case EntitlementSetAccess: switch otherAccess.SetKind { case Disjunction: @@ -186,7 +186,7 @@ func (e EntitlementSetAccess) PermitsAccess(other Access) bool { func (e EntitlementSetAccess) IsLessPermissiveThan(other Access) bool { switch otherAccess := other.(type) { case PrimitiveAccess: - return ast.PrimitiveAccess(otherAccess) != ast.AccessPrivate + return ast.PrimitiveAccess(otherAccess) != ast.AccessSelf case EntitlementSetAccess: // subset check returns true on equality, and we want this function to be false on equality, so invert the >= check return !e.PermitsAccess(otherAccess) @@ -240,7 +240,7 @@ func (e EntitlementMapAccess) Equal(other Access) bool { func (e EntitlementMapAccess) PermitsAccess(other Access) bool { switch otherAccess := other.(type) { case PrimitiveAccess: - return otherAccess == PrimitiveAccess(ast.AccessPrivate) + return otherAccess == PrimitiveAccess(ast.AccessSelf) case EntitlementMapAccess: return e.Type.Equal(otherAccess.Type) // if we are initializing a field that was declared with an entitlement-mapped reference type, @@ -277,7 +277,7 @@ func (e EntitlementMapAccess) PermitsAccess(other Access) bool { func (e EntitlementMapAccess) IsLessPermissiveThan(other Access) bool { switch otherAccess := other.(type) { case PrimitiveAccess: - return ast.PrimitiveAccess(otherAccess) != ast.AccessPrivate + return ast.PrimitiveAccess(otherAccess) != ast.AccessSelf case EntitlementMapAccess: // this should be false on equality return !e.Type.Equal(otherAccess.Type) @@ -417,6 +417,6 @@ func (a PrimitiveAccess) PermitsAccess(otherAccess Access) bool { if otherPrimitive, ok := otherAccess.(PrimitiveAccess); ok { return ast.PrimitiveAccess(a) >= ast.PrimitiveAccess(otherPrimitive) } - // only priv access is guaranteed to be less permissive than entitlement-based access, but cannot appear in interfaces - return ast.PrimitiveAccess(a) != ast.AccessPrivate + // only access(self) access is guaranteed to be less permissive than entitlement-based access, but cannot appear in interfaces + return ast.PrimitiveAccess(a) != ast.AccessSelf } diff --git a/runtime/sema/accesscheckmode.go b/runtime/sema/accesscheckmode.go index 32c8683641..a0bb313b6f 100644 --- a/runtime/sema/accesscheckmode.go +++ b/runtime/sema/accesscheckmode.go @@ -74,13 +74,11 @@ func (mode AccessCheckMode) IsWriteableAccess(access Access) bool { switch mode { case AccessCheckModeStrict, AccessCheckModeNotSpecifiedRestricted: - - return access.PermitsAccess(PrimitiveAccess(ast.AccessPublicSettable)) + return false case AccessCheckModeNotSpecifiedUnrestricted: - return access == PrimitiveAccess(ast.AccessNotSpecified) || - access.PermitsAccess(PrimitiveAccess(ast.AccessPublicSettable)) + return access == PrimitiveAccess(ast.AccessNotSpecified) case AccessCheckModeNone: return true diff --git a/runtime/sema/account_capability_controller.cdc b/runtime/sema/account_capability_controller.cdc index 3dae2cc270..e1813cfe0d 100644 --- a/runtime/sema/account_capability_controller.cdc +++ b/runtime/sema/account_capability_controller.cdc @@ -1,16 +1,19 @@ -pub struct AccountCapabilityController { +access(all) struct AccountCapabilityController { /// An arbitrary "tag" for the controller. /// For example, it could be used to describe the purpose of the capability. /// Empty by default. - pub(set) var tag: String + access(all) var tag: String + + /// Updates this controller's tag to the provided string + access(all) fun setTag(_ tag: String) /// The type of the controlled capability, i.e. the T in `Capability`. - pub let borrowType: Type + access(all) let borrowType: Type /// The identifier of the controlled capability. /// All copies of a capability have the same ID. - pub let capabilityID: UInt64 + access(all) let capabilityID: UInt64 /// Delete this capability controller, /// and disable the controlled capability and its copies. @@ -23,5 +26,5 @@ pub struct AccountCapabilityController { /// /// Borrowing from the controlled capability or its copies will return nil. /// - pub fun delete() + access(all) fun delete() } \ No newline at end of file diff --git a/runtime/sema/account_capability_controller.gen.go b/runtime/sema/account_capability_controller.gen.go index 8777333b82..2d2d0841a9 100644 --- a/runtime/sema/account_capability_controller.gen.go +++ b/runtime/sema/account_capability_controller.gen.go @@ -31,6 +31,25 @@ For example, it could be used to describe the purpose of the capability. Empty by default. ` +const AccountCapabilityControllerTypeSetTagFunctionName = "setTag" + +var AccountCapabilityControllerTypeSetTagFunctionType = &FunctionType{ + Parameters: []Parameter{ + { + Label: ArgumentLabelNotRequired, + Identifier: "tag", + TypeAnnotation: NewTypeAnnotation(StringType), + }, + }, + ReturnTypeAnnotation: NewTypeAnnotation( + VoidType, + ), +} + +const AccountCapabilityControllerTypeSetTagFunctionDocString = ` +Updates this controller's tag to the provided string +` + const AccountCapabilityControllerTypeBorrowTypeFieldName = "borrowType" var AccountCapabilityControllerTypeBorrowTypeFieldType = MetaType @@ -89,15 +108,22 @@ func init() { return MembersAsResolvers([]*Member{ NewUnmeteredFieldMember( t, - ast.AccessPublicSettable, + ast.AccessAll, ast.VariableKindVariable, AccountCapabilityControllerTypeTagFieldName, AccountCapabilityControllerTypeTagFieldType, AccountCapabilityControllerTypeTagFieldDocString, ), + NewUnmeteredFunctionMember( + t, + ast.AccessAll, + AccountCapabilityControllerTypeSetTagFunctionName, + AccountCapabilityControllerTypeSetTagFunctionType, + AccountCapabilityControllerTypeSetTagFunctionDocString, + ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AccountCapabilityControllerTypeBorrowTypeFieldName, AccountCapabilityControllerTypeBorrowTypeFieldType, @@ -105,7 +131,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AccountCapabilityControllerTypeCapabilityIDFieldName, AccountCapabilityControllerTypeCapabilityIDFieldType, @@ -113,7 +139,7 @@ func init() { ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, AccountCapabilityControllerTypeDeleteFunctionName, AccountCapabilityControllerTypeDeleteFunctionType, AccountCapabilityControllerTypeDeleteFunctionDocString, diff --git a/runtime/sema/authaccount.cdc b/runtime/sema/authaccount.cdc index 05b8eb1bd4..e987a4094b 100644 --- a/runtime/sema/authaccount.cdc +++ b/runtime/sema/authaccount.cdc @@ -1,41 +1,41 @@ -pub struct AuthAccount { +access(all) struct AuthAccount { /// The address of the account. - pub let address: Address + access(all) let address: Address /// The FLOW balance of the default vault of this account. - pub let balance: UFix64 + access(all) let balance: UFix64 /// The FLOW balance of the default vault of this account that is available to be moved. - pub let availableBalance: UFix64 + access(all) let availableBalance: UFix64 /// The current amount of storage used by the account in bytes. - pub let storageUsed: UInt64 + access(all) let storageUsed: UInt64 /// The storage capacity of the account in bytes. - pub let storageCapacity: UInt64 + access(all) let storageCapacity: UInt64 /// The contracts deployed to the account. - pub let contracts: AuthAccount.Contracts + access(all) let contracts: AuthAccount.Contracts /// The keys assigned to the account. - pub let keys: AuthAccount.Keys + access(all) let keys: AuthAccount.Keys /// The inbox allows bootstrapping (sending and receiving) capabilities. - pub let inbox: AuthAccount.Inbox + access(all) let inbox: AuthAccount.Inbox /// The capabilities of the account. - pub let capabilities: AuthAccount.Capabilities + access(all) let capabilities: AuthAccount.Capabilities /// All public paths of this account. - pub let publicPaths: [PublicPath] + access(all) let publicPaths: [PublicPath] /// All private paths of this account. - pub let privatePaths: [PrivatePath] + access(all) let privatePaths: [PrivatePath] /// All storage paths of this account. - pub let storagePaths: [StoragePath] + access(all) let storagePaths: [StoragePath] /// Saves the given object into the account's storage at the given path. /// @@ -44,7 +44,7 @@ pub struct AuthAccount { /// If there is already an object stored under the given path, the program aborts. /// /// The path must be a storage path, i.e., only the domain `storage` is allowed. - pub fun save(_ value: T, to: StoragePath) + access(all) fun save(_ value: T, to: StoragePath) /// Reads the type of an object from the account's storage which is stored under the given path, /// or nil if no object is stored under the given path. @@ -52,7 +52,7 @@ pub struct AuthAccount { /// If there is an object stored, the type of the object is returned without modifying the stored object. /// /// The path must be a storage path, i.e., only the domain `storage` is allowed. - pub view fun type(at path: StoragePath): Type? + access(all) view fun type(at path: StoragePath): Type? /// Loads an object from the account's storage which is stored under the given path, /// or nil if no object is stored under the given path. @@ -68,7 +68,7 @@ pub struct AuthAccount { /// The given type must not necessarily be exactly the same as the type of the loaded object. /// /// The path must be a storage path, i.e., only the domain `storage` is allowed. - pub fun load(from: StoragePath): T? + access(all) fun load(from: StoragePath): T? /// Returns a copy of a structure stored in account storage under the given path, /// without removing it from storage, @@ -83,7 +83,7 @@ pub struct AuthAccount { /// The given type must not necessarily be exactly the same as the type of the copied structure. /// /// The path must be a storage path, i.e., only the domain `storage` is allowed. - pub fun copy(from: StoragePath): T? + access(all) fun copy(from: StoragePath): T? /// Returns a reference to an object in storage without removing it from storage. /// @@ -95,15 +95,15 @@ pub struct AuthAccount { /// The given type must not necessarily be exactly the same as the type of the borrowed object. /// /// The path must be a storage path, i.e., only the domain `storage` is allowed - pub fun borrow(from: StoragePath): T? + access(all) fun borrow(from: StoragePath): T? - /// Returns true if the object in account storage under the given path satisfies the given type, + /// Returns true if the object in account storage under the given path satisfies the given type, /// i.e. could be borrowed using the given type. /// /// The given type must not necessarily be exactly the same as the type of the borrowed object. /// /// The path must be a storage path, i.e., only the domain `storage` is allowed. - pub fun check(from: StoragePath): Bool + access(all) fun check(from: StoragePath): Bool /// **DEPRECATED**: Instead, use `capabilities.storage.issue`, and `capabilities.publish` if the path is public. /// @@ -125,30 +125,30 @@ pub struct AuthAccount { /// /// The target value might be stored after the link is created, /// and the target value might be moved out after the link has been created. - pub fun link(_ newCapabilityPath: CapabilityPath, target: Path): Capability? + access(all) fun link(_ newCapabilityPath: CapabilityPath, target: Path): Capability? /// **DEPRECATED**: Use `capabilities.account.issue` instead. /// /// Creates a capability at the given public or private path which targets this account. /// /// Returns nil if a link for the given capability path already exists, or the newly created capability if not. - pub fun linkAccount(_ newCapabilityPath: PrivatePath): Capability<&AuthAccount>? + access(all) fun linkAccount(_ newCapabilityPath: PrivatePath): Capability<&AuthAccount>? /// **DEPRECATED**: Use `capabilities.get` instead. /// /// Returns the capability at the given private or public path. - pub fun getCapability(_ path: CapabilityPath): Capability + access(all) fun getCapability(_ path: CapabilityPath): Capability /// **DEPRECATED**: Use `capabilities.storage.getController` and `StorageCapabilityController.target()`. /// /// Returns the target path of the capability at the given public or private path, /// or nil if there exists no capability at the given path. - pub fun getLinkTarget(_ path: CapabilityPath): Path? + access(all) fun getLinkTarget(_ path: CapabilityPath): Path? /// **DEPRECATED**: Use `capabilities.unpublish` instead if the path is public. /// /// Removes the capability at the given public or private path. - pub fun unlink(_ path: CapabilityPath) + access(all) fun unlink(_ path: CapabilityPath) /// Iterate over all the public paths of an account, /// passing each path and type in turn to the provided callback function. @@ -166,7 +166,7 @@ pub struct AuthAccount { /// then the callback must stop iteration by returning false. /// Otherwise, iteration aborts. /// - pub fun forEachPublic(_ function: fun(PublicPath, Type): Bool) + access(all) fun forEachPublic(_ function: fun(PublicPath, Type): Bool) /// Iterate over all the private paths of an account, /// passing each path and type in turn to the provided callback function. @@ -177,13 +177,14 @@ pub struct AuthAccount { /// /// Iteration is stopped early if the callback function returns `false`. /// + /// The order of iteration is undefined. /// /// If an object is stored under a new private path, /// or an existing object is removed from a private path, /// then the callback must stop iteration by returning false. /// Otherwise, iteration aborts. - pub fun forEachPrivate(_ function: fun(PrivatePath, Type): Bool) + access(all) fun forEachPrivate(_ function: fun(PrivatePath, Type): Bool) /// Iterate over all the stored paths of an account, /// passing each path and type in turn to the provided callback function. @@ -194,16 +195,17 @@ pub struct AuthAccount { /// /// Iteration is stopped early if the callback function returns `false`. /// + /// If an object is stored under a new storage path, /// or an existing object is removed from a storage path, /// then the callback must stop iteration by returning false. /// Otherwise, iteration aborts. - pub fun forEachStored(_ function: fun(StoragePath, Type): Bool) + access(all) fun forEachStored(_ function: fun(StoragePath, Type): Bool) - pub struct Contracts { + access(all) struct Contracts { /// The names of all contracts deployed in the account. - pub let names: [String] + access(all) let names: [String] /// Adds the given contract to the account. /// @@ -219,7 +221,7 @@ pub struct AuthAccount { /// or if the given name does not match the name of the contract/contract interface declaration in the code. /// /// Returns the deployed contract. - pub fun add( + access(all) fun add( name: String, code: [UInt8] ): DeployedContract @@ -240,33 +242,33 @@ pub struct AuthAccount { /// or if the given name does not match the name of the contract/contract interface declaration in the code. /// /// Returns the deployed contract for the updated contract. - pub fun update__experimental(name: String, code: [UInt8]): DeployedContract + access(all) fun update__experimental(name: String, code: [UInt8]): DeployedContract /// Returns the deployed contract for the contract/contract interface with the given name in the account, if any. /// /// Returns nil if no contract/contract interface with the given name exists in the account. - pub fun get(name: String): DeployedContract? + access(all) fun get(name: String): DeployedContract? /// Removes the contract/contract interface from the account which has the given name, if any. /// /// Returns the removed deployed contract, if any. /// /// Returns nil if no contract/contract interface with the given name exists in the account. - pub fun remove(name: String): DeployedContract? + access(all) fun remove(name: String): DeployedContract? /// Returns a reference of the given type to the contract with the given name in the account, if any. /// /// Returns nil if no contract with the given name exists in the account, /// or if the contract does not conform to the given type. - pub fun borrow(name: String): T? + access(all) fun borrow(name: String): T? } - pub struct Keys { + access(all) struct Keys { /// Adds a new key with the given hashing algorithm and a weight. /// /// Returns the added key. - pub fun add( + access(all) fun add( publicKey: PublicKey, hashAlgorithm: HashAlgorithm, weight: UFix64 @@ -275,12 +277,12 @@ pub struct AuthAccount { /// Returns the key at the given index, if it exists, or nil otherwise. /// /// Revoked keys are always returned, but they have `isRevoked` field set to true. - pub fun get(keyIndex: Int): AccountKey? + access(all) fun get(keyIndex: Int): AccountKey? /// Marks the key at the given index revoked, but does not delete it. /// /// Returns the revoked key if it exists, or nil otherwise. - pub fun revoke(keyIndex: Int): AccountKey? + access(all) fun revoke(keyIndex: Int): AccountKey? /// Iterate over all unrevoked keys in this account, /// passing each key in turn to the provided function. @@ -288,24 +290,24 @@ pub struct AuthAccount { /// Iteration is stopped early if the function returns `false`. /// /// The order of iteration is undefined. - pub fun forEach(_ function: fun(AccountKey): Bool) + access(all) fun forEach(_ function: fun(AccountKey): Bool) /// The total number of unrevoked keys in this account. - pub let count: UInt64 + access(all) let count: UInt64 } - pub struct Inbox { + access(all) struct Inbox { /// Publishes a new Capability under the given name, /// to be claimed by the specified recipient. - pub fun publish(_ value: Capability, name: String, recipient: Address) + access(all) fun publish(_ value: Capability, name: String, recipient: Address) /// Unpublishes a Capability previously published by this account. /// /// Returns `nil` if no Capability is published under the given name. /// /// Errors if the Capability under that name does not match the provided type. - pub fun unpublish(_ name: String): Capability? + access(all) fun unpublish(_ name: String): Capability? /// Claims a Capability previously published by the specified provider. /// @@ -313,39 +315,39 @@ pub struct AuthAccount { /// or if this account is not its intended recipient. /// /// Errors if the Capability under that name does not match the provided type. - pub fun claim(_ name: String, provider: Address): Capability? + access(all) fun claim(_ name: String, provider: Address): Capability? } - pub struct Capabilities { + access(all) struct Capabilities { /// The storage capabilities of the account. - pub let storage: AuthAccount.StorageCapabilities + access(all) let storage: AuthAccount.StorageCapabilities /// The account capabilities of the account. - pub let account: AuthAccount.AccountCapabilities + access(all) let account: AuthAccount.AccountCapabilities /// Returns the capability at the given public path. /// Returns nil if the capability does not exist, /// or if the given type is not a supertype of the capability's borrow type. - pub fun get(_ path: PublicPath): Capability? + access(all) fun get(_ path: PublicPath): Capability? /// Borrows the capability at the given public path. /// Returns nil if the capability does not exist, or cannot be borrowed using the given type. /// The function is equivalent to `get(path)?.borrow()`. - pub fun borrow(_ path: PublicPath): T? + access(all) fun borrow(_ path: PublicPath): T? /// Publish the capability at the given public path. /// /// If there is already a capability published under the given path, the program aborts. /// /// The path must be a public path, i.e., only the domain `public` is allowed. - pub fun publish(_ capability: Capability, at: PublicPath) + access(all) fun publish(_ capability: Capability, at: PublicPath) /// Unpublish the capability published at the given path. /// /// Returns the capability if one was published at the path. /// Returns nil if no capability was published at the path. - pub fun unpublish(_ path: PublicPath): Capability? + access(all) fun unpublish(_ path: PublicPath): Capability? /// **DEPRECATED**: This function only exists temporarily to aid in the migration of links. /// This function will not be part of the final Capability Controller API. @@ -359,18 +361,18 @@ pub struct AuthAccount { /// /// Returns the ID of the issued capability controller, if any. /// Returns nil if migration fails. - pub fun migrateLink(_ newCapabilityPath: CapabilityPath): UInt64? + access(all) fun migrateLink(_ newCapabilityPath: CapabilityPath): UInt64? } - pub struct StorageCapabilities { + access(all) struct StorageCapabilities { /// Get the storage capability controller for the capability with the specified ID. /// /// Returns nil if the ID does not reference an existing storage capability. - pub fun getController(byCapabilityID: UInt64): &StorageCapabilityController? + access(all) fun getController(byCapabilityID: UInt64): &StorageCapabilityController? /// Get all storage capability controllers for capabilities that target this storage path - pub fun getControllers(forPath: StoragePath): [&StorageCapabilityController] + access(all) fun getControllers(forPath: StoragePath): [&StorageCapabilityController] /// Iterate over all storage capability controllers for capabilities that target this storage path, /// passing a reference to each controller to the provided callback function. @@ -382,20 +384,20 @@ pub struct AuthAccount { /// or a storage capability controller is retargeted from or to the path, /// then the callback must stop iteration by returning false. /// Otherwise, iteration aborts. - pub fun forEachController(forPath: StoragePath, _ function: fun(&StorageCapabilityController): Bool) + access(all) fun forEachController(forPath: StoragePath, _ function: fun(&StorageCapabilityController): Bool) /// Issue/create a new storage capability. - pub fun issue(_ path: StoragePath): Capability + access(all) fun issue(_ path: StoragePath): Capability } - pub struct AccountCapabilities { + access(all) struct AccountCapabilities { /// Get capability controller for capability with the specified ID. /// /// Returns nil if the ID does not reference an existing account capability. - pub fun getController(byCapabilityID: UInt64): &AccountCapabilityController? + access(all) fun getController(byCapabilityID: UInt64): &AccountCapabilityController? /// Get all capability controllers for all account capabilities. - pub fun getControllers(): [&AccountCapabilityController] + access(all) fun getControllers(): [&AccountCapabilityController] /// Iterate over all account capability controllers for all account capabilities, /// passing a reference to each controller to the provided callback function. @@ -406,9 +408,9 @@ pub struct AuthAccount { /// or an existing account capability controller for the account is deleted, /// then the callback must stop iteration by returning false. /// Otherwise, iteration aborts. - pub fun forEachController(_ function: fun(&AccountCapabilityController): Bool) + access(all) fun forEachController(_ function: fun(&AccountCapabilityController): Bool) /// Issue/create a new account capability. - pub fun issue(): Capability + access(all) fun issue(): Capability } } diff --git a/runtime/sema/authaccount.gen.go b/runtime/sema/authaccount.gen.go index 95da18ac7f..2106e5b452 100644 --- a/runtime/sema/authaccount.gen.go +++ b/runtime/sema/authaccount.gen.go @@ -841,7 +841,7 @@ func init() { var members = []*Member{ NewUnmeteredFieldMember( AuthAccountContractsType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountContractsTypeNamesFieldName, AuthAccountContractsTypeNamesFieldType, @@ -849,35 +849,35 @@ func init() { ), NewUnmeteredFunctionMember( AuthAccountContractsType, - ast.AccessPublic, + ast.AccessAll, AuthAccountContractsTypeAddFunctionName, AuthAccountContractsTypeAddFunctionType, AuthAccountContractsTypeAddFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountContractsType, - ast.AccessPublic, + ast.AccessAll, AuthAccountContractsTypeUpdate__experimentalFunctionName, AuthAccountContractsTypeUpdate__experimentalFunctionType, AuthAccountContractsTypeUpdate__experimentalFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountContractsType, - ast.AccessPublic, + ast.AccessAll, AuthAccountContractsTypeGetFunctionName, AuthAccountContractsTypeGetFunctionType, AuthAccountContractsTypeGetFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountContractsType, - ast.AccessPublic, + ast.AccessAll, AuthAccountContractsTypeRemoveFunctionName, AuthAccountContractsTypeRemoveFunctionType, AuthAccountContractsTypeRemoveFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountContractsType, - ast.AccessPublic, + ast.AccessAll, AuthAccountContractsTypeBorrowFunctionName, AuthAccountContractsTypeBorrowFunctionType, AuthAccountContractsTypeBorrowFunctionDocString, @@ -1018,35 +1018,35 @@ func init() { var members = []*Member{ NewUnmeteredFunctionMember( AuthAccountKeysType, - ast.AccessPublic, + ast.AccessAll, AuthAccountKeysTypeAddFunctionName, AuthAccountKeysTypeAddFunctionType, AuthAccountKeysTypeAddFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountKeysType, - ast.AccessPublic, + ast.AccessAll, AuthAccountKeysTypeGetFunctionName, AuthAccountKeysTypeGetFunctionType, AuthAccountKeysTypeGetFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountKeysType, - ast.AccessPublic, + ast.AccessAll, AuthAccountKeysTypeRevokeFunctionName, AuthAccountKeysTypeRevokeFunctionType, AuthAccountKeysTypeRevokeFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountKeysType, - ast.AccessPublic, + ast.AccessAll, AuthAccountKeysTypeForEachFunctionName, AuthAccountKeysTypeForEachFunctionType, AuthAccountKeysTypeForEachFunctionDocString, ), NewUnmeteredFieldMember( AuthAccountKeysType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountKeysTypeCountFieldName, AuthAccountKeysTypeCountFieldType, @@ -1190,21 +1190,21 @@ func init() { var members = []*Member{ NewUnmeteredFunctionMember( AuthAccountInboxType, - ast.AccessPublic, + ast.AccessAll, AuthAccountInboxTypePublishFunctionName, AuthAccountInboxTypePublishFunctionType, AuthAccountInboxTypePublishFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountInboxType, - ast.AccessPublic, + ast.AccessAll, AuthAccountInboxTypeUnpublishFunctionName, AuthAccountInboxTypeUnpublishFunctionType, AuthAccountInboxTypeUnpublishFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountInboxType, - ast.AccessPublic, + ast.AccessAll, AuthAccountInboxTypeClaimFunctionName, AuthAccountInboxTypeClaimFunctionType, AuthAccountInboxTypeClaimFunctionDocString, @@ -1406,7 +1406,7 @@ func init() { var members = []*Member{ NewUnmeteredFieldMember( AuthAccountCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountCapabilitiesTypeStorageFieldName, AuthAccountCapabilitiesTypeStorageFieldType, @@ -1414,7 +1414,7 @@ func init() { ), NewUnmeteredFieldMember( AuthAccountCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountCapabilitiesTypeAccountFieldName, AuthAccountCapabilitiesTypeAccountFieldType, @@ -1422,35 +1422,35 @@ func init() { ), NewUnmeteredFunctionMember( AuthAccountCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, AuthAccountCapabilitiesTypeGetFunctionName, AuthAccountCapabilitiesTypeGetFunctionType, AuthAccountCapabilitiesTypeGetFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, AuthAccountCapabilitiesTypeBorrowFunctionName, AuthAccountCapabilitiesTypeBorrowFunctionType, AuthAccountCapabilitiesTypeBorrowFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, AuthAccountCapabilitiesTypePublishFunctionName, AuthAccountCapabilitiesTypePublishFunctionType, AuthAccountCapabilitiesTypePublishFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, AuthAccountCapabilitiesTypeUnpublishFunctionName, AuthAccountCapabilitiesTypeUnpublishFunctionType, AuthAccountCapabilitiesTypeUnpublishFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, AuthAccountCapabilitiesTypeMigrateLinkFunctionName, AuthAccountCapabilitiesTypeMigrateLinkFunctionType, AuthAccountCapabilitiesTypeMigrateLinkFunctionDocString, @@ -1605,28 +1605,28 @@ func init() { var members = []*Member{ NewUnmeteredFunctionMember( AuthAccountStorageCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, AuthAccountStorageCapabilitiesTypeGetControllerFunctionName, AuthAccountStorageCapabilitiesTypeGetControllerFunctionType, AuthAccountStorageCapabilitiesTypeGetControllerFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountStorageCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, AuthAccountStorageCapabilitiesTypeGetControllersFunctionName, AuthAccountStorageCapabilitiesTypeGetControllersFunctionType, AuthAccountStorageCapabilitiesTypeGetControllersFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountStorageCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, AuthAccountStorageCapabilitiesTypeForEachControllerFunctionName, AuthAccountStorageCapabilitiesTypeForEachControllerFunctionType, AuthAccountStorageCapabilitiesTypeForEachControllerFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountStorageCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, AuthAccountStorageCapabilitiesTypeIssueFunctionName, AuthAccountStorageCapabilitiesTypeIssueFunctionType, AuthAccountStorageCapabilitiesTypeIssueFunctionDocString, @@ -1765,28 +1765,28 @@ func init() { var members = []*Member{ NewUnmeteredFunctionMember( AuthAccountAccountCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, AuthAccountAccountCapabilitiesTypeGetControllerFunctionName, AuthAccountAccountCapabilitiesTypeGetControllerFunctionType, AuthAccountAccountCapabilitiesTypeGetControllerFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountAccountCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, AuthAccountAccountCapabilitiesTypeGetControllersFunctionName, AuthAccountAccountCapabilitiesTypeGetControllersFunctionType, AuthAccountAccountCapabilitiesTypeGetControllersFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountAccountCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, AuthAccountAccountCapabilitiesTypeForEachControllerFunctionName, AuthAccountAccountCapabilitiesTypeForEachControllerFunctionType, AuthAccountAccountCapabilitiesTypeForEachControllerFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountAccountCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, AuthAccountAccountCapabilitiesTypeIssueFunctionName, AuthAccountAccountCapabilitiesTypeIssueFunctionType, AuthAccountAccountCapabilitiesTypeIssueFunctionDocString, @@ -1820,7 +1820,7 @@ func init() { var members = []*Member{ NewUnmeteredFieldMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountTypeAddressFieldName, AuthAccountTypeAddressFieldType, @@ -1828,7 +1828,7 @@ func init() { ), NewUnmeteredFieldMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountTypeBalanceFieldName, AuthAccountTypeBalanceFieldType, @@ -1836,7 +1836,7 @@ func init() { ), NewUnmeteredFieldMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountTypeAvailableBalanceFieldName, AuthAccountTypeAvailableBalanceFieldType, @@ -1844,7 +1844,7 @@ func init() { ), NewUnmeteredFieldMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountTypeStorageUsedFieldName, AuthAccountTypeStorageUsedFieldType, @@ -1852,7 +1852,7 @@ func init() { ), NewUnmeteredFieldMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountTypeStorageCapacityFieldName, AuthAccountTypeStorageCapacityFieldType, @@ -1860,7 +1860,7 @@ func init() { ), NewUnmeteredFieldMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountTypeContractsFieldName, AuthAccountTypeContractsFieldType, @@ -1868,7 +1868,7 @@ func init() { ), NewUnmeteredFieldMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountTypeKeysFieldName, AuthAccountTypeKeysFieldType, @@ -1876,7 +1876,7 @@ func init() { ), NewUnmeteredFieldMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountTypeInboxFieldName, AuthAccountTypeInboxFieldType, @@ -1884,7 +1884,7 @@ func init() { ), NewUnmeteredFieldMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountTypeCapabilitiesFieldName, AuthAccountTypeCapabilitiesFieldType, @@ -1892,7 +1892,7 @@ func init() { ), NewUnmeteredFieldMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountTypePublicPathsFieldName, AuthAccountTypePublicPathsFieldType, @@ -1900,7 +1900,7 @@ func init() { ), NewUnmeteredFieldMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountTypePrivatePathsFieldName, AuthAccountTypePrivatePathsFieldType, @@ -1908,7 +1908,7 @@ func init() { ), NewUnmeteredFieldMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, AuthAccountTypeStoragePathsFieldName, AuthAccountTypeStoragePathsFieldType, @@ -1916,98 +1916,98 @@ func init() { ), NewUnmeteredFunctionMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, AuthAccountTypeSaveFunctionName, AuthAccountTypeSaveFunctionType, AuthAccountTypeSaveFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, AuthAccountTypeTypeFunctionName, AuthAccountTypeTypeFunctionType, AuthAccountTypeTypeFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, AuthAccountTypeLoadFunctionName, AuthAccountTypeLoadFunctionType, AuthAccountTypeLoadFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, AuthAccountTypeCopyFunctionName, AuthAccountTypeCopyFunctionType, AuthAccountTypeCopyFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, AuthAccountTypeBorrowFunctionName, AuthAccountTypeBorrowFunctionType, AuthAccountTypeBorrowFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, AuthAccountTypeCheckFunctionName, AuthAccountTypeCheckFunctionType, AuthAccountTypeCheckFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, AuthAccountTypeLinkFunctionName, AuthAccountTypeLinkFunctionType, AuthAccountTypeLinkFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, AuthAccountTypeLinkAccountFunctionName, AuthAccountTypeLinkAccountFunctionType, AuthAccountTypeLinkAccountFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, AuthAccountTypeGetCapabilityFunctionName, AuthAccountTypeGetCapabilityFunctionType, AuthAccountTypeGetCapabilityFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, AuthAccountTypeGetLinkTargetFunctionName, AuthAccountTypeGetLinkTargetFunctionType, AuthAccountTypeGetLinkTargetFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, AuthAccountTypeUnlinkFunctionName, AuthAccountTypeUnlinkFunctionType, AuthAccountTypeUnlinkFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, AuthAccountTypeForEachPublicFunctionName, AuthAccountTypeForEachPublicFunctionType, AuthAccountTypeForEachPublicFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, AuthAccountTypeForEachPrivateFunctionName, AuthAccountTypeForEachPrivateFunctionType, AuthAccountTypeForEachPrivateFunctionDocString, ), NewUnmeteredFunctionMember( AuthAccountType, - ast.AccessPublic, + ast.AccessAll, AuthAccountTypeForEachStoredFunctionName, AuthAccountTypeForEachStoredFunctionType, AuthAccountTypeForEachStoredFunctionDocString, diff --git a/runtime/sema/block.cdc b/runtime/sema/block.cdc index 0e1eb2232e..df8562d954 100644 --- a/runtime/sema/block.cdc +++ b/runtime/sema/block.cdc @@ -1,19 +1,19 @@ -pub struct Block { +access(all) struct Block { /// The height of the block. /// /// If the blockchain is viewed as a tree with the genesis block at the root, /// the height of a node is the number of edges between the node and the genesis block /// - pub let height: UInt64 + access(all) let height: UInt64 /// The view of the block. /// /// It is a detail of the consensus algorithm. It is a monotonically increasing integer and counts rounds in the consensus algorithm. /// Since not all rounds result in a finalized block, the view number is strictly greater than or equal to the block height /// - pub let view: UInt64 + access(all) let view: UInt64 /// The timestamp of the block. /// @@ -23,9 +23,9 @@ pub struct Block { // from the true time the block was published. /// Consider observing blocks' status changes off-chain yourself to get a more reliable value. /// - pub let timestamp: UFix64 + access(all) let timestamp: UFix64 /// The ID of the block. /// It is essentially the hash of the block - pub let id: [UInt8; 32] + access(all) let id: [UInt8; 32] } diff --git a/runtime/sema/block.gen.go b/runtime/sema/block.gen.go index 8933b7adfa..0e1b5d11cb 100644 --- a/runtime/sema/block.gen.go +++ b/runtime/sema/block.gen.go @@ -83,7 +83,7 @@ func init() { return MembersAsResolvers([]*Member{ NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, BlockTypeHeightFieldName, BlockTypeHeightFieldType, @@ -91,7 +91,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, BlockTypeViewFieldName, BlockTypeViewFieldType, @@ -99,7 +99,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, BlockTypeTimestampFieldName, BlockTypeTimestampFieldType, @@ -107,7 +107,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, BlockTypeIdFieldName, BlockTypeIdFieldType, diff --git a/runtime/sema/character.cdc b/runtime/sema/character.cdc index 2f845b5d4c..86c9a68e04 100644 --- a/runtime/sema/character.cdc +++ b/runtime/sema/character.cdc @@ -1,6 +1,6 @@ -pub struct Character: Storable, Equatable, Comparable, Exportable, Importable { +access(all) struct Character: Storable, Equatable, Comparable, Exportable, Importable { /// Returns this character as a String - pub fun toString(): String + access(all) fun toString(): String } diff --git a/runtime/sema/character.gen.go b/runtime/sema/character.gen.go index bcd0fc9696..c2e2370a15 100644 --- a/runtime/sema/character.gen.go +++ b/runtime/sema/character.gen.go @@ -53,7 +53,7 @@ func init() { return MembersAsResolvers([]*Member{ NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, CharacterTypeToStringFunctionName, CharacterTypeToStringFunctionType, CharacterTypeToStringFunctionDocString, diff --git a/runtime/sema/check_assignment.go b/runtime/sema/check_assignment.go index c2c854a465..8d278a9207 100644 --- a/runtime/sema/check_assignment.go +++ b/runtime/sema/check_assignment.go @@ -122,8 +122,8 @@ func (checker *Checker) checkAssignment( // to a resource; because resources are moved instead of copied, we cannot currently // track the origin of a write target when it is a resource. Consider: // -// pub resource R { -// pub(set) var x: Int +// access(all) resource R { +// access(all) var x: Int // init(x: Int) { // self.x = x // } @@ -364,6 +364,7 @@ func (checker *Checker) visitMemberExpressionAssignment( checker.report( &InvalidAssignmentAccessError{ Name: member.Identifier.Identifier, + ContainerType: member.ContainerType, RestrictingAccess: member.Access, DeclarationKind: member.DeclarationKind, Range: ast.NewRangeFromPositioned(checker.memoryGauge, target.Identifier), diff --git a/runtime/sema/check_composite_declaration.go b/runtime/sema/check_composite_declaration.go index 2d9a6fef36..15b1630e1c 100644 --- a/runtime/sema/check_composite_declaration.go +++ b/runtime/sema/check_composite_declaration.go @@ -1067,7 +1067,7 @@ func (checker *Checker) declareContractValue( ty: compositeType, docString: declaration.DocString, // NOTE: contracts are always public - access: PrimitiveAccess(ast.AccessPublic), + access: PrimitiveAccess(ast.AccessAll), kind: common.DeclarationKindContract, pos: declaration.Identifier.Pos, isConstant: true, @@ -1112,7 +1112,7 @@ func (checker *Checker) declareEnumConstructor( &Member{ ContainerType: constructorType, // enum cases are always public - Access: PrimitiveAccess(ast.AccessPublic), + Access: PrimitiveAccess(ast.AccessAll), Identifier: enumCase.Identifier, TypeAnnotation: memberCaseTypeAnnotation, DeclarationKind: common.DeclarationKindField, @@ -1139,7 +1139,7 @@ func (checker *Checker) declareEnumConstructor( ty: constructorType, docString: declaration.DocString, // NOTE: enums are always public - access: PrimitiveAccess(ast.AccessPublic), + access: PrimitiveAccess(ast.AccessAll), kind: common.DeclarationKindEnum, pos: declaration.Identifier.Pos, isConstant: true, @@ -1961,7 +1961,7 @@ func (checker *Checker) defaultMembersAndOrigins( effectiveAccess := checker.effectiveMemberAccess(fieldAccess, containerKind) if requireNonPrivateMemberAccess && - effectiveAccess.Equal(PrimitiveAccess(ast.AccessPrivate)) { + effectiveAccess.Equal(PrimitiveAccess(ast.AccessSelf)) { checker.report( &InvalidAccessModifierError{ @@ -2037,7 +2037,7 @@ func (checker *Checker) defaultMembersAndOrigins( effectiveAccess := checker.effectiveMemberAccess(functionAccess, containerKind) if requireNonPrivateMemberAccess && - effectiveAccess.Equal(PrimitiveAccess(ast.AccessPrivate)) { + effectiveAccess.Equal(PrimitiveAccess(ast.AccessSelf)) { checker.report( &InvalidAccessModifierError{ @@ -2100,7 +2100,7 @@ func (checker *Checker) eventMembersAndOrigins( identifier.Identifier, &Member{ ContainerType: containerType, - Access: PrimitiveAccess(ast.AccessPublic), + Access: PrimitiveAccess(ast.AccessAll), Identifier: identifier, DeclarationKind: common.DeclarationKindField, TypeAnnotation: typeAnnotation, @@ -2152,7 +2152,7 @@ func (checker *Checker) enumMembersAndOrigins( // Enum cases must be effectively public enumAccess := checker.accessFromAstAccess(enumCase.Access) - if !checker.effectiveCompositeMemberAccess(enumAccess).Equal(PrimitiveAccess(ast.AccessPublic)) { + if !checker.effectiveCompositeMemberAccess(enumAccess).Equal(PrimitiveAccess(ast.AccessAll)) { checker.report( &InvalidAccessModifierError{ DeclarationKind: enumCase.DeclarationKind(), @@ -2173,7 +2173,7 @@ func (checker *Checker) enumMembersAndOrigins( EnumRawValueFieldName, &Member{ ContainerType: containerType, - Access: PrimitiveAccess(ast.AccessPublic), + Access: PrimitiveAccess(ast.AccessAll), Identifier: ast.NewIdentifier( checker.memoryGauge, EnumRawValueFieldName, @@ -2402,7 +2402,7 @@ func (checker *Checker) declareLowerScopedValue( variable := &Variable{ Identifier: identifier, - Access: PrimitiveAccess(ast.AccessPublic), + Access: PrimitiveAccess(ast.AccessAll), DeclarationKind: kind, Type: ty, IsConstant: true, @@ -2445,9 +2445,9 @@ func (checker *Checker) declareBaseValue(baseType Type, attachmentType *Composit // ------------------------------- // entitlement E // entitlement F - // pub attachment A for R { + // access(all) attachment A for R { // require entitlement E - // pub fun foo() { ... } + // access(all) fun foo() { ... } // } // ------------------------------- // within the body of `foo`, the `base` value will be entitled to `E` but not `F`, because only `E` was required in the attachment's declaration diff --git a/runtime/sema/check_function.go b/runtime/sema/check_function.go index 0b41506ab7..456f02cc95 100644 --- a/runtime/sema/check_function.go +++ b/runtime/sema/check_function.go @@ -316,7 +316,7 @@ func (checker *Checker) declareParameters( variable := &Variable{ Identifier: identifier.Identifier, - Access: PrimitiveAccess(ast.AccessPublic), + Access: PrimitiveAccess(ast.AccessAll), DeclarationKind: common.DeclarationKindParameter, IsConstant: true, Type: parameterType, diff --git a/runtime/sema/check_import_declaration.go b/runtime/sema/check_import_declaration.go index 912c0dbf74..91253db06c 100644 --- a/runtime/sema/check_import_declaration.go +++ b/runtime/sema/check_import_declaration.go @@ -246,7 +246,7 @@ func (checker *Checker) handleMissingImports(missing []ast.Identifier, available ) // NOTE: declare constant variable with invalid type to silence rest of program - const access = PrimitiveAccess(ast.AccessPrivate) + const access = PrimitiveAccess(ast.AccessSelf) _, err := checker.valueActivations.declare(variableDeclaration{ identifier: identifier.Identifier, diff --git a/runtime/sema/checker.go b/runtime/sema/checker.go index 4daae78b97..4b5972510a 100644 --- a/runtime/sema/checker.go +++ b/runtime/sema/checker.go @@ -1817,30 +1817,7 @@ func (checker *Checker) checkDeclarationAccessModifier( switch access := access.(type) { case PrimitiveAccess: switch ast.PrimitiveAccess(access) { - case ast.AccessPublicSettable: - // Public settable access for a constant is not sensible - // and type declarations must be public for now - - if isConstant || isTypeDeclaration { - var explanation string - switch { - case isConstant: - explanation = "constants can never be set" - case isTypeDeclaration: - explanation = invalidTypeDeclarationAccessModifierExplanation - } - - checker.report( - &InvalidAccessModifierError{ - Access: access, - Explanation: explanation, - DeclarationKind: declarationKind, - Pos: startPos, - }, - ) - } - - case ast.AccessPrivate: + case ast.AccessSelf: // Type declarations must be public for now if isTypeDeclaration { @@ -2158,7 +2135,7 @@ func (checker *Checker) predeclaredMembers(containerType Type) []*Member { IsInstanceFunctionName, IsInstanceFunctionType, common.DeclarationKindFunction, - ast.AccessPublic, + ast.AccessAll, true, isInstanceFunctionDocString, ) @@ -2169,7 +2146,7 @@ func (checker *Checker) predeclaredMembers(containerType Type) []*Member { GetTypeFunctionName, GetTypeFunctionType, common.DeclarationKindFunction, - ast.AccessPublic, + ast.AccessAll, true, getTypeFunctionDocString, ) @@ -2180,14 +2157,14 @@ func (checker *Checker) predeclaredMembers(containerType Type) []*Member { case common.CompositeKindContract: // All contracts have a predeclared member - // `priv let account: AuthAccount`, + // `access(self) let account: AuthAccount`, // which is ignored in serialization addPredeclaredMember( ContractAccountFieldName, AuthAccountType, common.DeclarationKindField, - ast.AccessPrivate, + ast.AccessSelf, true, contractAccountFieldDocString, ) @@ -2196,7 +2173,7 @@ func (checker *Checker) predeclaredMembers(containerType Type) []*Member { // All resources have two predeclared fields: - // `pub let owner: PublicAccount?`, + // `access(all) let owner: PublicAccount?`, // ignored in serialization addPredeclaredMember( @@ -2205,19 +2182,19 @@ func (checker *Checker) predeclaredMembers(containerType Type) []*Member { Type: PublicAccountType, }, common.DeclarationKindField, - ast.AccessPublic, + ast.AccessAll, true, resourceOwnerFieldDocString, ) - // `pub let uuid: UInt64`, + // `access(all) let uuid: UInt64`, // included in serialization addPredeclaredMember( ResourceUUIDFieldName, UInt64Type, common.DeclarationKindField, - ast.AccessPublic, + ast.AccessAll, false, resourceUUIDFieldDocString, ) @@ -2228,7 +2205,7 @@ func (checker *Checker) predeclaredMembers(containerType Type) []*Member { CompositeForEachAttachmentFunctionName, CompositeForEachAttachmentFunctionType(compositeKindedType.GetCompositeKind()), common.DeclarationKindFunction, - ast.AccessPublic, + ast.AccessAll, true, compositeForEachAttachmentFunctionDocString, ) @@ -2411,7 +2388,7 @@ func (checker *Checker) effectiveMemberAccess(access Access, containerKind Conta func (checker *Checker) effectiveInterfaceMemberAccess(access Access) Access { if access.Equal(PrimitiveAccess(ast.AccessNotSpecified)) { - return PrimitiveAccess(ast.AccessPublic) + return PrimitiveAccess(ast.AccessAll) } else { return access } @@ -2424,10 +2401,10 @@ func (checker *Checker) effectiveCompositeMemberAccess(access Access) Access { switch checker.Config.AccessCheckMode { case AccessCheckModeStrict, AccessCheckModeNotSpecifiedRestricted: - return PrimitiveAccess(ast.AccessPrivate) + return PrimitiveAccess(ast.AccessSelf) case AccessCheckModeNotSpecifiedUnrestricted, AccessCheckModeNone: - return PrimitiveAccess(ast.AccessPublic) + return PrimitiveAccess(ast.AccessAll) default: panic(errors.NewUnreachableError()) diff --git a/runtime/sema/deployedcontract.cdc b/runtime/sema/deployedcontract.cdc index ba9553c197..61f2195aa8 100644 --- a/runtime/sema/deployedcontract.cdc +++ b/runtime/sema/deployedcontract.cdc @@ -1,13 +1,13 @@ -pub struct DeployedContract { +access(all) struct DeployedContract { /// The address of the account where the contract is deployed at. - pub let address: Address + access(all) let address: Address /// The name of the contract. - pub let name: String + access(all) let name: String /// The code of the contract. - pub let code: [UInt8] + access(all) let code: [UInt8] /// Returns an array of `Type` objects representing all the public type declarations in this contract /// (e.g. structs, resources, enums). @@ -15,10 +15,10 @@ pub struct DeployedContract { /// For example, given a contract /// ``` /// contract Foo { - /// pub struct Bar {...} - /// pub resource Qux {...} + /// access(all) struct Bar {...} + /// access(all) resource Qux {...} /// } /// ``` /// then `.publicTypes()` will return an array equivalent to the expression `[Type(), Type()]` - pub fun publicTypes(): [Type] + access(all) fun publicTypes(): [Type] } diff --git a/runtime/sema/deployedcontract.gen.go b/runtime/sema/deployedcontract.gen.go index a335aa3ae5..87b3883b84 100644 --- a/runtime/sema/deployedcontract.gen.go +++ b/runtime/sema/deployedcontract.gen.go @@ -64,8 +64,8 @@ Returns an array of ` + "`Type`" + ` objects representing all the public type de For example, given a contract ` + ` contract Foo { -pub struct Bar {...} -pub resource Qux {...} +access(all) struct Bar {...} +access(all) resource Qux {...} } ` + ` then ` + "`.publicTypes()`" + ` will return an array equivalent to the expression ` + "`[Type(), Type()]`" + ` @@ -91,7 +91,7 @@ func init() { return MembersAsResolvers([]*Member{ NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, DeployedContractTypeAddressFieldName, DeployedContractTypeAddressFieldType, @@ -99,7 +99,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, DeployedContractTypeNameFieldName, DeployedContractTypeNameFieldType, @@ -107,7 +107,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, DeployedContractTypeCodeFieldName, DeployedContractTypeCodeFieldType, @@ -115,7 +115,7 @@ func init() { ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, DeployedContractTypePublicTypesFunctionName, DeployedContractTypePublicTypesFunctionType, DeployedContractTypePublicTypesFunctionDocString, diff --git a/runtime/sema/errors.go b/runtime/sema/errors.go index 0114bcb29b..6d091cc199 100644 --- a/runtime/sema/errors.go +++ b/runtime/sema/errors.go @@ -2899,6 +2899,7 @@ func (e *InvalidAccessError) Error() string { type InvalidAssignmentAccessError struct { Name string + ContainerType Type RestrictingAccess Access DeclarationKind common.DeclarationKind ast.Range @@ -2923,8 +2924,8 @@ func (e *InvalidAssignmentAccessError) Error() string { func (e *InvalidAssignmentAccessError) SecondaryError() string { return fmt.Sprintf( - "consider making it publicly settable with `%s`", - ast.AccessPublicSettable.Keyword(), + "consider adding a setter function to %s", + e.ContainerType.QualifiedString(), ) } @@ -4463,7 +4464,7 @@ func (e *InvalidAttachmentEntitlementError) Error() string { func (e *InvalidAttachmentEntitlementError) SecondaryError() string { switch access := e.AttachmentAccessModifier.(type) { case PrimitiveAccess: - return "attachments declared with `pub` access do not support entitlements on their members" + return "attachments declared with `access(all)` access do not support entitlements on their members" case EntitlementMapAccess: return fmt.Sprintf("`%s` must appear in the output of the entitlement mapping `%s`", e.InvalidEntitlement.QualifiedIdentifier(), diff --git a/runtime/sema/gen/testdata/comparable.cdc b/runtime/sema/gen/testdata/comparable.cdc index e39c3796e5..4f8520c6c5 100644 --- a/runtime/sema/gen/testdata/comparable.cdc +++ b/runtime/sema/gen/testdata/comparable.cdc @@ -1 +1 @@ -pub struct Test: Comparable {} +access(all) struct Test: Comparable {} diff --git a/runtime/sema/gen/testdata/docstrings.cdc b/runtime/sema/gen/testdata/docstrings.cdc index 8bd8413a4c..19b07b556f 100644 --- a/runtime/sema/gen/testdata/docstrings.cdc +++ b/runtime/sema/gen/testdata/docstrings.cdc @@ -1,28 +1,28 @@ -pub struct Docstrings { +access(all) struct Docstrings { /// This is a 1-line docstring. - pub let owo: Int + access(all) let owo: Int /// This is a 2-line docstring. /// This is the second line. - pub let uwu: [Int] + access(all) let uwu: [Int] /// This is a 3-line docstring for a function. /// This is the second line. /// And the third line! - pub fun nwn(x: Int): String? + access(all) fun nwn(x: Int): String? /// This is a multiline docstring. /// /// There should be two newlines before this line! - pub let withBlanks: Int + access(all) let withBlanks: Int /// The function `isSmolBean` has docstrings with backticks. /// These should be handled accordingly. - pub fun isSmolBean(): Bool + access(all) fun isSmolBean(): Bool /// A function with a docstring. /// This docstring is `cool` because it has inline backticked expressions. /// Look, I did it `again`, wowie!! - pub fun runningOutOfIdeas(): UInt64? + access(all) fun runningOutOfIdeas(): UInt64? } \ No newline at end of file diff --git a/runtime/sema/gen/testdata/docstrings.golden.go b/runtime/sema/gen/testdata/docstrings.golden.go index 46cbff7953..e27183f0e2 100644 --- a/runtime/sema/gen/testdata/docstrings.golden.go +++ b/runtime/sema/gen/testdata/docstrings.golden.go @@ -121,7 +121,7 @@ func init() { return MembersAsResolvers([]*Member{ NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, DocstringsTypeOwoFieldName, DocstringsTypeOwoFieldType, @@ -129,7 +129,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, DocstringsTypeUwuFieldName, DocstringsTypeUwuFieldType, @@ -137,14 +137,14 @@ func init() { ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, DocstringsTypeNwnFunctionName, DocstringsTypeNwnFunctionType, DocstringsTypeNwnFunctionDocString, ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, DocstringsTypeWithBlanksFieldName, DocstringsTypeWithBlanksFieldType, @@ -152,14 +152,14 @@ func init() { ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, DocstringsTypeIsSmolBeanFunctionName, DocstringsTypeIsSmolBeanFunctionType, DocstringsTypeIsSmolBeanFunctionDocString, ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, DocstringsTypeRunningOutOfIdeasFunctionName, DocstringsTypeRunningOutOfIdeasFunctionType, DocstringsTypeRunningOutOfIdeasFunctionDocString, diff --git a/runtime/sema/gen/testdata/equatable.cdc b/runtime/sema/gen/testdata/equatable.cdc index 6d05ef4e17..9ce1d08b9f 100644 --- a/runtime/sema/gen/testdata/equatable.cdc +++ b/runtime/sema/gen/testdata/equatable.cdc @@ -1 +1 @@ -pub struct Test: Equatable {} +access(all) struct Test: Equatable {} diff --git a/runtime/sema/gen/testdata/exportable.cdc b/runtime/sema/gen/testdata/exportable.cdc index dd7d1c469c..1aa2feb4f3 100644 --- a/runtime/sema/gen/testdata/exportable.cdc +++ b/runtime/sema/gen/testdata/exportable.cdc @@ -1 +1 @@ -pub struct Test: Exportable {} +access(all) struct Test: Exportable {} diff --git a/runtime/sema/gen/testdata/fields.cdc b/runtime/sema/gen/testdata/fields.cdc index 79535acd33..bd011b73fc 100644 --- a/runtime/sema/gen/testdata/fields.cdc +++ b/runtime/sema/gen/testdata/fields.cdc @@ -1,40 +1,40 @@ -pub struct Test { +access(all) struct Test { /// This is a test integer. - pub let testInt: UInt64 + access(all) let testInt: UInt64 /// This is a test optional integer. - pub let testOptInt: UInt64? + access(all) let testOptInt: UInt64? /// This is a test integer reference. - pub let testRefInt: &UInt64 + access(all) let testRefInt: &UInt64 /// This is a test variable-sized integer array. - pub let testVarInts: [UInt64] + access(all) let testVarInts: [UInt64] /// This is a test constant-sized integer array. - pub let testConstInts: [UInt64; 2] + access(all) let testConstInts: [UInt64; 2] /// This is a test parameterized-type field. - pub let testParam: Foo + access(all) let testParam: Foo /// This is a test address field. - pub let testAddress: Address + access(all) let testAddress: Address /// This is a test type field. - pub let testType: Type + access(all) let testType: Type /// This is a test unparameterized capability field. - pub let testCap: Capability + access(all) let testCap: Capability /// This is a test parameterized capability field. - pub let testCapInt: Capability + access(all) let testCapInt: Capability /// This is a test restricted type (without type) field. - pub let testRestrictedWithoutType: {Bar, Baz} + access(all) let testRestrictedWithoutType: {Bar, Baz} /// This is a test restricted type (with type) field. - pub let testRestrictedWithType: Foo{Bar, Baz} + access(all) let testRestrictedWithType: Foo{Bar, Baz} /// This is a test restricted type (without restrictions) field. - pub let testRestrictedWithoutRestrictions: Foo{} + access(all) let testRestrictedWithoutRestrictions: Foo{} } diff --git a/runtime/sema/gen/testdata/fields.golden.go b/runtime/sema/gen/testdata/fields.golden.go index c845aeba28..6a55805536 100644 --- a/runtime/sema/gen/testdata/fields.golden.go +++ b/runtime/sema/gen/testdata/fields.golden.go @@ -168,7 +168,7 @@ func init() { return MembersAsResolvers([]*Member{ NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, TestTypeTestIntFieldName, TestTypeTestIntFieldType, @@ -176,7 +176,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, TestTypeTestOptIntFieldName, TestTypeTestOptIntFieldType, @@ -184,7 +184,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, TestTypeTestRefIntFieldName, TestTypeTestRefIntFieldType, @@ -192,7 +192,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, TestTypeTestVarIntsFieldName, TestTypeTestVarIntsFieldType, @@ -200,7 +200,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, TestTypeTestConstIntsFieldName, TestTypeTestConstIntsFieldType, @@ -208,7 +208,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, TestTypeTestParamFieldName, TestTypeTestParamFieldType, @@ -216,7 +216,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, TestTypeTestAddressFieldName, TestTypeTestAddressFieldType, @@ -224,7 +224,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, TestTypeTestTypeFieldName, TestTypeTestTypeFieldType, @@ -232,7 +232,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, TestTypeTestCapFieldName, TestTypeTestCapFieldType, @@ -240,7 +240,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, TestTypeTestCapIntFieldName, TestTypeTestCapIntFieldType, @@ -248,7 +248,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, TestTypeTestRestrictedWithoutTypeFieldName, TestTypeTestRestrictedWithoutTypeFieldType, @@ -256,7 +256,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, TestTypeTestRestrictedWithTypeFieldName, TestTypeTestRestrictedWithTypeFieldType, @@ -264,7 +264,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, TestTypeTestRestrictedWithoutRestrictionsFieldName, TestTypeTestRestrictedWithoutRestrictionsFieldType, diff --git a/runtime/sema/gen/testdata/functions.cdc b/runtime/sema/gen/testdata/functions.cdc index 376ad84682..053d827cb6 100644 --- a/runtime/sema/gen/testdata/functions.cdc +++ b/runtime/sema/gen/testdata/functions.cdc @@ -1,25 +1,25 @@ -pub struct Test { +access(all) struct Test { /// This is a test function. - pub fun nothing() {} + access(all) fun nothing() {} /// This is a test function with parameters. - pub fun params(a: Int, _ b: String) {} + access(all) fun params(a: Int, _ b: String) {} /// This is a test function with a return type. - pub fun returnBool(): Bool {} + access(all) fun returnBool(): Bool {} /// This is a test function with parameters and a return type. - pub fun paramsAndReturn(a: Int, _ b: String): Bool {} + access(all) fun paramsAndReturn(a: Int, _ b: String): Bool {} /// This is a test function with a type parameter. - pub fun typeParam() {} + access(all) fun typeParam() {} /// This is a test function with a type parameter and a type bound. - pub fun typeParamWithBound() {} + access(all) fun typeParamWithBound() {} /// This is a test function with a type parameter and a parameter using it. - pub fun typeParamWithBoundAndParam(t: T) {} + access(all) fun typeParamWithBoundAndParam(t: T) {} /// This is a function with 'view' modifier - pub view fun viewFunction() {} + access(all) view fun viewFunction() {} } diff --git a/runtime/sema/gen/testdata/functions.golden.go b/runtime/sema/gen/testdata/functions.golden.go index c21aae1f6b..0e108fb480 100644 --- a/runtime/sema/gen/testdata/functions.golden.go +++ b/runtime/sema/gen/testdata/functions.golden.go @@ -193,56 +193,56 @@ func init() { return MembersAsResolvers([]*Member{ NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, TestTypeNothingFunctionName, TestTypeNothingFunctionType, TestTypeNothingFunctionDocString, ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, TestTypeParamsFunctionName, TestTypeParamsFunctionType, TestTypeParamsFunctionDocString, ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, TestTypeReturnBoolFunctionName, TestTypeReturnBoolFunctionType, TestTypeReturnBoolFunctionDocString, ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, TestTypeParamsAndReturnFunctionName, TestTypeParamsAndReturnFunctionType, TestTypeParamsAndReturnFunctionDocString, ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, TestTypeTypeParamFunctionName, TestTypeTypeParamFunctionType, TestTypeTypeParamFunctionDocString, ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, TestTypeTypeParamWithBoundFunctionName, TestTypeTypeParamWithBoundFunctionType, TestTypeTypeParamWithBoundFunctionDocString, ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, TestTypeTypeParamWithBoundAndParamFunctionName, TestTypeTypeParamWithBoundAndParamFunctionType, TestTypeTypeParamWithBoundAndParamFunctionDocString, ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, TestTypeViewFunctionFunctionName, TestTypeViewFunctionFunctionType, TestTypeViewFunctionFunctionDocString, diff --git a/runtime/sema/gen/testdata/importable.cdc b/runtime/sema/gen/testdata/importable.cdc index 4d5c664000..35a4167b29 100644 --- a/runtime/sema/gen/testdata/importable.cdc +++ b/runtime/sema/gen/testdata/importable.cdc @@ -1 +1 @@ -pub struct Test: Importable {} +access(all) struct Test: Importable {} diff --git a/runtime/sema/gen/testdata/nested.cdc b/runtime/sema/gen/testdata/nested.cdc index 4991f5961a..f647f2a233 100644 --- a/runtime/sema/gen/testdata/nested.cdc +++ b/runtime/sema/gen/testdata/nested.cdc @@ -1,12 +1,12 @@ struct Foo { /// foo - pub fun foo() + access(all) fun foo() /// Bar - pub let bar: Foo.Bar + access(all) let bar: Foo.Bar struct Bar { /// bar - pub fun bar() + access(all) fun bar() } } diff --git a/runtime/sema/gen/testdata/nested.golden.go b/runtime/sema/gen/testdata/nested.golden.go index 94a3136e68..446fe2716a 100644 --- a/runtime/sema/gen/testdata/nested.golden.go +++ b/runtime/sema/gen/testdata/nested.golden.go @@ -73,7 +73,7 @@ func init() { var members = []*Member{ NewUnmeteredFunctionMember( FooBarType, - ast.AccessPublic, + ast.AccessAll, FooBarTypeBarFunctionName, FooBarTypeBarFunctionType, FooBarTypeBarFunctionDocString, @@ -102,14 +102,14 @@ func init() { var members = []*Member{ NewUnmeteredFunctionMember( FooType, - ast.AccessPublic, + ast.AccessAll, FooTypeFooFunctionName, FooTypeFooFunctionType, FooTypeFooFunctionDocString, ), NewUnmeteredFieldMember( FooType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, FooTypeBarFieldName, FooTypeBarFieldType, diff --git a/runtime/sema/gen/testdata/simple-resource.cdc b/runtime/sema/gen/testdata/simple-resource.cdc index 422a201e5b..7f4da96636 100644 --- a/runtime/sema/gen/testdata/simple-resource.cdc +++ b/runtime/sema/gen/testdata/simple-resource.cdc @@ -1 +1 @@ -pub resource Test {} +access(all) resource Test {} diff --git a/runtime/sema/gen/testdata/simple-struct.cdc b/runtime/sema/gen/testdata/simple-struct.cdc index fe79d9f91a..db81f193e4 100644 --- a/runtime/sema/gen/testdata/simple-struct.cdc +++ b/runtime/sema/gen/testdata/simple-struct.cdc @@ -1 +1 @@ -pub struct Test {} +access(all) struct Test {} diff --git a/runtime/sema/gen/testdata/storable.cdc b/runtime/sema/gen/testdata/storable.cdc index 0c7fff3d84..9c324203bb 100644 --- a/runtime/sema/gen/testdata/storable.cdc +++ b/runtime/sema/gen/testdata/storable.cdc @@ -1 +1 @@ -pub struct Test: Storable {} +access(all) struct Test: Storable {} diff --git a/runtime/sema/publicaccount.cdc b/runtime/sema/publicaccount.cdc index 5cd5c0d00e..32453cf4d4 100644 --- a/runtime/sema/publicaccount.cdc +++ b/runtime/sema/publicaccount.cdc @@ -1,43 +1,43 @@ -pub struct PublicAccount { +access(all) struct PublicAccount { /// The address of the account. - pub let address: Address + access(all) let address: Address /// The FLOW balance of the default vault of this account. - pub let balance: UFix64 + access(all) let balance: UFix64 /// The FLOW balance of the default vault of this account that is available to be moved. - pub let availableBalance: UFix64 + access(all) let availableBalance: UFix64 /// The current amount of storage used by the account in bytes. - pub let storageUsed: UInt64 + access(all) let storageUsed: UInt64 /// The storage capacity of the account in bytes. - pub let storageCapacity: UInt64 + access(all) let storageCapacity: UInt64 /// The contracts deployed to the account. - pub let contracts: PublicAccount.Contracts + access(all) let contracts: PublicAccount.Contracts /// The keys assigned to the account. - pub let keys: PublicAccount.Keys + access(all) let keys: PublicAccount.Keys /// The capabilities of the account. - pub let capabilities: PublicAccount.Capabilities + access(all) let capabilities: PublicAccount.Capabilities /// All public paths of this account. - pub let publicPaths: [PublicPath] + access(all) let publicPaths: [PublicPath] /// **DEPRECATED**: Use `capabilities.get` instead. /// /// Returns the capability at the given public path. - pub fun getCapability(_ path: PublicPath): Capability + access(all) fun getCapability(_ path: PublicPath): Capability /// **DEPRECATED** /// /// Returns the target path of the capability at the given public or private path, /// or nil if there exists no capability at the given path. - pub fun getLinkTarget(_ path: CapabilityPath): Path? + access(all) fun getLinkTarget(_ path: CapabilityPath): Path? /// Iterate over all the public paths of an account. /// passing each path and type in turn to the provided callback function. @@ -50,51 +50,51 @@ pub struct PublicAccount { /// /// The order of iteration, as well as the behavior of adding or removing objects from storage during iteration, /// is undefined. - pub fun forEachPublic(_ function: fun(PublicPath, Type): Bool) + access(all) fun forEachPublic(_ function: fun(PublicPath, Type): Bool) - pub struct Contracts { + access(all) struct Contracts { /// The names of all contracts deployed in the account. - pub let names: [String] + access(all) let names: [String] /// Returns the deployed contract for the contract/contract interface with the given name in the account, if any. /// /// Returns nil if no contract/contract interface with the given name exists in the account. - pub fun get(name: String): DeployedContract? + access(all) fun get(name: String): DeployedContract? /// Returns a reference of the given type to the contract with the given name in the account, if any. /// /// Returns nil if no contract with the given name exists in the account, /// or if the contract does not conform to the given type. - pub fun borrow(name: String): T? + access(all) fun borrow(name: String): T? } - pub struct Keys { + access(all) struct Keys { /// Returns the key at the given index, if it exists, or nil otherwise. /// /// Revoked keys are always returned, but they have `isRevoked` field set to true. - pub fun get(keyIndex: Int): AccountKey? + access(all) fun get(keyIndex: Int): AccountKey? /// Iterate over all unrevoked keys in this account, /// passing each key in turn to the provided function. /// /// Iteration is stopped early if the function returns `false`. /// The order of iteration is undefined. - pub fun forEach(_ function: fun(AccountKey): Bool) + access(all) fun forEach(_ function: fun(AccountKey): Bool) /// The total number of unrevoked keys in this account. - pub let count: UInt64 + access(all) let count: UInt64 } - pub struct Capabilities { + access(all) struct Capabilities { /// get returns the storage capability at the given path, if one was stored there. - pub fun get(_ path: PublicPath): Capability? + access(all) fun get(_ path: PublicPath): Capability? /// borrow gets the storage capability at the given path, and borrows the capability if it exists. /// /// Returns nil if the capability does not exist or cannot be borrowed using the given type. /// The function is equivalent to `get(path)?.borrow()`. - pub fun borrow(_ path: PublicPath): T? + access(all) fun borrow(_ path: PublicPath): T? } } diff --git a/runtime/sema/publicaccount.gen.go b/runtime/sema/publicaccount.gen.go index 1933d4afa5..03838df1b8 100644 --- a/runtime/sema/publicaccount.gen.go +++ b/runtime/sema/publicaccount.gen.go @@ -285,7 +285,7 @@ func init() { var members = []*Member{ NewUnmeteredFieldMember( PublicAccountContractsType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, PublicAccountContractsTypeNamesFieldName, PublicAccountContractsTypeNamesFieldType, @@ -293,14 +293,14 @@ func init() { ), NewUnmeteredFunctionMember( PublicAccountContractsType, - ast.AccessPublic, + ast.AccessAll, PublicAccountContractsTypeGetFunctionName, PublicAccountContractsTypeGetFunctionType, PublicAccountContractsTypeGetFunctionDocString, ), NewUnmeteredFunctionMember( PublicAccountContractsType, - ast.AccessPublic, + ast.AccessAll, PublicAccountContractsTypeBorrowFunctionName, PublicAccountContractsTypeBorrowFunctionType, PublicAccountContractsTypeBorrowFunctionDocString, @@ -390,21 +390,21 @@ func init() { var members = []*Member{ NewUnmeteredFunctionMember( PublicAccountKeysType, - ast.AccessPublic, + ast.AccessAll, PublicAccountKeysTypeGetFunctionName, PublicAccountKeysTypeGetFunctionType, PublicAccountKeysTypeGetFunctionDocString, ), NewUnmeteredFunctionMember( PublicAccountKeysType, - ast.AccessPublic, + ast.AccessAll, PublicAccountKeysTypeForEachFunctionName, PublicAccountKeysTypeForEachFunctionType, PublicAccountKeysTypeForEachFunctionDocString, ), NewUnmeteredFieldMember( PublicAccountKeysType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, PublicAccountKeysTypeCountFieldName, PublicAccountKeysTypeCountFieldType, @@ -507,14 +507,14 @@ func init() { var members = []*Member{ NewUnmeteredFunctionMember( PublicAccountCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, PublicAccountCapabilitiesTypeGetFunctionName, PublicAccountCapabilitiesTypeGetFunctionType, PublicAccountCapabilitiesTypeGetFunctionDocString, ), NewUnmeteredFunctionMember( PublicAccountCapabilitiesType, - ast.AccessPublic, + ast.AccessAll, PublicAccountCapabilitiesTypeBorrowFunctionName, PublicAccountCapabilitiesTypeBorrowFunctionType, PublicAccountCapabilitiesTypeBorrowFunctionDocString, @@ -545,7 +545,7 @@ func init() { var members = []*Member{ NewUnmeteredFieldMember( PublicAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, PublicAccountTypeAddressFieldName, PublicAccountTypeAddressFieldType, @@ -553,7 +553,7 @@ func init() { ), NewUnmeteredFieldMember( PublicAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, PublicAccountTypeBalanceFieldName, PublicAccountTypeBalanceFieldType, @@ -561,7 +561,7 @@ func init() { ), NewUnmeteredFieldMember( PublicAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, PublicAccountTypeAvailableBalanceFieldName, PublicAccountTypeAvailableBalanceFieldType, @@ -569,7 +569,7 @@ func init() { ), NewUnmeteredFieldMember( PublicAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, PublicAccountTypeStorageUsedFieldName, PublicAccountTypeStorageUsedFieldType, @@ -577,7 +577,7 @@ func init() { ), NewUnmeteredFieldMember( PublicAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, PublicAccountTypeStorageCapacityFieldName, PublicAccountTypeStorageCapacityFieldType, @@ -585,7 +585,7 @@ func init() { ), NewUnmeteredFieldMember( PublicAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, PublicAccountTypeContractsFieldName, PublicAccountTypeContractsFieldType, @@ -593,7 +593,7 @@ func init() { ), NewUnmeteredFieldMember( PublicAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, PublicAccountTypeKeysFieldName, PublicAccountTypeKeysFieldType, @@ -601,7 +601,7 @@ func init() { ), NewUnmeteredFieldMember( PublicAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, PublicAccountTypeCapabilitiesFieldName, PublicAccountTypeCapabilitiesFieldType, @@ -609,7 +609,7 @@ func init() { ), NewUnmeteredFieldMember( PublicAccountType, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, PublicAccountTypePublicPathsFieldName, PublicAccountTypePublicPathsFieldType, @@ -617,21 +617,21 @@ func init() { ), NewUnmeteredFunctionMember( PublicAccountType, - ast.AccessPublic, + ast.AccessAll, PublicAccountTypeGetCapabilityFunctionName, PublicAccountTypeGetCapabilityFunctionType, PublicAccountTypeGetCapabilityFunctionDocString, ), NewUnmeteredFunctionMember( PublicAccountType, - ast.AccessPublic, + ast.AccessAll, PublicAccountTypeGetLinkTargetFunctionName, PublicAccountTypeGetLinkTargetFunctionType, PublicAccountTypeGetLinkTargetFunctionDocString, ), NewUnmeteredFunctionMember( PublicAccountType, - ast.AccessPublic, + ast.AccessAll, PublicAccountTypeForEachPublicFunctionName, PublicAccountTypeForEachPublicFunctionType, PublicAccountTypeForEachPublicFunctionDocString, diff --git a/runtime/sema/storage_capability_controller.cdc b/runtime/sema/storage_capability_controller.cdc index 7221a7b5c9..7d70961630 100644 --- a/runtime/sema/storage_capability_controller.cdc +++ b/runtime/sema/storage_capability_controller.cdc @@ -1,16 +1,19 @@ -pub struct StorageCapabilityController { +access(all) struct StorageCapabilityController { /// An arbitrary "tag" for the controller. /// For example, it could be used to describe the purpose of the capability. /// Empty by default. - pub(set) var tag: String + access(all) var tag: String + + /// Updates this controller's tag to the provided string + access(all) fun setTag(_ tag: String) /// The type of the controlled capability, i.e. the T in `Capability`. - pub let borrowType: Type + access(all) let borrowType: Type /// The identifier of the controlled capability. /// All copies of a capability have the same ID. - pub let capabilityID: UInt64 + access(all) let capabilityID: UInt64 /// Delete this capability controller, /// and disable the controlled capability and its copies. @@ -23,12 +26,12 @@ pub struct StorageCapabilityController { /// /// Borrowing from the controlled capability or its copies will return nil. /// - pub fun delete() + access(all) fun delete() /// Returns the targeted storage path of the controlled capability. - pub fun target(): StoragePath + access(all) fun target(): StoragePath /// Retarget the controlled capability to the given storage path. /// The path may be different or the same as the current path. - pub fun retarget(_ target: StoragePath) + access(all) fun retarget(_ target: StoragePath) } diff --git a/runtime/sema/storage_capability_controller.gen.go b/runtime/sema/storage_capability_controller.gen.go index d114032758..ac353f248e 100644 --- a/runtime/sema/storage_capability_controller.gen.go +++ b/runtime/sema/storage_capability_controller.gen.go @@ -31,6 +31,25 @@ For example, it could be used to describe the purpose of the capability. Empty by default. ` +const StorageCapabilityControllerTypeSetTagFunctionName = "setTag" + +var StorageCapabilityControllerTypeSetTagFunctionType = &FunctionType{ + Parameters: []Parameter{ + { + Label: ArgumentLabelNotRequired, + Identifier: "tag", + TypeAnnotation: NewTypeAnnotation(StringType), + }, + }, + ReturnTypeAnnotation: NewTypeAnnotation( + VoidType, + ), +} + +const StorageCapabilityControllerTypeSetTagFunctionDocString = ` +Updates this controller's tag to the provided string +` + const StorageCapabilityControllerTypeBorrowTypeFieldName = "borrowType" var StorageCapabilityControllerTypeBorrowTypeFieldType = MetaType @@ -121,15 +140,22 @@ func init() { return MembersAsResolvers([]*Member{ NewUnmeteredFieldMember( t, - ast.AccessPublicSettable, + ast.AccessAll, ast.VariableKindVariable, StorageCapabilityControllerTypeTagFieldName, StorageCapabilityControllerTypeTagFieldType, StorageCapabilityControllerTypeTagFieldDocString, ), + NewUnmeteredFunctionMember( + t, + ast.AccessAll, + StorageCapabilityControllerTypeSetTagFunctionName, + StorageCapabilityControllerTypeSetTagFunctionType, + StorageCapabilityControllerTypeSetTagFunctionDocString, + ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, StorageCapabilityControllerTypeBorrowTypeFieldName, StorageCapabilityControllerTypeBorrowTypeFieldType, @@ -137,7 +163,7 @@ func init() { ), NewUnmeteredFieldMember( t, - ast.AccessPublic, + ast.AccessAll, ast.VariableKindConstant, StorageCapabilityControllerTypeCapabilityIDFieldName, StorageCapabilityControllerTypeCapabilityIDFieldType, @@ -145,21 +171,21 @@ func init() { ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, StorageCapabilityControllerTypeDeleteFunctionName, StorageCapabilityControllerTypeDeleteFunctionType, StorageCapabilityControllerTypeDeleteFunctionDocString, ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, StorageCapabilityControllerTypeTargetFunctionName, StorageCapabilityControllerTypeTargetFunctionType, StorageCapabilityControllerTypeTargetFunctionDocString, ), NewUnmeteredFunctionMember( t, - ast.AccessPublic, + ast.AccessAll, StorageCapabilityControllerTypeRetargetFunctionName, StorageCapabilityControllerTypeRetargetFunctionType, StorageCapabilityControllerTypeRetargetFunctionDocString, diff --git a/runtime/sema/type.go b/runtime/sema/type.go index 1c289089b7..5f4cd6bf16 100644 --- a/runtime/sema/type.go +++ b/runtime/sema/type.go @@ -3434,7 +3434,7 @@ func baseTypeVariable(name string, ty Type) *Variable { Type: ty, DeclarationKind: common.DeclarationKindType, IsConstant: true, - Access: PrimitiveAccess(ast.AccessPublic), + Access: PrimitiveAccess(ast.AccessAll), } } @@ -3666,7 +3666,7 @@ func baseFunctionVariable(name string, ty *FunctionType, docString string) *Vari ArgumentLabels: ty.ArgumentLabels(), IsConstant: true, Type: ty, - Access: PrimitiveAccess(ast.AccessPublic), + Access: PrimitiveAccess(ast.AccessAll), DocString: docString, } } @@ -5500,7 +5500,7 @@ var _ Type = &ReferenceType{} var _ ValueIndexableType = &ReferenceType{} var _ TypeIndexableType = &ReferenceType{} -var UnauthorizedAccess Access = PrimitiveAccess(ast.AccessPublic) +var UnauthorizedAccess Access = PrimitiveAccess(ast.AccessAll) func NewReferenceType(memoryGauge common.MemoryGauge, typ Type, authorization Access) *ReferenceType { common.UseMemory(memoryGauge, common.ReferenceSemaTypeMemoryUsage) diff --git a/runtime/sema/type_test.go b/runtime/sema/type_test.go index 083f4e104b..3133cf0655 100644 --- a/runtime/sema/type_test.go +++ b/runtime/sema/type_test.go @@ -651,19 +651,19 @@ func TestIdentifierCacheUpdate(t *testing.T) { t.Parallel() code := ` - pub contract interface Test { + access(all) contract interface Test { - pub struct interface NestedInterface { - pub fun test(): Bool + access(all) struct interface NestedInterface { + access(all) fun test(): Bool } - pub struct Nested: NestedInterface {} + access(all) struct Nested: NestedInterface {} } - pub contract TestImpl { + access(all) contract TestImpl { - pub struct Nested { - pub fun test(): Bool { + access(all) struct Nested { + access(all) fun test(): Bool { return true } } diff --git a/runtime/sema/variable_activations.go b/runtime/sema/variable_activations.go index 21e1ad9eb1..ea089bc248 100644 --- a/runtime/sema/variable_activations.go +++ b/runtime/sema/variable_activations.go @@ -129,7 +129,7 @@ func (a *VariableActivation) DeclareValue(declaration ValueDeclaration) { DeclarationKind: declaration.ValueDeclarationKind(), Type: declaration.ValueDeclarationType(), // TODO: add access to ValueDeclaration and use declaration's access instead here - Access: PrimitiveAccess(ast.AccessPublic), + Access: PrimitiveAccess(ast.AccessAll), IsConstant: declaration.ValueDeclarationIsConstant(), ArgumentLabels: declaration.ValueDeclarationArgumentLabels(), Pos: declaration.ValueDeclarationPosition(), @@ -146,7 +146,7 @@ func (a *VariableActivation) DeclareType(declaration TypeDeclaration) { DeclarationKind: declaration.TypeDeclarationKind(), Type: declaration.TypeDeclarationType(), // TODO: add access to TypeDeclaration and use declaration's access instead here - Access: PrimitiveAccess(ast.AccessPublic), + Access: PrimitiveAccess(ast.AccessAll), IsConstant: true, ArgumentLabels: nil, Pos: declaration.TypeDeclarationPosition(), @@ -321,7 +321,7 @@ func (a *VariableActivations) DeclareValue(declaration ValueDeclaration) (*Varia kind: declaration.ValueDeclarationKind(), ty: declaration.ValueDeclarationType(), // TODO: add access to ValueDeclaration and use declaration's access instead here - access: PrimitiveAccess(ast.AccessPublic), + access: PrimitiveAccess(ast.AccessAll), isConstant: declaration.ValueDeclarationIsConstant(), argumentLabels: declaration.ValueDeclarationArgumentLabels(), pos: variablePos, @@ -363,7 +363,7 @@ func (a *VariableActivations) declareImplicitConstant( variableDeclaration{ identifier: identifier, ty: ty, - access: PrimitiveAccess(ast.AccessPublic), + access: PrimitiveAccess(ast.AccessAll), kind: kind, isConstant: true, allowOuterScopeShadowing: false, diff --git a/runtime/sharedstate_test.go b/runtime/sharedstate_test.go index e4df0d0c04..ea04588504 100644 --- a/runtime/sharedstate_test.go +++ b/runtime/sharedstate_test.go @@ -41,16 +41,16 @@ func TestRuntimeSharedState(t *testing.T) { signerAddress := common.MustBytesToAddress([]byte{0x1}) deploy1 := DeploymentTransaction("C1", []byte(` - pub contract C1 { - pub fun hello() { + access(all) contract C1 { + access(all) fun hello() { log("Hello from C1!") } } `)) deploy2 := DeploymentTransaction("C2", []byte(` - pub contract C2 { - pub fun hello() { + access(all) contract C2 { + access(all) fun hello() { log("Hello from C2!") } } diff --git a/runtime/stdlib/builtin_test.go b/runtime/stdlib/builtin_test.go index 6e1a7741b9..3f860e4bed 100644 --- a/runtime/stdlib/builtin_test.go +++ b/runtime/stdlib/builtin_test.go @@ -91,7 +91,7 @@ func TestAssert(t *testing.T) { t.Parallel() inter := newInterpreter(t, - `pub let test = assert`, + `access(all) let test = assert`, AssertFunction, ) @@ -136,7 +136,7 @@ func TestPanic(t *testing.T) { t.Parallel() inter := newInterpreter(t, - `pub let test = panic`, + `access(all) let test = panic`, PanicFunction, ) diff --git a/runtime/stdlib/contracts/crypto.cdc b/runtime/stdlib/contracts/crypto.cdc index 1a7df12a09..6d7d9ca276 100644 --- a/runtime/stdlib/contracts/crypto.cdc +++ b/runtime/stdlib/contracts/crypto.cdc @@ -1,20 +1,20 @@ -pub contract Crypto { +access(all) contract Crypto { - pub fun hash(_ data: [UInt8], algorithm: HashAlgorithm): [UInt8] { + access(all) fun hash(_ data: [UInt8], algorithm: HashAlgorithm): [UInt8] { return algorithm.hash(data) } - pub fun hashWithTag(_ data: [UInt8], tag: String, algorithm: HashAlgorithm): [UInt8] { + access(all) fun hashWithTag(_ data: [UInt8], tag: String, algorithm: HashAlgorithm): [UInt8] { return algorithm.hashWithTag(data, tag: tag) } - pub struct KeyListEntry { - pub let keyIndex: Int - pub let publicKey: PublicKey - pub let hashAlgorithm: HashAlgorithm - pub let weight: UFix64 - pub let isRevoked: Bool + access(all) struct KeyListEntry { + access(all) let keyIndex: Int + access(all) let publicKey: PublicKey + access(all) let hashAlgorithm: HashAlgorithm + access(all) let weight: UFix64 + access(all) let isRevoked: Bool init( keyIndex: Int, @@ -31,16 +31,16 @@ pub contract Crypto { } } - pub struct KeyList { + access(all) struct KeyList { - priv let entries: [KeyListEntry] + access(self) let entries: [KeyListEntry] init() { self.entries = [] } /// Adds a new key with the given weight - pub fun add( + access(all) fun add( _ publicKey: PublicKey, hashAlgorithm: HashAlgorithm, weight: UFix64 @@ -60,7 +60,7 @@ pub contract Crypto { /// Returns the key at the given index, if it exists. /// Revoked keys are always returned, but they have `isRevoked` field set to true - pub fun get(keyIndex: Int): KeyListEntry? { + access(all) fun get(keyIndex: Int): KeyListEntry? { if keyIndex >= self.entries.length { return nil } @@ -69,7 +69,7 @@ pub contract Crypto { } /// Marks the key at the given index revoked, but does not delete it - pub fun revoke(keyIndex: Int) { + access(all) fun revoke(keyIndex: Int) { if keyIndex >= self.entries.length { return } @@ -84,7 +84,7 @@ pub contract Crypto { } /// Returns true if the given signatures are valid for the given signed data - pub fun verify( + access(all) fun verify( signatureSet: [KeyListSignature], signedData: [UInt8] ): Bool { @@ -139,17 +139,17 @@ pub contract Crypto { } } - pub struct KeyListSignature { - pub let keyIndex: Int - pub let signature: [UInt8] + access(all) struct KeyListSignature { + access(all) let keyIndex: Int + access(all) let signature: [UInt8] - pub init(keyIndex: Int, signature: [UInt8]) { + access(all) init(keyIndex: Int, signature: [UInt8]) { self.keyIndex = keyIndex self.signature = signature } } - priv let domainSeparationTagUser: String + access(self) let domainSeparationTagUser: String init() { self.domainSeparationTagUser = "FLOW-V0.0-user" diff --git a/runtime/stdlib/contracts/crypto_test.cdc b/runtime/stdlib/contracts/crypto_test.cdc index 7c2dcfd9da..b1d1563f29 100644 --- a/runtime/stdlib/contracts/crypto_test.cdc +++ b/runtime/stdlib/contracts/crypto_test.cdc @@ -1,9 +1,9 @@ import Test -pub var blockchain = Test.newEmulatorBlockchain() -pub var account = blockchain.createAccount() +access(self) var blockchain = Test.newEmulatorBlockchain() +access(self) var account = blockchain.createAccount() -pub fun setup() { +access(self) fun setup() { blockchain.useConfiguration(Test.Configuration({ "Crypto": account.address })) @@ -19,57 +19,57 @@ pub fun setup() { Test.assert(err == nil) } -pub fun testCryptoHash() { +access(self) fun testCryptoHash() { let returnedValue = executeScript("./scripts/crypto_hash.cdc") Test.assert(returnedValue, message: "found: false") } -pub fun testCryptoHashWithTag() { +access(self) fun testCryptoHashWithTag() { let returnedValue = executeScript("./scripts/crypto_hash_with_tag.cdc") Test.assert(returnedValue, message: "found: false") } -pub fun testAddKeyToKeyList() { +access(self) fun testAddKeyToKeyList() { let returnedValue = executeScript("./scripts/crypto_key_list_add.cdc") Test.assert(returnedValue, message: "found: false") } -pub fun testGetKeyFromList() { +access(self) fun testGetKeyFromList() { let returnedValue = executeScript("./scripts/crypto_get_key_from_list.cdc") Test.assert(returnedValue, message: "found: false") } -pub fun testRevokeKeyFromList() { +access(self) fun testRevokeKeyFromList() { let returnedValue = executeScript("./scripts/crypto_revoke_key_from_list.cdc") Test.assert(returnedValue, message: "found: false") } -pub fun testKeyListVerify() { +access(self) fun testKeyListVerify() { let returnedValue = executeScript("./scripts/crypto_key_list_verify.cdc") Test.assert(returnedValue, message: "found: false") } -pub fun testKeyListVerifyInsufficientWeights() { +access(self) fun testKeyListVerifyInsufficientWeights() { let returnedValue = executeScript("./scripts/crypto_key_list_verify_insufficient_weights.cdc") Test.assert(returnedValue, message: "found: false") } -pub fun testKeyListVerifyWithRevokedKey() { +access(self) fun testKeyListVerifyWithRevokedKey() { let returnedValue = executeScript("./scripts/crypto_key_list_verify_revoked.cdc") Test.assert(returnedValue, message: "found: false") } -pub fun testKeyListVerifyWithMissingSignature() { +access(self) fun testKeyListVerifyWithMissingSignature() { let returnedValue = executeScript("./scripts/crypto_key_list_verify_missing_signature.cdc") Test.assert(returnedValue, message: "found: false") } -pub fun testKeyListVerifyDuplicateSignature() { +access(self) fun testKeyListVerifyDuplicateSignature() { let returnedValue = executeScript("./scripts/crypto_key_list_verify_duplicate_signature.cdc") Test.assert(returnedValue, message: "found: false") } -pub fun testKeyListVerifyInvalidSignature() { +access(self) fun testKeyListVerifyInvalidSignature() { let returnedValue = executeScript("./scripts/crypto_key_list_verify_invalid_signature.cdc") Test.assert(returnedValue, message: "found: false") } diff --git a/runtime/stdlib/contracts/scripts/crypto_get_key_from_list.cdc b/runtime/stdlib/contracts/scripts/crypto_get_key_from_list.cdc index cc2c3ef18a..0107456540 100644 --- a/runtime/stdlib/contracts/scripts/crypto_get_key_from_list.cdc +++ b/runtime/stdlib/contracts/scripts/crypto_get_key_from_list.cdc @@ -1,6 +1,6 @@ import Crypto from "Crypto" -pub fun main(): Bool { +access(self) fun main(): Bool { let keyList = Crypto.KeyList() let publicKey = PublicKey( diff --git a/runtime/stdlib/contracts/scripts/crypto_hash.cdc b/runtime/stdlib/contracts/scripts/crypto_hash.cdc index 3848a29f2f..8888b4b6e1 100644 --- a/runtime/stdlib/contracts/scripts/crypto_hash.cdc +++ b/runtime/stdlib/contracts/scripts/crypto_hash.cdc @@ -1,6 +1,6 @@ import Crypto from "Crypto" -pub fun main(): Bool { +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 index b38712efb5..fc50acac44 100644 --- a/runtime/stdlib/contracts/scripts/crypto_hash_with_tag.cdc +++ b/runtime/stdlib/contracts/scripts/crypto_hash_with_tag.cdc @@ -1,6 +1,6 @@ import Crypto from "Crypto" -pub fun main(): Bool { +access(self) fun main(): Bool { let hash = Crypto.hashWithTag( [1, 2, 3], tag: "v0.1.tag", diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_add.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_add.cdc index 31319ab87e..7adbbe5847 100644 --- a/runtime/stdlib/contracts/scripts/crypto_key_list_add.cdc +++ b/runtime/stdlib/contracts/scripts/crypto_key_list_add.cdc @@ -1,6 +1,6 @@ import Crypto from "Crypto" -pub fun main(): Bool { +access(self) fun main(): Bool { let keyList = Crypto.KeyList() let publicKey = PublicKey( diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_verify.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_verify.cdc index 8f91f993ae..fe341b4387 100644 --- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify.cdc +++ b/runtime/stdlib/contracts/scripts/crypto_key_list_verify.cdc @@ -1,6 +1,6 @@ import Crypto from "Crypto" -pub fun main(): Bool { +access(self) fun main(): Bool { let keyList = Crypto.KeyList() let publicKeyA = PublicKey( 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 index ea42acde84..f8d1508527 100644 --- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_duplicate_signature.cdc +++ b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_duplicate_signature.cdc @@ -1,6 +1,6 @@ import Crypto from "Crypto" -pub fun main(): Bool { +access(self) fun main(): Bool { let keyList = Crypto.KeyList() let publicKey = PublicKey( 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 index 43beb5ea19..c5f59ba3e5 100644 --- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_insufficient_weights.cdc +++ b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_insufficient_weights.cdc @@ -1,6 +1,6 @@ import Crypto from "Crypto" -pub fun main(): Bool { +access(self) fun main(): Bool { let keyList = Crypto.KeyList() let publicKeyA = PublicKey( 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 index 0e55f644e9..119f39b317 100644 --- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_invalid_signature.cdc +++ b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_invalid_signature.cdc @@ -1,6 +1,6 @@ import Crypto from "Crypto" -pub fun main(): Bool { +access(self) fun main(): Bool { let keyList = Crypto.KeyList() let publicKey = PublicKey( 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 index 5a57840443..ade85465e7 100644 --- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_missing_signature.cdc +++ b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_missing_signature.cdc @@ -1,6 +1,6 @@ import Crypto from "Crypto" -pub fun main(): Bool { +access(self) fun main(): Bool { let keyList = Crypto.KeyList() let publicKey = PublicKey( diff --git a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_revoked.cdc b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_revoked.cdc index 43d6dba9c4..f394f69152 100644 --- a/runtime/stdlib/contracts/scripts/crypto_key_list_verify_revoked.cdc +++ b/runtime/stdlib/contracts/scripts/crypto_key_list_verify_revoked.cdc @@ -1,6 +1,6 @@ import Crypto from "Crypto" -pub fun main(): Bool { +access(self) fun main(): Bool { let keyList = Crypto.KeyList() let publicKey = PublicKey( diff --git a/runtime/stdlib/contracts/scripts/crypto_revoke_key_from_list.cdc b/runtime/stdlib/contracts/scripts/crypto_revoke_key_from_list.cdc index ee8b6d875b..9b2de1477b 100644 --- a/runtime/stdlib/contracts/scripts/crypto_revoke_key_from_list.cdc +++ b/runtime/stdlib/contracts/scripts/crypto_revoke_key_from_list.cdc @@ -1,6 +1,6 @@ import Crypto from "Crypto" -pub fun main(): Bool { +access(self) fun main(): Bool { let keyList = Crypto.KeyList() let publicKey = PublicKey( diff --git a/runtime/stdlib/contracts/test.cdc b/runtime/stdlib/contracts/test.cdc index 5650b7b9c4..25392726b3 100644 --- a/runtime/stdlib/contracts/test.cdc +++ b/runtime/stdlib/contracts/test.cdc @@ -1,12 +1,12 @@ /// Test contract is the standard library that provides testing functionality in Cadence. /// -pub contract Test { +access(all) contract Test { /// Blockchain emulates a real network. /// - pub struct Blockchain { + access(all) struct Blockchain { - pub let backend: AnyStruct{BlockchainBackend} + access(all) let backend: AnyStruct{BlockchainBackend} init(backend: AnyStruct{BlockchainBackend}) { self.backend = backend @@ -15,7 +15,7 @@ pub contract Test { /// Executes a script and returns the script return value and the status. /// `returnValue` field of the result will be `nil` if the script failed. /// - pub fun executeScript(_ script: String, _ arguments: [AnyStruct]): ScriptResult { + access(all) fun executeScript(_ script: String, _ arguments: [AnyStruct]): ScriptResult { return self.backend.executeScript(script, arguments) } @@ -23,33 +23,33 @@ pub contract Test { /// The transaction is paid by the service account. /// The returned account can be used to sign and authorize transactions. /// - pub fun createAccount(): Account { + access(all) fun createAccount(): Account { return self.backend.createAccount() } /// Add a transaction to the current block. /// - pub fun addTransaction(_ tx: Transaction) { + access(all) fun addTransaction(_ tx: Transaction) { self.backend.addTransaction(tx) } /// Executes the next transaction in the block, if any. /// Returns the result of the transaction, or nil if no transaction was scheduled. /// - pub fun executeNextTransaction(): TransactionResult? { + access(all) fun executeNextTransaction(): TransactionResult? { return self.backend.executeNextTransaction() } /// Commit the current block. /// Committing will fail if there are un-executed transactions in the block. /// - pub fun commitBlock() { + access(all) fun commitBlock() { self.backend.commitBlock() } /// Executes a given transaction and commit the current block. /// - pub fun executeTransaction(_ tx: Transaction): TransactionResult { + access(all) fun executeTransaction(_ tx: Transaction): TransactionResult { self.addTransaction(tx) let txResult = self.executeNextTransaction()! self.commitBlock() @@ -58,7 +58,7 @@ pub contract Test { /// Executes a given set of transactions and commit the current block. /// - pub fun executeTransactions(_ transactions: [Transaction]): [TransactionResult] { + access(all) fun executeTransactions(_ transactions: [Transaction]): [TransactionResult] { for tx in transactions { self.addTransaction(tx) } @@ -75,7 +75,7 @@ pub contract Test { /// Deploys a given contract, and initilizes it with the arguments. /// - pub fun deployContract( + access(all) fun deployContract( name: String, code: String, account: Account, @@ -92,55 +92,55 @@ pub contract Test { /// Set the configuration to be used by the blockchain. /// Overrides any existing configuration. /// - pub fun useConfiguration(_ configuration: Configuration) { + access(all) fun useConfiguration(_ configuration: Configuration) { self.backend.useConfiguration(configuration) } /// Returns all the logs from the blockchain, up to the calling point. /// - pub fun logs(): [String] { + access(all) fun logs(): [String] { return self.backend.logs() } /// Returns the service account of the blockchain. Can be used to sign /// transactions with this account. /// - pub fun serviceAccount(): Account { + access(all) fun serviceAccount(): Account { return self.backend.serviceAccount() } /// Returns all events emitted from the blockchain. /// - pub fun events(): [AnyStruct] { + access(all) fun events(): [AnyStruct] { return self.backend.events(nil) } /// Returns all events emitted from the blockchain, /// filtered by type. /// - pub fun eventsOfType(_ type: Type): [AnyStruct] { + access(all) fun eventsOfType(_ type: Type): [AnyStruct] { return self.backend.events(type) } /// Resets the state of the blockchain. /// - pub fun reset() { + access(all) fun reset() { self.backend.reset() } } - pub struct Matcher { + access(all) struct Matcher { - pub let test: fun(AnyStruct): Bool + access(all) let test: fun(AnyStruct): Bool - pub init(test: fun(AnyStruct): Bool) { + access(all) init(test: fun(AnyStruct): Bool) { self.test = test } /// Combine this matcher with the given matcher. /// Returns a new matcher that succeeds if this and the given matcher succeed. /// - pub fun and(_ other: Matcher): Matcher { + access(all) fun and(_ other: Matcher): Matcher { return Matcher(test: fun (value: AnyStruct): Bool { return self.test(value) && other.test(value) }) @@ -150,7 +150,7 @@ pub contract Test { /// Returns a new matcher that succeeds if this or the given matcher succeed. /// If this matcher succeeds, then the other matcher would not be tested. /// - pub fun or(_ other: Matcher): Matcher { + access(all) fun or(_ other: Matcher): Matcher { return Matcher(test: fun (value: AnyStruct): Bool { return self.test(value) || other.test(value) }) @@ -159,25 +159,25 @@ pub contract Test { /// ResultStatus indicates status of a transaction or script execution. /// - pub enum ResultStatus: UInt8 { - pub case succeeded - pub case failed + access(all) enum ResultStatus: UInt8 { + access(all) case succeeded + access(all) case failed } /// Result is the interface to be implemented by the various execution /// operations, such as transactions and scripts. /// - pub struct interface Result { + access(all) struct interface Result { /// The resulted status of an executed operation. /// - pub let status: ResultStatus + access(all) let status: ResultStatus } /// The result of a transaction execution. /// - pub struct TransactionResult: Result { - pub let status: ResultStatus - pub let error: Error? + access(all) struct TransactionResult: Result { + access(all) let status: ResultStatus + access(all) let error: Error? init(status: ResultStatus, error: Error?) { self.status = status @@ -187,10 +187,10 @@ pub contract Test { /// The result of a script execution. /// - pub struct ScriptResult: Result { - pub let status: ResultStatus - pub let returnValue: AnyStruct? - pub let error: Error? + access(all) struct ScriptResult: Result { + access(all) let status: ResultStatus + access(all) let returnValue: AnyStruct? + access(all) let error: Error? init(status: ResultStatus, returnValue: AnyStruct?, error: Error?) { self.status = status @@ -201,8 +201,8 @@ pub contract Test { // Error is returned if something has gone wrong. // - pub struct Error { - pub let message: String + access(all) struct Error { + access(all) let message: String init(_ message: String) { self.message = message @@ -211,9 +211,9 @@ pub contract Test { /// Account represents info about the account created on the blockchain. /// - pub struct Account { - pub let address: Address - pub let publicKey: PublicKey + access(all) struct Account { + access(all) let address: Address + access(all) let publicKey: PublicKey init(address: Address, publicKey: PublicKey) { self.address = address @@ -224,8 +224,8 @@ pub contract Test { /// Configuration to be used by the blockchain. /// Can be used to set the address mappings. /// - pub struct Configuration { - pub let addresses: {String: Address} + access(all) struct Configuration { + access(all) let addresses: {String: Address} init(addresses: {String: Address}) { self.addresses = addresses @@ -234,11 +234,11 @@ pub contract Test { /// Transaction that can be submitted and executed on the blockchain. /// - pub struct Transaction { - pub let code: String - pub let authorizers: [Address] - pub let signers: [Account] - pub let arguments: [AnyStruct] + access(all) struct Transaction { + access(all) let code: String + access(all) let authorizers: [Address] + access(all) let signers: [Account] + access(all) let arguments: [AnyStruct] init(code: String, authorizers: [Address], signers: [Account], arguments: [AnyStruct]) { self.code = code @@ -250,36 +250,36 @@ pub contract Test { /// BlockchainBackend is the interface to be implemented by the backend providers. /// - pub struct interface BlockchainBackend { + access(all) struct interface BlockchainBackend { /// Executes a script and returns the script return value and the status. /// `returnValue` field of the result will be `nil` if the script failed. /// - pub fun executeScript(_ script: String, _ arguments: [AnyStruct]): ScriptResult + access(all) fun executeScript(_ script: String, _ arguments: [AnyStruct]): ScriptResult /// Creates a signer account by submitting an account creation transaction. /// The transaction is paid by the service account. /// The returned account can be used to sign and authorize transactions. /// - pub fun createAccount(): Account + access(all) fun createAccount(): Account /// Add a transaction to the current block. /// - pub fun addTransaction(_ tx: Transaction) + access(all) fun addTransaction(_ tx: Transaction) /// Executes the next transaction in the block, if any. /// Returns the result of the transaction, or nil if no transaction was scheduled. /// - pub fun executeNextTransaction(): TransactionResult? + access(all) fun executeNextTransaction(): TransactionResult? /// Commit the current block. /// Committing will fail if there are un-executed transactions in the block. /// - pub fun commitBlock() + access(all) fun commitBlock() /// Deploys a given contract, and initilizes it with the arguments. /// - pub fun deployContract( + access(all) fun deployContract( name: String, code: String, account: Account, @@ -289,30 +289,30 @@ pub contract Test { /// Set the configuration to be used by the blockchain. /// Overrides any existing configuration. /// - pub fun useConfiguration(_ configuration: Configuration) + access(all) fun useConfiguration(_ configuration: Configuration) /// Returns all the logs from the blockchain, up to the calling point. /// - pub fun logs(): [String] + access(all) fun logs(): [String] /// Returns the service account of the blockchain. Can be used to sign /// transactions with this account. /// - pub fun serviceAccount(): Account + access(all) fun serviceAccount(): Account /// Returns all events emitted from the blockchain, optionally filtered /// by type. /// - pub fun events(_ type: Type?): [AnyStruct] + access(all) fun events(_ type: Type?): [AnyStruct] /// Resets the state of the blockchain. /// - pub fun reset() + access(all) fun reset() } /// Returns a new matcher that negates the test of the given matcher. /// - pub fun not(_ matcher: Matcher): Matcher { + access(all) fun not(_ matcher: Matcher): Matcher { return Matcher(test: fun (value: AnyStruct): Bool { return !matcher.test(value) }) @@ -322,7 +322,7 @@ pub contract Test { /// a ScriptResult or TransactionResult and the ResultStatus is succeeded. /// Returns false in any other case. /// - pub fun beSucceeded(): Matcher { + access(all) fun beSucceeded(): Matcher { return Matcher(test: fun (value: AnyStruct): Bool { return (value as! {Result}).status == ResultStatus.succeeded }) @@ -332,7 +332,7 @@ pub contract Test { /// a ScriptResult or TransactionResult and the ResultStatus is failed. /// Returns false in any other case. /// - pub fun beFailed(): Matcher { + access(all) fun beFailed(): Matcher { return Matcher(test: fun (value: AnyStruct): Bool { return (value as! {Result}).status == ResultStatus.failed }) @@ -340,7 +340,7 @@ pub contract Test { /// Returns a new matcher that checks if the given test value is nil. /// - pub fun beNil(): Matcher { + access(all) fun beNil(): Matcher { return Matcher(test: fun (value: AnyStruct): Bool { return value == nil }) diff --git a/runtime/stdlib/test_test.go b/runtime/stdlib/test_test.go index 326e9577aa..69541e05f9 100644 --- a/runtime/stdlib/test_test.go +++ b/runtime/stdlib/test_test.go @@ -141,7 +141,7 @@ func TestTestNewMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let matcher = Test.newMatcher(fun (_ value: AnyStruct): Bool { if !value.getType().isSubtype(of: Type()) { return false @@ -168,7 +168,7 @@ func TestTestNewMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let matcher = Test.newMatcher(fun (_ value: Int): Bool { return value == 7 @@ -192,7 +192,7 @@ func TestTestNewMatcher(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let matcher = Test.newMatcher(fun (_ value: Int): Bool { return (value + 7) == 4 @@ -217,7 +217,7 @@ func TestTestNewMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let matcher = Test.newMatcher(fun (_ value: &Foo): Bool { return value.a == 4 @@ -232,8 +232,8 @@ func TestTestNewMatcher(t *testing.T) { return res } - pub resource Foo { - pub let a: Int + access(all) resource Foo { + access(all) let a: Int init(_ a: Int) { self.a = a @@ -255,7 +255,7 @@ func TestTestNewMatcher(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let matcher = Test.newMatcher(fun (_ value: @Foo): Bool { destroy value @@ -263,7 +263,7 @@ func TestTestNewMatcher(t *testing.T) { }) } - pub resource Foo {} + access(all) resource Foo {} ` _, err := newTestContractInterpreter(t, script) @@ -278,7 +278,7 @@ func TestTestNewMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let matcher = Test.newMatcher(fun (_ value: Int): Bool { return value == 7 @@ -302,7 +302,7 @@ func TestTestNewMatcher(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let matcher = Test.newMatcher(fun (_ value: Int): Bool { return value == 7 @@ -323,7 +323,7 @@ func TestTestNewMatcher(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let matcher1 = Test.newMatcher(fun (_ value: Int): Bool { return (value + 5) == 10 @@ -359,7 +359,7 @@ func TestTestEqualMatcher(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { Test.equal(1) } ` @@ -377,7 +377,7 @@ func TestTestEqualMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let matcher = Test.equal(1) return matcher.test(1) } @@ -397,13 +397,13 @@ func TestTestEqualMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let f = Foo() let matcher = Test.equal(f) return matcher.test(f) } - pub struct Foo {} + access(all) struct Foo {} ` inter, err := newTestContractInterpreter(t, script) @@ -420,13 +420,13 @@ func TestTestEqualMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let f <- create Foo() let matcher = Test.equal(<-f) return matcher.test(<- create Foo()) } - pub resource Foo {} + access(all) resource Foo {} ` _, err := newTestContractInterpreter(t, script) @@ -443,7 +443,7 @@ func TestTestEqualMatcher(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let matcher = Test.equal("hello") } ` @@ -461,7 +461,7 @@ func TestTestEqualMatcher(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let matcher = Test.equal(1) } ` @@ -479,7 +479,7 @@ func TestTestEqualMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let one = Test.equal(1) let two = Test.equal(2) @@ -504,7 +504,7 @@ func TestTestEqualMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let one = Test.equal(1) let two = Test.equal(2) @@ -528,7 +528,7 @@ func TestTestEqualMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let one = Test.equal(1) let two = Test.equal(2) @@ -552,7 +552,7 @@ func TestTestEqualMatcher(t *testing.T) { script := ` import Test - pub fun testMatch(): Bool { + access(all) fun testMatch(): Bool { let one = Test.equal(1) let notOne = Test.not(one) @@ -560,7 +560,7 @@ func TestTestEqualMatcher(t *testing.T) { return notOne.test(2) } - pub fun testNoMatch(): Bool { + access(all) fun testNoMatch(): Bool { let one = Test.equal(1) let notOne = Test.not(one) @@ -587,7 +587,7 @@ func TestTestEqualMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let one = Test.equal(1) let two = Test.equal(2) let three = Test.equal(3) @@ -612,7 +612,7 @@ func TestTestEqualMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let foo <- create Foo() let bar <- create Bar() @@ -625,8 +625,8 @@ func TestTestEqualMatcher(t *testing.T) { && matcher.test(<-create Bar()) } - pub resource Foo {} - pub resource Bar {} + access(all) resource Foo {} + access(all) resource Bar {} ` _, err := newTestContractInterpreter(t, script) @@ -644,7 +644,7 @@ func TestTestEqualMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let foo <- create Foo() let bar <- create Bar() @@ -656,8 +656,8 @@ func TestTestEqualMatcher(t *testing.T) { return matcher.test(<-create Foo()) } - pub resource Foo {} - pub resource Bar {} + access(all) resource Foo {} + access(all) resource Bar {} ` _, err := newTestContractInterpreter(t, script) @@ -964,7 +964,7 @@ func TestTestBeSucceededMatcher(t *testing.T) { script := ` import Test - pub fun testMatch(): Bool { + access(all) fun testMatch(): Bool { let successful = Test.beSucceeded() let scriptResult = Test.ScriptResult( @@ -976,7 +976,7 @@ func TestTestBeSucceededMatcher(t *testing.T) { return successful.test(scriptResult) } - pub fun testNoMatch(): Bool { + access(all) fun testNoMatch(): Bool { let successful = Test.beSucceeded() let scriptResult = Test.ScriptResult( @@ -1007,7 +1007,7 @@ func TestTestBeSucceededMatcher(t *testing.T) { script := ` import Test - pub fun testMatch(): Bool { + access(all) fun testMatch(): Bool { let successful = Test.beSucceeded() let transactionResult = Test.TransactionResult( @@ -1018,7 +1018,7 @@ func TestTestBeSucceededMatcher(t *testing.T) { return successful.test(transactionResult) } - pub fun testNoMatch(): Bool { + access(all) fun testNoMatch(): Bool { let successful = Test.beSucceeded() let transactionResult = Test.TransactionResult( @@ -1048,7 +1048,7 @@ func TestTestBeSucceededMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let successful = Test.beSucceeded() return successful.test("hello") @@ -1073,7 +1073,7 @@ func TestTestBeFailedMatcher(t *testing.T) { script := ` import Test - pub fun testMatch(): Bool { + access(all) fun testMatch(): Bool { let failed = Test.beFailed() let scriptResult = Test.ScriptResult( @@ -1085,7 +1085,7 @@ func TestTestBeFailedMatcher(t *testing.T) { return failed.test(scriptResult) } - pub fun testNoMatch(): Bool { + access(all) fun testNoMatch(): Bool { let failed = Test.beFailed() let scriptResult = Test.ScriptResult( @@ -1116,7 +1116,7 @@ func TestTestBeFailedMatcher(t *testing.T) { script := ` import Test - pub fun testMatch(): Bool { + access(all) fun testMatch(): Bool { let failed = Test.beFailed() let transactionResult = Test.TransactionResult( @@ -1127,7 +1127,7 @@ func TestTestBeFailedMatcher(t *testing.T) { return failed.test(transactionResult) } - pub fun testNoMatch(): Bool { + access(all) fun testNoMatch(): Bool { let failed = Test.beFailed() let transactionResult = Test.TransactionResult( @@ -1157,7 +1157,7 @@ func TestTestBeFailedMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let failed = Test.beFailed() return failed.test([]) @@ -1182,13 +1182,13 @@ func TestTestBeNilMatcher(t *testing.T) { script := ` import Test - pub fun testMatch(): Bool { + access(all) fun testMatch(): Bool { let isNil = Test.beNil() return isNil.test(nil) } - pub fun testNoMatch(): Bool { + access(all) fun testNoMatch(): Bool { let isNil = Test.beNil() return isNil.test([1, 2]) @@ -1218,13 +1218,13 @@ func TestTestBeEmptyMatcher(t *testing.T) { script := ` import Test - pub fun testMatch(): Bool { + access(all) fun testMatch(): Bool { let emptyArray = Test.beEmpty() return emptyArray.test([]) } - pub fun testNoMatch(): Bool { + access(all) fun testNoMatch(): Bool { let emptyArray = Test.beEmpty() return emptyArray.test([42, 23, 31]) @@ -1249,14 +1249,14 @@ func TestTestBeEmptyMatcher(t *testing.T) { script := ` import Test - pub fun testMatch(): Bool { + access(all) fun testMatch(): Bool { let emptyDict = Test.beEmpty() let dict: {Bool: Int} = {} return emptyDict.test(dict) } - pub fun testNoMatch(): Bool { + access(all) fun testNoMatch(): Bool { let emptyDict = Test.beEmpty() let dict: {Bool: Int} = {true: 1, false: 0} @@ -1282,7 +1282,7 @@ func TestTestBeEmptyMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let emptyDict = Test.beEmpty() return emptyDict.test("empty") @@ -1309,13 +1309,13 @@ func TestTestHaveElementCountMatcher(t *testing.T) { script := ` import Test - pub fun testMatch(): Bool { + access(all) fun testMatch(): Bool { let hasThreeElements = Test.haveElementCount(3) return hasThreeElements.test([42, 23, 31]) } - pub fun testNoMatch(): Bool { + access(all) fun testNoMatch(): Bool { let hasThreeElements = Test.haveElementCount(3) return hasThreeElements.test([42]) @@ -1340,14 +1340,14 @@ func TestTestHaveElementCountMatcher(t *testing.T) { script := ` import Test - pub fun testMatch(): Bool { + access(all) fun testMatch(): Bool { let hasTwoElements = Test.haveElementCount(2) let dict: {Bool: Int} = {true: 1, false: 0} return hasTwoElements.test(dict) } - pub fun testNoMatch(): Bool { + access(all) fun testNoMatch(): Bool { let hasTwoElements = Test.haveElementCount(2) let dict: {Bool: Int} = {} @@ -1373,7 +1373,7 @@ func TestTestHaveElementCountMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let hasTwoElements = Test.haveElementCount(2) return hasTwoElements.test("two") @@ -1400,13 +1400,13 @@ func TestTestContainMatcher(t *testing.T) { script := ` import Test - pub fun testMatch(): Bool { + access(all) fun testMatch(): Bool { let containsTwenty = Test.contain(20) return containsTwenty.test([42, 20, 31]) } - pub fun testNoMatch(): Bool { + access(all) fun testNoMatch(): Bool { let containsTwenty = Test.contain(20) return containsTwenty.test([42]) @@ -1431,14 +1431,14 @@ func TestTestContainMatcher(t *testing.T) { script := ` import Test - pub fun testMatch(): Bool { + access(all) fun testMatch(): Bool { let containsFalse = Test.contain(false) let dict: {Bool: Int} = {true: 1, false: 0} return containsFalse.test(dict) } - pub fun testNoMatch(): Bool { + access(all) fun testNoMatch(): Bool { let containsFive = Test.contain(5) let dict: {Int: Bool} = {1: true, 0: false} @@ -1464,7 +1464,7 @@ func TestTestContainMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let containsFalse = Test.contain(false) return containsFalse.test("false") @@ -1491,13 +1491,13 @@ func TestTestBeGreaterThanMatcher(t *testing.T) { script := ` import Test - pub fun testMatch(): Bool { + access(all) fun testMatch(): Bool { let greaterThanFive = Test.beGreaterThan(5) return greaterThanFive.test(7) } - pub fun testNoMatch(): Bool { + access(all) fun testNoMatch(): Bool { let greaterThanFive = Test.beGreaterThan(5) return greaterThanFive.test(2) @@ -1522,7 +1522,7 @@ func TestTestBeGreaterThanMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let greaterThanFive = Test.beGreaterThan(5) return greaterThanFive.test("7") @@ -1547,13 +1547,13 @@ func TestTestBeLessThanMatcher(t *testing.T) { script := ` import Test - pub fun testMatch(): Bool { + access(all) fun testMatch(): Bool { let lessThanSeven = Test.beLessThan(7) return lessThanSeven.test(5) } - pub fun testNoMatch(): Bool { + access(all) fun testNoMatch(): Bool { let lessThanSeven = Test.beLessThan(7) return lessThanSeven.test(9) @@ -1578,7 +1578,7 @@ func TestTestBeLessThanMatcher(t *testing.T) { script := ` import Test - pub fun test(): Bool { + access(all) fun test(): Bool { let lessThanSeven = Test.beLessThan(7) return lessThanSeven.test(true) @@ -1603,7 +1603,7 @@ func TestTestExpect(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { Test.expect("this string", Test.equal("this string")) } ` @@ -1621,7 +1621,7 @@ func TestTestExpect(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { Test.expect("this string", Test.equal("other string")) } ` @@ -1640,7 +1640,7 @@ func TestTestExpect(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { Test.expect("string", Test.equal(1)) } ` @@ -1659,7 +1659,7 @@ func TestTestExpect(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { Test.expect("hello", Test.equal("hello")) } ` @@ -1677,7 +1677,7 @@ func TestTestExpect(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { Test.expect("string", Test.equal(1)) } ` @@ -1695,13 +1695,13 @@ func TestTestExpect(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let f1 <- create Foo() let f2 <- create Foo() Test.expect(<-f1, Test.equal(<-f2)) } - pub resource Foo {} + access(all) resource Foo {} ` _, err := newTestContractInterpreter(t, script) @@ -1717,14 +1717,14 @@ func TestTestExpect(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let foo <- create Foo() let bar = Bar() Test.expect(<-foo, Test.equal(bar)) } - pub resource Foo {} - pub struct Bar {} + access(all) resource Foo {} + access(all) struct Bar {} ` _, err := newTestContractInterpreter(t, script) @@ -1739,14 +1739,14 @@ func TestTestExpect(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let foo = Foo() let bar <- create Bar() Test.expect(foo, Test.equal(<-bar)) } - pub struct Foo {} - pub resource Bar {} + access(all) struct Foo {} + access(all) resource Bar {} ` _, err := newTestContractInterpreter(t, script) @@ -1766,21 +1766,21 @@ func TestTestExpectFailure(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let foo = Foo(answer: 42) Test.expectFailure(fun(): Void { foo.correctAnswer(42) }, errorMessageSubstring: "wrong answer!") } - pub struct Foo { - priv let answer: UInt8 + access(all) struct Foo { + access(self) let answer: UInt8 init(answer: UInt8) { self.answer = answer } - pub fun correctAnswer(_ input: UInt8): Bool { + access(all) fun correctAnswer(_ input: UInt8): Bool { if self.answer != input { panic("wrong answer!") } @@ -1807,21 +1807,21 @@ func TestTestExpectFailure(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let foo = Foo(answer: 42) Test.expectFailure(fun(): Void { foo.correctAnswer(43) }, errorMessageSubstring: "wrong answer!") } - pub struct Foo { - priv let answer: UInt8 + access(all) struct Foo { + access(self) let answer: UInt8 init(answer: UInt8) { self.answer = answer } - pub fun correctAnswer(_ input: UInt8): Bool { + access(all) fun correctAnswer(_ input: UInt8): Bool { if self.answer != input { panic("wrong answer!") } @@ -1843,21 +1843,21 @@ func TestTestExpectFailure(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let foo = Foo(answer: 42) Test.expectFailure(fun(): Void { foo.correctAnswer(43) }, errorMessageSubstring: "what is wrong?") } - pub struct Foo { - priv let answer: UInt8 + access(all) struct Foo { + access(self) let answer: UInt8 init(answer: UInt8) { self.answer = answer } - pub fun correctAnswer(_ input: UInt8): Bool { + access(all) fun correctAnswer(_ input: UInt8): Bool { if self.answer != input { panic("wrong answer!") } @@ -1884,7 +1884,7 @@ func TestTestExpectFailure(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let foo = Foo(answer: 42) Test.expectFailure(fun(answer: UInt64): Foo { foo.correctAnswer(42) @@ -1892,14 +1892,14 @@ func TestTestExpectFailure(t *testing.T) { }, errorMessageSubstring: "wrong answer") } - pub struct Foo { - priv let answer: UInt8 + access(all) struct Foo { + access(self) let answer: UInt8 init(answer: UInt8) { self.answer = answer } - pub fun correctAnswer(_ input: UInt8): Bool { + access(all) fun correctAnswer(_ input: UInt8): Bool { if self.answer != input { panic("wrong answer!") } @@ -1919,21 +1919,21 @@ func TestTestExpectFailure(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let foo = Foo(answer: 42) Test.expectFailure(fun(): Void { foo.correctAnswer(42) }, errorMessageSubstring: ["wrong answer"]) } - pub struct Foo { - priv let answer: UInt8 + access(all) struct Foo { + access(self) let answer: UInt8 init(answer: UInt8) { self.answer = answer } - pub fun correctAnswer(_ input: UInt8): Bool { + access(all) fun correctAnswer(_ input: UInt8): Bool { if self.answer != input { panic("wrong answer!") } diff --git a/runtime/storage_test.go b/runtime/storage_test.go index 6053fe862d..95944c64a4 100644 --- a/runtime/storage_test.go +++ b/runtime/storage_test.go @@ -285,31 +285,31 @@ func TestRuntimePublicCapabilityBorrowTypeConfusion(t *testing.T) { const ducContract = ` import FungibleToken from 0xaad3e26e406987c2 - pub contract DapperUtilityCoin: FungibleToken { + access(all) contract DapperUtilityCoin: FungibleToken { // Total supply of DapperUtilityCoins in existence - pub var totalSupply: UFix64 + access(all) var totalSupply: UFix64 // Event that is emitted when the contract is created - pub event TokensInitialized(initialSupply: UFix64) + access(all) event TokensInitialized(initialSupply: UFix64) // Event that is emitted when tokens are withdrawn from a Vault - pub event TokensWithdrawn(amount: UFix64, from: Address?) + access(all) event TokensWithdrawn(amount: UFix64, from: Address?) // Event that is emitted when tokens are deposited to a Vault - pub event TokensDeposited(amount: UFix64, to: Address?) + access(all) event TokensDeposited(amount: UFix64, to: Address?) // Event that is emitted when new tokens are minted - pub event TokensMinted(amount: UFix64) + access(all) event TokensMinted(amount: UFix64) // Event that is emitted when tokens are destroyed - pub event TokensBurned(amount: UFix64) + access(all) event TokensBurned(amount: UFix64) // Event that is emitted when a new minter resource is created - pub event MinterCreated(allowedAmount: UFix64) + access(all) event MinterCreated(allowedAmount: UFix64) // Event that is emitted when a new burner resource is created - pub event BurnerCreated() + access(all) event BurnerCreated() // Vault // @@ -323,10 +323,10 @@ func TestRuntimePublicCapabilityBorrowTypeConfusion(t *testing.T) { // out of thin air. A special Minter resource needs to be defined to mint // new tokens. // - pub resource Vault: FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance { + access(all) resource Vault: FungibleToken.Provider, FungibleToken.Receiver, FungibleToken.Balance { // holds the balance of a users tokens - pub var balance: UFix64 + access(all) var balance: UFix64 // initialize the balance at resource creation time init(balance: UFix64) { @@ -342,7 +342,7 @@ func TestRuntimePublicCapabilityBorrowTypeConfusion(t *testing.T) { // created Vault to the context that called so it can be deposited // elsewhere. // - pub fun withdraw(amount: UFix64): @FungibleToken.Vault { + access(all) fun withdraw(amount: UFix64): @FungibleToken.Vault { self.balance = self.balance - amount emit TokensWithdrawn(amount: amount, from: self.owner?.address) return <-create Vault(balance: amount) @@ -355,7 +355,7 @@ func TestRuntimePublicCapabilityBorrowTypeConfusion(t *testing.T) { // It is allowed to destroy the sent Vault because the Vault // was a temporary holder of the tokens. The Vault's balance has // been consumed and therefore can be destroyed. - pub fun deposit(from: @FungibleToken.Vault) { + access(all) fun deposit(from: @FungibleToken.Vault) { let vault <- from as! @DapperUtilityCoin.Vault self.balance = self.balance + vault.balance emit TokensDeposited(amount: vault.balance, to: self.owner?.address) @@ -375,16 +375,16 @@ func TestRuntimePublicCapabilityBorrowTypeConfusion(t *testing.T) { // and store the returned Vault in their storage in order to allow their // account to be able to receive deposits of this token type. // - pub fun createEmptyVault(): @FungibleToken.Vault { + access(all) fun createEmptyVault(): @FungibleToken.Vault { return <-create Vault(balance: 0.0) } - pub resource Administrator { + access(all) resource Administrator { // createNewMinter // // Function that creates and returns a new minter resource // - pub fun createNewMinter(allowedAmount: UFix64): @Minter { + access(all) fun createNewMinter(allowedAmount: UFix64): @Minter { emit MinterCreated(allowedAmount: allowedAmount) return <-create Minter(allowedAmount: allowedAmount) } @@ -393,7 +393,7 @@ func TestRuntimePublicCapabilityBorrowTypeConfusion(t *testing.T) { // // Function that creates and returns a new burner resource // - pub fun createNewBurner(): @Burner { + access(all) fun createNewBurner(): @Burner { emit BurnerCreated() return <-create Burner() } @@ -403,17 +403,17 @@ func TestRuntimePublicCapabilityBorrowTypeConfusion(t *testing.T) { // // Resource object that token admin accounts can hold to mint new tokens. // - pub resource Minter { + access(all) resource Minter { // the amount of tokens that the minter is allowed to mint - pub var allowedAmount: UFix64 + access(all) var allowedAmount: UFix64 // mintTokens // // Function that mints new tokens, adds them to the total supply, // and returns them to the calling context. // - pub fun mintTokens(amount: UFix64): @DapperUtilityCoin.Vault { + access(all) fun mintTokens(amount: UFix64): @DapperUtilityCoin.Vault { pre { amount > UFix64(0): "Amount minted must be greater than zero" amount <= self.allowedAmount: "Amount minted must be less than the allowed amount" @@ -433,7 +433,7 @@ func TestRuntimePublicCapabilityBorrowTypeConfusion(t *testing.T) { // // Resource object that token admin accounts can hold to burn tokens. // - pub resource Burner { + access(all) resource Burner { // burnTokens // @@ -442,7 +442,7 @@ func TestRuntimePublicCapabilityBorrowTypeConfusion(t *testing.T) { // Note: the burned tokens are automatically subtracted from the // total supply in the Vault destructor. // - pub fun burnTokens(from: @FungibleToken.Vault) { + access(all) fun burnTokens(from: @FungibleToken.Vault) { let vault <- from as! @DapperUtilityCoin.Vault let amount = vault.balance destroy vault @@ -489,21 +489,25 @@ func TestRuntimePublicCapabilityBorrowTypeConfusion(t *testing.T) { const testContract = ` access(all) contract TestContract{ - pub struct fake{ - pub(set) var balance: UFix64 + access(all) struct fake{ + access(all) var balance: UFix64 init(){ self.balance = 0.0 } + + access(all) fun setBalance(_ balance: UFix64) { + self.balance = balance + } } - pub resource resourceConverter{ - pub fun convert(b: fake): AnyStruct { - b.balance = 100.0 + access(all) resource resourceConverter{ + access(all) fun convert(b: fake): AnyStruct { + b.setBalance(100.0) return b } } - pub resource resourceConverter2{ - pub fun convert(b: @AnyResource): AnyStruct { + access(all) resource resourceConverter2{ + access(all) fun convert(b: @AnyResource): AnyStruct { destroy b return "" } @@ -1022,33 +1026,33 @@ func TestRuntimeBatchMintAndTransfer(t *testing.T) { runtime := newTestInterpreterRuntime() const contract = ` - pub contract Test { + access(all) contract Test { - pub resource interface INFT {} + access(all) resource interface INFT {} - pub resource NFT: INFT {} + access(all) resource NFT: INFT {} - pub resource Collection { + access(all) resource Collection { - pub var ownedNFTs: @{UInt64: NFT} + access(all) var ownedNFTs: @{UInt64: NFT} init() { self.ownedNFTs <- {} } - pub fun withdraw(id: UInt64): @NFT { + access(all) fun withdraw(id: UInt64): @NFT { let token <- self.ownedNFTs.remove(key: id) ?? panic("Cannot withdraw: NFT does not exist in the collection") return <-token } - pub fun deposit(token: @NFT) { + access(all) fun deposit(token: @NFT) { let oldToken <- self.ownedNFTs[token.uuid] <- token destroy oldToken } - pub fun batchDeposit(collection: @Collection) { + access(all) fun batchDeposit(collection: @Collection) { let ids = collection.getIDs() for id in ids { @@ -1058,7 +1062,7 @@ func TestRuntimeBatchMintAndTransfer(t *testing.T) { destroy collection } - pub fun batchWithdraw(ids: [UInt64]): @Collection { + access(all) fun batchWithdraw(ids: [UInt64]): @Collection { let collection <- create Collection() for id in ids { @@ -1068,7 +1072,7 @@ func TestRuntimeBatchMintAndTransfer(t *testing.T) { return <-collection } - pub fun getIDs(): [UInt64] { + access(all) fun getIDs(): [UInt64] { return self.ownedNFTs.keys } @@ -1088,15 +1092,15 @@ func TestRuntimeBatchMintAndTransfer(t *testing.T) { ) } - pub fun mint(): @NFT { + access(all) fun mint(): @NFT { return <- create NFT() } - pub fun createEmptyCollection(): @Collection { + access(all) fun createEmptyCollection(): @Collection { return <- create Collection() } - pub fun batchMint(count: UInt64): @Collection { + access(all) fun batchMint(count: UInt64): @Collection { let collection <- create Collection() var i: UInt64 = 0 @@ -1471,13 +1475,13 @@ func TestRuntimeStorageReferenceCast(t *testing.T) { signerAddress := common.MustBytesToAddress([]byte{0x42}) deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { + access(all) contract Test { - pub resource interface RI {} + access(all) resource interface RI {} - pub resource R: RI {} + access(all) resource R: RI {} - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } @@ -1568,15 +1572,15 @@ func TestRuntimeStorageReferenceDowncast(t *testing.T) { signerAddress := common.MustBytesToAddress([]byte{0x42}) deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { + access(all) contract Test { - pub resource interface RI {} + access(all) resource interface RI {} - pub resource R: RI {} + access(all) resource R: RI {} - pub entitlement E + access(all) entitlement E - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } @@ -1858,11 +1862,11 @@ func TestRuntimeResourceOwnerChange(t *testing.T) { var signers []Address deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { + access(all) contract Test { - pub resource R {} + access(all) resource R {} - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } @@ -2079,7 +2083,7 @@ func TestRuntimeStorageUsed(t *testing.T) { // that this should not clear temporary slabs script := []byte(` - pub fun main() { + access(all) fun main() { var addresses: [Address]= [ 0x2a3c4c2581cef731, 0x2a3c4c2581cef731, 0x2a3c4c2581cef731, 0x2a3c4c2581cef731, 0x2a3c4c2581cef731, 0x2a3c4c2581cef731, 0x2a3c4c2581cef731, 0x2a3c4c2581cef731, 0x2a3c4c2581cef731, 0x2a3c4c2581cef731, @@ -2192,40 +2196,40 @@ func TestRuntimeMissingSlab1173(t *testing.T) { t.Parallel() const contract = ` -pub contract Test { - pub enum Role: UInt8 { - pub case aaa - pub case bbb +access(all) contract Test { + access(all) enum Role: UInt8 { + access(all) case aaa + access(all) case bbb } - pub resource AAA { - pub fun callA(): String { + access(all) resource AAA { + access(all) fun callA(): String { return "AAA" } } - pub resource BBB { - pub fun callB(): String { + access(all) resource BBB { + access(all) fun callB(): String { return "BBB" } } - pub resource interface Receiver { - pub fun receive(asRole: Role, capability: Capability) + access(all) resource interface Receiver { + access(all) fun receive(asRole: Role, capability: Capability) } - pub resource Holder: Receiver { + access(all) resource Holder: Receiver { access(self) let roles: { Role: Capability } - pub fun receive(asRole: Role, capability: Capability) { + access(all) fun receive(asRole: Role, capability: Capability) { self.roles[asRole] = capability } - pub fun borrowA(): &AAA { + access(all) fun borrowA(): &AAA { let role = self.roles[Role.aaa]! return role.borrow<&AAA>()! } - pub fun borrowB(): &BBB { + access(all) fun borrowB(): &BBB { let role = self.roles[Role.bbb]! return role.borrow<&BBB>()! } @@ -2237,11 +2241,11 @@ pub contract Test { access(self) let capabilities: { Role: Capability } - pub fun createHolder(): @Holder { + access(all) fun createHolder(): @Holder { return <- create Holder() } - pub fun attach(asRole: Role, receiver: &AnyResource{Receiver}) { + access(all) fun attach(asRole: Role, receiver: &AnyResource{Receiver}) { // TODO: Now verify that the owner is valid. let capability = self.capabilities[asRole]! @@ -2352,10 +2356,10 @@ func TestRuntimeReferenceOwnerAccess(t *testing.T) { t.Parallel() const contract = ` - pub contract TestContract { - pub resource TestResource {} + access(all) contract TestContract { + access(all) resource TestResource {} - pub fun makeTestResource(): @TestResource { + access(all) fun makeTestResource(): @TestResource { return <- create TestResource() } } @@ -2495,10 +2499,10 @@ func TestRuntimeReferenceOwnerAccess(t *testing.T) { t.Parallel() const contract = ` - pub contract TestContract { - pub resource TestResource {} + access(all) contract TestContract { + access(all) resource TestResource {} - pub fun makeTestResource(): @TestResource { + access(all) fun makeTestResource(): @TestResource { return <- create TestResource() } } @@ -2617,11 +2621,11 @@ func TestRuntimeReferenceOwnerAccess(t *testing.T) { t.Parallel() const contract = ` - pub contract TestContract { - pub resource TestNestedResource {} + access(all) contract TestContract { + access(all) resource TestNestedResource {} - pub resource TestNestingResource { - pub let nestedResources: @[TestNestedResource] + access(all) resource TestNestingResource { + access(all) let nestedResources: @[TestNestedResource] init () { self.nestedResources <- [<- create TestNestedResource()] @@ -2632,7 +2636,7 @@ func TestRuntimeReferenceOwnerAccess(t *testing.T) { } } - pub fun makeTestNestingResource(): @TestNestingResource { + access(all) fun makeTestNestingResource(): @TestNestingResource { return <- create TestNestingResource() } } @@ -2757,10 +2761,10 @@ func TestRuntimeReferenceOwnerAccess(t *testing.T) { t.Parallel() const contract = ` - pub contract TestContract { - pub resource TestResource {} + access(all) contract TestContract { + access(all) resource TestResource {} - pub fun makeTestResource(): @TestResource { + access(all) fun makeTestResource(): @TestResource { return <- create TestResource() } } @@ -2879,10 +2883,10 @@ func TestRuntimeReferenceOwnerAccess(t *testing.T) { t.Parallel() const contract = ` - pub contract TestContract { - pub resource TestResource {} + access(all) contract TestContract { + access(all) resource TestResource {} - pub fun makeTestResource(): @TestResource { + access(all) fun makeTestResource(): @TestResource { return <- create TestResource() } } @@ -3090,16 +3094,16 @@ func TestRuntimeStorageEnumCase(t *testing.T) { Source: DeploymentTransaction( "C", []byte(` - pub contract C { + access(all) contract C { - pub enum E: UInt8 { - pub case A - pub case B + access(all) enum E: UInt8 { + access(all) case A + access(all) case B } - pub resource R { - pub let id: UInt64 - pub let e: E + access(all) resource R { + access(all) let id: UInt64 + access(all) let e: E init(id: UInt64, e: E) { self.id = id @@ -3107,22 +3111,22 @@ func TestRuntimeStorageEnumCase(t *testing.T) { } } - pub fun createR(id: UInt64, e: E): @R { + access(all) fun createR(id: UInt64, e: E): @R { return <- create R(id: id, e: e) } - pub resource Collection { - pub var rs: @{UInt64: R} + access(all) resource Collection { + access(all) var rs: @{UInt64: R} init () { self.rs <- {} } - pub fun withdraw(id: UInt64): @R { + access(all) fun withdraw(id: UInt64): @R { return <- self.rs.remove(key: id)! } - pub fun deposit(_ r: @R) { + access(all) fun deposit(_ r: @R) { let counts: {E: UInt64} = {} log(r.e) @@ -3138,7 +3142,7 @@ func TestRuntimeStorageEnumCase(t *testing.T) { } } - pub fun createEmptyCollection(): @Collection { + access(all) fun createEmptyCollection(): @Collection { return <- create Collection() } } @@ -3257,13 +3261,13 @@ func TestRuntimeStorageInternalAccess(t *testing.T) { address := common.MustBytesToAddress([]byte{0x1}) deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { + access(all) contract Test { - pub resource interface RI {} + access(all) resource interface RI {} - pub resource R: RI {} + access(all) resource R: RI {} - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } } @@ -3404,8 +3408,8 @@ func TestRuntimeStorageIteration(t *testing.T) { contractIsBroken := false deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub struct Foo {} + access(all) contract Test { + access(all) struct Foo {} } `)) @@ -3426,7 +3430,7 @@ func TestRuntimeStorageIteration(t *testing.T) { getAccountContractCode: func(location common.AddressLocation) (code []byte, err error) { if contractIsBroken { // Contract no longer has the type - return []byte(`pub contract Test {}`), nil + return []byte(`access(all) contract Test {}`), nil } code = accountCodes[location] @@ -3532,8 +3536,8 @@ func TestRuntimeStorageIteration(t *testing.T) { contractIsBroken := false deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub struct Foo {} + access(all) contract Test { + access(all) struct Foo {} } `)) @@ -3659,8 +3663,8 @@ func TestRuntimeStorageIteration(t *testing.T) { contractIsBroken := false deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub struct Foo {} + access(all) contract Test { + access(all) struct Foo {} } `)) @@ -3678,8 +3682,8 @@ func TestRuntimeStorageIteration(t *testing.T) { getAccountContractCode: func(location common.AddressLocation) (code []byte, err error) { if contractIsBroken { // Contract has a semantic error. i.e: cannot find `Bar` - return []byte(`pub contract Test { - pub struct Foo: Bar {} + return []byte(`access(all) contract Test { + access(all) struct Foo: Bar {} }`), nil } @@ -3784,8 +3788,8 @@ func TestRuntimeStorageIteration(t *testing.T) { contractIsBroken := false deployTx := DeploymentTransaction("Test", []byte(` - pub contract Test { - pub struct Foo {} + access(all) contract Test { + access(all) struct Foo {} } `)) @@ -3803,8 +3807,8 @@ func TestRuntimeStorageIteration(t *testing.T) { getAccountContractCode: func(location common.AddressLocation) (code []byte, err error) { if contractIsBroken { // Contract has a semantic error. i.e: cannot find `Bar` - return []byte(`pub contract Test { - pub struct Foo: Bar {} + return []byte(`access(all) contract Test { + access(all) struct Foo: Bar {} }`), nil } diff --git a/runtime/tests/checker/access_test.go b/runtime/tests/checker/access_test.go index c8d8b3ebd6..ab4ed38ef8 100644 --- a/runtime/tests/checker/access_test.go +++ b/runtime/tests/checker/access_test.go @@ -95,10 +95,9 @@ func TestCheckAccessModifierCompositeFunctionDeclaration(t *testing.T) { t.Parallel() tests := map[ast.Access]bool{ - ast.AccessNotSpecified: true, - ast.AccessPrivate: true, - ast.AccessPublic: true, - ast.AccessPublicSettable: false, + ast.AccessNotSpecified: true, + ast.AccessSelf: true, + ast.AccessAll: true, } require.Len(t, tests, len(ast.BasicAccesses)) @@ -147,28 +146,24 @@ func TestCheckAccessModifierInterfaceFunctionDeclaration(t *testing.T) { checkModeTests := map[sema.AccessCheckMode]map[ast.Access]error{ sema.AccessCheckModeStrict: { - ast.AccessNotSpecified: &sema.MissingAccessModifierError{}, - ast.AccessPrivate: &sema.InvalidAccessModifierError{}, - ast.AccessPublic: nil, - ast.AccessPublicSettable: &sema.InvalidAccessModifierError{}, + ast.AccessNotSpecified: &sema.MissingAccessModifierError{}, + ast.AccessSelf: &sema.InvalidAccessModifierError{}, + ast.AccessAll: nil, }, sema.AccessCheckModeNotSpecifiedRestricted: { - ast.AccessNotSpecified: nil, - ast.AccessPrivate: &sema.InvalidAccessModifierError{}, - ast.AccessPublic: nil, - ast.AccessPublicSettable: &sema.InvalidAccessModifierError{}, + ast.AccessNotSpecified: nil, + ast.AccessSelf: &sema.InvalidAccessModifierError{}, + ast.AccessAll: nil, }, sema.AccessCheckModeNotSpecifiedUnrestricted: { - ast.AccessNotSpecified: nil, - ast.AccessPrivate: &sema.InvalidAccessModifierError{}, - ast.AccessPublic: nil, - ast.AccessPublicSettable: &sema.InvalidAccessModifierError{}, + ast.AccessNotSpecified: nil, + ast.AccessSelf: &sema.InvalidAccessModifierError{}, + ast.AccessAll: nil, }, sema.AccessCheckModeNone: { - ast.AccessNotSpecified: nil, - ast.AccessPrivate: &sema.InvalidAccessModifierError{}, - ast.AccessPublic: nil, - ast.AccessPublicSettable: &sema.InvalidAccessModifierError{}, + ast.AccessNotSpecified: nil, + ast.AccessSelf: &sema.InvalidAccessModifierError{}, + ast.AccessAll: nil, }, } @@ -193,7 +188,7 @@ func TestCheckAccessModifierInterfaceFunctionDeclaration(t *testing.T) { _, err := ParseAndCheckWithOptions(t, fmt.Sprintf( ` - pub %[1]s interface Test { + access(all) %[1]s interface Test { %[2]s fun test() } `, @@ -228,15 +223,12 @@ func TestCheckAccessModifierCompositeConstantFieldDeclaration(t *testing.T) { ast.AccessNotSpecified: func(_ bool) bool { return true }, - ast.AccessPrivate: func(isInterface bool) bool { + ast.AccessSelf: func(isInterface bool) bool { return !isInterface }, - ast.AccessPublic: func(_ bool) bool { + ast.AccessAll: func(_ bool) bool { return true }, - ast.AccessPublicSettable: func(_ bool) bool { - return false - }, } require.Len(t, tests, len(ast.BasicAccesses)) @@ -328,7 +320,7 @@ func TestCheckAccessModifierCompositeVariableFieldDeclaration(t *testing.T) { // private fields in interfaces are invalid - if isInterface && access == ast.AccessPrivate { + if isInterface && access == ast.AccessSelf { expectInvalidAccessModifierError(t, err) } else { assert.NoError(t, err) @@ -344,10 +336,9 @@ func TestCheckAccessModifierGlobalFunctionDeclaration(t *testing.T) { t.Parallel() tests := map[ast.Access]bool{ - ast.AccessNotSpecified: true, - ast.AccessPrivate: true, - ast.AccessPublic: true, - ast.AccessPublicSettable: false, + ast.AccessNotSpecified: true, + ast.AccessSelf: true, + ast.AccessAll: true, } require.Len(t, tests, len(ast.BasicAccesses)) @@ -379,10 +370,9 @@ func TestCheckAccessModifierGlobalVariableDeclaration(t *testing.T) { t.Parallel() tests := map[ast.Access]bool{ - ast.AccessNotSpecified: true, - ast.AccessPrivate: true, - ast.AccessPublic: true, - ast.AccessPublicSettable: true, + ast.AccessNotSpecified: true, + ast.AccessSelf: true, + ast.AccessAll: true, } require.Len(t, tests, len(ast.BasicAccesses)) @@ -414,10 +404,9 @@ func TestCheckAccessModifierGlobalConstantDeclaration(t *testing.T) { t.Parallel() tests := map[ast.Access]bool{ - ast.AccessNotSpecified: true, - ast.AccessPrivate: true, - ast.AccessPublic: true, - ast.AccessPublicSettable: false, + ast.AccessNotSpecified: true, + ast.AccessSelf: true, + ast.AccessAll: true, } require.Len(t, tests, len(ast.BasicAccesses)) @@ -449,10 +438,9 @@ func TestCheckAccessModifierLocalVariableDeclaration(t *testing.T) { t.Parallel() tests := map[ast.Access]bool{ - ast.AccessNotSpecified: true, - ast.AccessPrivate: false, - ast.AccessPublic: false, - ast.AccessPublicSettable: false, + ast.AccessNotSpecified: true, + ast.AccessSelf: false, + ast.AccessAll: false, } require.Len(t, tests, len(ast.BasicAccesses)) @@ -496,10 +484,9 @@ func TestCheckAccessModifierLocalFunctionDeclaration(t *testing.T) { t.Parallel() tests := map[ast.Access]bool{ - ast.AccessNotSpecified: true, - ast.AccessPrivate: false, - ast.AccessPublic: false, - ast.AccessPublicSettable: false, + ast.AccessNotSpecified: true, + ast.AccessSelf: false, + ast.AccessAll: false, } require.Len(t, tests, len(ast.BasicAccesses)) @@ -540,28 +527,24 @@ func TestCheckAccessModifierGlobalCompositeDeclaration(t *testing.T) { checkModeTests := map[sema.AccessCheckMode]map[ast.Access]func(*testing.T, error){ sema.AccessCheckModeStrict: { - ast.AccessNotSpecified: expectMissingAccessModifierError, - ast.AccessPrivate: expectInvalidAccessModifierError, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectInvalidAccessModifierError, + ast.AccessNotSpecified: expectMissingAccessModifierError, + ast.AccessSelf: expectInvalidAccessModifierError, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNotSpecifiedRestricted: { - ast.AccessNotSpecified: expectMissingAccessModifierError, - ast.AccessPrivate: expectInvalidAccessModifierError, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectInvalidAccessModifierError, + ast.AccessNotSpecified: expectMissingAccessModifierError, + ast.AccessSelf: expectInvalidAccessModifierError, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNotSpecifiedUnrestricted: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectInvalidAccessModifierError, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectInvalidAccessModifierError, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectInvalidAccessModifierError, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNone: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectInvalidAccessModifierError, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectInvalidAccessModifierError, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectInvalidAccessModifierError, + ast.AccessAll: expectSuccess, }, } @@ -643,28 +626,24 @@ func TestCheckAccessCompositeFunction(t *testing.T) { checkModeTests := map[sema.AccessCheckMode]map[ast.Access]func(*testing.T, error){ sema.AccessCheckModeStrict: { - ast.AccessNotSpecified: nil, - ast.AccessPrivate: expectInvalidAccessError, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: nil, + ast.AccessNotSpecified: nil, + ast.AccessSelf: expectInvalidAccessError, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNotSpecifiedRestricted: { - ast.AccessNotSpecified: expectInvalidAccessError, - ast.AccessPrivate: expectInvalidAccessError, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: nil, + ast.AccessNotSpecified: expectInvalidAccessError, + ast.AccessSelf: expectInvalidAccessError, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNotSpecifiedUnrestricted: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectInvalidAccessError, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: nil, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectInvalidAccessError, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNone: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectSuccess, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: nil, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectSuccess, + ast.AccessAll: expectSuccess, }, } @@ -708,15 +687,15 @@ func TestCheckAccessCompositeFunction(t *testing.T) { _, err := ParseAndCheckWithOptions(t, fmt.Sprintf( ` - pub %[1]s Test { + access(all) %[1]s Test { %[2]s fun test() {} - pub fun test2() { + access(all) fun test2() { self.test() } } - pub fun test() { + access(all) fun test() { %[3]s %[4]s.test() %[5]s @@ -750,28 +729,24 @@ func TestCheckAccessInterfaceFunction(t *testing.T) { checkModeTests := map[sema.AccessCheckMode]map[ast.Access]func(*testing.T, error){ sema.AccessCheckModeStrict: { - ast.AccessNotSpecified: nil, - ast.AccessPrivate: expectInvalidAccessModifierAndInvalidAccessErrors, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: nil, + ast.AccessNotSpecified: nil, + ast.AccessSelf: expectInvalidAccessModifierAndInvalidAccessErrors, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNotSpecifiedRestricted: { - ast.AccessNotSpecified: expectConformanceAndInvalidAccessErrors, - ast.AccessPrivate: expectInvalidAccessModifierAndInvalidAccessErrors, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: nil, + ast.AccessNotSpecified: expectConformanceAndInvalidAccessErrors, + ast.AccessSelf: expectInvalidAccessModifierAndInvalidAccessErrors, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNotSpecifiedUnrestricted: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectInvalidAccessModifierAndInvalidAccessErrors, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: nil, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectInvalidAccessModifierAndInvalidAccessErrors, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNone: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectInvalidAccessModifierError, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: nil, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectInvalidAccessModifierError, + ast.AccessAll: expectSuccess, }, } @@ -819,19 +794,19 @@ func TestCheckAccessInterfaceFunction(t *testing.T) { _, err := ParseAndCheckWithOptions(t, fmt.Sprintf( ` - pub %[1]s interface Test { + access(all) %[1]s interface Test { %[2]s fun test() } - pub %[1]s TestImpl: Test { + access(all) %[1]s TestImpl: Test { %[2]s fun test() {} - pub fun test2() { + access(all) fun test2() { self.test() } } - pub fun test() { + access(all) fun test() { %[3]s %[4]s.test() %[5]s @@ -863,28 +838,24 @@ func TestCheckAccessCompositeFieldRead(t *testing.T) { checkModeTests := map[sema.AccessCheckMode]map[ast.Access]func(*testing.T, error){ sema.AccessCheckModeStrict: { - ast.AccessNotSpecified: nil, - ast.AccessPrivate: expectInvalidAccessError, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: nil, + ast.AccessSelf: expectInvalidAccessError, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNotSpecifiedRestricted: { - ast.AccessNotSpecified: expectInvalidAccessError, - ast.AccessPrivate: expectInvalidAccessError, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectInvalidAccessError, + ast.AccessSelf: expectInvalidAccessError, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNotSpecifiedUnrestricted: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectInvalidAccessError, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectInvalidAccessError, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNone: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectSuccess, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectSuccess, + ast.AccessAll: expectSuccess, }, } @@ -930,19 +901,19 @@ func TestCheckAccessCompositeFieldRead(t *testing.T) { _, err := ParseAndCheckWithOptions(t, fmt.Sprintf( ` - pub %[1]s Test { + access(all) %[1]s Test { %[2]s var test: Int init() { self.test = 0 } - pub fun test2() { + access(all) fun test2() { self.test } } - pub fun test() { + access(all) fun test() { %[3]s %[4]s.test %[5]s @@ -974,28 +945,24 @@ func TestCheckAccessInterfaceFieldRead(t *testing.T) { checkModeTests := map[sema.AccessCheckMode]map[ast.Access]func(*testing.T, error){ sema.AccessCheckModeStrict: { - ast.AccessNotSpecified: nil, - ast.AccessPrivate: expectInvalidAccessModifierAndInvalidAccessErrors, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: nil, + ast.AccessSelf: expectInvalidAccessModifierAndInvalidAccessErrors, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNotSpecifiedRestricted: { - ast.AccessNotSpecified: expectConformanceAndInvalidAccessErrors, - ast.AccessPrivate: expectInvalidAccessModifierAndInvalidAccessErrors, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectConformanceAndInvalidAccessErrors, + ast.AccessSelf: expectInvalidAccessModifierAndInvalidAccessErrors, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNotSpecifiedUnrestricted: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectInvalidAccessModifierAndInvalidAccessErrors, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectInvalidAccessModifierAndInvalidAccessErrors, + ast.AccessAll: expectSuccess, }, sema.AccessCheckModeNone: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectInvalidAccessModifierError, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectInvalidAccessModifierError, + ast.AccessAll: expectSuccess, }, } @@ -1045,23 +1012,23 @@ func TestCheckAccessInterfaceFieldRead(t *testing.T) { _, err := ParseAndCheckWithOptions(t, fmt.Sprintf( ` - pub %[1]s interface Test { + access(all) %[1]s interface Test { %[2]s var test: Int } - pub %[1]s TestImpl: Test { + access(all) %[1]s TestImpl: Test { %[2]s var test: Int init() { self.test = 0 } - pub fun test2() { + access(all) fun test2() { self.test } } - pub fun test() { + access(all) fun test() { %[3]s %[4]s.test %[5]s @@ -1093,28 +1060,24 @@ func TestCheckAccessCompositeFieldAssignmentAndSwap(t *testing.T) { checkModeTests := map[sema.AccessCheckMode]map[ast.Access]func(*testing.T, error){ sema.AccessCheckModeStrict: { - ast.AccessNotSpecified: nil, - ast.AccessPrivate: expectTwoAccessErrors, - ast.AccessPublic: expectTwoInvalidAssignmentAccessErrors, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: nil, + ast.AccessSelf: expectTwoAccessErrors, + ast.AccessAll: expectTwoInvalidAssignmentAccessErrors, }, sema.AccessCheckModeNotSpecifiedRestricted: { - ast.AccessNotSpecified: expectTwoAccessErrors, - ast.AccessPrivate: expectTwoAccessErrors, - ast.AccessPublic: expectTwoInvalidAssignmentAccessErrors, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectTwoAccessErrors, + ast.AccessSelf: expectTwoAccessErrors, + ast.AccessAll: expectTwoInvalidAssignmentAccessErrors, }, sema.AccessCheckModeNotSpecifiedUnrestricted: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectTwoAccessErrors, - ast.AccessPublic: expectTwoInvalidAssignmentAccessErrors, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectTwoAccessErrors, + ast.AccessAll: expectTwoInvalidAssignmentAccessErrors, }, sema.AccessCheckModeNone: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectSuccess, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectSuccess, + ast.AccessAll: expectSuccess, }, } @@ -1159,21 +1122,21 @@ func TestCheckAccessCompositeFieldAssignmentAndSwap(t *testing.T) { _, err := ParseAndCheckWithOptions(t, fmt.Sprintf( ` - pub %[1]s Test { + access(all) %[1]s Test { %[2]s var test: Int init() { self.test = 0 } - pub fun test2() { + access(all) fun test2() { self.test = 1 var temp = 2 self.test <-> temp } } - pub fun test() { + access(all) fun test() { %[3]s %[4]s.test = 3 @@ -1229,28 +1192,24 @@ func TestCheckAccessInterfaceFieldWrite(t *testing.T) { checkModeTests := map[sema.AccessCheckMode]map[ast.Access]func(*testing.T, error){ sema.AccessCheckModeStrict: { - ast.AccessNotSpecified: nil, - ast.AccessPrivate: expectInvalidAccessModifierAndAccessErrors, - ast.AccessPublic: expectTwoInvalidAssignmentAccessErrors, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: nil, + ast.AccessSelf: expectInvalidAccessModifierAndAccessErrors, + ast.AccessAll: expectTwoInvalidAssignmentAccessErrors, }, sema.AccessCheckModeNotSpecifiedRestricted: { - ast.AccessNotSpecified: expectConformanceAndAccessErrors, - ast.AccessPrivate: expectInvalidAccessModifierAndAccessErrors, - ast.AccessPublic: expectTwoInvalidAssignmentAccessErrors, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectConformanceAndAccessErrors, + ast.AccessSelf: expectInvalidAccessModifierAndAccessErrors, + ast.AccessAll: expectTwoInvalidAssignmentAccessErrors, }, sema.AccessCheckModeNotSpecifiedUnrestricted: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectInvalidAccessModifierAndAccessErrors, - ast.AccessPublic: expectTwoInvalidAssignmentAccessErrors, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectInvalidAccessModifierAndAccessErrors, + ast.AccessAll: expectTwoInvalidAssignmentAccessErrors, }, sema.AccessCheckModeNone: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectInvalidAccessModifierError, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectInvalidAccessModifierError, + ast.AccessAll: expectSuccess, }, } @@ -1300,25 +1259,25 @@ func TestCheckAccessInterfaceFieldWrite(t *testing.T) { _, err := ParseAndCheckWithOptions(t, fmt.Sprintf( ` - pub %[1]s interface Test { + access(all) %[1]s interface Test { %[2]s var test: Int } - pub %[1]s TestImpl: Test { + access(all) %[1]s TestImpl: Test { %[2]s var test: Int init() { self.test = 0 } - pub fun test2() { + access(all) fun test2() { self.test = 1 var temp = 2 self.test <-> temp } } - pub fun test() { + access(all) fun test() { %[3]s %[4]s.test = 3 var temp = 4 @@ -1352,28 +1311,24 @@ func TestCheckAccessCompositeFieldVariableDeclarationWithSecondValue(t *testing. checkModeTests := map[sema.AccessCheckMode]map[ast.Access]func(*testing.T, error){ sema.AccessCheckModeStrict: { - ast.AccessNotSpecified: nil, - ast.AccessPrivate: expectAccessErrors, - ast.AccessPublic: expectInvalidAssignmentAccessError, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: nil, + ast.AccessSelf: expectAccessErrors, + ast.AccessAll: expectInvalidAssignmentAccessError, }, sema.AccessCheckModeNotSpecifiedRestricted: { - ast.AccessNotSpecified: expectAccessErrors, - ast.AccessPrivate: expectAccessErrors, - ast.AccessPublic: expectInvalidAssignmentAccessError, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectAccessErrors, + ast.AccessSelf: expectAccessErrors, + ast.AccessAll: expectInvalidAssignmentAccessError, }, sema.AccessCheckModeNotSpecifiedUnrestricted: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectAccessErrors, - ast.AccessPublic: expectInvalidAssignmentAccessError, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectAccessErrors, + ast.AccessAll: expectInvalidAssignmentAccessError, }, sema.AccessCheckModeNone: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectSuccess, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectSuccess, + ast.AccessAll: expectSuccess, }, } @@ -1399,9 +1354,9 @@ func TestCheckAccessCompositeFieldVariableDeclarationWithSecondValue(t *testing. _, err := ParseAndCheckWithOptions(t, fmt.Sprintf( ` - pub resource A {} + access(all) resource A {} - pub resource B { + access(all) resource B { %[1]s var a: @A init() { @@ -1412,13 +1367,13 @@ func TestCheckAccessCompositeFieldVariableDeclarationWithSecondValue(t *testing. destroy self.a } - pub fun test() { + access(all) fun test() { let oldA <- self.a <- create A() destroy oldA } } - pub fun test() { + access(all) fun test() { let b <- create B() let oldA <- b.a <- create A() destroy oldA @@ -1454,10 +1409,9 @@ func TestCheckAccessInterfaceFieldVariableDeclarationWithSecondValue(t *testing. checkModeTests := map[sema.AccessCheckMode]map[ast.Access]func(*testing.T, error){ sema.AccessCheckModeStrict: { - ast.AccessNotSpecified: nil, - ast.AccessPrivate: expectPrivateAccessErrors, - ast.AccessPublic: expectInvalidAssignmentAccessError, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: nil, + ast.AccessSelf: expectPrivateAccessErrors, + ast.AccessAll: expectInvalidAssignmentAccessError, }, sema.AccessCheckModeNotSpecifiedRestricted: { ast.AccessNotSpecified: func(t *testing.T, err error) { @@ -1467,21 +1421,18 @@ func TestCheckAccessInterfaceFieldVariableDeclarationWithSecondValue(t *testing. assert.IsType(t, &sema.InvalidAccessError{}, errs[1]) assert.IsType(t, &sema.InvalidAssignmentAccessError{}, errs[2]) }, - ast.AccessPrivate: expectPrivateAccessErrors, - ast.AccessPublic: expectInvalidAssignmentAccessError, - ast.AccessPublicSettable: expectSuccess, + ast.AccessSelf: expectPrivateAccessErrors, + ast.AccessAll: expectInvalidAssignmentAccessError, }, sema.AccessCheckModeNotSpecifiedUnrestricted: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectPrivateAccessErrors, - ast.AccessPublic: expectInvalidAssignmentAccessError, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectPrivateAccessErrors, + ast.AccessAll: expectInvalidAssignmentAccessError, }, sema.AccessCheckModeNone: { - ast.AccessNotSpecified: expectSuccess, - ast.AccessPrivate: expectInvalidAccessModifierError, - ast.AccessPublic: expectSuccess, - ast.AccessPublicSettable: expectSuccess, + ast.AccessNotSpecified: expectSuccess, + ast.AccessSelf: expectInvalidAccessModifierError, + ast.AccessAll: expectSuccess, }, } @@ -1507,13 +1458,13 @@ func TestCheckAccessInterfaceFieldVariableDeclarationWithSecondValue(t *testing. _, err := ParseAndCheckWithOptions(t, fmt.Sprintf( ` - pub resource A {} + access(all) resource A {} - pub resource interface B { + access(all) resource interface B { %[1]s var a: @A } - pub resource BImpl: B { + access(all) resource BImpl: B { %[1]s var a: @A init() { @@ -1524,13 +1475,13 @@ func TestCheckAccessInterfaceFieldVariableDeclarationWithSecondValue(t *testing. destroy self.a } - pub fun test() { + access(all) fun test() { let oldA <- self.a <- create A() destroy oldA } } - pub fun test() { + access(all) fun test() { let b: @AnyResource{B} <- create BImpl() let oldA <- b.a <- create A() destroy oldA @@ -1607,14 +1558,14 @@ func TestCheckAccessImportGlobalValue(t *testing.T) { lastAccessModifier := "" if checkMode == sema.AccessCheckModeStrict { - lastAccessModifier = "priv" + lastAccessModifier = "access(self)" } tests := []string{ fmt.Sprintf( ` - priv fun a() {} - pub fun b() {} + access(self) fun a() {} + access(all) fun b() {} %s fun c() {} `, lastAccessModifier, @@ -1626,8 +1577,8 @@ func TestCheckAccessImportGlobalValue(t *testing.T) { tests = append(tests, fmt.Sprintf( ` - priv %[1]s a = 1 - pub %[1]s b = 2 + access(self) %[1]s a = 1 + access(all) %[1]s b = 2 %[2]s %[1]s c = 3 `, variableKind.Keyword(), @@ -1817,14 +1768,14 @@ func TestCheckAccessImportGlobalValueAssignmentAndSwap(t *testing.T) { lastAccessModifier := "" if checkMode == sema.AccessCheckModeStrict { - lastAccessModifier = "priv" + lastAccessModifier = "access(self)" } imported, err := ParseAndCheck(t, fmt.Sprintf( ` - priv var a = 1 - pub var b = 2 + access(self) var a = 1 + access(all) var b = 2 %s var c = 3 `, lastAccessModifier, @@ -1836,7 +1787,7 @@ func TestCheckAccessImportGlobalValueAssignmentAndSwap(t *testing.T) { ` import a, b, c from "imported" - pub fun test() { + access(all) fun test() { a = 4 b = 5 c = 6 @@ -1873,14 +1824,14 @@ func TestCheckAccessImportGlobalValueVariableDeclarationWithSecondValue(t *testi t.Parallel() imported, err := ParseAndCheck(t, ` - pub resource R {} + access(all) resource R {} - pub fun createR(): @R { + access(all) fun createR(): @R { return <-create R() } - priv var x <- createR() - pub var y <- createR() + access(self) var x <- createR() + access(all) var y <- createR() `) require.NoError(t, err) @@ -1888,7 +1839,7 @@ func TestCheckAccessImportGlobalValueVariableDeclarationWithSecondValue(t *testi ` import x, y, createR from "imported" - pub fun test() { + access(all) fun test() { let oldX <- x <- createR() destroy oldX @@ -1938,7 +1889,7 @@ func TestCheckContractNestedDeclarationPrivateAccess(t *testing.T) { const contract = ` contract Outer { - priv let num: Int + access(self) let num: Int init(num: Int) { self.num = num @@ -1972,10 +1923,10 @@ func TestCheckAccessSameContractInnerStructField(t *testing.T) { t.Parallel() tests := map[ast.Access]bool{ - ast.AccessPrivate: false, + ast.AccessSelf: false, ast.AccessContract: true, ast.AccessAccount: true, - ast.AccessPublic: true, + ast.AccessAll: true, } for access, expectSuccess := range tests { @@ -2019,10 +1970,10 @@ func TestCheckAccessSameContractInnerStructInterfaceField(t *testing.T) { t.Parallel() tests := map[ast.Access]bool{ - ast.AccessPrivate: false, + ast.AccessSelf: false, ast.AccessContract: true, ast.AccessAccount: true, - ast.AccessPublic: true, + ast.AccessAll: true, } for access, expectSuccess := range tests { @@ -2071,10 +2022,10 @@ func TestCheckAccessOtherContractInnerStructField(t *testing.T) { t.Parallel() tests := map[ast.Access]bool{ - ast.AccessPrivate: false, + ast.AccessSelf: false, ast.AccessContract: false, ast.AccessAccount: true, - ast.AccessPublic: true, + ast.AccessAll: true, } for access, expectSuccess := range tests { @@ -2120,7 +2071,7 @@ func TestCheckAccessOtherContractInnerStructInterfaceField(t *testing.T) { t.Parallel() tests := map[ast.Access][]error{ - ast.AccessPrivate: { + ast.AccessSelf: { &sema.InvalidAccessModifierError{}, &sema.InvalidAccessError{}, }, @@ -2128,7 +2079,7 @@ func TestCheckAccessOtherContractInnerStructInterfaceField(t *testing.T) { &sema.InvalidAccessError{}, }, ast.AccessAccount: nil, - ast.AccessPublic: nil, + ast.AccessAll: nil, } for access, expectedErrorTypes := range tests { @@ -2177,7 +2128,7 @@ func TestCheckRestrictiveAccessModifier(t *testing.T) { for _, access := range ast.AllAccesses { - if access <= ast.AccessPrivate { + if access <= ast.AccessSelf { continue } @@ -2188,17 +2139,17 @@ func TestCheckRestrictiveAccessModifier(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf( ` - pub contract interface CI { + access(all) contract interface CI { - pub resource R { + access(all) resource R { %[1]s var x: Int } } - pub contract C: CI { + access(all) contract C: CI { - pub resource R { + access(all) resource R { %[1]s var x: Int @@ -2220,12 +2171,12 @@ func TestCheckRestrictiveAccessModifier(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf( ` - pub resource interface RI { + access(all) resource interface RI { %[1]s var x: Int } - pub resource R: RI { + access(all) resource R: RI { %[1]s var x: Int @@ -2252,7 +2203,7 @@ func TestCheckInvalidRestrictiveAccessModifier(t *testing.T) { for _, access := range ast.AllAccesses { if access == ast.AccessNotSpecified || - access > ast.AccessPrivate { + access > ast.AccessSelf { continue } @@ -2264,9 +2215,9 @@ func TestCheckInvalidRestrictiveAccessModifier(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf( ` - pub contract interface CI { + access(all) contract interface CI { - pub resource R { + access(all) resource R { %[1]s var x: Int } @@ -2284,7 +2235,7 @@ func TestCheckInvalidRestrictiveAccessModifier(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf( ` - pub resource interface RI { + access(all) resource interface RI { %[1]s var x: Int } @@ -2323,8 +2274,8 @@ func TestCheckAccountAccess(t *testing.T) { const importingCode = ` import A from 0x1 - pub contract B { - pub fun use() { + access(all) contract B { + access(all) fun use() { let b = A.a } } @@ -2363,7 +2314,7 @@ func TestCheckAccountAccess(t *testing.T) { importedChecker, err := ParseAndCheckWithOptions(t, fmt.Sprintf( ` - pub contract A { + access(all) contract A { access(account) %s a: Int init() { diff --git a/runtime/tests/checker/assert_test.go b/runtime/tests/checker/assert_test.go index a726834519..c41f0b1d1b 100644 --- a/runtime/tests/checker/assert_test.go +++ b/runtime/tests/checker/assert_test.go @@ -36,7 +36,7 @@ func TestCheckAssertWithoutMessage(t *testing.T) { _, err := ParseAndCheckWithOptions(t, ` - pub fun test() { + access(all) fun test() { assert(1 == 2) } `, @@ -59,7 +59,7 @@ func TestCheckAssertWithMessage(t *testing.T) { _, err := ParseAndCheckWithOptions(t, ` - pub fun test() { + access(all) fun test() { assert(1 == 2, message: "test message") } `, diff --git a/runtime/tests/checker/attachments_test.go b/runtime/tests/checker/attachments_test.go index a6a151451d..99e26816e7 100644 --- a/runtime/tests/checker/attachments_test.go +++ b/runtime/tests/checker/attachments_test.go @@ -448,7 +448,7 @@ func TestCheckNestedBaseType(t *testing.T) { fun foo() {} } } - pub attachment A for C.S { + access(all) attachment A for C.S { fun bar() { base.foo() } @@ -470,7 +470,7 @@ func TestCheckNestedBaseType(t *testing.T) { fun foo() {} } } - pub attachment A for S { + access(all) attachment A for S { } `, ) @@ -1343,16 +1343,16 @@ func TestCheckBaseScoping(t *testing.T) { t.Parallel() - t.Run("pub member", func(t *testing.T) { + t.Run("access(all) member", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub struct S { - pub fun foo() {} + access(all) struct S { + access(all) fun foo() {} } - pub attachment Test for S { + access(all) attachment Test for S { fun foo() { base.foo() } @@ -1362,16 +1362,16 @@ func TestCheckBaseScoping(t *testing.T) { require.NoError(t, err) }) - t.Run("priv member", func(t *testing.T) { + t.Run("access(self) member", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub struct S { - priv fun foo() {} + access(all) struct S { + access(self) fun foo() {} } - pub attachment Test for S { + access(all) attachment Test for S { fun foo() { base.foo() } @@ -1389,12 +1389,12 @@ func TestCheckBaseScoping(t *testing.T) { _, err := ParseAndCheck(t, ` - pub contract C { - pub struct S { + access(all) contract C { + access(all) struct S { access(contract) fun foo() {} } } - pub attachment Test for C.S { + access(all) attachment Test for C.S { fun foo() { base.foo() } @@ -1412,11 +1412,11 @@ func TestCheckBaseScoping(t *testing.T) { _, err := ParseAndCheck(t, ` - pub contract C { - pub struct S { + access(all) contract C { + access(all) struct S { access(contract) fun foo() {} } - pub attachment Test for S { + access(all) attachment Test for S { fun foo() { base.foo() } @@ -1755,7 +1755,7 @@ func TestCheckIllegalInit(t *testing.T) { _, err := ParseAndCheck(t, `attachment Test for AnyResource {} - pub fun foo() { + access(all) fun foo() { let t <- Test() destroy t } @@ -1778,8 +1778,8 @@ func TestCheckAttachNonAttachment(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun A() {} - pub fun foo() { + access(all) fun A() {} + access(all) fun foo() { attach A() to 4 } `, @@ -1796,8 +1796,8 @@ func TestCheckAttachNonAttachment(t *testing.T) { _, err := ParseAndCheck(t, ` - pub struct S {} - pub fun foo() { + access(all) struct S {} + access(all) fun foo() { attach S() to 4 } `, @@ -1814,8 +1814,8 @@ func TestCheckAttachNonAttachment(t *testing.T) { _, err := ParseAndCheck(t, ` - pub resource R {} - pub fun foo() { + access(all) resource R {} + access(all) fun foo() { attach R() to 4 } `, @@ -1835,7 +1835,7 @@ func TestCheckAttachNonAttachment(t *testing.T) { _, err := ParseAndCheck(t, ` event E() - pub fun foo() { + access(all) fun foo() { attach E() to 4 } `, @@ -1853,7 +1853,7 @@ func TestCheckAttachNonAttachment(t *testing.T) { _, err := ParseAndCheck(t, ` enum E: Int {} - pub fun foo() { + access(all) fun foo() { attach E(rawValue: 0) to 4 } `, @@ -1871,7 +1871,7 @@ func TestCheckAttachNonAttachment(t *testing.T) { _, err := ParseAndCheck(t, ` contract C {} - pub fun foo() { + access(all) fun foo() { attach C() to 4 } `, @@ -1894,7 +1894,7 @@ func TestCheckAttachToNonComposite(t *testing.T) { _, err := ParseAndCheck(t, ` attachment A for AnyStruct {} - pub fun foo() { + access(all) fun foo() { attach A() to 4 } `, @@ -1913,7 +1913,7 @@ func TestCheckAttachToNonComposite(t *testing.T) { ` struct S{} attachment A for AnyStruct {} - pub fun foo() { + access(all) fun foo() { let s = S() attach A() to (&s as &S) } @@ -1932,7 +1932,7 @@ func TestCheckAttachToNonComposite(t *testing.T) { _, err := ParseAndCheck(t, ` attachment A for AnyResource {} - pub fun foo() { + access(all) fun foo() { attach A() to 4 } `, @@ -1951,7 +1951,7 @@ func TestCheckAttachToNonComposite(t *testing.T) { _, err := ParseAndCheck(t, ` attachment A for AnyStruct {} - pub fun foo() { + access(all) fun foo() { attach A() to [4] } `, @@ -1970,7 +1970,7 @@ func TestCheckAttachToNonComposite(t *testing.T) { ` attachment A for AnyStruct {} event E() - pub fun foo() { + access(all) fun foo() { attach A() to E() } `, @@ -1989,7 +1989,7 @@ func TestCheckAttachToNonComposite(t *testing.T) { ` attachment A for AnyStruct {} contract C {} - pub fun foo() { + access(all) fun foo() { attach A() to C() } `, @@ -2008,7 +2008,7 @@ func TestCheckAttachToNonComposite(t *testing.T) { ` attachment A for AnyStruct {} attachment B for AnyStruct {} - pub fun foo() { + access(all) fun foo() { attach A() to B() } `, @@ -2027,7 +2027,7 @@ func TestCheckAttachToNonComposite(t *testing.T) { ` attachment A for AnyStruct {} enum E: Int { } - pub fun foo() { + access(all) fun foo() { attach A() to E(rawValue: 0) } `, @@ -2046,7 +2046,7 @@ func TestCheckAttachToNonComposite(t *testing.T) { ` resource R {} attachment A for AnyResource {} - pub fun foo() { + access(all) fun foo() { let r <- attach A() to <-[<-create R()] destroy r } @@ -2071,7 +2071,7 @@ func TestCheckAttach(t *testing.T) { ` struct S {} attachment A for S {} - pub fun foo() { + access(all) fun foo() { attach A() to S() } `, @@ -2088,7 +2088,7 @@ func TestCheckAttach(t *testing.T) { ` resource R {} attachment A for R {} - pub fun foo() { + access(all) fun foo() { attach A() to <-create R() } `, @@ -2107,7 +2107,7 @@ func TestCheckAttach(t *testing.T) { ` resource R {} attachment A for R {} - pub fun foo() { + access(all) fun foo() { let r <- attach A() to <-create R() destroy r } @@ -2125,7 +2125,7 @@ func TestCheckAttach(t *testing.T) { ` resource R {} attachment A for R {} - pub fun foo() { + access(all) fun foo() { let r <- create R() let r2: @R <- attach A() to <-r destroy r2 @@ -2144,7 +2144,7 @@ func TestCheckAttach(t *testing.T) { ` resource R {} attachment A for R {} - pub fun foo() { + access(all) fun foo() { let r <- attach A() to create R() destroy r } @@ -2164,7 +2164,7 @@ func TestCheckAttach(t *testing.T) { ` struct S {} attachment A for AnyStruct {} - pub fun foo() { + access(all) fun foo() { attach A() to S() } `, @@ -2181,7 +2181,7 @@ func TestCheckAttach(t *testing.T) { ` struct S {} attachment A for AnyStruct {} - pub fun foo() { + access(all) fun foo() { attach A() to (S() as AnyStruct) } `, @@ -2200,7 +2200,7 @@ func TestCheckAttach(t *testing.T) { ` resource S {} attachment A for AnyResource {} - pub fun foo() { + access(all) fun foo() { destroy attach A() to <-(create S() as @AnyResource) } `, @@ -2219,7 +2219,7 @@ func TestCheckAttach(t *testing.T) { ` resource R {} attachment A for AnyResource {} - pub fun foo() { + access(all) fun foo() { let r <- attach A() to <-create R() destroy r } @@ -2238,7 +2238,7 @@ func TestCheckAttach(t *testing.T) { struct S: I {} struct interface I {} attachment A for I {} - pub fun foo() { + access(all) fun foo() { attach A() to S() } `, @@ -2256,7 +2256,7 @@ func TestCheckAttach(t *testing.T) { struct S {} struct interface I {} attachment A for I {} - pub fun foo() { + access(all) fun foo() { attach A() to S() } `, @@ -2276,7 +2276,7 @@ func TestCheckAttach(t *testing.T) { resource R: I {} resource interface I {} attachment A for I {} - pub fun foo() { + access(all) fun foo() { let r <- attach A() to <-create R() destroy r } @@ -2295,7 +2295,7 @@ func TestCheckAttach(t *testing.T) { resource R {} resource interface I {} attachment A for I {} - pub fun foo() { + access(all) fun foo() { let r <- attach A() to <-create R() destroy r } @@ -2316,7 +2316,7 @@ func TestCheckAttach(t *testing.T) { struct S {} resource interface I {} attachment A for I {} - pub fun foo() { + access(all) fun foo() { let r <- attach A() to S() destroy r } @@ -2338,7 +2338,7 @@ func TestCheckAttach(t *testing.T) { resource R {} struct interface I {} attachment A for I {} - pub fun foo() { + access(all) fun foo() { attach A() to <-create R() } `, @@ -2357,7 +2357,7 @@ func TestCheckAttach(t *testing.T) { ` resource R {} attachment A for AnyStruct {} - pub fun foo() { + access(all) fun foo() { attach A() to <-create R() } `, @@ -2376,7 +2376,7 @@ func TestCheckAttach(t *testing.T) { ` struct S {} attachment A for AnyResource {} - pub fun foo() { + access(all) fun foo() { let r <- attach A() to S() destroy r } @@ -2398,7 +2398,7 @@ func TestCheckAttach(t *testing.T) { struct interface I {} struct S: I {} attachment A for AnyStruct {} - pub fun foo() { + access(all) fun foo() { let s: S{I} = S() attach A() to s } @@ -2422,7 +2422,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { struct interface I {} struct S: I {} attachment A for AnyStruct {} - pub fun foo() { + access(all) fun foo() { let s: S{I} = S() attach A() to s } @@ -2441,7 +2441,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { struct interface I {} struct S: I {} attachment A for AnyStruct {} - pub fun foo() { + access(all) fun foo() { let s: {I} = S() attach A() to s } @@ -2460,7 +2460,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { resource interface I {} resource R: I {} attachment A for AnyResource {} - pub fun foo() { + access(all) fun foo() { let r: @R{I} <- create R() destroy attach A() to <-r } @@ -2479,7 +2479,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { resource interface I {} resource R: I {} attachment A for AnyResource {} - pub fun foo() { + access(all) fun foo() { let r: @{I} <- create R() destroy attach A() to <-r } @@ -2498,7 +2498,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { struct interface I {} struct S: I {} attachment A for I {} - pub fun foo() { + access(all) fun foo() { let s: S{I} = S() attach A() to s } @@ -2517,7 +2517,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { struct interface I {} struct S: I {} attachment A for S {} - pub fun foo() { + access(all) fun foo() { let s: S{I} = S() attach A() to s } @@ -2539,7 +2539,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { struct interface I {} struct S: I {} attachment A for S {} - pub fun foo() { + access(all) fun foo() { let s: {I} = S() attach A() to s } @@ -2560,7 +2560,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { resource interface I {} resource R: I {} attachment A for I {} - pub fun foo() { + access(all) fun foo() { let r: @R{I} <- create R() destroy attach A() to <-r } @@ -2579,7 +2579,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { resource interface I {} resource R: I {} attachment A for R {} - pub fun foo() { + access(all) fun foo() { let r: @R{I} <- create R() destroy attach A() to <-r } @@ -2601,7 +2601,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { resource interface I {} resource R: I {} attachment A for R {} - pub fun foo() { + access(all) fun foo() { let r: @{I} <- create R() destroy attach A() to <-r } @@ -2622,7 +2622,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { struct interface I {} struct S: I {} attachment A for I {} - pub fun foo() { + access(all) fun foo() { let s: {I} = S() attach A() to s } @@ -2642,7 +2642,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { struct interface I2 {} struct S: I, I2 {} attachment A for I {} - pub fun foo() { + access(all) fun foo() { let s: {I, I2} = S() attach A() to s } @@ -2661,7 +2661,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { resource interface I {} resource R: I {} attachment A for I {} - pub fun foo() { + access(all) fun foo() { let r: @{I} <- create R() destroy attach A() to <-r } @@ -2681,7 +2681,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { resource interface I2 {} resource R: I, I2 {} attachment A for I {} - pub fun foo() { + access(all) fun foo() { let r: @{I, I2} <- create R() destroy attach A() to <-r } @@ -2701,7 +2701,7 @@ func TestCheckAttachToRestrictedType(t *testing.T) { resource interface I2: I {} resource R: I2 {} attachment A for I {} - pub fun foo() { + access(all) fun foo() { let r: @{I2} <- create R() destroy attach A() to <-r } @@ -2729,7 +2729,7 @@ func TestCheckAttachWithArguments(t *testing.T) { self.x = x } } - pub fun foo() { + access(all) fun foo() { attach A(x: 3) to S() } `, @@ -2751,7 +2751,7 @@ func TestCheckAttachWithArguments(t *testing.T) { self.x = x } } - pub fun foo() { + access(all) fun foo() { attach A(x: base) to S() } `, @@ -2777,7 +2777,7 @@ func TestCheckAttachWithArguments(t *testing.T) { self.y = y } } - pub fun foo() { + access(all) fun foo() { attach A(x: 3, y: "") to S() } `, @@ -2801,7 +2801,7 @@ func TestCheckAttachWithArguments(t *testing.T) { self.y = y } } - pub fun foo() { + access(all) fun foo() { attach A(3, "") to S() } `, @@ -2828,7 +2828,7 @@ func TestCheckAttachWithArguments(t *testing.T) { self.y = y } } - pub fun foo() { + access(all) fun foo() { attach A(z: 3, a: "") to S() } `, @@ -2849,7 +2849,7 @@ func TestCheckAttachInvalidType(t *testing.T) { ` resource C {} attachment A for B {} - pub fun foo() { + access(all) fun foo() { destroy attach A() to <- create C() }`, ) @@ -2938,7 +2938,7 @@ func TestCheckAnyAttachmentTypes(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` %s - pub fun foo(x: &%s): &AnyStructAttachment { + access(all) fun foo(x: &%s): &AnyStructAttachment { return x } `, testCase.setupCode, testCase.subType), @@ -2961,7 +2961,7 @@ func TestCheckAnyAttachmentTypes(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` %s - pub fun foo(x: &%s): &AnyResourceAttachment { + access(all) fun foo(x: &%s): &AnyResourceAttachment { return x } `, testCase.setupCode, testCase.subType), @@ -2990,7 +2990,7 @@ func TestCheckRemove(t *testing.T) { ` struct S {} attachment A for S {} - pub fun foo(s: S) { + access(all) fun foo(s: S) { remove A from s } `, @@ -3007,7 +3007,7 @@ func TestCheckRemove(t *testing.T) { ` resource R {} attachment A for R {} - pub fun foo(r: @R) { + access(all) fun foo(r: @R) { remove A from r destroy r } @@ -3025,7 +3025,7 @@ func TestCheckRemove(t *testing.T) { ` resource R {} attachment A for R {} - pub fun foo(r: @R) { + access(all) fun foo(r: @R) { remove A from r } `, @@ -3043,7 +3043,7 @@ func TestCheckRemove(t *testing.T) { ` struct S {} attachment A for AnyStruct {} - pub fun foo(s: S) { + access(all) fun foo(s: S) { remove A from s } `, @@ -3061,7 +3061,7 @@ func TestCheckRemove(t *testing.T) { struct S: I {} struct interface I {} attachment A for I {} - pub fun foo(s: S) { + access(all) fun foo(s: S) { remove A from s } `, @@ -3079,7 +3079,7 @@ func TestCheckRemove(t *testing.T) { struct S {} struct interface I {} attachment A for I {} - pub fun foo(s: S) { + access(all) fun foo(s: S) { remove A from s } `, @@ -3097,7 +3097,7 @@ func TestCheckRemove(t *testing.T) { ` resource R {} attachment A for AnyResource {} - pub fun foo(r: @R) { + access(all) fun foo(r: @R) { remove A from r destroy r } @@ -3116,7 +3116,7 @@ func TestCheckRemove(t *testing.T) { resource R: I {} resource interface I {} attachment A for I {} - pub fun foo(r: @R) { + access(all) fun foo(r: @R) { remove A from r destroy r } @@ -3135,7 +3135,7 @@ func TestCheckRemove(t *testing.T) { resource R {} resource interface I {} attachment A for I {} - pub fun foo(r: @R) { + access(all) fun foo(r: @R) { remove A from r destroy r } @@ -3156,7 +3156,7 @@ func TestCheckRemove(t *testing.T) { struct S {} attachment A for S {} } - pub fun foo(s: C.S) { + access(all) fun foo(s: C.S) { remove C.A from s } `, @@ -3173,7 +3173,7 @@ func TestCheckRemove(t *testing.T) { ` struct S {} attachment A for S {} - pub fun foo(s: Int) { + access(all) fun foo(s: Int) { remove A from s } `, @@ -3190,7 +3190,7 @@ func TestCheckRemove(t *testing.T) { _, err := ParseAndCheck(t, ` attachment A for AnyStruct {} - pub fun foo(s: AnyStruct) { + access(all) fun foo(s: AnyStruct) { remove A from s } `, @@ -3207,7 +3207,7 @@ func TestCheckRemove(t *testing.T) { _, err := ParseAndCheck(t, ` attachment A for AnyResource {} - pub fun foo(s: @AnyResource) { + access(all) fun foo(s: @AnyResource) { remove A from s destroy s } @@ -3225,7 +3225,7 @@ func TestCheckRemove(t *testing.T) { _, err := ParseAndCheck(t, ` attachment A for AnyStruct {} - pub fun foo(s: Int) { + access(all) fun foo(s: Int) { remove A from s } `, @@ -3243,7 +3243,7 @@ func TestCheckRemove(t *testing.T) { ` struct S {} attachment A for S {} - pub fun foo(s: S) { + access(all) fun foo(s: S) { remove S from s } `, @@ -3261,7 +3261,7 @@ func TestCheckRemove(t *testing.T) { ` resource S {} attachment A for S {} - pub fun foo(s: @S) { + access(all) fun foo(s: @S) { remove S from s destroy s } @@ -3280,7 +3280,7 @@ func TestCheckRemove(t *testing.T) { ` struct S {} attachment A for S {} - pub fun foo(s: S) { + access(all) fun foo(s: S) { remove X from s } `, @@ -3298,7 +3298,7 @@ func TestCheckRemove(t *testing.T) { ` struct S {} event E() - pub fun foo(s: S) { + access(all) fun foo(s: S) { remove E from s } `, @@ -3316,7 +3316,7 @@ func TestCheckRemove(t *testing.T) { ` struct S {} contract C {} - pub fun foo(s: S) { + access(all) fun foo(s: S) { remove C from s } `, @@ -3334,7 +3334,7 @@ func TestCheckRemove(t *testing.T) { ` struct S {} resource interface C {} - pub fun foo(s: S) { + access(all) fun foo(s: S) { remove C from s } `, @@ -3352,7 +3352,7 @@ func TestCheckRemove(t *testing.T) { ` struct S {} resource interface C {} - pub fun foo(s: S) { + access(all) fun foo(s: S) { remove C from s } `, @@ -3369,7 +3369,7 @@ func TestCheckRemove(t *testing.T) { _, err := ParseAndCheck(t, ` struct S {} - pub fun foo(s: S) { + access(all) fun foo(s: S) { remove AnyStruct from s } `, @@ -3386,7 +3386,7 @@ func TestCheckRemove(t *testing.T) { _, err := ParseAndCheck(t, ` resource S {} - pub fun foo(s: @S) { + access(all) fun foo(s: @S) { remove AnyResource from s destroy s } @@ -3404,7 +3404,7 @@ func TestCheckRemove(t *testing.T) { _, err := ParseAndCheck(t, ` struct S {} - pub fun foo(s: S) { + access(all) fun foo(s: S) { remove AnyStructAttachment from s } `, @@ -3421,7 +3421,7 @@ func TestCheckRemove(t *testing.T) { _, err := ParseAndCheck(t, ` resource S {} - pub fun foo(s: @S) { + access(all) fun foo(s: @S) { remove AnyResourceAttachment from s destroy s } @@ -3447,7 +3447,7 @@ func TestCheckRemoveFromRestricted(t *testing.T) { struct S: I {} struct interface I {} attachment A for S {} - pub fun foo(s: S{I}) { + access(all) fun foo(s: S{I}) { remove A from s } `, @@ -3465,7 +3465,7 @@ func TestCheckRemoveFromRestricted(t *testing.T) { struct S: I {} struct interface I {} attachment A for I {} - pub fun foo(s: S{I}) { + access(all) fun foo(s: S{I}) { remove A from s } `, @@ -3483,7 +3483,7 @@ func TestCheckRemoveFromRestricted(t *testing.T) { resource S: I {} resource interface I {} attachment A for S {} - pub fun foo(s: @S{I}) { + access(all) fun foo(s: @S{I}) { remove A from s destroy s } @@ -3504,7 +3504,7 @@ func TestCheckRemoveFromRestricted(t *testing.T) { resource S: I {} resource interface I {} attachment A for I {} - pub fun foo(s: @S{I}) { + access(all) fun foo(s: @S{I}) { remove A from s destroy s } @@ -3523,7 +3523,7 @@ func TestCheckRemoveFromRestricted(t *testing.T) { struct S: I {} struct interface I {} attachment A for S {} - pub fun foo(s: {I}) { + access(all) fun foo(s: {I}) { remove A from s } `, @@ -3542,7 +3542,7 @@ func TestCheckRemoveFromRestricted(t *testing.T) { resource S: I {} resource interface I {} attachment A for S {} - pub fun foo(s: @{I}) { + access(all) fun foo(s: @{I}) { remove A from s destroy s } @@ -3561,7 +3561,7 @@ func TestCheckRemoveFromRestricted(t *testing.T) { ` struct interface I {} attachment A for I {} - pub fun foo(s: {I}) { + access(all) fun foo(s: {I}) { remove A from s } `, @@ -3578,7 +3578,7 @@ func TestCheckRemoveFromRestricted(t *testing.T) { ` resource interface I {} attachment A for I {} - pub fun foo(s: @{I}) { + access(all) fun foo(s: @{I}) { remove A from s destroy s } @@ -3598,7 +3598,7 @@ func TestCheckRemoveFromRestricted(t *testing.T) { struct interface I {} struct interface J {} attachment A for I {} - pub fun foo(s: S{I, J}) { + access(all) fun foo(s: S{I, J}) { remove A from s } `, @@ -3616,7 +3616,7 @@ func TestCheckRemoveFromRestricted(t *testing.T) { struct interface I {} struct interface J {} attachment A for I {} - pub fun foo(s: {I, J}) { + access(all) fun foo(s: {I, J}) { remove A from s } `, @@ -3638,7 +3638,7 @@ func TestCheckAccessAttachment(t *testing.T) { fmt.Sprintf(` resource R {} attachment A for R {} - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { let a: &A? = r[A] %s }`, sigil, destructor), @@ -3653,7 +3653,7 @@ func TestCheckAccessAttachment(t *testing.T) { fmt.Sprintf(` resource R {} attachment A for R {} - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { let a: &A? = r[Int] %s }`, sigil, destructor), @@ -3669,7 +3669,7 @@ func TestCheckAccessAttachment(t *testing.T) { fmt.Sprintf(` resource R {} struct D {} - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { r[D] %s }`, sigil, destructor), @@ -3685,7 +3685,7 @@ func TestCheckAccessAttachment(t *testing.T) { fmt.Sprintf(` resource R {} resource X {} - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { r[X] %s } @@ -3702,7 +3702,7 @@ func TestCheckAccessAttachment(t *testing.T) { fmt.Sprintf(` resource R {} contract X {} - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { r[X] %s } @@ -3719,7 +3719,7 @@ func TestCheckAccessAttachment(t *testing.T) { fmt.Sprintf(` resource R {} event X() - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { r[X] %s } @@ -3736,7 +3736,7 @@ func TestCheckAccessAttachment(t *testing.T) { fmt.Sprintf(` resource R {} enum X: Int {} - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { r[X] %s } @@ -3752,7 +3752,7 @@ func TestCheckAccessAttachment(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` resource R {} - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { r[AnyStructAttachment] %s } @@ -3768,7 +3768,7 @@ func TestCheckAccessAttachment(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` resource R {} - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { r[AnyResourceAttachment] %s } @@ -3784,7 +3784,7 @@ func TestCheckAccessAttachment(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` resource R {} - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { r[AnyStruct] %s } @@ -3800,7 +3800,7 @@ func TestCheckAccessAttachment(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` resource R {} - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { r[AnyResource] %s } @@ -3816,7 +3816,7 @@ func TestCheckAccessAttachment(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` attachment A for AnyResource {} - pub fun foo(r: %sAnyResource) { + access(all) fun foo(r: %sAnyResource) { r[A] %s } @@ -3834,7 +3834,7 @@ func TestCheckAccessAttachment(t *testing.T) { resource interface I {} resource R: I {} attachment A for I {} - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { let a: &A? = r[A] %s } @@ -3851,7 +3851,7 @@ func TestCheckAccessAttachment(t *testing.T) { resource R {} resource interface I {} attachment A for AnyResource: I {} - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { r[I] %s } @@ -3869,7 +3869,7 @@ func TestCheckAccessAttachment(t *testing.T) { resource interface I {} resource R {} attachment A for I {} - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { let a: &A? = r[A] %s } @@ -3886,7 +3886,7 @@ func TestCheckAccessAttachment(t *testing.T) { fmt.Sprintf(` resource R {} attachment A for R {} - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { r[A] = 3 %s } @@ -3905,7 +3905,7 @@ func TestCheckAccessAttachment(t *testing.T) { contract C { attachment A for R {} } - pub fun foo(r: %sR) { + access(all) fun foo(r: %sR) { let a: &C.A? = r[C.A] %s } @@ -3924,7 +3924,7 @@ func TestCheckAccessAttachment(t *testing.T) { _, err := ParseAndCheck(t, ` attachment A for AnyStruct {} - pub fun foo(r: AnyStruct) { + access(all) fun foo(r: AnyStruct) { r[A] } `, @@ -3940,7 +3940,7 @@ func TestCheckAccessAttachment(t *testing.T) { ` attachment A for S {} struct S {} - pub fun foo(r: S) { + access(all) fun foo(r: S) { r[[A]] } `, @@ -3962,7 +3962,7 @@ func TestCheckAccessAttachmentRestricted(t *testing.T) { struct R: I {} struct interface I {} attachment A for I {} - pub fun foo(r: R{I}) { + access(all) fun foo(r: R{I}) { r[A] } `, @@ -3978,7 +3978,7 @@ func TestCheckAccessAttachmentRestricted(t *testing.T) { struct R: I {} struct interface I {} attachment A for R {} - pub fun foo(r: {I}) { + access(all) fun foo(r: {I}) { r[A] } `, @@ -3995,7 +3995,7 @@ func TestCheckAccessAttachmentRestricted(t *testing.T) { struct R: I {} struct interface I {} attachment A for R {} - pub fun foo(r: &R{I}) { + access(all) fun foo(r: &R{I}) { r[A] } `, @@ -4011,7 +4011,7 @@ func TestCheckAccessAttachmentRestricted(t *testing.T) { struct R: I {} struct interface I {} attachment A for R {} - pub fun foo(r: &{I}) { + access(all) fun foo(r: &{I}) { r[A] } `, @@ -4027,7 +4027,7 @@ func TestCheckAccessAttachmentRestricted(t *testing.T) { ` struct interface I {} attachment A for I {} - pub fun foo(r: {I}) { + access(all) fun foo(r: {I}) { r[A] } `, @@ -4042,7 +4042,7 @@ func TestCheckAccessAttachmentRestricted(t *testing.T) { ` struct interface I {} attachment A for I {} - pub fun foo(r: &{I}) { + access(all) fun foo(r: &{I}) { r[A] } `, @@ -4058,7 +4058,7 @@ func TestCheckAccessAttachmentRestricted(t *testing.T) { struct interface I {} struct interface J {} attachment A for I {} - pub fun foo(r: {J}) { + access(all) fun foo(r: {J}) { r[A] } `, @@ -4077,7 +4077,7 @@ func TestCheckAccessAttachmentRestricted(t *testing.T) { struct interface I {} struct interface J {} attachment A for I {} - pub fun foo(r: R{J}) { + access(all) fun foo(r: R{J}) { r[A] } `, @@ -4096,7 +4096,7 @@ func TestCheckAccessAttachmentRestricted(t *testing.T) { struct interface I {} struct interface J {} attachment A for I {} - pub fun foo(r: &R{J}) { + access(all) fun foo(r: &R{J}) { r[A] } `, @@ -4114,7 +4114,7 @@ func TestCheckAccessAttachmentRestricted(t *testing.T) { struct interface I {} struct interface J {} attachment A for I {} - pub fun foo(r: {I, J}) { + access(all) fun foo(r: {I, J}) { r[A] } `, @@ -4131,7 +4131,7 @@ func TestCheckAccessAttachmentRestricted(t *testing.T) { struct interface I {} struct interface J {} attachment A for I {} - pub fun foo(r: &{I, J}) { + access(all) fun foo(r: &{I, J}) { r[A] } `, @@ -4150,9 +4150,9 @@ func TestCheckAttachmentsExternalMutation(t *testing.T) { _, err := ParseAndCheck(t, ` - pub resource R {} - pub attachment A for R { - pub let x: [String] + access(all) resource R {} + access(all) attachment A for R { + access(all) let x: [String] init() { self.x = ["x"] } @@ -4175,13 +4175,13 @@ func TestCheckAttachmentsExternalMutation(t *testing.T) { _, err := ParseAndCheck(t, ` - pub resource R { - pub fun foo() { + access(all) resource R { + access(all) fun foo() { self[A]!.x.append("y") } } - pub attachment A for R { - pub let x: [String] + access(all) attachment A for R { + access(all) let x: [String] init() { self.x = ["x"] } @@ -4200,13 +4200,13 @@ func TestCheckAttachmentsExternalMutation(t *testing.T) { _, err := ParseAndCheck(t, ` - pub resource R {} - pub attachment A for R { - pub let x: [String] + access(all) resource R {} + access(all) attachment A for R { + access(all) let x: [String] init() { self.x = ["x"] } - pub fun foo() { + access(all) fun foo() { base[A]!.x.append("y") } } @@ -4227,9 +4227,9 @@ func TestInterpretAttachmentBaseNonMember(t *testing.T) { _, err := ParseAndCheck(t, ` - pub resource R {} - pub attachment A for R { - pub let base: &R + access(all) resource R {} + access(all) attachment A for R { + access(all) let base: &R init() { self.base = base } @@ -4245,9 +4245,9 @@ func TestInterpretAttachmentBaseNonMember(t *testing.T) { _, err := ParseAndCheck(t, ` - pub resource R {} - pub attachment A for R { - pub let bases: [&R] + access(all) resource R {} + access(all) attachment A for R { + access(all) let bases: [&R] init() { self.bases = [base] } @@ -4263,9 +4263,9 @@ func TestInterpretAttachmentBaseNonMember(t *testing.T) { _, err := ParseAndCheck(t, ` - pub resource R {} - pub attachment A for R { - pub let bases: [&R] + access(all) resource R {} + access(all) attachment A for R { + access(all) let bases: [&R] init() { self.bases = [] self.bases.append(base) @@ -4282,9 +4282,9 @@ func TestInterpretAttachmentBaseNonMember(t *testing.T) { _, err := ParseAndCheck(t, ` - pub resource R {} - pub attachment A for R { - pub let bases: [&R] + access(all) resource R {} + access(all) attachment A for R { + access(all) let bases: [&R] init() { self.bases = [] self.bases[0] = base @@ -4425,7 +4425,7 @@ func TestCheckForEachAttachment(t *testing.T) { ` fun bar (_: &AnyStructAttachment) {} struct A {} - pub fun foo(s: A) { + access(all) fun foo(s: A) { s.forEachAttachment(bar) } `, @@ -4442,7 +4442,7 @@ func TestCheckForEachAttachment(t *testing.T) { ` fun bar (_: &AnyStructAttachment): Bool { return false } struct A {} - pub fun foo(s: A) { + access(all) fun foo(s: A) { s.forEachAttachment(bar) } `, @@ -4460,7 +4460,7 @@ func TestCheckForEachAttachment(t *testing.T) { ` fun bar (_: AnyStructAttachment) { } struct A {} - pub fun foo(s: A) { + access(all) fun foo(s: A) { s.forEachAttachment(bar) } `, @@ -4478,7 +4478,7 @@ func TestCheckForEachAttachment(t *testing.T) { ` fun bar (_: &AnyResource) { } struct A {} - pub fun foo(s: A) { + access(all) fun foo(s: A) { s.forEachAttachment(bar) } `, @@ -4496,7 +4496,7 @@ func TestCheckForEachAttachment(t *testing.T) { ` fun bar (_: &AnyStruct) { } struct A {} - pub fun foo(s: A) { + access(all) fun foo(s: A) { s.forEachAttachment(bar) } `, @@ -4513,7 +4513,7 @@ func TestCheckForEachAttachment(t *testing.T) { ` fun bar (_: &AnyResourceAttachment) {} resource A {} - pub fun foo(s: @A) { + access(all) fun foo(s: @A) { s.forEachAttachment(bar) destroy s } @@ -4531,7 +4531,7 @@ func TestCheckForEachAttachment(t *testing.T) { ` fun bar (_: &AnyStructAttachment) {} resource A {} - pub fun foo(s: @A) { + access(all) fun foo(s: @A) { s.forEachAttachment(bar) destroy s } @@ -4549,7 +4549,7 @@ func TestCheckForEachAttachment(t *testing.T) { _, err := ParseAndCheck(t, ` fun bar (_: &AnyResourceAttachment) {} - pub fun foo(s: AnyStruct) { + access(all) fun foo(s: AnyStruct) { s.forEachAttachment(bar) } `, @@ -4565,7 +4565,7 @@ func TestCheckForEachAttachment(t *testing.T) { _, err := ParseAndCheck(t, ` fun bar (_: &AnyResourceAttachment) {} - pub fun foo(s: @AnyResource) { + access(all) fun foo(s: @AnyResource) { s.forEachAttachment(bar) destroy s } @@ -4582,7 +4582,7 @@ func TestCheckForEachAttachment(t *testing.T) { _, err := ParseAndCheck(t, ` fun bar (_: &AnyResourceAttachment) {} - pub fun foo(s: &AnyResourceAttachment) { + access(all) fun foo(s: &AnyResourceAttachment) { s.forEachAttachment(bar) } `, @@ -4598,7 +4598,7 @@ func TestCheckForEachAttachment(t *testing.T) { _, err := ParseAndCheck(t, ` fun bar (_: &AnyStructAttachment) {} - pub fun foo(s: &AnyStructAttachment) { + access(all) fun foo(s: &AnyStructAttachment) { s.forEachAttachment(bar) } `, @@ -4615,7 +4615,7 @@ func TestCheckForEachAttachment(t *testing.T) { ` fun bar (_: &AnyStructAttachment) {} event E() - pub fun foo(s: E) { + access(all) fun foo(s: E) { s.forEachAttachment(bar) } `, @@ -4632,7 +4632,7 @@ func TestCheckForEachAttachment(t *testing.T) { ` fun bar (_: &AnyStructAttachment) {} contract C {} - pub fun foo(s: C) { + access(all) fun foo(s: C) { s.forEachAttachment(bar) } `, @@ -4649,7 +4649,7 @@ func TestCheckForEachAttachment(t *testing.T) { ` fun bar (_: &AnyStructAttachment) {} enum S:Int {} - pub fun foo(s: S) { + access(all) fun foo(s: S) { s.forEachAttachment(bar) } `, @@ -4666,7 +4666,7 @@ func TestCheckForEachAttachment(t *testing.T) { ` fun bar (_: &AnyStructAttachment) {} attachment S for AnyStruct {} - pub fun foo(s: &S) { + access(all) fun foo(s: &S) { s.forEachAttachment(bar) } `, @@ -4683,7 +4683,7 @@ func TestCheckForEachAttachment(t *testing.T) { ` fun bar (_: &AnyStructAttachment) {} attachment R for AnyResource {} - pub fun foo(s: &R) { + access(all) fun foo(s: &R) { s.forEachAttachment(bar) } `, @@ -4698,8 +4698,8 @@ func TestCheckForEachAttachment(t *testing.T) { _, err := ParseAndCheck(t, ` - pub struct S { - pub fun forEachAttachment() {} + access(all) struct S { + access(all) fun forEachAttachment() {} } `, ) @@ -4728,7 +4728,7 @@ func TestCheckForEachAttachment(t *testing.T) { access(M) attachment A for R { access(F) fun foo() {} } - pub fun foo(s: @R) { + access(all) fun foo(s: @R) { s.forEachAttachment(bar) destroy s } diff --git a/runtime/tests/checker/capability_controller_test.go b/runtime/tests/checker/capability_controller_test.go index 7fd5e27b04..12de0e7116 100644 --- a/runtime/tests/checker/capability_controller_test.go +++ b/runtime/tests/checker/capability_controller_test.go @@ -80,7 +80,7 @@ func TestCheckStorageCapabilityController(t *testing.T) { let _: Void = controller.retarget(/storage/test) fun setTag() { - controller.tag = "something" + controller.setTag("something") } `) @@ -138,7 +138,7 @@ func TestCheckAccountCapabilityController(t *testing.T) { let capabilityID: UInt64 = controller.capabilityID fun setTag() { - controller.tag = "something" + controller.setTag("something") } `) diff --git a/runtime/tests/checker/casting_test.go b/runtime/tests/checker/casting_test.go index d0a081633b..93e476f0fe 100644 --- a/runtime/tests/checker/casting_test.go +++ b/runtime/tests/checker/casting_test.go @@ -6628,7 +6628,7 @@ func TestCheckStaticCastElaboration(t *testing.T) { let y = x.bar as String struct Foo { - pub var bar: String + access(all) var bar: String init() { self.bar = "hello" diff --git a/runtime/tests/checker/composite_test.go b/runtime/tests/checker/composite_test.go index 691d508110..166026925a 100644 --- a/runtime/tests/checker/composite_test.go +++ b/runtime/tests/checker/composite_test.go @@ -107,13 +107,13 @@ func TestCheckComposite(t *testing.T) { fmt.Sprintf( ` %s Test %s { - pub(set) var foo: Int + access(all) var foo: Int init(foo: Int) { self.foo = foo } - pub fun getFoo(): Int { + access(all) fun getFoo(): Int { return self.foo } } @@ -2208,7 +2208,7 @@ func TestCheckInvalidStructureFunctionWithMissingBody(t *testing.T) { _, err := ParseAndCheck(t, ` struct Test { - pub fun getFoo(): Int + access(all) fun getFoo(): Int } `) diff --git a/runtime/tests/checker/conformance_test.go b/runtime/tests/checker/conformance_test.go index 2308048197..668d48f4b4 100644 --- a/runtime/tests/checker/conformance_test.go +++ b/runtime/tests/checker/conformance_test.go @@ -33,14 +33,14 @@ func TestCheckInvalidEventTypeRequirementConformance(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub contract interface CI { + access(all) contract interface CI { - pub event E(a: Int) + access(all) event E(a: Int) } - pub contract C: CI { + access(all) contract C: CI { - pub event E(b: String) + access(all) event E(b: String) } `) @@ -59,11 +59,11 @@ func TestCheckTypeRequirementConformance(t *testing.T) { ` %s - pub contract interface CI { + access(all) contract interface CI { %s } - pub contract C: CI { + access(all) contract C: CI { %s } `, @@ -88,8 +88,8 @@ func TestCheckTypeRequirementConformance(t *testing.T) { test( ``, - `pub struct S {}`, - `pub struct S {}`, + `access(all) struct S {}`, + `access(all) struct S {}`, true, ) }) @@ -101,10 +101,10 @@ func TestCheckTypeRequirementConformance(t *testing.T) { test( ``, ` - pub struct S {} + access(all) struct S {} `, ` - pub struct S { + access(all) struct S { fun foo() {} } `, @@ -119,12 +119,12 @@ func TestCheckTypeRequirementConformance(t *testing.T) { test( ``, ` - pub struct S { + access(all) struct S { fun foo() } `, ` - pub struct S {} + access(all) struct S {} `, false, ) @@ -137,12 +137,12 @@ func TestCheckTypeRequirementConformance(t *testing.T) { test( ``, ` - pub struct S { + access(all) struct S { fun foo(x: Int) } `, ` - pub struct S { + access(all) struct S { fun foo(y: Int) {} } `, @@ -157,12 +157,12 @@ func TestCheckTypeRequirementConformance(t *testing.T) { test( ``, ` - pub struct S { + access(all) struct S { fun foo(x: Int) } `, ` - pub struct S { + access(all) struct S { fun foo(x: String) {} } `, @@ -177,12 +177,12 @@ func TestCheckTypeRequirementConformance(t *testing.T) { test( ``, ` - pub struct S { + access(all) struct S { fun foo(x y: String) } `, ` - pub struct S { + access(all) struct S { fun foo(x z: String) {} } `, @@ -196,16 +196,16 @@ func TestCheckTypeRequirementConformance(t *testing.T) { test( ` - pub struct interface I {} - pub struct T: I {} + access(all) struct interface I {} + access(all) struct T: I {} `, ` - pub struct S { + access(all) struct S { fun foo(bar: {I}) } `, ` - pub struct S { + access(all) struct S { fun foo(bar: T) {} } `, @@ -219,17 +219,17 @@ func TestCheckTypeRequirementConformance(t *testing.T) { test( ` - pub contract X { + access(all) contract X { struct Bar {} } `, ` - pub struct S { + access(all) struct S { fun foo(bar: X.Bar) } `, ` - pub struct S { + access(all) struct S { fun foo(bar: X.Bar) {} } `, @@ -243,21 +243,21 @@ func TestCheckTypeRequirementConformance(t *testing.T) { test( ` - pub contract X { + access(all) contract X { struct Bar {} } - pub contract Y { + access(all) contract Y { struct Bar {} } `, ` - pub struct S { + access(all) struct S { fun foo(bar: X.Bar) } `, ` - pub struct S { + access(all) struct S { fun foo(bar: Y.Bar) {} } `, @@ -508,12 +508,12 @@ func TestCheckInitializerConformanceErrorMessages(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub resource interface I { + access(all) resource interface I { let x: Int init(x: Int) } - pub resource R: I { + access(all) resource R: I { let x: Int init() { self.x = 1 @@ -532,8 +532,8 @@ func TestCheckInitializerConformanceErrorMessages(t *testing.T) { require.Equal(t, &sema.MemberMismatchNote{ Range: ast.Range{ - StartPos: ast.Position{Offset: 142, Line: 9, Column: 8}, - EndPos: ast.Position{Offset: 145, Line: 9, Column: 11}, + StartPos: ast.Position{Offset: 158, Line: 9, Column: 8}, + EndPos: ast.Position{Offset: 161, Line: 9, Column: 11}, }, }, notes[0]) }) @@ -543,11 +543,11 @@ func TestCheckInitializerConformanceErrorMessages(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub resource interface I { + access(all) resource interface I { fun foo(): Int } - pub resource R: I { + access(all) resource R: I { } `) @@ -563,12 +563,12 @@ func TestCheckInitializerConformanceErrorMessages(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub resource interface I { + access(all) resource interface I { fun foo(): Int fun bar(): Int } - pub resource R: I { + access(all) resource R: I { } `) @@ -584,11 +584,11 @@ func TestCheckInitializerConformanceErrorMessages(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub contract interface I { - pub struct S {} + access(all) contract interface I { + access(all) struct S {} } - pub contract C: I { + access(all) contract C: I { } `) @@ -604,12 +604,12 @@ func TestCheckInitializerConformanceErrorMessages(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub contract interface I { - pub struct S {} - pub resource R {} + access(all) contract interface I { + access(all) struct S {} + access(all) resource R {} } - pub contract C: I { + access(all) contract C: I { } `) @@ -625,12 +625,12 @@ func TestCheckInitializerConformanceErrorMessages(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub contract interface I { - pub struct S {} - pub fun foo() + access(all) contract interface I { + access(all) struct S {} + access(all) fun foo() } - pub contract C: I { + access(all) contract C: I { } `) diff --git a/runtime/tests/checker/entitlements_test.go b/runtime/tests/checker/entitlements_test.go index 2f56c515b7..af12849123 100644 --- a/runtime/tests/checker/entitlements_test.go +++ b/runtime/tests/checker/entitlements_test.go @@ -43,10 +43,10 @@ func TestCheckBasicEntitlementDeclaration(t *testing.T) { assert.Equal(t, "E", entitlement.String()) }) - t.Run("priv access", func(t *testing.T) { + t.Run("access(self) access", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - priv entitlement E + access(self) entitlement E `) errs := RequireCheckerErrors(t, err, 1) @@ -88,10 +88,10 @@ func TestCheckBasicEntitlementMappingDeclaration(t *testing.T) { assert.Equal(t, 2, len(entitlement.Relations)) }) - t.Run("priv access", func(t *testing.T) { + t.Run("access(self) access", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - priv entitlement mapping M {} + access(self) entitlement mapping M {} `) errs := RequireCheckerErrors(t, err, 1) @@ -816,7 +816,7 @@ func TestCheckBasicEntitlementMappingAccess(t *testing.T) { struct S { access(M) fun foo(): auth(M) &Int { let x = &1 as auth(M) &Int - // cannot cast, because M may be pub + // cannot cast, because M may be access(all) let y: auth(F) &Int = x return y } @@ -2078,12 +2078,12 @@ func TestCheckEntitlementInheritance(t *testing.T) { require.IsType(t, &sema.InterfaceMemberConflictError{}, errs[0]) }) - t.Run("pub subtyping invalid", func(t *testing.T) { + t.Run("access(all) subtyping invalid", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` entitlement E struct interface I { - pub fun foo() + access(all) fun foo() } struct S: I { access(E) fun foo() {} @@ -2095,12 +2095,12 @@ func TestCheckEntitlementInheritance(t *testing.T) { require.IsType(t, &sema.ConformanceError{}, errs[0]) }) - t.Run("pub(set) subtyping invalid", func(t *testing.T) { + t.Run("access(all) subtyping invalid", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` entitlement E struct interface I { - pub(set) var x: String + access(all) var x: String } struct S: I { access(E) var x: String @@ -2115,7 +2115,7 @@ func TestCheckEntitlementInheritance(t *testing.T) { require.IsType(t, &sema.ConformanceError{}, errs[0]) }) - t.Run("pub supertying invalid", func(t *testing.T) { + t.Run("access(all) supertying invalid", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` entitlement E @@ -2123,7 +2123,7 @@ func TestCheckEntitlementInheritance(t *testing.T) { access(E) fun foo() } struct S: I { - pub fun foo() {} + access(all) fun foo() {} } `) @@ -2132,7 +2132,7 @@ func TestCheckEntitlementInheritance(t *testing.T) { require.IsType(t, &sema.ConformanceError{}, errs[0]) }) - t.Run("pub(set) supertyping invalid", func(t *testing.T) { + t.Run("access(all) supertyping invalid", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` entitlement E @@ -2140,7 +2140,7 @@ func TestCheckEntitlementInheritance(t *testing.T) { access(E) var x: String } struct S: I { - pub(set) var x: String + access(all) var x: String init() { self.x = "" } @@ -2220,7 +2220,7 @@ func TestCheckEntitlementInheritance(t *testing.T) { require.IsType(t, &sema.ConformanceError{}, errs[0]) }) - t.Run("priv supertying invalid", func(t *testing.T) { + t.Run("access(self) supertying invalid", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` entitlement E @@ -2228,7 +2228,7 @@ func TestCheckEntitlementInheritance(t *testing.T) { access(E) fun foo() } struct S: I { - priv fun foo() {} + access(self) fun foo() {} } `) @@ -2745,7 +2745,7 @@ func TestCheckEntitlementTypeAnnotation(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` entitlement E - pub fun foo(e: E) {} + access(all) fun foo(e: E) {} `) errs := RequireCheckerErrors(t, err, 1) @@ -2758,7 +2758,7 @@ func TestCheckEntitlementTypeAnnotation(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement E resource interface I { - pub fun foo(): E + access(all) fun foo(): E } `) @@ -2970,7 +2970,7 @@ func TestCheckEntitlementMappingTypeAnnotation(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` entitlement mapping E {} - pub fun foo(e: E) {} + access(all) fun foo(e: E) {} `) errs := RequireCheckerErrors(t, err, 1) @@ -2983,7 +2983,7 @@ func TestCheckEntitlementMappingTypeAnnotation(t *testing.T) { _, err := ParseAndCheck(t, ` entitlement mapping E {} resource interface I { - pub fun foo(): E + access(all) fun foo(): E } `) @@ -3233,7 +3233,7 @@ func TestCheckEntitlementSetAccess(t *testing.T) { entitlement Z struct R { - pub fun p() {} + access(all) fun p() {} access(X) fun x() {} access(Y) fun y() {} @@ -3251,7 +3251,7 @@ func TestCheckEntitlementSetAccess(t *testing.T) { access(X | Y | Z) fun xyzOr() {} - priv fun private() {} + access(self) fun private() {} access(contract) fun c() {} access(account) fun a() {} } @@ -3770,7 +3770,7 @@ func TestCheckEntitlementMapAccess(t *testing.T) { errs := RequireCheckerErrors(t, err, 1) - // access results in pub access because D is not mapped + // access results in access(all) access because D is not mapped require.IsType(t, &sema.TypeMismatchError{}, errs[0]) require.Equal(t, errs[0].(*sema.TypeMismatchError).ExpectedType.QualifiedString(), "auth(D) &Int") require.Equal(t, errs[0].(*sema.TypeMismatchError).ActualType.QualifiedString(), "&Int") @@ -4119,7 +4119,7 @@ func TestCheckAttachmentEntitlements(t *testing.T) { let a: auth(Y) &A = self let b: &S = base } - pub fun unentitled() { + access(all) fun unentitled() { let a: auth(X, Y) &A = self // err let b: auth(X) &S = base // err } @@ -4147,10 +4147,10 @@ func TestCheckAttachmentEntitlements(t *testing.T) { struct S {} access(M) attachment A for S { require entitlement X - pub fun unentitled() { + access(all) fun unentitled() { let b: &S = base } - pub fun entitled() { + access(all) fun entitled() { let b: auth(X, Y) &S = base } } @@ -4173,10 +4173,10 @@ func TestCheckAttachmentEntitlements(t *testing.T) { } struct S {} access(M) attachment A for S { - pub fun unentitled() { + access(all) fun unentitled() { let b: &S = base } - pub fun entitled() { + access(all) fun entitled() { let b: auth(X) &S = base } } @@ -4201,10 +4201,10 @@ func TestCheckAttachmentEntitlements(t *testing.T) { access(M) attachment A for S { require entitlement X require entitlement Y - pub fun unentitled() { + access(all) fun unentitled() { let b: &S = base } - pub fun entitled() { + access(all) fun entitled() { let b: auth(X, Y) &S = base } } @@ -4231,7 +4231,7 @@ func TestCheckAttachmentEntitlements(t *testing.T) { access(F, Y) fun entitled() { let a: auth(F, Y) &A = self } - pub fun unentitled() { + access(all) fun unentitled() { let a: auth(F, Y, E) &A = self // err } } @@ -4336,7 +4336,7 @@ func TestCheckAttachmentEntitlements(t *testing.T) { require.IsType(t, &sema.InvalidMappedEntitlementMemberError{}, errs[0]) }) - t.Run("pub decl", func(t *testing.T) { + t.Run("access(all) decl", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` entitlement X @@ -4345,7 +4345,7 @@ func TestCheckAttachmentEntitlements(t *testing.T) { attachment A for S { access(Y) fun entitled() {} access(Y) let entitledField: Int - pub fun unentitled() { + access(all) fun unentitled() { let a: auth(Y) &A = self // err let b: auth(X) &S = base // err } @@ -4469,7 +4469,7 @@ func TestCheckAttachmentAccessEntitlements(t *testing.T) { require.Equal(t, errs[1].(*sema.TypeMismatchError).ActualType.QualifiedString(), "auth(F) &A?") }) - t.Run("pub access entitled attachment", func(t *testing.T) { + t.Run("access(all) access entitled attachment", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` entitlement X @@ -4493,7 +4493,7 @@ func TestCheckAttachmentAccessEntitlements(t *testing.T) { require.Equal(t, errs[0].(*sema.TypeMismatchError).ActualType.QualifiedString(), "&A?") }) - t.Run("entitled access pub attachment", func(t *testing.T) { + t.Run("entitled access access(all) attachment", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` entitlement X @@ -4504,8 +4504,8 @@ func TestCheckAttachmentAccessEntitlements(t *testing.T) { struct S { access(X) fun foo() {} } - pub attachment A for S { - pub fun foo() {} + access(all) attachment A for S { + access(all) fun foo() {} } let s = attach A() to S() let ref = &s as auth(X) &S @@ -4519,7 +4519,7 @@ func TestCheckAttachmentAccessEntitlements(t *testing.T) { require.Equal(t, errs[0].(*sema.TypeMismatchError).ActualType.QualifiedString(), "&A?") }) - t.Run("pub access pub attachment", func(t *testing.T) { + t.Run("access(all) access access(all) attachment", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` entitlement X @@ -4528,7 +4528,7 @@ func TestCheckAttachmentAccessEntitlements(t *testing.T) { X -> Y } struct S {} - pub attachment A for S {} + access(all) attachment A for S {} let s = attach A() to S() let ref = &s as &S let a1: auth(Y) &A = ref[A]! diff --git a/runtime/tests/checker/entrypoint_test.go b/runtime/tests/checker/entrypoint_test.go index 502e8a14ae..fd3193ef4a 100644 --- a/runtime/tests/checker/entrypoint_test.go +++ b/runtime/tests/checker/entrypoint_test.go @@ -35,7 +35,7 @@ func TestEntryPointParameters(t *testing.T) { t.Parallel() checker, err := ParseAndCheck(t, ` - pub fun main() {} + access(all) fun main() {} `) require.NoError(t, err) @@ -50,7 +50,7 @@ func TestEntryPointParameters(t *testing.T) { t.Parallel() checker, err := ParseAndCheck(t, ` - pub fun main(a: Int) {} + access(all) fun main(a: Int) {} `) require.NoError(t, err) @@ -113,9 +113,9 @@ func TestEntryPointParameters(t *testing.T) { t.Parallel() checker, err := ParseAndCheck(t, ` - pub struct SomeStruct {} + access(all) struct SomeStruct {} - pub fun main(a: Int) {} + access(all) fun main(a: Int) {} `) require.NoError(t, err) @@ -139,9 +139,9 @@ func TestEntryPointParameters(t *testing.T) { t.Parallel() checker, err := ParseAndCheck(t, ` - pub struct interface SomeInterface {} + access(all) struct interface SomeInterface {} - pub fun main(a: Int) {} + access(all) fun main(a: Int) {} `) require.NoError(t, err) @@ -165,7 +165,7 @@ func TestEntryPointParameters(t *testing.T) { t.Parallel() checker, err := ParseAndCheck(t, ` - pub struct SomeStruct {} + access(all) struct SomeStruct {} transaction(a: Int) {} `) @@ -182,7 +182,7 @@ func TestEntryPointParameters(t *testing.T) { t.Parallel() checker, err := ParseAndCheck(t, ` - pub fun main(a: Int) {} + access(all) fun main(a: Int) {} transaction(a: Int) {} `) diff --git a/runtime/tests/checker/enum_test.go b/runtime/tests/checker/enum_test.go index c317d14195..6c8bab19cf 100644 --- a/runtime/tests/checker/enum_test.go +++ b/runtime/tests/checker/enum_test.go @@ -181,7 +181,7 @@ func TestCheckInvalidNonPublicEnumCase(t *testing.T) { _, err := ParseAndCheck(t, ` enum E: Int { - priv case a + access(self) case a } `) @@ -232,8 +232,8 @@ func TestCheckEnumInContract(t *testing.T) { _, err := ParseAndCheck(t, ` contract C { enum E: UInt8 { - pub case a - pub case b + access(all) case a + access(all) case b } var e: E diff --git a/runtime/tests/checker/errors_test.go b/runtime/tests/checker/errors_test.go index 50913ec55c..5426028f10 100644 --- a/runtime/tests/checker/errors_test.go +++ b/runtime/tests/checker/errors_test.go @@ -76,8 +76,8 @@ func TestCheckErrorShortCircuiting(t *testing.T) { _, err := ParseAndCheckWithOptions(t, ` - pub let x = X - pub let y = Y + access(all) let x = X + access(all) let y = Y `, ParseAndCheckOptions{ Location: utils.ImportedLocation, diff --git a/runtime/tests/checker/events_test.go b/runtime/tests/checker/events_test.go index 4ad1b2b798..6e8860a23b 100644 --- a/runtime/tests/checker/events_test.go +++ b/runtime/tests/checker/events_test.go @@ -261,7 +261,7 @@ func TestCheckEmitEvent(t *testing.T) { importedChecker, err := ParseAndCheckWithOptions(t, ` - pub event Transfer(to: Int, from: Int) + access(all) event Transfer(to: Int, from: Int) `, ParseAndCheckOptions{ Location: utils.ImportedLocation, @@ -272,7 +272,7 @@ func TestCheckEmitEvent(t *testing.T) { _, err = ParseAndCheckWithOptions(t, ` import Transfer from "imported" - pub fun test() { + access(all) fun test() { emit Transfer(to: 1, from: 2) } `, diff --git a/runtime/tests/checker/external_mutation_test.go b/runtime/tests/checker/external_mutation_test.go index d2428afbff..50744ad276 100644 --- a/runtime/tests/checker/external_mutation_test.go +++ b/runtime/tests/checker/external_mutation_test.go @@ -34,7 +34,7 @@ func TestCheckArrayUpdateIndexAccess(t *testing.T) { t.Parallel() accessModifiers := []ast.Access{ - ast.AccessPublic, + ast.AccessAll, ast.AccessAccount, ast.AccessContract, } @@ -65,8 +65,8 @@ func TestCheckArrayUpdateIndexAccess(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` - pub contract C { - pub %s Foo { + access(all) contract C { + access(all) %s Foo { %s %s x: [Int] init() { @@ -74,7 +74,7 @@ func TestCheckArrayUpdateIndexAccess(t *testing.T) { } } - pub fun bar() { + access(all) fun bar() { let foo %s Foo() foo.x[0] = 3 %s @@ -103,7 +103,7 @@ func TestCheckDictionaryUpdateIndexAccess(t *testing.T) { t.Parallel() accessModifiers := []ast.Access{ - ast.AccessPublic, + ast.AccessAll, ast.AccessAccount, ast.AccessContract, } @@ -134,8 +134,8 @@ func TestCheckDictionaryUpdateIndexAccess(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` - pub contract C { - pub %s Foo { + access(all) contract C { + access(all) %s Foo { %s %s x: {Int: Int} init() { @@ -143,7 +143,7 @@ func TestCheckDictionaryUpdateIndexAccess(t *testing.T) { } } - pub fun bar() { + access(all) fun bar() { let foo %s Foo() foo.x[0] = 3 %s @@ -172,7 +172,7 @@ func TestCheckNestedArrayUpdateIndexAccess(t *testing.T) { t.Parallel() accessModifiers := []ast.Access{ - ast.AccessPublic, + ast.AccessAll, ast.AccessAccount, ast.AccessContract, } @@ -191,15 +191,15 @@ func TestCheckNestedArrayUpdateIndexAccess(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` - pub contract C { - pub struct Bar { - pub let foo: Foo + access(all) contract C { + access(all) struct Bar { + access(all) let foo: Foo init() { self.foo = Foo() } } - pub struct Foo { + access(all) struct Foo { %s %s x: [Int] init() { @@ -207,7 +207,7 @@ func TestCheckNestedArrayUpdateIndexAccess(t *testing.T) { } } - pub fun bar() { + access(all) fun bar() { let bar = Bar() bar.foo.x[0] = 3 } @@ -233,7 +233,7 @@ func TestCheckNestedDictionaryUpdateIndexAccess(t *testing.T) { t.Parallel() accessModifiers := []ast.Access{ - ast.AccessPublic, + ast.AccessAll, ast.AccessAccount, ast.AccessContract, } @@ -252,15 +252,15 @@ func TestCheckNestedDictionaryUpdateIndexAccess(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` - pub contract C { - pub struct Bar { - pub let foo: Foo + access(all) contract C { + access(all) struct Bar { + access(all) let foo: Foo init() { self.foo = Foo() } } - pub struct Foo { + access(all) struct Foo { %s %s x: {Int: Int} init() { @@ -268,7 +268,7 @@ func TestCheckNestedDictionaryUpdateIndexAccess(t *testing.T) { } } - pub fun bar() { + access(all) fun bar() { let bar = Bar() bar.foo.x[0] = 3 } @@ -294,7 +294,7 @@ func TestCheckMutateContractIndexAccess(t *testing.T) { t.Parallel() accessModifiers := []ast.Access{ - ast.AccessPublic, + ast.AccessAll, ast.AccessAccount, ast.AccessContract, } @@ -313,7 +313,7 @@ func TestCheckMutateContractIndexAccess(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` - pub contract Foo { + access(all) contract Foo { %s %s x: [Int] init() { @@ -321,7 +321,7 @@ func TestCheckMutateContractIndexAccess(t *testing.T) { } } - pub fun bar() { + access(all) fun bar() { Foo.x[0] = 1 } `, access.Keyword(), declaration.Keywords()), @@ -354,7 +354,7 @@ func TestCheckContractNestedStructIndexAccess(t *testing.T) { t.Parallel() accessModifiers := []ast.Access{ - ast.AccessPublic, + ast.AccessAll, ast.AccessAccount, ast.AccessContract, } @@ -373,10 +373,10 @@ func TestCheckContractNestedStructIndexAccess(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` - pub contract Foo { - pub let x: S + access(all) contract Foo { + access(all) let x: S - pub struct S { + access(all) struct S { %s %s y: [Int] init() { self.y = [3] @@ -388,7 +388,7 @@ func TestCheckContractNestedStructIndexAccess(t *testing.T) { } } - pub fun bar() { + access(all) fun bar() { Foo.x.y[0] = 1 } `, access.Keyword(), declaration.Keywords()), @@ -421,7 +421,7 @@ func TestCheckContractStructInitIndexAccess(t *testing.T) { t.Parallel() accessModifiers := []ast.Access{ - ast.AccessPublic, + ast.AccessAll, ast.AccessAccount, ast.AccessContract, } @@ -440,10 +440,10 @@ func TestCheckContractStructInitIndexAccess(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` - pub contract Foo { - pub let x: S + access(all) contract Foo { + access(all) let x: S - pub struct S { + access(all) struct S { %s %s y: [Int] init() { self.y = [3] @@ -476,7 +476,7 @@ func TestCheckArrayUpdateMethodCall(t *testing.T) { t.Parallel() accessModifiers := []ast.Access{ - ast.AccessPublic, + ast.AccessAll, ast.AccessAccount, ast.AccessContract, } @@ -525,8 +525,8 @@ func TestCheckArrayUpdateMethodCall(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` - pub contract C { - pub %s Foo { + access(all) contract C { + access(all) %s Foo { %s %s x: [Int] init() { @@ -534,7 +534,7 @@ func TestCheckArrayUpdateMethodCall(t *testing.T) { } } - pub fun bar() { + access(all) fun bar() { let foo %s Foo() foo.x%s %s @@ -569,7 +569,7 @@ func TestCheckDictionaryUpdateMethodCall(t *testing.T) { t.Parallel() accessModifiers := []ast.Access{ - ast.AccessPublic, + ast.AccessAll, ast.AccessAccount, ast.AccessContract, } @@ -614,8 +614,8 @@ func TestCheckDictionaryUpdateMethodCall(t *testing.T) { _, err := ParseAndCheck(t, fmt.Sprintf(` - pub contract C { - pub %s Foo { + access(all) contract C { + access(all) %s Foo { %s %s x: {Int: Int} init() { @@ -623,7 +623,7 @@ func TestCheckDictionaryUpdateMethodCall(t *testing.T) { } } - pub fun bar() { + access(all) fun bar() { let foo %s Foo() foo.x%s %s @@ -653,92 +653,25 @@ func TestCheckDictionaryUpdateMethodCall(t *testing.T) { } } -func TestCheckPubSetAccessModifier(t *testing.T) { - - t.Parallel() - t.Run("pub set dict", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - pub contract C { - pub struct Foo { - pub(set) var x: {Int: Int} - - init() { - self.x = {3: 3} - } - } - - pub fun bar() { - let foo = Foo() - foo.x[0] = 3 - } - } - `, - ) - require.NoError(t, err) - - }) -} - -func TestCheckPubSetNestedAccessModifier(t *testing.T) { - - t.Parallel() - t.Run("pub set nested", func(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, - ` - pub contract C { - pub struct Bar { - pub let foo: Foo - init() { - self.foo = Foo() - } - } - - pub struct Foo { - pub(set) var x: [Int] - - init() { - self.x = [3] - } - } - - pub fun bar() { - let bar = Bar() - bar.foo.x[0] = 3 - } - } - `, - ) - require.NoError(t, err) - - }) -} - func TestCheckSelfContainingStruct(t *testing.T) { t.Parallel() - t.Run("pub let", func(t *testing.T) { + t.Run("access(all) let", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub contract C { - pub struct Foo { - pub let x: {Int: Int} + access(all) contract C { + access(all) struct Foo { + access(all) let x: {Int: Int} init() { self.x = {3: 3} } - pub fun bar() { + access(all) fun bar() { let foo = Foo() foo.x[0] = 3 } @@ -755,26 +688,26 @@ func TestCheckMutationThroughReference(t *testing.T) { t.Parallel() - t.Run("pub let", func(t *testing.T) { + t.Run("access(all) let", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub fun main() { + access(all) fun main() { let foo = Foo() foo.ref.arr.append("y") } - pub struct Foo { - pub let ref: &Bar + access(all) struct Foo { + access(all) let ref: &Bar init() { self.ref = &Bar() as &Bar } } - pub struct Bar { - pub let arr: [String] + access(all) struct Bar { + access(all) let arr: [String] init() { self.arr = ["x"] } @@ -791,27 +724,27 @@ func TestCheckMutationThroughInnerReference(t *testing.T) { t.Parallel() - t.Run("pub let", func(t *testing.T) { + t.Run("access(all) let", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub fun main() { + access(all) fun main() { let foo = Foo() var arrayRef = &foo.ref.arr as &[String] arrayRef[0] = "y" } - pub struct Foo { - pub let ref: &Bar + access(all) struct Foo { + access(all) let ref: &Bar init() { self.ref = &Bar() as &Bar } } - pub struct Bar { - pub let arr: [String] + access(all) struct Bar { + access(all) let arr: [String] init() { self.arr = ["x"] } @@ -826,32 +759,32 @@ func TestCheckMutationThroughAccess(t *testing.T) { t.Parallel() - t.Run("pub let", func(t *testing.T) { + t.Run("access(all) let", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub contract C { - pub struct Foo { - pub let arr: [Int] + access(all) contract C { + access(all) struct Foo { + access(all) let arr: [Int] init() { self.arr = [3] } } - priv let foo : Foo + access(self) let foo : Foo init() { self.foo = Foo() } - pub fun getFoo(): Foo { + access(all) fun getFoo(): Foo { return self.foo } } - pub fun main() { + access(all) fun main() { let a = C.getFoo() a.arr.append(0) // a.arr is now [3, 0] } diff --git a/runtime/tests/checker/function_test.go b/runtime/tests/checker/function_test.go index 5a53d957c5..90ade5eba3 100644 --- a/runtime/tests/checker/function_test.go +++ b/runtime/tests/checker/function_test.go @@ -133,23 +133,12 @@ func TestCheckFunctionAccess(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub fun test() {} + access(all) fun test() {} `) require.NoError(t, err) } -func TestCheckInvalidFunctionAccess(t *testing.T) { - - t.Parallel() - - _, err := ParseAndCheck(t, ` - pub(set) fun test() {} - `) - - expectInvalidAccessModifierError(t, err) -} - func TestCheckReturnWithoutExpression(t *testing.T) { t.Parallel() @@ -465,14 +454,14 @@ func TestCheckResultVariable(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub resource R { - pub let id: UInt64 + access(all) resource R { + access(all) let id: UInt64 init() { self.id = 1 } } - pub fun main(): @R { + access(all) fun main(): @R { post { result.id == 1234: "Invalid id" } @@ -487,14 +476,14 @@ func TestCheckResultVariable(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub resource R { - pub let id: UInt64 + access(all) resource R { + access(all) let id: UInt64 init() { self.id = 1 } } - pub fun main(): @R? { + access(all) fun main(): @R? { post { result!.id == 1234: "invalid id" } diff --git a/runtime/tests/checker/import_test.go b/runtime/tests/checker/import_test.go index d5e2d4db98..b012968957 100644 --- a/runtime/tests/checker/import_test.go +++ b/runtime/tests/checker/import_test.go @@ -52,8 +52,8 @@ func TestCheckRepeatedImport(t *testing.T) { importedChecker, err := ParseAndCheckWithOptions(t, ` - pub let x = 1 - pub let y = 2 + access(all) let x = 1 + access(all) let y = 2 `, ParseAndCheckOptions{ Location: utils.ImportedLocation, @@ -87,11 +87,11 @@ func TestCheckRepeatedImportResolution(t *testing.T) { importedCheckerX, err := ParseAndCheckWithOptions(t, ` - pub fun test(): Int { + access(all) fun test(): Int { return 1 } - pub let x = test() + access(all) let x = test() `, ParseAndCheckOptions{ Location: common.AddressLocation{ @@ -104,11 +104,11 @@ func TestCheckRepeatedImportResolution(t *testing.T) { importedCheckerY, err := ParseAndCheckWithOptions(t, ` - pub fun test(): Int { + access(all) fun test(): Int { return 2 } - pub let y = test() + access(all) let y = test() `, ParseAndCheckOptions{ Location: common.AddressLocation{ @@ -166,7 +166,7 @@ func TestCheckInvalidRepeatedImport(t *testing.T) { importedChecker, err := ParseAndCheckWithOptions(t, ` - pub let x = 1 + access(all) let x = 1 `, ParseAndCheckOptions{ Location: utils.ImportedLocation, @@ -204,11 +204,11 @@ func TestCheckImportResolutionSplit(t *testing.T) { importedCheckerX, err := ParseAndCheckWithOptions(t, ` - pub fun test(): Int { + access(all) fun test(): Int { return 1 } - pub let x = test() + access(all) let x = test() `, ParseAndCheckOptions{ Location: common.AddressLocation{ @@ -221,11 +221,11 @@ func TestCheckImportResolutionSplit(t *testing.T) { importedCheckerY, err := ParseAndCheckWithOptions(t, ` - pub fun test(): Int { + access(all) fun test(): Int { return 2 } - pub let y = test() + access(all) let y = test() `, ParseAndCheckOptions{ Location: common.AddressLocation{ @@ -282,7 +282,7 @@ func TestCheckImportAll(t *testing.T) { importedChecker, err := ParseAndCheckWithOptions(t, ` - pub fun answer(): Int { + access(all) fun answer(): Int { return 42 } `, @@ -297,7 +297,7 @@ func TestCheckImportAll(t *testing.T) { ` import "imported" - pub let x = answer() + access(all) let x = answer() `, ParseAndCheckOptions{ Config: &sema.Config{ @@ -319,7 +319,7 @@ func TestCheckInvalidImportUnexported(t *testing.T) { importedChecker, err := ParseAndCheckWithOptions(t, ` - pub let x = 1 + access(all) let x = 1 `, ParseAndCheckOptions{ Location: utils.ImportedLocation, @@ -332,7 +332,7 @@ func TestCheckInvalidImportUnexported(t *testing.T) { ` import answer from "imported" - pub let x = answer() + access(all) let x = answer() `, ParseAndCheckOptions{ Config: &sema.Config{ @@ -356,11 +356,11 @@ func TestCheckImportSome(t *testing.T) { importedChecker, err := ParseAndCheckWithOptions(t, ` - pub fun answer(): Int { + access(all) fun answer(): Int { return 42 } - pub let x = 1 + access(all) let x = 1 `, ParseAndCheckOptions{ Location: utils.ImportedLocation, @@ -373,7 +373,7 @@ func TestCheckImportSome(t *testing.T) { ` import answer from "imported" - pub let x = answer() + access(all) let x = answer() `, ParseAndCheckOptions{ Config: &sema.Config{ @@ -438,9 +438,9 @@ func TestCheckImportTypes(t *testing.T) { importedChecker, err := ParseAndCheckWithOptions(t, fmt.Sprintf( ` - pub %[1]s Test %[2]s + access(all) %[1]s Test %[2]s - pub %[1]s interface TestInterface %[2]s + access(all) %[1]s interface TestInterface %[2]s `, compositeKind.Keyword(), body, @@ -455,7 +455,7 @@ func TestCheckImportTypes(t *testing.T) { var useCode string if compositeKind != common.CompositeKindContract { useCode = fmt.Sprintf( - `pub let x: %[1]sTest %[2]s %[3]s Test%[4]s`, + `access(all) let x: %[1]sTest %[2]s %[3]s Test%[4]s`, compositeKind.Annotation(), compositeKind.TransferOperator(), compositeKind.ConstructionKeyword(), @@ -468,7 +468,7 @@ func TestCheckImportTypes(t *testing.T) { ` import "imported" - pub %[1]s TestImpl: TestInterface {} + access(all) %[1]s TestImpl: TestInterface {} %[2]s `, @@ -575,7 +575,7 @@ func TestCheckInvalidImportCycleTwoLocations(t *testing.T) { const codeEven = ` import odd from "odd" - pub fun even(_ n: Int): Bool { + access(all) fun even(_ n: Int): Bool { if n == 0 { return true } @@ -588,7 +588,7 @@ func TestCheckInvalidImportCycleTwoLocations(t *testing.T) { const codeOdd = ` import even from "even" - pub fun odd(_ n: Int): Bool { + access(all) fun odd(_ n: Int): Bool { if n == 0 { return false } diff --git a/runtime/tests/checker/interface_test.go b/runtime/tests/checker/interface_test.go index caeed7c9b2..93ff22ace3 100644 --- a/runtime/tests/checker/interface_test.go +++ b/runtime/tests/checker/interface_test.go @@ -288,9 +288,9 @@ func TestCheckInterfaceUse(t *testing.T) { _, err := ParseAndCheckWithPanic(t, fmt.Sprintf( ` - pub %[1]s interface Test %[2]s + access(all) %[1]s interface Test %[2]s - pub let test: %[3]s%[4]s %[5]s panic("") + access(all) let test: %[3]s%[4]s %[5]s panic("") `, kind.Keyword(), body, @@ -880,7 +880,7 @@ func TestCheckInvalidInterfaceConformanceFunctionPrivateAccessModifier(t *testin } %[1]s TestImpl: Test { - priv fun test(): Int { + access(self) fun test(): Int { return 1 } } @@ -990,7 +990,7 @@ func TestCheckInvalidInterfaceConformanceFieldPrivateAccessModifier(t *testing.T } %[1]s TestImpl: Test { - priv var x: Int + access(self) var x: Int init(x: Int) { self.x = x @@ -1019,11 +1019,11 @@ func TestCheckInvalidInterfaceConformanceFieldMismatchAccessModifierMoreRestrict fmt.Sprintf( ` %[1]s interface Test { - pub(set) x: Int + access(all) x: Int } %[1]s TestImpl: Test { - pub var x: Int + access(account) var x: Int init(x: Int) { self.x = x @@ -1052,7 +1052,7 @@ func TestCheckInvalidInterfaceConformanceFunctionMismatchAccessModifierMoreRestr fmt.Sprintf( ` %[1]s interface Test { - pub fun x() + access(all) fun x() } %[1]s TestImpl: Test { @@ -1081,11 +1081,11 @@ func TestCheckInterfaceConformanceFieldMorePermissiveAccessModifier(t *testing.T fmt.Sprintf( ` %[1]s interface Test { - pub x: Int + access(all) x: Int } %[1]s TestImpl: Test { - pub(set) var x: Int + access(all) var x: Int init(x: Int) { self.x = x @@ -2964,11 +2964,11 @@ func TestCheckInterfaceInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface Foo { - pub fun hello() + access(all) fun hello() } struct interface Bar: Foo { - pub fun hello() + access(all) fun hello() } `) @@ -2982,11 +2982,11 @@ func TestCheckInterfaceInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface Foo { - pub fun hello() + access(all) fun hello() } struct interface Bar: Foo { - pub fun hello(): String + access(all) fun hello(): String } `) @@ -3010,7 +3010,7 @@ func TestCheckInterfaceInheritance(t *testing.T) { } struct interface Bar: Foo { - pub fun hello(): String + access(all) fun hello(): String } `) @@ -3028,11 +3028,11 @@ func TestCheckInterfaceInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface Foo { - pub var x: String + access(all) var x: String } struct interface Bar: Foo { - pub var x: String + access(all) var x: String } `) @@ -3045,11 +3045,11 @@ func TestCheckInterfaceInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface Foo { - pub var x: String + access(all) var x: String } struct interface Bar: Foo { - pub var x: Int + access(all) var x: Int } `) @@ -3069,7 +3069,7 @@ func TestCheckInterfaceInheritance(t *testing.T) { entitlement X struct interface Foo { - pub var x: String + access(all) var x: String } struct interface Bar: Foo { @@ -3091,11 +3091,11 @@ func TestCheckInterfaceInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface Foo { - pub var x: String + access(all) var x: String } struct interface Bar: Foo { - pub let x: String + access(all) let x: String } `) @@ -3113,11 +3113,11 @@ func TestCheckInterfaceInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface Foo { - pub(set) var x: String + access(all) var x: String } struct interface Bar: Foo { - pub var x: String + access(account) var x: String } `) @@ -3135,11 +3135,11 @@ func TestCheckInterfaceInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface Foo { - pub fun hello() + access(all) fun hello() } struct interface Bar: Foo { - pub var hello: Void + access(all) var hello: Void } `) @@ -3157,13 +3157,13 @@ func TestCheckInterfaceInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface Foo { - pub fun hello() { + access(all) fun hello() { pre { true } } } struct interface Bar: Foo { - pub fun hello() + access(all) fun hello() } `) @@ -3176,11 +3176,11 @@ func TestCheckInterfaceInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface Foo { - pub fun hello() + access(all) fun hello() } struct interface Bar: Foo { - pub fun hello() { + access(all) fun hello() { pre { true } } } @@ -3195,13 +3195,13 @@ func TestCheckInterfaceInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello(): Int + access(all) fun hello(): Int } struct interface B: A {} struct interface P { - pub fun hello(): String + access(all) fun hello(): String } struct interface Q: P {} @@ -3224,13 +3224,13 @@ func TestCheckInterfaceInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello(): Int + access(all) fun hello(): Int } struct interface B: A {} struct interface P { - pub fun hello(): String + access(all) fun hello(): String } struct interface Q: P {} @@ -3256,13 +3256,13 @@ func TestCheckInterfaceInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello(): Int + access(all) fun hello(): Int } struct interface B: A {} struct interface P { - pub fun hello(): Int + access(all) fun hello(): Int } struct interface Q: P {} @@ -3296,7 +3296,7 @@ func TestCheckInterfaceInheritance(t *testing.T) { struct interface B: A {} struct interface P { - pub fun hello(): Int + access(all) fun hello(): Int } struct interface Q: P {} @@ -3322,7 +3322,7 @@ func TestCheckInterfaceInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello() { + access(all) fun hello() { var a = 1 } } @@ -3343,7 +3343,7 @@ func TestCheckInterfaceInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello() { + access(all) fun hello() { var a = 1 } } @@ -3398,7 +3398,7 @@ func TestCheckInterfaceDefaultMethodsInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello() { + access(all) fun hello() { var a = 1 } } @@ -3407,7 +3407,7 @@ func TestCheckInterfaceDefaultMethodsInheritance(t *testing.T) { struct C: B {} - pub fun main() { + access(all) fun main() { var c = C() c.hello() } @@ -3422,13 +3422,13 @@ func TestCheckInterfaceDefaultMethodsInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello() { + access(all) fun hello() { var a = 1 } } struct interface B: A { - pub fun hello() { + access(all) fun hello() { pre { true } } } @@ -3448,13 +3448,13 @@ func TestCheckInterfaceDefaultMethodsInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello() { + access(all) fun hello() { var a = 1 } } struct interface B: A { - pub fun hello() + access(all) fun hello() } `) @@ -3475,14 +3475,14 @@ func TestCheckInterfaceDefaultMethodsInheritance(t *testing.T) { } struct interface B: A { - pub fun hello() { + access(all) fun hello() { var a = 1 } } struct C: B {} - pub fun main() { + access(all) fun main() { var c = C() c.hello() } @@ -3497,13 +3497,13 @@ func TestCheckInterfaceDefaultMethodsInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello() { + access(all) fun hello() { pre { true } } } struct interface B: A { - pub fun hello() { + access(all) fun hello() { var a = 1 } } @@ -3523,11 +3523,11 @@ func TestCheckInterfaceDefaultMethodsInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello() + access(all) fun hello() } struct interface B: A { - pub fun hello() { + access(all) fun hello() { var a = 1 } } @@ -3547,13 +3547,13 @@ func TestCheckInterfaceDefaultMethodsInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello() { + access(all) fun hello() { var a = 1 } } struct interface B: A { - pub fun hello() { + access(all) fun hello() { var a = 2 } } @@ -3573,17 +3573,17 @@ func TestCheckInterfaceDefaultMethodsInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello() { + access(all) fun hello() { var a = 1 } } struct interface B: A { - pub fun hello() + access(all) fun hello() } struct interface C: B { - pub fun hello() { + access(all) fun hello() { var a = 2 } } @@ -3614,13 +3614,13 @@ func TestCheckInterfaceDefaultMethodsInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello() { + access(all) fun hello() { var a = 1 } } struct interface B { - pub fun hello() { + access(all) fun hello() { var a = 2 } } @@ -3642,13 +3642,13 @@ func TestCheckInterfaceDefaultMethodsInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello() { + access(all) fun hello() { var a = 1 } } struct interface B: A { - pub fun hello() { + access(all) fun hello() { var a = 2 } } @@ -3674,13 +3674,13 @@ func TestCheckInterfaceDefaultMethodsInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello() { + access(all) fun hello() { var a = 1 } } struct interface B { - pub fun hello() { + access(all) fun hello() { pre { true } } } @@ -3701,13 +3701,13 @@ func TestCheckInterfaceDefaultMethodsInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` struct interface A { - pub fun hello() { + access(all) fun hello() { var a = 1 } } struct interface B { - pub fun hello() { + access(all) fun hello() { pre { true } } } @@ -3739,7 +3739,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` contract interface A { struct Nested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -3751,7 +3751,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { contract X: C { struct Nested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -3768,7 +3768,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` contract interface A { struct Nested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -3794,7 +3794,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { contract interface A { struct Nested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -3824,7 +3824,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` contract interface A { struct ANested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -3832,7 +3832,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { contract interface B { struct BNested { - pub fun test(): Int { + access(all) fun test(): Int { return 4 } } @@ -3842,13 +3842,13 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { contract X: C { struct ANested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } struct BNested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -3865,7 +3865,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` contract interface A { struct ANested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -3873,7 +3873,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { contract interface B { struct BNested { - pub fun test(): Int { + access(all) fun test(): Int { return 4 } } @@ -3883,7 +3883,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { contract X: C { struct ANested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -3891,7 +3891,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { contract Y: C { struct BNested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -3919,7 +3919,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` contract interface A { struct Nested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -3927,7 +3927,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { contract interface B: A { struct Nested { - pub fun test(): String { + access(all) fun test(): String { return "three" } } @@ -3948,7 +3948,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` contract interface A { struct Nested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -3956,7 +3956,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { contract interface B: A { struct Nested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -3977,7 +3977,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` contract interface A { resource interface Nested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -3985,7 +3985,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { contract interface B: A { resource interface Nested { - pub fun test(): String { + access(all) fun test(): String { return "three" } } @@ -4006,7 +4006,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` contract interface A { struct interface Nested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -4014,7 +4014,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { contract interface B: A { resource Nested { - pub fun test(): String { + access(all) fun test(): String { return "three" } } @@ -4035,7 +4035,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` contract interface A { struct Nested { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -4043,7 +4043,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { contract interface B { struct Nested { - pub fun test(): String { + access(all) fun test(): String { return "three" } } @@ -4066,7 +4066,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { _, err := ParseAndCheck(t, ` contract interface A { struct NestedA { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -4074,7 +4074,7 @@ func TestCheckInterfaceTypeDefinitionInheritance(t *testing.T) { contract interface B { struct NestedB { - pub fun test(): String { + access(all) fun test(): String { return "three" } } @@ -4124,7 +4124,7 @@ func TestCheckInterfaceEventsInheritance(t *testing.T) { } contract X: A { - pub fun test() { + access(all) fun test() { emit FooEvent("hello") } } @@ -4154,7 +4154,7 @@ func TestCheckInterfaceEventsInheritance(t *testing.T) { contract interface C: B {} contract X: C { - pub fun test() { + access(all) fun test() { emit FooEvent("hello") } } diff --git a/runtime/tests/checker/invocation_test.go b/runtime/tests/checker/invocation_test.go index 8b0bc192cc..f841239f76 100644 --- a/runtime/tests/checker/invocation_test.go +++ b/runtime/tests/checker/invocation_test.go @@ -332,7 +332,7 @@ func TestCheckInvocationWithOnlyVarargs(t *testing.T) { _, err := ParseAndCheckWithOptions(t, ` - pub fun test() { + access(all) fun test() { foo(1) } `, diff --git a/runtime/tests/checker/never_test.go b/runtime/tests/checker/never_test.go index f1a75dc8eb..ef5cfc2a33 100644 --- a/runtime/tests/checker/never_test.go +++ b/runtime/tests/checker/never_test.go @@ -36,7 +36,7 @@ func TestCheckNever(t *testing.T) { _, err := ParseAndCheckWithPanic(t, ` - pub fun test(): Int { + access(all) fun test(): Int { return panic("XXX") } `, @@ -50,7 +50,7 @@ func TestCheckNever(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { var x: Never = 5 } `, @@ -70,7 +70,7 @@ func TestCheckNever(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { var x: Never = "c" } `, @@ -90,7 +90,7 @@ func TestCheckNever(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { var x: Never = "hello" } `, @@ -110,7 +110,7 @@ func TestCheckNever(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test(a: Never, b: Never) { + access(all) fun test(a: Never, b: Never) { var x: Int = a + b } `, @@ -129,7 +129,7 @@ func TestCheckNever(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test(a: Never) { + access(all) fun test(a: Never) { var x: Bool = !a } `, @@ -148,7 +148,7 @@ func TestCheckNever(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test(a: Never?) { + access(all) fun test(a: Never?) { var x: Int = a ?? 4 } `, diff --git a/runtime/tests/checker/nft_test.go b/runtime/tests/checker/nft_test.go index 47070f3c50..56711f2dfa 100644 --- a/runtime/tests/checker/nft_test.go +++ b/runtime/tests/checker/nft_test.go @@ -34,39 +34,39 @@ const realNonFungibleTokenContractInterface = ` // The main NFT contract interface. Other NFT contracts will // import and implement this interface // -pub contract interface NonFungibleToken { +access(all) contract interface NonFungibleToken { // The total number of tokens of this type in existence - pub var totalSupply: UInt64 + access(all) var totalSupply: UInt64 // Event that emitted when the NFT contract is initialized // - pub event ContractInitialized() + access(all) event ContractInitialized() // Event that is emitted when a token is withdrawn, // indicating the owner of the collection that it was withdrawn from. // // If the collection is not in an account's storage, from will be nil. // - pub event Withdraw(id: UInt64, from: Address?) + access(all) event Withdraw(id: UInt64, from: Address?) // Event that emitted when a token is deposited to a collection. // // It indicates the owner of the collection that it was deposited to. // - pub event Deposit(id: UInt64, to: Address?) + access(all) event Deposit(id: UInt64, to: Address?) // Interface that the NFTs have to conform to // - pub resource interface INFT { + access(all) resource interface INFT { // The unique ID that each NFT has - pub let id: UInt64 + access(all) let id: UInt64 } // Requirement that all conforming NFT smart contracts have // to define a resource called NFT that conforms to INFT - pub resource NFT: INFT { - pub let id: UInt64 + access(all) resource NFT: INFT { + access(all) let id: UInt64 } // entitles references to withdraw: @@ -75,7 +75,7 @@ pub contract interface NonFungibleToken { // Interface to mediate withdraws from the Collection // - pub resource interface Provider { + access(all) resource interface Provider { // withdraw removes an NFT from the collection and moves it to the caller access(Withdrawable) fun withdraw(withdrawID: UInt64): @NFT { post { @@ -86,42 +86,42 @@ pub contract interface NonFungibleToken { // Interface to mediate deposits to the Collection // - pub resource interface Receiver { + access(all) resource interface Receiver { // deposit takes an NFT as an argument and adds it to the Collection // - pub fun deposit(token: @NFT) + access(all) fun deposit(token: @NFT) } // Interface that an account would commonly // publish for their collection - pub resource interface CollectionPublic { - pub fun deposit(token: @NFT) - pub fun getIDs(): [UInt64] - pub fun borrowNFT(id: UInt64): &NFT + access(all) resource interface CollectionPublic { + access(all) fun deposit(token: @NFT) + access(all) fun getIDs(): [UInt64] + access(all) fun borrowNFT(id: UInt64): &NFT } // Requirement for the the concrete resource type // to be declared in the implementing contract // - pub resource Collection: Provider, Receiver, CollectionPublic { + access(all) resource Collection: Provider, Receiver, CollectionPublic { // Dictionary to hold the NFTs in the Collection - pub var ownedNFTs: @{UInt64: NFT} + access(all) var ownedNFTs: @{UInt64: NFT} // withdraw removes an NFT from the collection and moves it to the caller access(Withdrawable) fun withdraw(withdrawID: UInt64): @NFT // deposit takes a NFT and adds it to the collections dictionary // and adds the ID to the id array - pub fun deposit(token: @NFT) + access(all) fun deposit(token: @NFT) // getIDs returns an array of the IDs that are in the collection - pub fun getIDs(): [UInt64] + access(all) fun getIDs(): [UInt64] // Returns a borrowed reference to an NFT in the collection // so that the caller can read data and call methods from it - pub fun borrowNFT(id: UInt64): &NFT { + access(all) fun borrowNFT(id: UInt64): &NFT { pre { self.ownedNFTs[id] != nil: "NFT does not exist in the collection!" } @@ -130,7 +130,7 @@ pub contract interface NonFungibleToken { // createEmptyCollection creates an empty Collection // and returns it to the caller so that they can own NFTs - pub fun createEmptyCollection(): @Collection { + access(all) fun createEmptyCollection(): @Collection { post { result.ownedNFTs.length == 0: "The created collection must be empty!" } @@ -142,42 +142,42 @@ const topShotContract = ` import NonFungibleToken from 0x1 -pub contract TopShot: NonFungibleToken { +access(all) contract TopShot: NonFungibleToken { // ----------------------------------------------------------------------- // TopShot contract Events // ----------------------------------------------------------------------- // Emitted when the TopShot contract is created - pub event ContractInitialized() + access(all) event ContractInitialized() // Emitted when a new Play struct is created - pub event PlayCreated(id: UInt32, metadata: {String:String}) + access(all) event PlayCreated(id: UInt32, metadata: {String:String}) // Emitted when a new series has been triggered by an admin - pub event NewSeriesStarted(newCurrentSeries: UInt32) + access(all) event NewSeriesStarted(newCurrentSeries: UInt32) // Events for Set-Related actions // // Emitted when a new Set is created - pub event SetCreated(setID: UInt32, series: UInt32) + access(all) event SetCreated(setID: UInt32, series: UInt32) // Emitted when a new Play is added to a Set - pub event PlayAddedToSet(setID: UInt32, playID: UInt32) + access(all) event PlayAddedToSet(setID: UInt32, playID: UInt32) // Emitted when a Play is retired from a Set and cannot be used to mint - pub event PlayRetiredFromSet(setID: UInt32, playID: UInt32, numMoments: UInt32) + access(all) event PlayRetiredFromSet(setID: UInt32, playID: UInt32, numMoments: UInt32) // Emitted when a Set is locked, meaning Plays cannot be added - pub event SetLocked(setID: UInt32) + access(all) event SetLocked(setID: UInt32) // Emitted when a Moment is minted from a Set - pub event MomentMinted(momentID: UInt64, playID: UInt32, setID: UInt32, serialNumber: UInt32) + access(all) event MomentMinted(momentID: UInt64, playID: UInt32, setID: UInt32, serialNumber: UInt32) // Events for Collection-related actions // // Emitted when a moment is withdrawn from a Collection - pub event Withdraw(id: UInt64, from: Address?) + access(all) event Withdraw(id: UInt64, from: Address?) // Emitted when a moment is deposited into a Collection - pub event Deposit(id: UInt64, to: Address?) + access(all) event Deposit(id: UInt64, to: Address?) // Emitted when a Moment is destroyed - pub event MomentDestroyed(id: UInt64) + access(all) event MomentDestroyed(id: UInt64) // ----------------------------------------------------------------------- // TopShot contract-level fields. @@ -187,7 +187,7 @@ pub contract TopShot: NonFungibleToken { // Series that this Set belongs to. // Series is a concept that indicates a group of Sets through time. // Many Sets can exist at a time, but only one series. - pub var currentSeries: UInt32 + access(all) var currentSeries: UInt32 // Variable size dictionary of Play structs access(self) var playDatas: {UInt32: Play} @@ -201,17 +201,17 @@ pub contract TopShot: NonFungibleToken { // The ID that is used to create Plays. // Every time a Play is created, playID is assigne // to the new Play's ID and then is incremented by 1. - pub var nextPlayID: UInt32 + access(all) var nextPlayID: UInt32 // The ID that is used to create Sets. Every time a Set is created // setID is assigned to the new set's ID and then is incremented by 1. - pub var nextSetID: UInt32 + access(all) var nextSetID: UInt32 // The total number of Top shot Moment NFTs that have been created // Because NFTs can be destroyed, it doesn't necessarily mean that this // reflects the total number of NFTs in existence, just the number that // have been minted to date. Also used as global moment IDs for minting. - pub var totalSupply: UInt64 + access(all) var totalSupply: UInt64 // ----------------------------------------------------------------------- // TopShot contract-level Composite Type definitions @@ -231,16 +231,16 @@ pub contract TopShot: NonFungibleToken { // its metadata. The plays are publicly accessible, so anyone can // read the metadata associated with a specific play ID // - pub struct Play { + access(all) struct Play { // The unique ID for the Play - pub let playID: UInt32 + access(all) let playID: UInt32 // Stores all the metadata about the play as a string mapping // This is not the long term way NFT metadata will be stored. It's a temporary // construct while we figure out a better way to do metadata. // - pub let metadata: {String: String} + access(all) let metadata: {String: String} init(metadata: {String: String}) { pre { @@ -266,19 +266,19 @@ pub contract TopShot: NonFungibleToken { // at the end of the contract. Only the admin has the ability // to modify any data in the private Set resource. // - pub struct SetData { + access(all) struct SetData { // Unique ID for the Set - pub let setID: UInt32 + access(all) let setID: UInt32 // Name of the Set // ex. "Times when the Toronto Raptors choked in the playoffs" - pub let name: String + access(all) let name: String // Series that this Set belongs to. // Series is a concept that indicates a group of Sets through time. // Many Sets can exist at a time, but only one series. - pub let series: UInt32 + access(all) let series: UInt32 init(name: String) { pre { @@ -314,20 +314,20 @@ pub contract TopShot: NonFungibleToken { // // If retireAll() and lock() are called back-to-back, // the Set is closed off forever and nothing more can be done with it. - pub resource Set { + access(all) resource Set { // Unique ID for the set - pub let setID: UInt32 + access(all) let setID: UInt32 // Array of plays that are a part of this set. // When a play is added to the set, its ID gets appended here. // The ID does not get removed from this array when a Play is retired. - pub var plays: [UInt32] + access(all) var plays: [UInt32] // Map of Play IDs that Indicates if a Play in this Set can be minted. // When a Play is added to a Set, it is mapped to false (not retired). // When a Play is retired, this is set to true and cannot be changed. - pub var retired: {UInt32: Bool} + access(all) var retired: {UInt32: Bool} // Indicates if the Set is currently locked. // When a Set is created, it is unlocked @@ -338,13 +338,13 @@ pub contract TopShot: NonFungibleToken { // If a Set is locked, Plays cannot be added, but // Moments can still be minted from Plays // that exist in the Set. - pub var locked: Bool + access(all) var locked: Bool // Mapping of Play IDs that indicates the number of Moments // that have been minted for specific Plays in this Set. // When a Moment is minted, this value is stored in the Moment to // show its place in the Set, eg. 13 of 60. - pub var numberMintedPerPlay: {UInt32: UInt32} + access(all) var numberMintedPerPlay: {UInt32: UInt32} init(name: String) { self.setID = TopShot.nextSetID @@ -366,7 +366,7 @@ pub contract TopShot: NonFungibleToken { // The Set needs to be not locked // The Play can't have already been added to the Set // - pub fun addPlay(playID: UInt32) { + access(all) fun addPlay(playID: UInt32) { pre { TopShot.playDatas[playID] != nil: "Cannot add the Play to Set: Play doesn't exist." !self.locked: "Cannot add the play to the Set after the set has been locked." @@ -390,7 +390,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: playIDs: The IDs of the Plays that are being added // as an array // - pub fun addPlays(playIDs: [UInt32]) { + access(all) fun addPlays(playIDs: [UInt32]) { for play in playIDs { self.addPlay(playID: play) } @@ -403,7 +403,7 @@ pub contract TopShot: NonFungibleToken { // Pre-Conditions: // The Play is part of the Set and not retired (available for minting). // - pub fun retirePlay(playID: UInt32) { + access(all) fun retirePlay(playID: UInt32) { pre { self.retired[playID] != nil: "Cannot retire the Play: Play doesn't exist in this set!" } @@ -418,7 +418,7 @@ pub contract TopShot: NonFungibleToken { // retireAll retires all the plays in the Set // Afterwards, none of the retired Plays will be able to mint new Moments // - pub fun retireAll() { + access(all) fun retireAll() { for play in self.plays { self.retirePlay(playID: play) } @@ -428,7 +428,7 @@ pub contract TopShot: NonFungibleToken { // // Pre-Conditions: // The Set should not be locked - pub fun lock() { + access(all) fun lock() { if !self.locked { self.locked = true emit SetLocked(setID: self.setID) @@ -444,7 +444,7 @@ pub contract TopShot: NonFungibleToken { // // Returns: The NFT that was minted // - pub fun mintMoment(playID: UInt32): @NFT { + access(all) fun mintMoment(playID: UInt32): @NFT { pre { self.retired[playID] != nil: "Cannot mint the moment: This play doesn't exist." !self.retired[playID]!: "Cannot mint the moment from this play: This play has been retired." @@ -473,7 +473,7 @@ pub contract TopShot: NonFungibleToken { // // Returns: Collection object that contains all the Moments that were minted // - pub fun batchMintMoment(playID: UInt32, quantity: UInt64): @Collection { + access(all) fun batchMintMoment(playID: UInt32, quantity: UInt64): @Collection { let newCollection <- create Collection() var i: UInt64 = 0 @@ -486,17 +486,17 @@ pub contract TopShot: NonFungibleToken { } } - pub struct MomentData { + access(all) struct MomentData { // The ID of the Set that the Moment comes from - pub let setID: UInt32 + access(all) let setID: UInt32 // The ID of the Play that the Moment references - pub let playID: UInt32 + access(all) let playID: UInt32 // The place in the edition that this Moment was minted // Otherwise know as the serial number - pub let serialNumber: UInt32 + access(all) let serialNumber: UInt32 init(setID: UInt32, playID: UInt32, serialNumber: UInt32) { self.setID = setID @@ -508,13 +508,13 @@ pub contract TopShot: NonFungibleToken { // The resource that represents the Moment NFTs // - pub resource NFT: NonFungibleToken.INFT { + access(all) resource NFT: NonFungibleToken.INFT { // Global unique moment ID - pub let id: UInt64 + access(all) let id: UInt64 // Struct of Moment metadata - pub let data: MomentData + access(all) let data: MomentData init(serialNumber: UInt32, playID: UInt32, setID: UInt32) { // Increment the global Moment IDs @@ -539,7 +539,7 @@ pub contract TopShot: NonFungibleToken { // allows the owner to perform important functions to modify the // various aspects of the Plays, Sets, and Moments // - pub resource Admin { + access(all) resource Admin { // createPlay creates a new Play struct // and stores it in the Plays dictionary in the TopShot smart contract @@ -550,7 +550,7 @@ pub contract TopShot: NonFungibleToken { // // Returns: the ID of the new Play object // - pub fun createPlay(metadata: {String: String}): UInt32 { + access(all) fun createPlay(metadata: {String: String}): UInt32 { // Create the new Play var newPlay = Play(metadata: metadata) let newID = newPlay.playID @@ -566,7 +566,7 @@ pub contract TopShot: NonFungibleToken { // // Parameters: name: The name of the Set // - pub fun createSet(name: String) { + access(all) fun createSet(name: String) { // Create the new Set var newSet <- create Set(name: name) @@ -583,7 +583,7 @@ pub contract TopShot: NonFungibleToken { // Returns: A reference to the Set with all of the fields // and methods exposed // - pub fun borrowSet(setID: UInt32): &Set { + access(all) fun borrowSet(setID: UInt32): &Set { pre { TopShot.sets[setID] != nil: "Cannot borrow Set: The Set doesn't exist" } @@ -599,7 +599,7 @@ pub contract TopShot: NonFungibleToken { // // Returns: The new series number // - pub fun startNewSeries(): UInt32 { + access(all) fun startNewSeries(): UInt32 { // End the current series and start a new one // by incrementing the TopShot series number TopShot.currentSeries = TopShot.currentSeries + UInt32(1) @@ -611,7 +611,7 @@ pub contract TopShot: NonFungibleToken { // createNewAdmin creates a new Admin resource // - pub fun createNewAdmin(): @Admin { + access(all) fun createNewAdmin(): @Admin { return <-create Admin() } } @@ -619,12 +619,12 @@ pub contract TopShot: NonFungibleToken { // This is the interface that users can cast their Moment Collection as // to allow others to deposit Moments into their Collection. It also allows for reading // the IDs of Moments in the Collection. - pub resource interface MomentCollectionPublic { - pub fun deposit(token: @NonFungibleToken.NFT) - pub fun batchDeposit(tokens: @NonFungibleToken.Collection) - pub fun getIDs(): [UInt64] - pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT - pub fun borrowMoment(id: UInt64): &TopShot.NFT? { + access(all) resource interface MomentCollectionPublic { + access(all) fun deposit(token: @NonFungibleToken.NFT) + access(all) fun batchDeposit(tokens: @NonFungibleToken.Collection) + access(all) fun getIDs(): [UInt64] + access(all) fun borrowNFT(id: UInt64): &NonFungibleToken.NFT + access(all) fun borrowMoment(id: UInt64): &TopShot.NFT? { // If the result isn't nil, the id of the returned reference // should be the same as the argument to the function post { @@ -637,10 +637,10 @@ pub contract TopShot: NonFungibleToken { // Collection is a resource that every user who owns NFTs // will store in their account to manage their NFTS // - pub resource Collection: MomentCollectionPublic, NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic { + access(all) resource Collection: MomentCollectionPublic, NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic { // Dictionary of Moment conforming tokens // NFT is a resource type with a UInt64 ID field - pub var ownedNFTs: @{UInt64: NonFungibleToken.NFT} + access(all) var ownedNFTs: @{UInt64: NonFungibleToken.NFT} init() { self.ownedNFTs <- {} @@ -671,7 +671,7 @@ pub contract TopShot: NonFungibleToken { // Returns: @NonFungibleToken.Collection: A collection that contains // the withdrawn moments // - pub fun batchWithdraw(ids: [UInt64]): @NonFungibleToken.Collection { + access(all) fun batchWithdraw(ids: [UInt64]): @NonFungibleToken.Collection { // Create a new empty Collection var batchCollection <- create Collection() @@ -688,7 +688,7 @@ pub contract TopShot: NonFungibleToken { // // Parameters: token: the NFT to be deposited in the collection // - pub fun deposit(token: @NonFungibleToken.NFT) { + access(all) fun deposit(token: @NonFungibleToken.NFT) { // Cast the deposited token as a TopShot NFT to make sure // it is the correct type @@ -712,7 +712,7 @@ pub contract TopShot: NonFungibleToken { // batchDeposit takes a Collection object as an argument // and deposits each contained NFT into this Collection - pub fun batchDeposit(tokens: @NonFungibleToken.Collection) { + access(all) fun batchDeposit(tokens: @NonFungibleToken.Collection) { // Get an array of the IDs to be deposited let keys = tokens.getIDs() @@ -727,7 +727,7 @@ pub contract TopShot: NonFungibleToken { } // getIDs returns an array of the IDs that are in the Collection - pub fun getIDs(): [UInt64] { + access(all) fun getIDs(): [UInt64] { return self.ownedNFTs.keys } @@ -742,7 +742,7 @@ pub contract TopShot: NonFungibleToken { // not any topshot specific data. Please use borrowMoment to // read Moment data. // - pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT { + access(all) fun borrowNFT(id: UInt64): &NonFungibleToken.NFT { return (&self.ownedNFTs[id] as &NonFungibleToken.NFT?)! } @@ -756,7 +756,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: id: The ID of the NFT to get the reference for // // Returns: A reference to the NFT - pub fun borrowMoment(id: UInt64): &TopShot.NFT? { + access(all) fun borrowMoment(id: UInt64): &TopShot.NFT? { if self.ownedNFTs[id] != nil { let ref = (&self.ownedNFTs[id] as &NonFungibleToken.NFT?)! return ref as! &TopShot.NFT @@ -784,14 +784,14 @@ pub contract TopShot: NonFungibleToken { // Once they have a Collection in their storage, they are able to receive // Moments in transactions. // - pub fun createEmptyCollection(): @NonFungibleToken.Collection { + access(all) fun createEmptyCollection(): @NonFungibleToken.Collection { return <-create TopShot.Collection() } // getAllPlays returns all the plays in topshot // // Returns: An array of all the plays that have been created - pub fun getAllPlays(): [TopShot.Play] { + access(all) fun getAllPlays(): [TopShot.Play] { return TopShot.playDatas.values } @@ -800,7 +800,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: playID: The id of the Play that is being searched // // Returns: The metadata as a String to String mapping optional - pub fun getPlayMetaData(playID: UInt32): {String: String}? { + access(all) fun getPlayMetaData(playID: UInt32): {String: String}? { return self.playDatas[playID]?.metadata } @@ -813,7 +813,7 @@ pub contract TopShot: NonFungibleToken { // field: The field to search for // // Returns: The metadata field as a String Optional - pub fun getPlayMetaDataByField(playID: UInt32, field: String): String? { + access(all) fun getPlayMetaDataByField(playID: UInt32, field: String): String? { // Don't force a revert if the playID or field is invalid if let play = TopShot.playDatas[playID] { return play.metadata[field] @@ -828,7 +828,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: setID: The id of the Set that is being searched // // Returns: The name of the Set - pub fun getSetName(setID: UInt32): String? { + access(all) fun getSetName(setID: UInt32): String? { // Don't force a revert if the setID is invalid return TopShot.setDatas[setID]?.name } @@ -839,7 +839,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: setID: The id of the Set that is being searched // // Returns: The series that the Set belongs to - pub fun getSetSeries(setID: UInt32): UInt32? { + access(all) fun getSetSeries(setID: UInt32): UInt32? { // Don't force a revert if the setID is invalid return TopShot.setDatas[setID]?.series } @@ -850,7 +850,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: setName: The name of the Set that is being searched // // Returns: An array of the IDs of the Set if it exists, or nil if doesn't - pub fun getSetIDsByName(setName: String): [UInt32]? { + access(all) fun getSetIDsByName(setName: String): [UInt32]? { var setIDs: [UInt32] = [] // Iterate through all the setDatas and search for the name @@ -875,7 +875,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: setID: The id of the Set that is being searched // // Returns: An array of Play IDs - pub fun getPlaysInSet(setID: UInt32): [UInt32]? { + access(all) fun getPlaysInSet(setID: UInt32): [UInt32]? { // Don't force a revert if the setID is invalid return TopShot.sets[setID]?.plays } @@ -889,7 +889,7 @@ pub contract TopShot: NonFungibleToken { // playID: The id of the Play that is being searched // // Returns: Boolean indicating if the edition is retired or not - pub fun isEditionRetired(setID: UInt32, playID: UInt32): Bool? { + access(all) fun isEditionRetired(setID: UInt32, playID: UInt32): Bool? { // Don't force a revert if the set or play ID is invalid // Remove the set from the dictionary to get its field if let setToRead <- TopShot.sets.remove(key: setID) { @@ -917,7 +917,7 @@ pub contract TopShot: NonFungibleToken { // Parameters: setID: The id of the Set that is being searched // // Returns: Boolean indicating if the Set is locked or not - pub fun isSetLocked(setID: UInt32): Bool? { + access(all) fun isSetLocked(setID: UInt32): Bool? { // Don't force a revert if the setID is invalid return TopShot.sets[setID]?.locked } @@ -930,7 +930,7 @@ pub contract TopShot: NonFungibleToken { // // Returns: The total number of Moments // that have been minted from an edition - pub fun getNumMomentsInEdition(setID: UInt32, playID: UInt32): UInt32? { + access(all) fun getNumMomentsInEdition(setID: UInt32, playID: UInt32): UInt32? { // Don't force a revert if the Set or play ID is invalid // Remove the Set from the dictionary to get its field if let setToRead <- TopShot.sets.remove(key: setID) { diff --git a/runtime/tests/checker/nil_coalescing_test.go b/runtime/tests/checker/nil_coalescing_test.go index 729569cc9f..98105b74fe 100644 --- a/runtime/tests/checker/nil_coalescing_test.go +++ b/runtime/tests/checker/nil_coalescing_test.go @@ -217,8 +217,8 @@ func TestCheckNilCoalescingWithNever(t *testing.T) { _, err := ParseAndCheckWithPanic(t, ` - pub let x: Int? = nil - pub let y = x ?? panic("nope") + access(all) let x: Int? = nil + access(all) let y = x ?? panic("nope") `, ) diff --git a/runtime/tests/checker/predeclaredvalues_test.go b/runtime/tests/checker/predeclaredvalues_test.go index 1a48db36ba..cd69920f4f 100644 --- a/runtime/tests/checker/predeclaredvalues_test.go +++ b/runtime/tests/checker/predeclaredvalues_test.go @@ -45,7 +45,7 @@ func TestCheckPredeclaredValues(t *testing.T) { _, err := ParseAndCheckWithOptions(t, ` - pub fun test() { + access(all) fun test() { foo() } `, diff --git a/runtime/tests/checker/purity_test.go b/runtime/tests/checker/purity_test.go index f22cf2f86a..805a1ec2e0 100644 --- a/runtime/tests/checker/purity_test.go +++ b/runtime/tests/checker/purity_test.go @@ -560,8 +560,13 @@ func TestCheckPurityEnforcement(t *testing.T) { t.Run("struct external write", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub struct R { - pub(set) var x: Int + access(all) struct R { + access(all) var x: Int + + access(all) fun setX(_ x: Int) { + self.x = x + } + init(x: Int) { self.x = x } @@ -569,7 +574,7 @@ func TestCheckPurityEnforcement(t *testing.T) { let r = R(x: 0) view fun foo(){ - r.x = 3 + r.setX(3) } `) @@ -577,24 +582,23 @@ func TestCheckPurityEnforcement(t *testing.T) { assert.IsType(t, &sema.PurityError{}, errs[0]) assert.Equal(t, errs[0].(*sema.PurityError).Range, ast.Range{ - StartPos: ast.Position{Offset: 203, Line: 11, Column: 12}, - EndPos: ast.Position{Offset: 209, Line: 11, Column: 18}, + StartPos: ast.Position{Offset: 272, Line: 16, Column: 12}, + EndPos: ast.Position{Offset: 280, Line: 16, Column: 20}, }) }) t.Run("struct param write", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub struct R { - pub(set) var x: Int + access(all) struct R { + access(all) var x: Int init(x: Int) { self.x = x } - } - - view fun foo(_ r: R): R { - r.x = 3 - return r + view fun foo(_ r: R): R { + r.x = 3 + return r + } } `) @@ -604,20 +608,20 @@ func TestCheckPurityEnforcement(t *testing.T) { t.Run("struct param nested write", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub struct R { - pub(set) var x: Int + access(all) struct R { + access(all) var x: Int init(x: Int) { self.x = x } - } - - view fun foo(_ r: R): R { - if true { - while true { - r.x = 3 - } - } - return r + + access(all) view fun foo(_ r: R): R { + if true { + while true { + r.x = 3 + } + } + return r + } } `) @@ -712,14 +716,14 @@ func TestCheckPurityEnforcement(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` struct S { - pub(set) var x: Int + access(all) var x: Int init(x: Int) { self.x = x } - } - - view fun foo(_ s: &S) { - s.x = 3 + + view fun foo(_ s: &S) { + s.x = 3 + } } `) @@ -727,8 +731,8 @@ func TestCheckPurityEnforcement(t *testing.T) { assert.IsType(t, &sema.PurityError{}, errs[0]) assert.Equal(t, errs[0].(*sema.PurityError).Range, ast.Range{ - StartPos: ast.Position{Offset: 183, Line: 10, Column: 12}, - EndPos: ast.Position{Offset: 189, Line: 10, Column: 18}, + StartPos: ast.Position{Offset: 155, Line: 9, Column: 4}, + EndPos: ast.Position{Offset: 161, Line: 9, Column: 10}, }) }) @@ -736,16 +740,14 @@ func TestCheckPurityEnforcement(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` struct S { - pub(set) var x: Int + access(all) var x: Int init(_ x: Int) { self.x = x } - } - let s = [&S(0) as &S] - - view fun foo() { - s[0].x = 3 + access(all) view fun foo(_ s: [&S]) { + s[0].x = 3 + } } `) @@ -753,8 +755,8 @@ func TestCheckPurityEnforcement(t *testing.T) { assert.IsType(t, &sema.PurityError{}, errs[0]) assert.Equal(t, errs[0].(*sema.PurityError).Range, ast.Range{ - StartPos: ast.Position{Offset: 204, Line: 12, Column: 13}, - EndPos: ast.Position{Offset: 212, Line: 12, Column: 21}, + StartPos: ast.Position{Offset: 172, Line: 9, Column: 5}, + EndPos: ast.Position{Offset: 180, Line: 9, Column: 13}, }) }) @@ -762,7 +764,7 @@ func TestCheckPurityEnforcement(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` struct S { - pub(set) var x: Int + access(all) var x: Int init(x: Int) { self.x = x } @@ -778,8 +780,8 @@ func TestCheckPurityEnforcement(t *testing.T) { assert.IsType(t, &sema.NotDeclaredError{}, errs[0]) assert.IsType(t, &sema.PurityError{}, errs[1]) assert.Equal(t, errs[1].(*sema.PurityError).Range, ast.Range{ - StartPos: ast.Position{Offset: 168, Line: 10, Column: 12}, - EndPos: ast.Position{Offset: 174, Line: 10, Column: 18}, + StartPos: ast.Position{Offset: 171, Line: 10, Column: 12}, + EndPos: ast.Position{Offset: 177, Line: 10, Column: 18}, }) }) } @@ -788,16 +790,15 @@ func TestCheckResourceWritePurity(t *testing.T) { t.Run("resource param write", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub resource R { - pub(set) var x: Int + access(all) resource R { + access(all) var x: Int init(x: Int) { self.x = x } - } - - view fun foo(_ r: @R): @R { - r.x = 3 - return <-r + view fun foo(_ r: @R): @R { + r.x = 3 + return <-r + } } `) @@ -805,15 +806,15 @@ func TestCheckResourceWritePurity(t *testing.T) { assert.IsType(t, &sema.PurityError{}, errs[0]) assert.Equal(t, errs[0].(*sema.PurityError).Range, ast.Range{ - StartPos: ast.Position{Offset: 217, Line: 10, Column: 16}, - EndPos: ast.Position{Offset: 223, Line: 10, Column: 22}, + StartPos: ast.Position{Offset: 194, Line: 8, Column: 5}, + EndPos: ast.Position{Offset: 200, Line: 8, Column: 11}, }) }) t.Run("destroy", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub resource R {} + access(all) resource R {} view fun foo(_ r: @R){ destroy r @@ -824,28 +825,27 @@ func TestCheckResourceWritePurity(t *testing.T) { assert.IsType(t, &sema.PurityError{}, errs[0]) assert.Equal(t, errs[0].(*sema.PurityError).Range, ast.Range{ - StartPos: ast.Position{Offset: 83, Line: 5, Column: 16}, - EndPos: ast.Position{Offset: 91, Line: 5, Column: 24}, + StartPos: ast.Position{Offset: 91, Line: 5, Column: 16}, + EndPos: ast.Position{Offset: 99, Line: 5, Column: 24}, }) }) t.Run("resource param nested write", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub resource R { - pub(set) var x: Int + access(all) resource R { + access(all) var x: Int init(x: Int) { self.x = x } - } - - view fun foo(_ r: @R): @R { - if true { - while true { - r.x = 3 - } - } - return <-r + view fun foo(_ r: @R): @R { + if true { + while true { + r.x = 3 + } + } + return <-r + } } `) @@ -853,25 +853,24 @@ func TestCheckResourceWritePurity(t *testing.T) { assert.IsType(t, &sema.PurityError{}, errs[0]) assert.Equal(t, errs[0].(*sema.PurityError).Range, ast.Range{ - StartPos: ast.Position{Offset: 284, Line: 12, Column: 24}, - EndPos: ast.Position{Offset: 290, Line: 12, Column: 30}, + StartPos: ast.Position{Offset: 230, Line: 10, Column: 7}, + EndPos: ast.Position{Offset: 236, Line: 10, Column: 13}, }) }) t.Run("internal resource write", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub resource R { - pub(set) var x: Int + access(all) resource R { + access(all) var x: Int view init(x: Int) { self.x = x } - } - - view fun foo(): @R { - let r <- create R(x: 0) - r.x = 1 - return <-r + view fun foo(): @R { + let r <- create R(x: 0) + r.x = 1 + return <-r + } } `) @@ -879,25 +878,24 @@ func TestCheckResourceWritePurity(t *testing.T) { assert.IsType(t, &sema.PurityError{}, errs[0]) assert.Equal(t, errs[0].(*sema.PurityError).Range, ast.Range{ - StartPos: ast.Position{Offset: 255, Line: 11, Column: 16}, - EndPos: ast.Position{Offset: 261, Line: 11, Column: 22}, + StartPos: ast.Position{Offset: 221, Line: 9, Column: 5}, + EndPos: ast.Position{Offset: 227, Line: 9, Column: 11}, }) }) t.Run("external resource move", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub resource R { - pub(set) var x: Int + access(all) resource R { + access(all) var x: Int init(x: Int) { self.x = x } - } - - view fun foo(_ f: @R): @R { - let b <- f - b.x = 3 - return <-b + view fun foo(_ f: @R): @R { + let b <- f + b.x = 3 + return <-b + } } `) @@ -905,8 +903,8 @@ func TestCheckResourceWritePurity(t *testing.T) { assert.IsType(t, &sema.PurityError{}, errs[0]) assert.Equal(t, errs[0].(*sema.PurityError).Range, ast.Range{ - StartPos: ast.Position{Offset: 244, Line: 11, Column: 16}, - EndPos: ast.Position{Offset: 250, Line: 11, Column: 22}, + StartPos: ast.Position{Offset: 210, Line: 9, Column: 5}, + EndPos: ast.Position{Offset: 216, Line: 9, Column: 11}, }) }) @@ -914,15 +912,14 @@ func TestCheckResourceWritePurity(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` resource R { - pub(set) var x: Int + access(all) var x: Int init(_ x: Int) { self.x = x } - } - - view fun foo(_ a: @[R], _ x: Int): @[R] { - a[x].x = 4 - return <-a + view fun foo(_ a: @[R], _ x: Int): @[R] { + a[x].x = 4 + return <-a + } } `) @@ -930,8 +927,8 @@ func TestCheckResourceWritePurity(t *testing.T) { assert.IsType(t, &sema.PurityError{}, errs[0]) assert.Equal(t, errs[0].(*sema.PurityError).Range, ast.Range{ - StartPos: ast.Position{Offset: 206, Line: 10, Column: 13}, - EndPos: ast.Position{Offset: 214, Line: 10, Column: 21}, + StartPos: ast.Position{Offset: 177, Line: 8, Column: 5}, + EndPos: ast.Position{Offset: 185, Line: 8, Column: 13}, }) }) @@ -939,15 +936,14 @@ func TestCheckResourceWritePurity(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` resource R { - pub(set) var x: Int + access(all) var x: Int init(_ x: Int) { self.x = x } - } - - view fun foo(_ a: @[[R]], _ x: Int): @[[R]] { - a[x][x].x = 4 - return <-a + view fun foo(_ a: @[[R]], _ x: Int): @[[R]] { + a[x][x].x = 4 + return <-a + } } `) @@ -955,16 +951,16 @@ func TestCheckResourceWritePurity(t *testing.T) { assert.IsType(t, &sema.PurityError{}, errs[0]) assert.Equal(t, errs[0].(*sema.PurityError).Range, ast.Range{ - StartPos: ast.Position{Offset: 213, Line: 10, Column: 16}, - EndPos: ast.Position{Offset: 221, Line: 10, Column: 24}, + StartPos: ast.Position{Offset: 184, Line: 8, Column: 8}, + EndPos: ast.Position{Offset: 192, Line: 8, Column: 16}, }) }) t.Run("resource moves", func(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub resource R { - pub(set) var x: Int + access(all) resource R { + access(all) var x: Int init(x: Int) { self.x = x } diff --git a/runtime/tests/checker/reference_test.go b/runtime/tests/checker/reference_test.go index 9a364c6057..36ac72c5d1 100644 --- a/runtime/tests/checker/reference_test.go +++ b/runtime/tests/checker/reference_test.go @@ -1328,8 +1328,8 @@ func TestCheckInvalidDictionaryAccessOptionalReference(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub struct S { - pub let foo: Number + access(all) struct S { + access(all) let foo: Number init() { self.foo = 0 } @@ -1349,8 +1349,8 @@ func TestCheckInvalidDictionaryAccessNonOptionalReference(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub struct S { - pub let foo: Number + access(all) struct S { + access(all) let foo: Number init() { self.foo = 0 } @@ -1369,8 +1369,8 @@ func TestCheckArrayAccessReference(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub struct S { - pub let foo: Number + access(all) struct S { + access(all) let foo: Number init() { self.foo = 0 } @@ -1444,15 +1444,15 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x <- create R() let xRef = &x as &R xRef.a destroy x } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -1470,15 +1470,15 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x <- create R() let xRef = &x as &R destroy x xRef.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -1498,15 +1498,15 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x <- [<-create R()] let xRef = &x as &[R] destroy x xRef[0].a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -1526,15 +1526,15 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x <- {1: <- create R()} let xRef = &x as &{Int: R} destroy x xRef[1]?.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -1554,19 +1554,19 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x <- create R() let xRef = &x as &R consume(<-x) xRef.a } - pub fun consume(_ r: @AnyResource) { + access(all) fun consume(_ r: @AnyResource) { destroy r } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -1586,19 +1586,19 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x <- [<-create R()] let xRef = &x as &[R] consume(<-x) xRef[0].a } - pub fun consume(_ r: @AnyResource) { + access(all) fun consume(_ r: @AnyResource) { destroy r } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -1618,19 +1618,19 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x <- {1: <- create R()} let xRef = &x as &{Int: R} consume(<-x) xRef[1]?.a } - pub fun consume(_ r: @AnyResource) { + access(all) fun consume(_ r: @AnyResource) { destroy r } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -1650,7 +1650,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { var x <- create R() var y <- create R() let xRef = &x as &R @@ -1660,8 +1660,8 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { xRef.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -1681,7 +1681,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x <- create R() let xRef = &x as &R if true { @@ -1698,8 +1698,8 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { } } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -1719,7 +1719,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheckAccount(t, ` - pub fun test() { + access(all) fun test() { authAccount.save(<-[<-create R()], to: /storage/a) let collectionRef = authAccount.borrow<&[R]>(from: /storage/a)! @@ -1728,11 +1728,15 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { let collection <- authAccount.load<@[R]>(from: /storage/a)! authAccount.save(<- collection, to: /storage/b) - ref.a = 2 + ref.setA(2) } - pub resource R { - pub(set) var a: Int + access(all) resource R { + access(all) var a: Int + + access(all) fun setA(_ a: Int) { + self.a = a + } init() { self.a = 5 @@ -1751,7 +1755,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let f = fun() { let x <- create R() let xRef = &x as &R @@ -1762,8 +1766,8 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { f() } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -1783,20 +1787,20 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub contract Test { - priv var x: @R + access(all) contract Test { + access(self) var x: @R init() { self.x <- create R() } - pub fun test() { + access(all) fun test() { let xRef = &self.x as &R xRef.a } } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -1814,20 +1818,20 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub contract Test { - priv var x: @R + access(all) contract Test { + access(self) var x: @R init() { self.x <- create R() } - pub fun test() { + access(all) fun test() { let xRef = &Test.x as &R xRef.a } } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 } @@ -1844,7 +1848,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { var r: @{UInt64: {UInt64: [R]}} <- {} let ref1 = (&r[0] as &{UInt64: [R]}?)! let ref2 = (&ref1[0] as &[R]?)! @@ -1854,8 +1858,8 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { destroy r } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -1873,7 +1877,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { var r: @{UInt64: {UInt64: [R]}} <- {} let ref1 = (&r[0] as &{UInt64: [R]}?)! let ref2 = (&ref1[0] as &[R]?)! @@ -1882,8 +1886,8 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { ref3.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 } @@ -1902,15 +1906,15 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x <- create R() let xRef = (&x as &R?)! destroy x xRef.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 } @@ -1929,15 +1933,15 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { importedChecker, err := ParseAndCheckWithOptions(t, ` - pub contract Foo { - pub let field: @AnyResource + access(all) contract Foo { + access(all) let field: @AnyResource init() { self.field <- create R() } } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 } @@ -1955,7 +1959,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { ` import Foo from "imported" - pub fun test() { + access(all) fun test() { let xRef = &Foo.field as &AnyResource xRef } @@ -1980,14 +1984,14 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 } - pub fun test() { + access(all) fun test() { let xRef = &self as &R xRef.a } @@ -2004,15 +2008,15 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub contract Test { - pub let a: @{UInt64: {UInt64: Test.R}} + access(all) contract Test { + access(all) let a: @{UInt64: {UInt64: Test.R}} init() { self.a <- {} } - pub resource R { - pub fun test() { + access(all) resource R { + access(all) fun test() { if let storage = &Test.a[0] as &{UInt64: Test.R}? { let nftRef = (&storage[0] as &Test.R?)! nftRef @@ -2032,9 +2036,9 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub contract Test { - pub resource R { - pub fun test () { + access(all) contract Test { + access(all) resource R { + access(all) fun test () { let sourceRefNFTs: {UInt64: &Test.R} = {} let sourceNFTs: @[Test.R] <- [] @@ -2051,7 +2055,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { destroy sourceNFTs } - pub fun bar(): Bool { + access(all) fun bar(): Bool { return true } } @@ -2068,9 +2072,9 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub contract Test { - pub resource R { - pub fun test(packList: &[Test.R]) { + access(all) contract Test { + access(all) resource R { + access(all) fun test(packList: &[Test.R]) { var i = 0; while i < packList.length { let pack = &packList[i] as &Test.R; @@ -2095,7 +2099,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x <- create R() let xRef = &x as &R if true { @@ -2108,8 +2112,8 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { destroy x } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -2136,15 +2140,15 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x: @R? <- create R() let ref = (&x as &R?) ?? nil destroy x ref!.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -2165,7 +2169,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x: @R? <- create R() let y: @R <- create R() @@ -2175,8 +2179,8 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { destroy x } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -2197,7 +2201,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x: @R? <- create R() let y: @R <- create R() @@ -2207,8 +2211,8 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { ref!.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -2230,7 +2234,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x: @R? <- create R() let y: @R <- create R() let z: @R? <- create R() @@ -2243,8 +2247,8 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { ref2!.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -2267,7 +2271,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x <- create R() var ref1: &R? = nil ref1 = &x as &R @@ -2276,8 +2280,8 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { ref1!.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -2297,7 +2301,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x = S() var ref1: &S? = nil ref1 = &x as &S @@ -2305,10 +2309,10 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { ref1!.a } - pub fun consume(_ s:S) {} + access(all) fun consume(_ s:S) {} - pub struct S { - pub let a: Int + access(all) struct S { + access(all) let a: Int init() { self.a = 5 @@ -2326,7 +2330,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x <- create R() let ref1 = &x as &R let ref2 = ref1 @@ -2335,8 +2339,8 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { ref3.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -2356,25 +2360,29 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let r <- create R() let s = S() - s.b = &r as &R + s.setB(&r as &R) destroy r s.b!.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 } } - pub struct S { - pub(set) var b: &R? + access(all) struct S { + access(all) var b: &R? + + access(all) fun setB(_ b: &R) { + self.b = b + } init() { self.b = nil @@ -2392,26 +2400,30 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let r <- create R() let s = S() - s.b = &r as &R + s.setB(&r as &R) let x = s.b! destroy r x.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 } } - pub struct S { - pub(set) var b: &R? + access(all) struct S { + access(all) var b: &R? + + access(all) fun setB(_ b: &R) { + self.b = b + } init() { self.b = nil @@ -2429,15 +2441,15 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x: @R? <- create R() let ref = true ? (&x as &R?) : nil destroy x ref!.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -2458,7 +2470,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x: @R? <- create R() let y: @R <- create R() @@ -2468,8 +2480,8 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { destroy x } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -2490,7 +2502,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x: @R? <- create R() let y: @R <- create R() @@ -2500,8 +2512,8 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { ref!.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -2523,15 +2535,15 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { _, err := ParseAndCheck(t, ` - pub fun test() { + access(all) fun test() { let x <- create R() let xRef = &x as &R destroy x xRef.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 @@ -2554,7 +2566,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { t, prevInvalidationNote.Range.StartPos, ast.Position{ - Offset: 126, + Offset: 134, Line: 5, Column: 24, }) @@ -2562,7 +2574,7 @@ func TestCheckInvalidatedReferenceUse(t *testing.T) { t, prevInvalidationNote.Range.EndPos, ast.Position{ - Offset: 126, + Offset: 134, Line: 5, Column: 24, }) diff --git a/runtime/tests/checker/resources_test.go b/runtime/tests/checker/resources_test.go index a464a8a773..74e83f92e7 100644 --- a/runtime/tests/checker/resources_test.go +++ b/runtime/tests/checker/resources_test.go @@ -1627,7 +1627,7 @@ func TestCheckInvalidCreateImportedResource(t *testing.T) { importedChecker, err := ParseAndCheckWithOptions(t, ` - pub resource R {} + access(all) resource R {} `, ParseAndCheckOptions{ Location: ImportedLocation, @@ -1640,7 +1640,7 @@ func TestCheckInvalidCreateImportedResource(t *testing.T) { ` import R from "imported" - pub fun test() { + access(all) fun test() { destroy create R() } `, @@ -1674,7 +1674,7 @@ func TestCheckResourceCreationInContracts(t *testing.T) { contract B { - pub fun test() { + access(all) fun test() { destroy create A.R() } } @@ -1693,7 +1693,7 @@ func TestCheckResourceCreationInContracts(t *testing.T) { contract A { resource R {} - pub fun test() { + access(all) fun test() { destroy create R() } } @@ -1811,11 +1811,11 @@ func TestCheckInvalidResourceLoss(t *testing.T) { _, err := ParseAndCheck(t, ` resource Foo {} - pub fun foo(): @Foo? { + access(all) fun foo(): @Foo? { return <- create Foo() } - pub let isNil = foo() == nil + access(all) let isNil = foo() == nil `) errs := RequireCheckerErrors(t, err, 1) @@ -5325,7 +5325,7 @@ func TestCheckInvalidResourceLossInNestedContractResource(t *testing.T) { _, err := ParseAndCheck(t, ` - pub contract C { + access(all) contract C { resource R { @@ -5336,7 +5336,7 @@ func TestCheckInvalidResourceLossInNestedContractResource(t *testing.T) { } } - pub fun bar() { + access(all) fun bar() { return } } diff --git a/runtime/tests/checker/return_test.go b/runtime/tests/checker/return_test.go index 046f3948fd..6c5ad9649c 100644 --- a/runtime/tests/checker/return_test.go +++ b/runtime/tests/checker/return_test.go @@ -170,13 +170,13 @@ func TestCheckInvalidMissingReturnStatementStructFunction(t *testing.T) { _, err := ParseAndCheck(t, ` struct Test { - pub(set) var foo: Int + access(all) var foo: Int init(foo: Int) { self.foo = foo } - pub fun getFoo(): Int { + access(all) fun getFoo(): Int { if 2 > 1 { return 0 } diff --git a/runtime/tests/checker/type_inference_test.go b/runtime/tests/checker/type_inference_test.go index 73bf7b95ef..46088d0b18 100644 --- a/runtime/tests/checker/type_inference_test.go +++ b/runtime/tests/checker/type_inference_test.go @@ -816,17 +816,17 @@ func TestCheckArraySupertypeInference(t *testing.T) { code: ` let x = [Foo(), Bar(), Baz()] - pub struct interface I1 {} + access(all) struct interface I1 {} - pub struct interface I2 {} + access(all) struct interface I2 {} - pub struct interface I3 {} + access(all) struct interface I3 {} - pub struct Foo: I1, I2 {} + access(all) struct Foo: I1, I2 {} - pub struct Bar: I2, I3 {} + access(all) struct Bar: I2, I3 {} - pub struct Baz: I1, I2, I3 {} + access(all) struct Baz: I1, I2, I3 {} `, expectedElementType: &sema.RestrictedType{ Type: sema.AnyStructType, @@ -844,11 +844,11 @@ func TestCheckArraySupertypeInference(t *testing.T) { code: ` let x = [[Bar()], [Baz()]] - pub struct interface Foo {} + access(all) struct interface Foo {} - pub struct Bar: Foo {} + access(all) struct Bar: Foo {} - pub struct Baz: Foo {} + access(all) struct Baz: Foo {} `, expectedElementType: &sema.VariableSizedType{ Type: &sema.RestrictedType{ @@ -869,11 +869,11 @@ func TestCheckArraySupertypeInference(t *testing.T) { // Covariance is supported with explicit type annotation. let x = [[Bar()], [Baz()]] as [[{Foo}]] - pub struct interface Foo {} + access(all) struct interface Foo {} - pub struct Bar: Foo {} + access(all) struct Bar: Foo {} - pub struct Baz: Foo {} + access(all) struct Baz: Foo {} `, expectedElementType: &sema.VariableSizedType{ Type: &sema.RestrictedType{ @@ -937,9 +937,9 @@ func TestCheckArraySupertypeInference(t *testing.T) { code := ` let x = [<- create Foo(), Bar()] - pub resource Foo {} + access(all) resource Foo {} - pub struct Bar {} + access(all) struct Bar {} ` _, err := ParseAndCheck(t, code) errs := RequireCheckerErrors(t, err, 1) @@ -1016,17 +1016,17 @@ func TestCheckDictionarySupertypeInference(t *testing.T) { code: ` let x = {0: Foo(), 1: Bar(), 2: Baz()} - pub struct interface I1 {} + access(all) struct interface I1 {} - pub struct interface I2 {} + access(all) struct interface I2 {} - pub struct interface I3 {} + access(all) struct interface I3 {} - pub struct Foo: I1, I2 {} + access(all) struct Foo: I1, I2 {} - pub struct Bar: I2, I3 {} + access(all) struct Bar: I2, I3 {} - pub struct Baz: I1, I2, I3 {} + access(all) struct Baz: I1, I2, I3 {} `, expectedKeyType: sema.IntType, expectedValueType: &sema.RestrictedType{ @@ -1045,11 +1045,11 @@ func TestCheckDictionarySupertypeInference(t *testing.T) { code: ` let x = { 0: {100: Bar()}, 1: {200: Baz()} } - pub struct interface Foo {} + access(all) struct interface Foo {} - pub struct Bar: Foo {} + access(all) struct Bar: Foo {} - pub struct Baz: Foo {} + access(all) struct Baz: Foo {} `, expectedKeyType: sema.IntType, expectedValueType: &sema.DictionaryType{ @@ -1072,11 +1072,11 @@ func TestCheckDictionarySupertypeInference(t *testing.T) { // Covariance is supported with explicit type annotation. let x = { 0: {100: Bar()}, 1: {200: Baz()} } as {Int: {Int: {Foo}}} - pub struct interface Foo {} + access(all) struct interface Foo {} - pub struct Bar: Foo {} + access(all) struct Bar: Foo {} - pub struct Baz: Foo {} + access(all) struct Baz: Foo {} `, expectedKeyType: sema.IntType, expectedValueType: &sema.DictionaryType{ @@ -1104,7 +1104,7 @@ func TestCheckDictionarySupertypeInference(t *testing.T) { code: ` let x <- {0: <- {10: <- create Foo()}, 1: <- {"one": <- create Foo()}} - pub resource Foo {} + access(all) resource Foo {} `, expectedKeyType: sema.IntType, expectedValueType: sema.AnyResourceType, @@ -1133,9 +1133,9 @@ func TestCheckDictionarySupertypeInference(t *testing.T) { code := ` let x = {0: <- create Foo(), 1: Bar()} - pub resource Foo {} + access(all) resource Foo {} - pub struct Bar {} + access(all) struct Bar {} ` _, err := ParseAndCheck(t, code) errs := RequireCheckerErrors(t, err, 1) @@ -1232,15 +1232,15 @@ func TestCheckCompositeSupertypeInference(t *testing.T) { code := ` let x = true ? Foo() : Bar() - pub struct interface I1 {} + access(all) struct interface I1 {} - pub struct interface I2: I1 {} + access(all) struct interface I2: I1 {} - pub struct interface I3: I1 {} + access(all) struct interface I3: I1 {} - pub struct Foo: I2 {} + access(all) struct Foo: I2 {} - pub struct Bar: I3 {} + access(all) struct Bar: I3 {} ` expectedType := &sema.RestrictedType{ diff --git a/runtime/tests/examples/examples.go b/runtime/tests/examples/examples.go index cc5cffd408..855b9e5ccb 100644 --- a/runtime/tests/examples/examples.go +++ b/runtime/tests/examples/examples.go @@ -19,48 +19,48 @@ package examples const FungibleTokenContractInterface = ` - pub contract interface FungibleToken { + access(all) contract interface FungibleToken { - pub resource interface Provider { + access(all) resource interface Provider { - pub fun withdraw(amount: Int): @Vault + access(all) fun withdraw(amount: Int): @Vault } - pub resource interface Receiver { + access(all) resource interface Receiver { - pub fun deposit(vault: @Vault) + access(all) fun deposit(vault: @Vault) } - pub resource Vault: Provider, Receiver { + access(all) resource Vault: Provider, Receiver { - pub balance: Int + access(all) balance: Int init(balance: Int) } - pub fun absorb(vault: @Vault) + access(all) fun absorb(vault: @Vault) - pub fun sprout(balance: Int): @Vault + access(all) fun sprout(balance: Int): @Vault } ` const ExampleFungibleTokenContract = ` - pub contract ExampleToken: FungibleToken { + access(all) contract ExampleToken: FungibleToken { - pub resource Vault: FungibleToken.Receiver, FungibleToken.Provider { + access(all) resource Vault: FungibleToken.Receiver, FungibleToken.Provider { - pub var balance: Int + access(all) var balance: Int init(balance: Int) { self.balance = balance } - pub fun withdraw(amount: Int): @FungibleToken.Vault { + access(all) fun withdraw(amount: Int): @FungibleToken.Vault { self.balance = self.balance - amount return <-create Vault(balance: amount) } - pub fun deposit(vault: @FungibleToken.Vault) { + access(all) fun deposit(vault: @FungibleToken.Vault) { if let exampleVault <- vault as? @Vault { self.balance = self.balance + exampleVault.balance destroy exampleVault @@ -71,11 +71,11 @@ const ExampleFungibleTokenContract = ` } } - pub fun absorb(vault: @FungibleToken.Vault) { + access(all) fun absorb(vault: @FungibleToken.Vault) { destroy vault } - pub fun sprout(balance: Int): @FungibleToken.Vault { + access(all) fun sprout(balance: Int): @FungibleToken.Vault { return <-create Vault(balance: balance) } } diff --git a/runtime/tests/interpreter/account_test.go b/runtime/tests/interpreter/account_test.go index 07fd0004cf..c301e9c9a2 100644 --- a/runtime/tests/interpreter/account_test.go +++ b/runtime/tests/interpreter/account_test.go @@ -3095,7 +3095,7 @@ func TestInterpretAccountIterationMutation(t *testing.T) { importedChecker, err := checker.ParseAndCheckWithOptions(t, ` - pub fun foo() { + access(all) fun foo() { account.save("bar", to: /storage/foo5) } `, diff --git a/runtime/tests/interpreter/attachments_test.go b/runtime/tests/interpreter/attachments_test.go index 6880dbbac8..e900f1ce14 100644 --- a/runtime/tests/interpreter/attachments_test.go +++ b/runtime/tests/interpreter/attachments_test.go @@ -1570,7 +1570,12 @@ func TestInterpretAttachmentResourceReferenceInvalidation(t *testing.T) { inter, _ := testAccount(t, address, true, ` resource R {} attachment A for R { - pub(set) var id: UInt8 + access(all) var id: UInt8 + + access(all) fun setID(_ id: UInt8) { + self.id = id + } + init() { self.id = 1 } @@ -1585,7 +1590,7 @@ func TestInterpretAttachmentResourceReferenceInvalidation(t *testing.T) { // Then update the field of the attachment. var r3 <- r2 let a2 = r3[A]! - a2.id = 5 + a2.setID(5) authAccount.save(<-r3, to: /storage/foo) // Access the attachment filed from the previous reference. @@ -1645,7 +1650,12 @@ func TestInterpretAttachmentResourceReferenceInvalidation(t *testing.T) { } } attachment A for R { - pub(set) var id: UInt8 + access(all) var id: UInt8 + + access(all) fun setID(_ id: UInt8) { + self.id = id + } + init() { self.id = 1 } @@ -1658,7 +1668,7 @@ func TestInterpretAttachmentResourceReferenceInvalidation(t *testing.T) { // Then update the field of the attachment. var r3 <- r2 let a2 = r3.r[A]! - a2.id = 5 + a2.setID(5) authAccount.save(<-r3, to: /storage/foo) // Access the attachment filed from the previous reference. @@ -1680,8 +1690,13 @@ func TestInterpretAttachmentResourceReferenceInvalidation(t *testing.T) { address := interpreter.NewUnmeteredAddressValueFromBytes([]byte{42}) inter, _ := testAccount(t, address, true, ` - pub resource R { - pub(set) var id: UInt8 + access(all) resource R { + access(all) var id: UInt8 + + access(all) fun setID(_ id: UInt8) { + self.id = id + } + init() { self.id = 1 } @@ -1702,7 +1717,7 @@ func TestInterpretAttachmentResourceReferenceInvalidation(t *testing.T) { a.saveBaseRef() var r2 <- r - r2.id = 5 + r2.setID(5) authAccount.save(<-r2, to: /storage/foo) return ref!.id }`, @@ -1758,12 +1773,17 @@ func TestInterpretAttachmentResourceReferenceInvalidation(t *testing.T) { address := interpreter.NewUnmeteredAddressValueFromBytes([]byte{42}) inter, _ := testAccount(t, address, true, ` - pub resource R {} + access(all) resource R {} var ref: &A? = nil attachment A for R { - pub(set) var id: UInt8 + access(all) var id: UInt8 + + access(all) fun setID(_ id: UInt8) { + self.id = id + } + init() { self.id = 1 } @@ -1779,7 +1799,7 @@ func TestInterpretAttachmentResourceReferenceInvalidation(t *testing.T) { var r2 <- r let a = r2[A]! - a.id = 5 + a.setID(5) authAccount.save(<-r2, to: /storage/foo) return ref!.id }`, diff --git a/runtime/tests/interpreter/condition_test.go b/runtime/tests/interpreter/condition_test.go index bc85ef6cf6..d57d961ffe 100644 --- a/runtime/tests/interpreter/condition_test.go +++ b/runtime/tests/interpreter/condition_test.go @@ -404,16 +404,16 @@ func TestInterpretInterfaceFunctionUseWithPreCondition(t *testing.T) { inter, err := parseCheckAndInterpretWithOptions(t, fmt.Sprintf( ` - pub %[1]s interface Test { - pub fun test(x: Int): Int { + access(all) %[1]s interface Test { + access(all) fun test(x: Int): Int { pre { x > 0: "x must be positive" } } } - pub %[1]s TestImpl: Test { - pub fun test(x: Int): Int { + access(all) %[1]s TestImpl: Test { + access(all) fun test(x: Int): Int { pre { x < 2: "x must be smaller than 2" } @@ -421,7 +421,7 @@ func TestInterpretInterfaceFunctionUseWithPreCondition(t *testing.T) { } } - pub fun callTest(x: Int): Int { + access(all) fun callTest(x: Int): Int { %[2]s let res = %[3]s.test(x: x) %[4]s @@ -491,7 +491,7 @@ func TestInterpretInitializerWithInterfacePreCondition(t *testing.T) { if compositeKind == common.CompositeKindContract { // use the contract singleton, so it is loaded testFunction = ` - pub fun test() { + access(all) fun test() { TestImpl } ` @@ -501,7 +501,7 @@ func TestInterpretInitializerWithInterfacePreCondition(t *testing.T) { testFunction = fmt.Sprintf( ` - pub fun test(x: Int): %[1]s%[2]s { + access(all) fun test(x: Int): %[1]s%[2]s { return %[3]s %[4]s TestImpl%[5]s } `, @@ -516,7 +516,7 @@ func TestInterpretInitializerWithInterfacePreCondition(t *testing.T) { checker, err := checker.ParseAndCheck(t, fmt.Sprintf( ` - pub %[1]s interface Test { + access(all) %[1]s interface Test { init(x: Int) { pre { x > 0: "x must be positive" @@ -524,7 +524,7 @@ func TestInterpretInitializerWithInterfacePreCondition(t *testing.T) { } } - pub %[1]s TestImpl: Test { + access(all) %[1]s TestImpl: Test { init(x: Int) { pre { x < 2: "x must be smaller than 2" @@ -623,18 +623,18 @@ func TestInterpretTypeRequirementWithPreCondition(t *testing.T) { inter, err := parseCheckAndInterpretWithOptions(t, ` - pub struct interface Also { - pub fun test(x: Int) { + access(all) struct interface Also { + access(all) fun test(x: Int) { pre { x >= 0: "x >= 0" } } } - pub contract interface Test { + access(all) contract interface Test { - pub struct Nested { - pub fun test(x: Int) { + access(all) struct Nested { + access(all) fun test(x: Int) { pre { x >= 1: "x >= 1" } @@ -642,10 +642,10 @@ func TestInterpretTypeRequirementWithPreCondition(t *testing.T) { } } - pub contract TestImpl: Test { + access(all) contract TestImpl: Test { - pub struct Nested: Also { - pub fun test(x: Int) { + access(all) struct Nested: Also { + access(all) fun test(x: Int) { pre { x < 2: "x < 2" } @@ -653,7 +653,7 @@ func TestInterpretTypeRequirementWithPreCondition(t *testing.T) { } } - pub fun test(x: Int) { + access(all) fun test(x: Int) { TestImpl.Nested().test(x: x) } `, @@ -797,11 +797,11 @@ func TestInterpretResourceTypeRequirementInitializerAndDestructorPreConditions(t inter, err := parseCheckAndInterpretWithOptions(t, ` - pub contract interface CI { + access(all) contract interface CI { - pub resource R { + access(all) resource R { - pub x: Int + access(all) x: Int init(_ x: Int) { pre { x > 1: "invalid init" } @@ -813,18 +813,18 @@ func TestInterpretResourceTypeRequirementInitializerAndDestructorPreConditions(t } } - pub contract C: CI { + access(all) contract C: CI { - pub resource R { + access(all) resource R { - pub let x: Int + access(all) let x: Int init(_ x: Int) { self.x = x } } - pub fun test(_ x: Int) { + access(all) fun test(_ x: Int) { let r <- create C.R(x) destroy r } diff --git a/runtime/tests/interpreter/entitlements_test.go b/runtime/tests/interpreter/entitlements_test.go index 2ca14dc3dd..048def6493 100644 --- a/runtime/tests/interpreter/entitlements_test.go +++ b/runtime/tests/interpreter/entitlements_test.go @@ -278,7 +278,7 @@ func TestInterpretEntitledReferences(t *testing.T) { true, ` entitlement X - pub fun test(): Bool { + access(all) fun test(): Bool { let ref = &1 as auth(X) &Int let anyStruct = ref as AnyStruct let downRef = (anyStruct as? &Int)! @@ -1572,7 +1572,7 @@ func TestInterpretEntitlementMappingFields(t *testing.T) { E -> F } struct S { - priv let myFoo: Int + access(self) let myFoo: Int access(M) fun foo(): auth(M) &Int { return &self.myFoo as auth(M) &Int } @@ -2777,7 +2777,7 @@ func TestInterpretEntitledAttachments(t *testing.T) { struct S {} struct T {} access(M) attachment A for S { - priv let t: T + access(self) let t: T init(t: T) { self.t = t } diff --git a/runtime/tests/interpreter/enum_test.go b/runtime/tests/interpreter/enum_test.go index ce6988bb40..a79cbded02 100644 --- a/runtime/tests/interpreter/enum_test.go +++ b/runtime/tests/interpreter/enum_test.go @@ -226,8 +226,8 @@ func TestInterpretEnumInContract(t *testing.T) { ` contract C { enum E: UInt8 { - pub case a - pub case b + access(all) case a + access(all) case b } var e: E diff --git a/runtime/tests/interpreter/function_test.go b/runtime/tests/interpreter/function_test.go index 29d10857fa..5b04cc21bc 100644 --- a/runtime/tests/interpreter/function_test.go +++ b/runtime/tests/interpreter/function_test.go @@ -39,14 +39,14 @@ func TestInterpretResultVariable(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - pub resource R { - pub let id: UInt8 + access(all) resource R { + access(all) let id: UInt8 init() { self.id = 1 } } - pub fun main(): @R { + access(all) fun main(): @R { post { result.id == 1: "invalid id" } @@ -72,14 +72,14 @@ func TestInterpretResultVariable(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - pub resource R { - pub let id: UInt8 + access(all) resource R { + access(all) let id: UInt8 init() { self.id = 1 } } - pub fun main(): @R? { + access(all) fun main(): @R? { post { result!.id == 1: "invalid id" } @@ -110,14 +110,14 @@ func TestInterpretResultVariable(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - pub resource R { - pub let id: UInt8 + access(all) resource R { + access(all) let id: UInt8 init() { self.id = 1 } } - pub fun main(): @R? { + access(all) fun main(): @R? { post { result == nil: "invalid result" } @@ -134,14 +134,14 @@ func TestInterpretResultVariable(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - pub resource R { - pub let id: UInt8 + access(all) resource R { + access(all) let id: UInt8 init() { self.id = 1 } } - pub fun main(): @AnyResource { + access(all) fun main(): @AnyResource { post { result != nil: "invalid value" } @@ -176,8 +176,11 @@ func TestInterpretResultVariable(t *testing.T) { var checkerErrors []error inter, err := parseCheckAndInterpretWithOptions(t, ` - pub resource R { - pub(set) var id: UInt8 + access(all) resource R { + access(all) var id: UInt8 + access(all) fun setID(_ id: UInt8) { + self.id = id + } init() { self.id = 1 } @@ -185,29 +188,29 @@ func TestInterpretResultVariable(t *testing.T) { var ref: &R? = nil - pub fun main(): @R? { + access(all) fun main(): @R? { var r <- createAndStoreRef() if var r2 <- r { - r2.id = 2 + r2.setID(2) return <- r2 } return nil } - pub fun createAndStoreRef(): @R? { + access(all) fun createAndStoreRef(): @R? { post { storeRef(result) } return <- create R() } - pub fun storeRef(_ r: &R?): Bool { + access(all) fun storeRef(_ r: &R?): Bool { ref = r return r != nil } - pub fun getID(): UInt8 { + access(all) fun getID(): UInt8 { return ref!.id }`, ParseCheckAndInterpretOptions{ @@ -234,8 +237,13 @@ func TestInterpretResultVariable(t *testing.T) { var checkerErrors []error inter, err := parseCheckAndInterpretWithOptions(t, ` - pub resource R { - pub(set) var id: UInt8 + access(all) resource R { + access(all) var id: UInt8 + + access(all) fun setID(_ id: UInt8) { + self.id = id + } + init() { self.id = 1 } @@ -243,25 +251,25 @@ func TestInterpretResultVariable(t *testing.T) { var ref: &R? = nil - pub fun main(): @R { + access(all) fun main(): @R { var r <- createAndStoreRef() - r.id = 2 + r.setID(2) return <- r } - pub fun createAndStoreRef(): @R { + access(all) fun createAndStoreRef(): @R { post { storeRef(result) } return <- create R() } - pub fun storeRef(_ r: &R): Bool { + access(all) fun storeRef(_ r: &R): Bool { ref = r return r != nil } - pub fun getID(): UInt8 { + access(all) fun getID(): UInt8 { return ref!.id }`, ParseCheckAndInterpretOptions{ diff --git a/runtime/tests/interpreter/if_test.go b/runtime/tests/interpreter/if_test.go index 5d45cebda1..bf341724b7 100644 --- a/runtime/tests/interpreter/if_test.go +++ b/runtime/tests/interpreter/if_test.go @@ -37,7 +37,7 @@ func TestInterpretIfStatement(t *testing.T) { inter, err := parseCheckAndInterpretWithOptions(t, ` - pub fun testTrue(): Int { + access(all) fun testTrue(): Int { if true { return 2 } else { @@ -46,7 +46,7 @@ func TestInterpretIfStatement(t *testing.T) { return 4 } - pub fun testFalse(): Int { + access(all) fun testFalse(): Int { if false { return 2 } else { @@ -55,14 +55,14 @@ func TestInterpretIfStatement(t *testing.T) { return 4 } - pub fun testNoElse(): Int { + access(all) fun testNoElse(): Int { if true { return 2 } return 3 } - pub fun testElseIf(): Int { + access(all) fun testElseIf(): Int { if false { return 2 } else if true { @@ -71,7 +71,7 @@ func TestInterpretIfStatement(t *testing.T) { return 4 } - pub fun testElseIfElse(): Int { + access(all) fun testElseIfElse(): Int { if false { return 2 } else if false { diff --git a/runtime/tests/interpreter/import_test.go b/runtime/tests/interpreter/import_test.go index 3cf0c784f6..ff699b8cbc 100644 --- a/runtime/tests/interpreter/import_test.go +++ b/runtime/tests/interpreter/import_test.go @@ -156,12 +156,12 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) { importedCheckerA, err := checker.ParseAndCheckWithOptions(t, ` // this function *SHOULD* be imported in the importing program - pub fun a(): Int { + access(all) fun a(): Int { return 1 } // this function should *NOT* be imported in the importing program - pub fun b(): Int { + access(all) fun b(): Int { return 11 } `, @@ -177,12 +177,12 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) { importedCheckerB, err := checker.ParseAndCheckWithOptions(t, ` // this function *SHOULD* be imported in the importing program - pub fun b(): Int { + access(all) fun b(): Int { return 2 } // this function should *NOT* be imported in the importing program - pub fun a(): Int { + access(all) fun a(): Int { return 22 } `, @@ -199,7 +199,7 @@ func TestInterpretImportMultipleProgramsFromLocation(t *testing.T) { ` import a, b from 0x1 - pub fun test(): Int { + access(all) fun test(): Int { return a() + b() } `, diff --git a/runtime/tests/interpreter/interface_test.go b/runtime/tests/interpreter/interface_test.go index 37d0fafe61..7e8713f2a9 100644 --- a/runtime/tests/interpreter/interface_test.go +++ b/runtime/tests/interpreter/interface_test.go @@ -275,7 +275,7 @@ func TestInterpretInterfaceInheritance(t *testing.T) { } } - pub fun main(): Int { + access(all) fun main(): Int { let c = C() return c.test() } @@ -315,7 +315,7 @@ func TestInterpretInterfaceInheritance(t *testing.T) { } } - pub fun main(): Int { + access(all) fun main(): Int { let c <- create C() let x = c.test() destroy c @@ -338,11 +338,11 @@ func TestInterpretInterfaceInheritance(t *testing.T) { inter := parseCheckAndInterpret(t, ` struct interface A { - pub fun test(): Int + access(all) fun test(): Int } struct interface B: A { - pub fun test(): Int + access(all) fun test(): Int } struct C: B { @@ -351,7 +351,7 @@ func TestInterpretInterfaceInheritance(t *testing.T) { } } - pub fun main(): Int { + access(all) fun main(): Int { let c = C() return c.test() } @@ -372,7 +372,7 @@ func TestInterpretInterfaceInheritance(t *testing.T) { inter := parseCheckAndInterpret(t, ` struct interface A { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -381,7 +381,7 @@ func TestInterpretInterfaceInheritance(t *testing.T) { struct C: B {} - pub fun main(): Int { + access(all) fun main(): Int { let c = C() return c.test() } @@ -402,7 +402,7 @@ func TestInterpretInterfaceInheritance(t *testing.T) { inter := parseCheckAndInterpret(t, ` struct interface A { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -413,7 +413,7 @@ func TestInterpretInterfaceInheritance(t *testing.T) { struct D: B, C {} - pub fun main(): Int { + access(all) fun main(): Int { let d = D() return d.test() } @@ -435,7 +435,7 @@ func TestInterpretInterfaceInheritance(t *testing.T) { inter, err := parseCheckAndInterpretWithOptions(t, ` contract interface A { struct NestedA { - pub fun test(): Int { + access(all) fun test(): Int { return 3 } } @@ -443,7 +443,7 @@ func TestInterpretInterfaceInheritance(t *testing.T) { contract interface B { struct NestedB { - pub fun test(): String { + access(all) fun test(): String { return "three" } } @@ -456,16 +456,16 @@ func TestInterpretInterfaceInheritance(t *testing.T) { struct NestedB {} - pub fun getNestedA(): NestedA { + access(all) fun getNestedA(): NestedA { return NestedA() } - pub fun getNestedB(): NestedB { + access(all) fun getNestedB(): NestedB { return NestedB() } } - pub fun main(): Int { + access(all) fun main(): Int { return D.getNestedA().test() }`, @@ -497,13 +497,13 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) { inter := parseCheckAndInterpret(t, ` struct interface A { - pub fun test(_ a: Int): Int { + access(all) fun test(_ a: Int): Int { pre { a > 10 } } } struct interface B: A { - pub fun test(_ a: Int): Int + access(all) fun test(_ a: Int): Int } struct C: B { @@ -512,7 +512,7 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) { } } - pub fun main(_ a: Int): Int { + access(all) fun main(_ a: Int): Int { let c = C() return c.test(a) } @@ -537,11 +537,11 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) { inter := parseCheckAndInterpret(t, ` struct interface A { - pub fun test(_ a: Int): Int + access(all) fun test(_ a: Int): Int } struct interface B: A { - pub fun test(_ a: Int): Int { + access(all) fun test(_ a: Int): Int { pre { a > 10 } } } @@ -552,7 +552,7 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) { } } - pub fun main(_ a: Int): Int { + access(all) fun main(_ a: Int): Int { let c = C() return c.test(a) } @@ -577,13 +577,13 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) { inter := parseCheckAndInterpret(t, ` struct interface A { - pub fun test(_ a: Int): Int { + access(all) fun test(_ a: Int): Int { pre { a < 20 } } } struct interface B: A { - pub fun test(_ a: Int): Int { + access(all) fun test(_ a: Int): Int { pre { a > 10 } } } @@ -594,7 +594,7 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) { } } - pub fun main(_ a: Int): Int { + access(all) fun main(_ a: Int): Int { let c = C() return c.test(a) } @@ -624,13 +624,13 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) { inter := parseCheckAndInterpret(t, ` struct interface A { - pub fun test(_ a: Int): Int { + access(all) fun test(_ a: Int): Int { pre { a < 20 } } } struct interface B { - pub fun test(_ a: Int): Int { + access(all) fun test(_ a: Int): Int { pre { a > 10 } } } @@ -643,7 +643,7 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) { } } - pub fun main(_ a: Int): Int { + access(all) fun main(_ a: Int): Int { let d = D() return d.test(a) } @@ -712,47 +712,47 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) { inter, err := parseCheckAndInterpretWithOptions(t, ` struct A: B { - pub fun test() { + access(all) fun test() { pre { print("A") } } } struct interface B: C, D { - pub fun test() { + access(all) fun test() { pre { print("B") } } } struct interface C: E, F { - pub fun test() { + access(all) fun test() { pre { print("C") } } } struct interface D: F { - pub fun test() { + access(all) fun test() { pre { print("D") } } } struct interface E { - pub fun test() { + access(all) fun test() { pre { print("E") } } } struct interface F { - pub fun test() { + access(all) fun test() { pre { print("F") } } } - pub view fun print(_ msg: String): Bool { + access(all) view fun print(_ msg: String): Bool { log(msg) return true } - pub fun main() { + access(all) fun main() { let a = A() a.test() }`, @@ -820,47 +820,47 @@ func TestInterpretInterfaceFunctionConditionsInheritance(t *testing.T) { inter, err := parseCheckAndInterpretWithOptions(t, ` struct A: B { - pub fun test() { + access(all) fun test() { post { print("A") } } } struct interface B: C, D { - pub fun test() { + access(all) fun test() { post { print("B") } } } struct interface C: E, F { - pub fun test() { + access(all) fun test() { post { print("C") } } } struct interface D: F { - pub fun test() { + access(all) fun test() { post { print("D") } } } struct interface E { - pub fun test() { + access(all) fun test() { post { print("E") } } } struct interface F { - pub fun test() { + access(all) fun test() { post { print("F") } } } - pub view fun print(_ msg: String): Bool { + access(all) view fun print(_ msg: String): Bool { log(msg) return true } - pub fun main() { + access(all) fun main() { let a = A() a.test() }`, diff --git a/runtime/tests/interpreter/interpreter_test.go b/runtime/tests/interpreter/interpreter_test.go index e694b618da..77715e8155 100644 --- a/runtime/tests/interpreter/interpreter_test.go +++ b/runtime/tests/interpreter/interpreter_test.go @@ -1092,7 +1092,7 @@ func TestInterpretReturns(t *testing.T) { inter, err := parseCheckAndInterpretWithOptions(t, ` - pub fun returnEarly(): Int { + access(all) fun returnEarly(): Int { return 2 return 1 } @@ -1882,7 +1882,7 @@ func TestInterpretHostFunction(t *testing.T) { t.Parallel() const code = ` - pub let a = test(1, 2) + access(all) let a = test(1, 2) ` program, err := parser.ParseProgram(nil, []byte(code), parser.Config{}) @@ -1962,7 +1962,7 @@ func TestInterpretHostFunctionWithVariableArguments(t *testing.T) { t.Parallel() const code = ` - pub let nothing = test(1, true, "test") + access(all) let nothing = test(1, true, "test") ` program, err := parser.ParseProgram(nil, []byte(code), parser.Config{}) @@ -2072,9 +2072,9 @@ func TestInterpretCompositeDeclaration(t *testing.T) { inter, err := parseCheckAndInterpretWithOptions(t, fmt.Sprintf( ` - pub %[1]s Test {} + access(all) %[1]s Test {} - pub fun test(): %[2]sTest { + access(all) fun test(): %[2]sTest { return %[3]s %[4]s Test%[5]s } `, @@ -3671,7 +3671,7 @@ func TestInterpretCompositeNilEquality(t *testing.T) { identifier = "X" } else { setupCode = fmt.Sprintf( - `pub let x: %[1]sX? %[2]s %[3]s X%[4]s`, + `access(all) let x: %[1]sX? %[2]s %[3]s X%[4]s`, compositeKind.Annotation(), compositeKind.TransferOperator(), compositeKind.ConstructionKeyword(), @@ -3693,12 +3693,12 @@ func TestInterpretCompositeNilEquality(t *testing.T) { inter, err := parseCheckAndInterpretWithOptions(t, fmt.Sprintf( ` - pub %[1]s X%[2]s %[3]s + access(all) %[1]s X%[2]s %[3]s %[4]s - pub let y = %[5]s == nil - pub let z = nil == %[5]s + access(all) let y = %[5]s == nil + access(all) let z = nil == %[5]s `, compositeKind.Keyword(), conformances, @@ -3761,11 +3761,11 @@ func TestInterpretInterfaceConformanceNoRequirements(t *testing.T) { inter := parseCheckAndInterpret(t, fmt.Sprintf( ` - pub %[1]s interface Test {} + access(all) %[1]s interface Test {} - pub %[1]s TestImpl: Test {} + access(all) %[1]s TestImpl: Test {} - pub let test: %[2]s%[3]s %[4]s %[5]s TestImpl%[6]s + access(all) let test: %[2]s%[3]s %[4]s %[5]s TestImpl%[6]s `, compositeKind.Keyword(), compositeKind.Annotation(), @@ -3801,7 +3801,7 @@ func TestInterpretInterfaceFieldUse(t *testing.T) { interfaceType := AsInterfaceType("Test", compositeKind) setupCode = fmt.Sprintf( - `pub let test: %[1]s%[2]s %[3]s %[4]s TestImpl%[5]s`, + `access(all) let test: %[1]s%[2]s %[3]s %[4]s TestImpl%[5]s`, compositeKind.Annotation(), interfaceType, compositeKind.TransferOperator(), @@ -3816,12 +3816,12 @@ func TestInterpretInterfaceFieldUse(t *testing.T) { inter, err := parseCheckAndInterpretWithOptions(t, fmt.Sprintf( ` - pub %[1]s interface Test { - pub x: Int + access(all) %[1]s interface Test { + access(all) x: Int } - pub %[1]s TestImpl: Test { - pub var x: Int + access(all) %[1]s TestImpl: Test { + access(all) var x: Int init(x: Int) { self.x = x @@ -3830,7 +3830,7 @@ func TestInterpretInterfaceFieldUse(t *testing.T) { %[2]s - pub let x = %[3]s.x + access(all) let x = %[3]s.x `, compositeKind.Keyword(), setupCode, @@ -3881,7 +3881,7 @@ func TestInterpretInterfaceFunctionUse(t *testing.T) { interfaceType := AsInterfaceType("Test", compositeKind) setupCode = fmt.Sprintf( - `pub let test: %[1]s %[2]s %[3]s %[4]s TestImpl%[5]s`, + `access(all) let test: %[1]s %[2]s %[3]s %[4]s TestImpl%[5]s`, compositeKind.Annotation(), interfaceType, compositeKind.TransferOperator(), @@ -3896,19 +3896,19 @@ func TestInterpretInterfaceFunctionUse(t *testing.T) { inter, err := parseCheckAndInterpretWithOptions(t, fmt.Sprintf( ` - pub %[1]s interface Test { - pub fun test(): Int + access(all) %[1]s interface Test { + access(all) fun test(): Int } - pub %[1]s TestImpl: Test { - pub fun test(): Int { + access(all) %[1]s TestImpl: Test { + access(all) fun test(): Int { return 2 } } %[2]s - pub let val = %[3]s.test() + access(all) let val = %[3]s.test() `, compositeKind.Keyword(), setupCode, @@ -3938,7 +3938,7 @@ func TestInterpretImport(t *testing.T) { importedChecker, err := checker.ParseAndCheckWithOptions(t, ` - pub fun answer(): Int { + access(all) fun answer(): Int { return 42 } `, @@ -3952,7 +3952,7 @@ func TestInterpretImport(t *testing.T) { ` import answer from "imported" - pub fun test(): Int { + access(all) fun test(): Int { return answer() } `, @@ -4056,7 +4056,7 @@ func TestInterpretImportError(t *testing.T) { } const importedCode1 = ` - pub fun realAnswer(): Int { + access(all) fun realAnswer(): Int { return panic("?!") } ` @@ -4066,7 +4066,7 @@ func TestInterpretImportError(t *testing.T) { const importedCode2 = ` import realAnswer from "imported1" - pub fun answer(): Int { + access(all) fun answer(): Int { return realAnswer() } ` @@ -4076,7 +4076,7 @@ func TestInterpretImportError(t *testing.T) { const code = ` import answer from "imported2" - pub fun test(): Int { + access(all) fun test(): Int { return answer() } ` @@ -6515,12 +6515,12 @@ func TestInterpretCompositeFunctionInvocationFromImportingProgram(t *testing.T) importedChecker, err := checker.ParseAndCheckWithOptions(t, ` // function must have arguments - pub fun x(x: Int) {} + access(all) fun x(x: Int) {} // invocation must be in composite - pub struct Y { + access(all) struct Y { - pub fun x() { + access(all) fun x() { x(x: 1) } } @@ -6535,7 +6535,7 @@ func TestInterpretCompositeFunctionInvocationFromImportingProgram(t *testing.T) ` import Y from "imported" - pub fun test() { + access(all) fun test() { // get member must bind using imported interpreter Y().x() } @@ -7568,7 +7568,7 @@ func TestInterpretReferenceExpression(t *testing.T) { inter := parseCheckAndInterpret(t, ` resource R { - pub let x: Int + access(all) let x: Int init(_ x: Int) { self.x = x @@ -7600,25 +7600,25 @@ func TestInterpretReferenceUse(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - pub resource R { - pub(set) var x: Int + access(all) resource R { + access(all) var x: Int init() { self.x = 0 } - pub fun setX(_ newX: Int) { + access(all) fun setX(_ newX: Int) { self.x = newX } } - pub fun test(): [Int] { + access(all) fun test(): [Int] { let r <- create R() let ref1 = &r as &R let ref2 = &r as &R - ref1.x = 1 + ref1.setX(1) let x1 = ref1.x ref1.setX(2) let x2 = ref1.x @@ -7656,23 +7656,23 @@ func TestInterpretReferenceUseAccess(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - pub resource R { - pub(set) var x: Int + access(all) resource R { + access(all) var x: Int init() { self.x = 0 } - pub fun setX(_ newX: Int) { + access(all) fun setX(_ newX: Int) { self.x = newX } } - pub fun test(): [Int] { + access(all) fun test(): [Int] { let rs <- [<-create R()] let ref = &rs as &[R] let x0 = ref[0].x - ref[0].x = 1 + ref[0].setX(1) let x1 = ref[0].x ref[0].setX(2) let x2 = ref[0].x @@ -8110,22 +8110,22 @@ func TestInterpretCompositeDeclarationNestedTypeScopingOuterInner(t *testing.T) inter, err := parseCheckAndInterpretWithOptions(t, ` - pub contract Test { + access(all) contract Test { - pub struct X { + access(all) struct X { - pub fun test(): X { + access(all) fun test(): X { return Test.x() } } - pub fun x(): X { + access(all) fun x(): X { return X() } } - pub let x1 = Test.x() - pub let x2 = x1.test() + access(all) let x1 = Test.x() + access(all) let x2 = x1.test() `, ParseCheckAndInterpretOptions{ Config: &interpreter.Config{ @@ -8165,12 +8165,12 @@ func TestInterpretCompositeDeclarationNestedConstructor(t *testing.T) { inter, err := parseCheckAndInterpretWithOptions(t, ` - pub contract Test { + access(all) contract Test { - pub struct X {} + access(all) struct X {} } - pub let x = Test.X() + access(all) let x = Test.X() `, ParseCheckAndInterpretOptions{ Config: &interpreter.Config{ @@ -8202,7 +8202,7 @@ func TestInterpretFungibleTokenContract(t *testing.T) { examples.FungibleTokenContractInterface, examples.ExampleFungibleTokenContract, ` - pub fun test(): [Int; 2] { + access(all) fun test(): [Int; 2] { let publisher <- ExampleToken.sprout(balance: 100) let receiver <- ExampleToken.sprout(balance: 0) @@ -8269,21 +8269,21 @@ func TestInterpretContractAccountFieldUse(t *testing.T) { t.Parallel() code := ` - pub contract Test { - pub let address: Address + access(all) contract Test { + access(all) let address: Address init() { // field 'account' can be used, as it is considered initialized self.address = self.account.address } - pub fun test(): Address { + access(all) fun test(): Address { return self.account.address } } - pub let address1 = Test.address - pub let address2 = Test.test() + access(all) let address1 = Test.address + access(all) let address2 = Test.test() ` addressValue := interpreter.AddressValue{ @@ -8422,11 +8422,11 @@ func TestInterpretContractUseInNestedDeclaration(t *testing.T) { t.Parallel() inter, err := parseCheckAndInterpretWithOptions(t, ` - pub contract C { + access(all) contract C { - pub var i: Int + access(all) var i: Int - pub struct S { + access(all) struct S { init() { C.i = C.i + 1 @@ -8811,9 +8811,9 @@ func TestInterpretResourceOwnerFieldUse(t *testing.T) { t.Parallel() code := ` - pub resource R {} + access(all) resource R {} - pub fun test(): [Address?] { + access(all) fun test(): [Address?] { let addresses: [Address?] = [] let r <- create R() @@ -9210,7 +9210,7 @@ func TestInterpretEphemeralReferenceToOptional(t *testing.T) { var rs: @{Int: R} resource R { - pub let id: Int + access(all) let id: Int init(id: Int) { self.id = id @@ -9248,16 +9248,16 @@ func TestInterpretNestedDeclarationOrder(t *testing.T) { _, err := parseCheckAndInterpretWithOptions(t, ` - pub contract Test { + access(all) contract Test { - pub resource A { + access(all) resource A { - pub fun b(): @B { + access(all) fun b(): @B { return <-create B() } } - pub resource B {} + access(all) resource B {} init() { let a <- create A() @@ -9282,13 +9282,13 @@ func TestInterpretNestedDeclarationOrder(t *testing.T) { _, err := parseCheckAndInterpretWithOptions(t, ` - pub contract Test { + access(all) contract Test { - pub resource B {} + access(all) resource B {} - pub resource A { + access(all) resource A { - pub fun b(): @B { + access(all) fun b(): @B { return <-create B() } } @@ -9545,7 +9545,7 @@ func TestInterpretInternalAssignment(t *testing.T) { inter := parseCheckAndInterpret(t, ` struct S { - priv let xs: {String: Int} + access(self) let xs: {String: Int} init() { self.xs = {"a": 1} diff --git a/runtime/tests/interpreter/memory_metering_test.go b/runtime/tests/interpreter/memory_metering_test.go index 1dcb7959a1..796cad6933 100644 --- a/runtime/tests/interpreter/memory_metering_test.go +++ b/runtime/tests/interpreter/memory_metering_test.go @@ -71,7 +71,7 @@ func TestInterpretArrayMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: [Int8] = [] let y: [[String]] = [[]] let z: [[[Bool]]] = [[[]]] @@ -104,7 +104,7 @@ func TestInterpretArrayMetering(t *testing.T) { t.Parallel() const script = ` - pub fun main() { + access(all) fun main() { let values: [[Int128]] = [[], [], []] for value in values { let a = value @@ -134,7 +134,7 @@ func TestInterpretArrayMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: [Int128] = [] x.contains(5) } @@ -157,7 +157,7 @@ func TestInterpretArrayMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: [Int8] = [] x.append(3) x.append(4) @@ -180,7 +180,7 @@ func TestInterpretArrayMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: [Int128] = [] // 2 data slabs x.append(0) // fits in existing slab x.append(1) // fits in existing slab @@ -210,7 +210,7 @@ func TestInterpretArrayMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { var i = 0; let x: [Int128] = [] // 2 data slabs while i < 120 { // should result in 4 meta data slabs and 60 slabs @@ -236,7 +236,7 @@ func TestInterpretArrayMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: [Int128] = [] x.insert(at:0, 3) x.insert(at:1, 3) @@ -258,7 +258,7 @@ func TestInterpretArrayMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: [Int8] = [] x.insert(at:0, 3) x.insert(at:1, 3) @@ -282,7 +282,7 @@ func TestInterpretArrayMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: [Int128] = [0, 1, 2, 3] // uses 2 data slabs and 1 metadata slab x[0] = 1 // adds 1 data and 1 metadata slab x[2] = 1 // adds 1 data and 1 metadata slab @@ -304,7 +304,7 @@ func TestInterpretArrayMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: [Int128] = [0, 1, 2] // uses 2 data slabs and 1 metadata slab x[0] = 1 // fits in existing slab x[2] = 1 // fits in existing slab @@ -326,7 +326,7 @@ func TestInterpretArrayMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: [Int8; 0] = [] let y: [Int8; 1] = [2] let z: [Int8; 2] = [2, 4] @@ -359,7 +359,7 @@ func TestInterpretArrayMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: [Int128] = [] // 2 data slabs x.insert(at:0, 3) // fits in existing slab x.insert(at:1, 3) // fits in existing slab @@ -396,7 +396,7 @@ func TestInterpretDictionaryMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: {Int8: String} = {} let y: {String: {Int8: String}} = {"a": {}} } @@ -428,7 +428,7 @@ func TestInterpretDictionaryMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let values: [{Int8: String}] = [{}, {}, {}] for value in values { let a = value @@ -459,7 +459,7 @@ func TestInterpretDictionaryMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: {Int8: String} = {} x.containsKey(5) } @@ -478,7 +478,7 @@ func TestInterpretDictionaryMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: {Int8: String} = {} x.insert(key: 5, "") x.insert(key: 4, "") @@ -504,7 +504,7 @@ func TestInterpretDictionaryMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: {Int8: String} = {} // 2 data slabs x.insert(key: 0, "") // fits in slab x.insert(key: 1, "") // fits in slab @@ -535,7 +535,7 @@ func TestInterpretDictionaryMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: {Int8: Int8} = {} // 2 data slabs x.insert(key: 0, 0) // all fit in slab x.insert(key: 1, 1) @@ -566,7 +566,7 @@ func TestInterpretDictionaryMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: {Int8: String} = {3: "a"} // 2 data slabs x[3] = "b" // fits in existing slab x[3] = "c" // fits in existing slab @@ -591,7 +591,7 @@ func TestInterpretDictionaryMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: {Int8: String} = {3: "a"} // 2 data slabs x[3] = "b" // fits in existing slab x[4] = "d" // fits in existing slab @@ -618,11 +618,11 @@ func TestInterpretCompositeMetering(t *testing.T) { t.Parallel() script := ` - pub struct S {} + access(all) struct S {} - pub resource R { - pub let a: String - pub let b: String + access(all) resource R { + access(all) let a: String + access(all) let b: String init(a: String, b: String) { self.a = a @@ -630,7 +630,7 @@ func TestInterpretCompositeMetering(t *testing.T) { } } - pub fun main() { + access(all) fun main() { let s = S() let r <- create R(a: "a", b: "b") destroy r @@ -661,9 +661,9 @@ func TestInterpretCompositeMetering(t *testing.T) { t.Parallel() script := ` - pub struct S {} + access(all) struct S {} - pub fun main() { + access(all) fun main() { let values = [S(), S(), S()] for value in values { let a = value @@ -697,7 +697,7 @@ func TestInterpretSimpleCompositeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(a: AuthAccount) { + access(all) fun main(a: AuthAccount) { } ` @@ -716,7 +716,7 @@ func TestInterpretSimpleCompositeMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(a: PublicAccount) { + access(all) fun main(a: PublicAccount) { } ` @@ -739,8 +739,8 @@ func TestInterpretCompositeFieldMetering(t *testing.T) { t.Parallel() script := ` - pub struct S {} - pub fun main() { + access(all) struct S {} + access(all) fun main() { let s = S() } ` @@ -762,13 +762,13 @@ func TestInterpretCompositeFieldMetering(t *testing.T) { t.Parallel() script := ` - pub struct S { - pub let a: String + access(all) struct S { + access(all) let a: String init(_ a: String) { self.a = a } } - pub fun main() { + access(all) fun main() { let s = S("a") } ` @@ -791,15 +791,15 @@ func TestInterpretCompositeFieldMetering(t *testing.T) { t.Parallel() script := ` - pub struct S { - pub let a: String - pub let b: String + access(all) struct S { + access(all) let a: String + access(all) let b: String init(_ a: String, _ b: String) { self.a = a self.b = b } } - pub fun main() { + access(all) fun main() { let s = S("a", "b") } ` @@ -826,7 +826,7 @@ func TestInterpretInterpretedFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() {} + access(all) fun main() {} ` meter := newTestMemoryGauge() @@ -843,7 +843,7 @@ func TestInterpretInterpretedFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let funcPointer = fun(a: String): String { return a } @@ -864,7 +864,7 @@ func TestInterpretInterpretedFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let funcPointer1 = fun(a: String): String { return a } @@ -893,11 +893,11 @@ func TestInterpretInterpretedFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub struct Foo { - pub fun bar() {} + access(all) struct Foo { + access(all) fun bar() {} } - pub fun main() {} + access(all) fun main() {} ` meter := newTestMemoryGauge() @@ -914,11 +914,11 @@ func TestInterpretInterpretedFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub struct Foo { + access(all) struct Foo { init() {} } - pub fun main() {} + access(all) fun main() {} ` meter := newTestMemoryGauge() @@ -941,7 +941,7 @@ func TestInterpretHostFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() {} + access(all) fun main() {} ` meter := newTestMemoryGauge() @@ -956,7 +956,7 @@ func TestInterpretHostFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let funcPointer1 = fun(a: String): String { return a } @@ -980,11 +980,11 @@ func TestInterpretHostFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub struct Foo { - pub fun bar() {} + access(all) struct Foo { + access(all) fun bar() {} } - pub fun main() {} + access(all) fun main() {} ` meter := newTestMemoryGauge() @@ -1001,11 +1001,11 @@ func TestInterpretHostFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub struct Foo { + access(all) struct Foo { init() {} } - pub fun main() {} + access(all) fun main() {} ` meter := newTestMemoryGauge() @@ -1022,7 +1022,7 @@ func TestInterpretHostFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let a = Int8(5) let b = CompositeType("PublicKey") @@ -1045,7 +1045,7 @@ func TestInterpretHostFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { assert(true) } ` @@ -1085,7 +1085,7 @@ func TestInterpretHostFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let publicKey = PublicKey( publicKey: "0102".decodeHex(), signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 @@ -1134,7 +1134,7 @@ func TestInterpretHostFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let publicKey1 = PublicKey( publicKey: "0102".decodeHex(), signatureAlgorithm: SignatureAlgorithm.ECDSA_P256 @@ -1192,11 +1192,11 @@ func TestInterpretBoundFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub struct Foo { - pub fun bar() {} + access(all) struct Foo { + access(all) fun bar() {} } - pub fun main() {} + access(all) fun main() {} ` meter := newTestMemoryGauge() @@ -1213,11 +1213,11 @@ func TestInterpretBoundFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub struct Foo { + access(all) struct Foo { init() {} } - pub fun main() {} + access(all) fun main() {} ` meter := newTestMemoryGauge() @@ -1234,11 +1234,11 @@ func TestInterpretBoundFunctionMetering(t *testing.T) { t.Parallel() script := ` - pub struct Foo { - pub fun bar() {} + access(all) struct Foo { + access(all) fun bar() {} } - pub fun main() { + access(all) fun main() { let foo = Foo() foo.bar() foo.bar() @@ -1265,7 +1265,7 @@ func TestInterpretOptionalValueMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: String? = "hello" } ` @@ -1283,7 +1283,7 @@ func TestInterpretOptionalValueMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: {Int8: String} = {1: "foo", 2: "bar"} let y = x[0] let z = x[1] @@ -1307,7 +1307,7 @@ func TestInterpretOptionalValueMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: {Int8: String} = {1: "foo", 2: "bar"} x[0] = "a" x[1] = "b" @@ -1330,7 +1330,7 @@ func TestInterpretOptionalValueMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let type: Type = Type() let a = OptionalType(type) } @@ -1358,7 +1358,7 @@ func TestInterpretIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 } ` @@ -1377,7 +1377,7 @@ func TestInterpretIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 + 2 } ` @@ -1396,7 +1396,7 @@ func TestInterpretIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 - 2 } ` @@ -1415,7 +1415,7 @@ func TestInterpretIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 * 2 } ` @@ -1434,7 +1434,7 @@ func TestInterpretIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 / 2 } ` @@ -1453,7 +1453,7 @@ func TestInterpretIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 % 2 } ` @@ -1472,7 +1472,7 @@ func TestInterpretIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 | 2 } ` @@ -1491,7 +1491,7 @@ func TestInterpretIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 ^ 2 } ` @@ -1510,7 +1510,7 @@ func TestInterpretIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 & 2 } ` @@ -1529,7 +1529,7 @@ func TestInterpretIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 << 2 } ` @@ -1548,7 +1548,7 @@ func TestInterpretIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 >> 2 } ` @@ -1567,7 +1567,7 @@ func TestInterpretIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 let y = -x } @@ -1592,7 +1592,7 @@ func TestInterpretUIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt } ` @@ -1612,7 +1612,7 @@ func TestInterpretUIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt + 2 as UInt } ` @@ -1631,7 +1631,7 @@ func TestInterpretUIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 3 as UInt - 2 as UInt } ` @@ -1650,7 +1650,7 @@ func TestInterpretUIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt).saturatingSubtract(2 as UInt) } ` @@ -1669,7 +1669,7 @@ func TestInterpretUIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt * 2 as UInt } ` @@ -1688,7 +1688,7 @@ func TestInterpretUIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt / 2 as UInt } ` @@ -1707,7 +1707,7 @@ func TestInterpretUIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt % 2 as UInt } ` @@ -1726,7 +1726,7 @@ func TestInterpretUIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt | 2 as UInt } ` @@ -1745,7 +1745,7 @@ func TestInterpretUIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt ^ 2 as UInt } ` @@ -1764,7 +1764,7 @@ func TestInterpretUIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt & 2 as UInt } ` @@ -1783,7 +1783,7 @@ func TestInterpretUIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt << 2 as UInt } ` @@ -1802,7 +1802,7 @@ func TestInterpretUIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt >> 2 as UInt } ` @@ -1821,7 +1821,7 @@ func TestInterpretUIntMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 let y = -x } @@ -1846,7 +1846,7 @@ func TestInterpretUInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt8 } ` @@ -1866,7 +1866,7 @@ func TestInterpretUInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt8 + 2 as UInt8 } ` @@ -1887,7 +1887,7 @@ func TestInterpretUInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt8).saturatingAdd(2 as UInt8) } ` @@ -1908,7 +1908,7 @@ func TestInterpretUInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 3 as UInt8 - 2 as UInt8 } ` @@ -1929,7 +1929,7 @@ func TestInterpretUInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt8).saturatingSubtract(2 as UInt8) } ` @@ -1950,7 +1950,7 @@ func TestInterpretUInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt8 * 2 as UInt8 } ` @@ -1971,7 +1971,7 @@ func TestInterpretUInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt8).saturatingMultiply(2 as UInt8) } ` @@ -1992,7 +1992,7 @@ func TestInterpretUInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt8 / 2 as UInt8 } ` @@ -2013,7 +2013,7 @@ func TestInterpretUInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt8 % 2 as UInt8 } ` @@ -2034,7 +2034,7 @@ func TestInterpretUInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt8 | 2 as UInt8 } ` @@ -2055,7 +2055,7 @@ func TestInterpretUInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt8 ^ 2 as UInt8 } ` @@ -2076,7 +2076,7 @@ func TestInterpretUInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt8 & 2 as UInt8 } ` @@ -2098,7 +2098,7 @@ func TestInterpretUInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt8 << 2 as UInt8 } ` @@ -2119,7 +2119,7 @@ func TestInterpretUInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt8 >> 2 as UInt8 } ` @@ -2145,7 +2145,7 @@ func TestInterpretUInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt16 } ` @@ -2165,7 +2165,7 @@ func TestInterpretUInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt16 + 2 as UInt16 } ` @@ -2186,7 +2186,7 @@ func TestInterpretUInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt16).saturatingAdd(2 as UInt16) } ` @@ -2207,7 +2207,7 @@ func TestInterpretUInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 3 as UInt16 - 2 as UInt16 } ` @@ -2228,7 +2228,7 @@ func TestInterpretUInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt16).saturatingSubtract(2 as UInt16) } ` @@ -2249,7 +2249,7 @@ func TestInterpretUInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt16 * 2 as UInt16 } ` @@ -2270,7 +2270,7 @@ func TestInterpretUInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt16).saturatingMultiply(2 as UInt16) } ` @@ -2291,7 +2291,7 @@ func TestInterpretUInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt16 / 2 as UInt16 } ` @@ -2312,7 +2312,7 @@ func TestInterpretUInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt16 % 2 as UInt16 } ` @@ -2333,7 +2333,7 @@ func TestInterpretUInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt16 | 2 as UInt16 } ` @@ -2354,7 +2354,7 @@ func TestInterpretUInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt16 ^ 2 as UInt16 } ` @@ -2375,7 +2375,7 @@ func TestInterpretUInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt16 & 2 as UInt16 } ` @@ -2396,7 +2396,7 @@ func TestInterpretUInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt16 << 2 as UInt16 } ` @@ -2417,7 +2417,7 @@ func TestInterpretUInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt16 >> 2 as UInt16 } ` @@ -2443,7 +2443,7 @@ func TestInterpretUInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt32 } ` @@ -2463,7 +2463,7 @@ func TestInterpretUInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt32 + 2 as UInt32 } ` @@ -2484,7 +2484,7 @@ func TestInterpretUInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt32).saturatingAdd(2 as UInt32) } ` @@ -2505,7 +2505,7 @@ func TestInterpretUInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 3 as UInt32 - 2 as UInt32 } ` @@ -2526,7 +2526,7 @@ func TestInterpretUInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt32).saturatingSubtract(2 as UInt32) } ` @@ -2547,7 +2547,7 @@ func TestInterpretUInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt32 * 2 as UInt32 } ` @@ -2568,7 +2568,7 @@ func TestInterpretUInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt32).saturatingMultiply(2 as UInt32) } ` @@ -2589,7 +2589,7 @@ func TestInterpretUInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt32 / 2 as UInt32 } ` @@ -2610,7 +2610,7 @@ func TestInterpretUInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt32 % 2 as UInt32 } ` @@ -2631,7 +2631,7 @@ func TestInterpretUInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt32 | 2 as UInt32 } ` @@ -2652,7 +2652,7 @@ func TestInterpretUInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt32 ^ 2 as UInt32 } ` @@ -2673,7 +2673,7 @@ func TestInterpretUInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt32 & 2 as UInt32 } ` @@ -2694,7 +2694,7 @@ func TestInterpretUInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt32 << 2 as UInt32 } ` @@ -2715,7 +2715,7 @@ func TestInterpretUInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt32 >> 2 as UInt32 } ` @@ -2741,7 +2741,7 @@ func TestInterpretUInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt64 } ` @@ -2761,7 +2761,7 @@ func TestInterpretUInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt64 + 2 as UInt64 } ` @@ -2782,7 +2782,7 @@ func TestInterpretUInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt64).saturatingAdd(2 as UInt64) } ` @@ -2803,7 +2803,7 @@ func TestInterpretUInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 3 as UInt64 - 2 as UInt64 } ` @@ -2824,7 +2824,7 @@ func TestInterpretUInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt64).saturatingSubtract(2 as UInt64) } ` @@ -2845,7 +2845,7 @@ func TestInterpretUInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt64 * 2 as UInt64 } ` @@ -2866,7 +2866,7 @@ func TestInterpretUInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt64).saturatingMultiply(2 as UInt64) } ` @@ -2887,7 +2887,7 @@ func TestInterpretUInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt64 / 2 as UInt64 } ` @@ -2908,7 +2908,7 @@ func TestInterpretUInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt64 % 2 as UInt64 } ` @@ -2929,7 +2929,7 @@ func TestInterpretUInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt64 | 2 as UInt64 } ` @@ -2950,7 +2950,7 @@ func TestInterpretUInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt64 ^ 2 as UInt64 } ` @@ -2971,7 +2971,7 @@ func TestInterpretUInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt64 & 2 as UInt64 } ` @@ -2992,7 +2992,7 @@ func TestInterpretUInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt64 << 2 as UInt64 } ` @@ -3013,7 +3013,7 @@ func TestInterpretUInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt64 >> 2 as UInt64 } ` @@ -3039,7 +3039,7 @@ func TestInterpretUInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt128 } ` @@ -3059,7 +3059,7 @@ func TestInterpretUInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt128 + 2 as UInt128 } ` @@ -3080,7 +3080,7 @@ func TestInterpretUInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt128).saturatingAdd(2 as UInt128) } ` @@ -3101,7 +3101,7 @@ func TestInterpretUInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 3 as UInt128 - 2 as UInt128 } ` @@ -3122,7 +3122,7 @@ func TestInterpretUInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt128).saturatingSubtract(2 as UInt128) } ` @@ -3144,7 +3144,7 @@ func TestInterpretUInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt128 * 2 as UInt128 } ` @@ -3165,7 +3165,7 @@ func TestInterpretUInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt128).saturatingMultiply(2 as UInt128) } ` @@ -3186,7 +3186,7 @@ func TestInterpretUInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt128 / 2 as UInt128 } ` @@ -3207,7 +3207,7 @@ func TestInterpretUInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt128 % 2 as UInt128 } ` @@ -3228,7 +3228,7 @@ func TestInterpretUInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt128 | 2 as UInt128 } ` @@ -3249,7 +3249,7 @@ func TestInterpretUInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt128 ^ 2 as UInt128 } ` @@ -3270,7 +3270,7 @@ func TestInterpretUInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt128 & 2 as UInt128 } ` @@ -3291,7 +3291,7 @@ func TestInterpretUInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt128 << 2 as UInt128 } ` @@ -3312,7 +3312,7 @@ func TestInterpretUInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt128 >> 2 as UInt128 } ` @@ -3338,7 +3338,7 @@ func TestInterpretUInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt256 } ` @@ -3358,7 +3358,7 @@ func TestInterpretUInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt256 + 2 as UInt256 } ` @@ -3379,7 +3379,7 @@ func TestInterpretUInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt256).saturatingAdd(2 as UInt256) } ` @@ -3400,7 +3400,7 @@ func TestInterpretUInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 3 as UInt256 - 2 as UInt256 } ` @@ -3421,7 +3421,7 @@ func TestInterpretUInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt256).saturatingSubtract(2 as UInt256) } ` @@ -3442,7 +3442,7 @@ func TestInterpretUInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as UInt256 * 2 as UInt256 } ` @@ -3463,7 +3463,7 @@ func TestInterpretUInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = (1 as UInt256).saturatingMultiply(2 as UInt256) } ` @@ -3484,7 +3484,7 @@ func TestInterpretUInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt256 / 2 as UInt256 } ` @@ -3505,7 +3505,7 @@ func TestInterpretUInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt256 % 2 as UInt256 } ` @@ -3526,7 +3526,7 @@ func TestInterpretUInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt256 | 2 as UInt256 } ` @@ -3547,7 +3547,7 @@ func TestInterpretUInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt256 ^ 2 as UInt256 } ` @@ -3568,7 +3568,7 @@ func TestInterpretUInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt256 & 2 as UInt256 } ` @@ -3589,7 +3589,7 @@ func TestInterpretUInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt256 << 2 as UInt256 } ` @@ -3610,7 +3610,7 @@ func TestInterpretUInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as UInt256 >> 2 as UInt256 } ` @@ -3636,7 +3636,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 1 } ` @@ -3655,7 +3655,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 1 + 2 } ` @@ -3676,7 +3676,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 1 let y: Int8 = x.saturatingAdd(2) } @@ -3698,7 +3698,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 1 - 2 } ` @@ -3719,7 +3719,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 1 let y: Int8 = x.saturatingSubtract(2) } @@ -3741,7 +3741,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 1 * 2 } ` @@ -3762,7 +3762,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 1 let y: Int8 = x.saturatingMultiply(2) } @@ -3784,7 +3784,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 3 / 2 } ` @@ -3805,7 +3805,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 3 let y: Int8 = x.saturatingMultiply(2) } @@ -3827,7 +3827,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 3 % 2 } ` @@ -3848,7 +3848,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 1 let y: Int8 = -x } @@ -3870,7 +3870,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 3 | 2 } ` @@ -3891,7 +3891,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 3 ^ 2 } ` @@ -3912,7 +3912,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 3 & 2 } ` @@ -3933,7 +3933,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 3 << 2 } ` @@ -3954,7 +3954,7 @@ func TestInterpretInt8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int8 = 3 >> 2 } ` @@ -3981,7 +3981,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 1 } ` @@ -4000,7 +4000,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 1 + 2 } ` @@ -4021,7 +4021,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 1 let y: Int16 = x.saturatingAdd(2) } @@ -4043,7 +4043,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 1 - 2 } ` @@ -4064,7 +4064,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 1 let y: Int16 = x.saturatingSubtract(2) } @@ -4086,7 +4086,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 1 * 2 } ` @@ -4107,7 +4107,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 1 let y: Int16 = x.saturatingMultiply(2) } @@ -4129,7 +4129,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 3 / 2 } ` @@ -4150,7 +4150,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 3 let y: Int16 = x.saturatingMultiply(2) } @@ -4172,7 +4172,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 3 % 2 } ` @@ -4193,7 +4193,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 1 let y: Int16 = -x } @@ -4215,7 +4215,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 3 | 2 } ` @@ -4236,7 +4236,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 3 ^ 2 } ` @@ -4257,7 +4257,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 3 & 2 } ` @@ -4278,7 +4278,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 3 << 2 } ` @@ -4299,7 +4299,7 @@ func TestInterpretInt16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int16 = 3 >> 2 } ` @@ -4325,7 +4325,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 1 } ` @@ -4344,7 +4344,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 1 + 2 } ` @@ -4365,7 +4365,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 1 let y: Int32 = x.saturatingAdd(2) } @@ -4387,7 +4387,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 1 - 2 } ` @@ -4408,7 +4408,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 1 let y: Int32 = x.saturatingSubtract(2) } @@ -4430,7 +4430,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 1 * 2 } ` @@ -4451,7 +4451,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 1 let y: Int32 = x.saturatingMultiply(2) } @@ -4473,7 +4473,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 3 / 2 } ` @@ -4494,7 +4494,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 3 let y: Int32 = x.saturatingMultiply(2) } @@ -4516,7 +4516,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 3 % 2 } ` @@ -4537,7 +4537,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 1 let y: Int32 = -x } @@ -4559,7 +4559,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 3 | 2 } ` @@ -4580,7 +4580,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 3 ^ 2 } ` @@ -4601,7 +4601,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 3 & 2 } ` @@ -4622,7 +4622,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 3 << 2 } ` @@ -4643,7 +4643,7 @@ func TestInterpretInt32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int32 = 3 >> 2 } ` @@ -4669,7 +4669,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 1 } ` @@ -4688,7 +4688,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 1 + 2 } ` @@ -4709,7 +4709,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 1 let y: Int64 = x.saturatingAdd(2) } @@ -4731,7 +4731,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 1 - 2 } ` @@ -4752,7 +4752,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 1 let y: Int64 = x.saturatingSubtract(2) } @@ -4774,7 +4774,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 1 * 2 } ` @@ -4795,7 +4795,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 1 let y: Int64 = x.saturatingMultiply(2) } @@ -4817,7 +4817,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 3 / 2 } ` @@ -4838,7 +4838,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 3 let y: Int64 = x.saturatingMultiply(2) } @@ -4860,7 +4860,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 3 % 2 } ` @@ -4881,7 +4881,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 1 let y: Int64 = -x } @@ -4903,7 +4903,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 3 | 2 } ` @@ -4924,7 +4924,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 3 ^ 2 } ` @@ -4945,7 +4945,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 3 & 2 } ` @@ -4966,7 +4966,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 3 << 2 } ` @@ -4987,7 +4987,7 @@ func TestInterpretInt64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int64 = 3 >> 2 } ` @@ -5013,7 +5013,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 1 } ` @@ -5032,7 +5032,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 1 + 2 } ` @@ -5053,7 +5053,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 1 let y: Int128 = x.saturatingAdd(2) } @@ -5075,7 +5075,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 1 - 2 } ` @@ -5096,7 +5096,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 1 let y: Int128 = x.saturatingSubtract(2) } @@ -5118,7 +5118,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 1 * 2 } ` @@ -5139,7 +5139,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 1 let y: Int128 = x.saturatingMultiply(2) } @@ -5161,7 +5161,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 3 / 2 } ` @@ -5182,7 +5182,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 3 let y: Int128 = x.saturatingMultiply(2) } @@ -5204,7 +5204,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 3 % 2 } ` @@ -5225,7 +5225,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 1 let y: Int128 = -x } @@ -5247,7 +5247,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 3 | 2 } ` @@ -5268,7 +5268,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 3 ^ 2 } ` @@ -5289,7 +5289,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 3 & 2 } ` @@ -5310,7 +5310,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 3 << 2 } ` @@ -5331,7 +5331,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 3 >> 2 } ` @@ -5352,7 +5352,7 @@ func TestInterpretInt128Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int128 = 1 x == 1 x != 1 @@ -5382,7 +5382,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 1 } ` @@ -5401,7 +5401,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 1 + 2 } ` @@ -5422,7 +5422,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 1 let y: Int256 = x.saturatingAdd(2) } @@ -5444,7 +5444,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 1 - 2 } ` @@ -5465,7 +5465,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 1 let y: Int256 = x.saturatingSubtract(2) } @@ -5487,7 +5487,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 1 * 2 } ` @@ -5508,7 +5508,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 1 let y: Int256 = x.saturatingMultiply(2) } @@ -5530,7 +5530,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 3 / 2 } ` @@ -5551,7 +5551,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 3 let y: Int256 = x.saturatingMultiply(2) } @@ -5573,7 +5573,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 3 % 2 } ` @@ -5594,7 +5594,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 1 let y: Int256 = -x } @@ -5616,7 +5616,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 3 | 2 } ` @@ -5637,7 +5637,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 3 ^ 2 } ` @@ -5658,7 +5658,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 3 & 2 } ` @@ -5679,7 +5679,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 3 << 2 } ` @@ -5700,7 +5700,7 @@ func TestInterpretInt256Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Int256 = 3 >> 2 } ` @@ -5726,7 +5726,7 @@ func TestInterpretWord8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as Word8 } ` @@ -5747,7 +5747,7 @@ func TestInterpretWord8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as Word8 + 2 as Word8 } ` @@ -5768,7 +5768,7 @@ func TestInterpretWord8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 3 as Word8 - 2 as Word8 } ` @@ -5789,7 +5789,7 @@ func TestInterpretWord8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as Word8 * 2 as Word8 } ` @@ -5810,7 +5810,7 @@ func TestInterpretWord8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word8 / 2 as Word8 } ` @@ -5831,7 +5831,7 @@ func TestInterpretWord8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word8 % 2 as Word8 } ` @@ -5852,7 +5852,7 @@ func TestInterpretWord8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word8 | 2 as Word8 } ` @@ -5873,7 +5873,7 @@ func TestInterpretWord8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word8 ^ 2 as Word8 } ` @@ -5894,7 +5894,7 @@ func TestInterpretWord8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word8 & 2 as Word8 } ` @@ -5915,7 +5915,7 @@ func TestInterpretWord8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word8 << 2 as Word8 } ` @@ -5936,7 +5936,7 @@ func TestInterpretWord8Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word8 >> 2 as Word8 } ` @@ -5962,7 +5962,7 @@ func TestInterpretWord16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as Word16 } ` @@ -5982,7 +5982,7 @@ func TestInterpretWord16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as Word16 + 2 as Word16 } ` @@ -6003,7 +6003,7 @@ func TestInterpretWord16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 3 as Word16 - 2 as Word16 } ` @@ -6024,7 +6024,7 @@ func TestInterpretWord16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as Word16 * 2 as Word16 } ` @@ -6045,7 +6045,7 @@ func TestInterpretWord16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word16 / 2 as Word16 } ` @@ -6066,7 +6066,7 @@ func TestInterpretWord16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word16 % 2 as Word16 } ` @@ -6087,7 +6087,7 @@ func TestInterpretWord16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word16 | 2 as Word16 } ` @@ -6108,7 +6108,7 @@ func TestInterpretWord16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word16 ^ 2 as Word16 } ` @@ -6129,7 +6129,7 @@ func TestInterpretWord16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word16 & 2 as Word16 } ` @@ -6150,7 +6150,7 @@ func TestInterpretWord16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word16 << 2 as Word16 } ` @@ -6171,7 +6171,7 @@ func TestInterpretWord16Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word16 >> 2 as Word16 } ` @@ -6197,7 +6197,7 @@ func TestInterpretWord32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as Word32 } ` @@ -6217,7 +6217,7 @@ func TestInterpretWord32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as Word32 + 2 as Word32 } ` @@ -6238,7 +6238,7 @@ func TestInterpretWord32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 3 as Word32 - 2 as Word32 } ` @@ -6259,7 +6259,7 @@ func TestInterpretWord32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as Word32 * 2 as Word32 } ` @@ -6280,7 +6280,7 @@ func TestInterpretWord32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word32 / 2 as Word32 } ` @@ -6301,7 +6301,7 @@ func TestInterpretWord32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word32 % 2 as Word32 } ` @@ -6322,7 +6322,7 @@ func TestInterpretWord32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word32 | 2 as Word32 } ` @@ -6343,7 +6343,7 @@ func TestInterpretWord32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word32 ^ 2 as Word32 } ` @@ -6364,7 +6364,7 @@ func TestInterpretWord32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word32 & 2 as Word32 } ` @@ -6385,7 +6385,7 @@ func TestInterpretWord32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word32 << 2 as Word32 } ` @@ -6406,7 +6406,7 @@ func TestInterpretWord32Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word32 >> 2 as Word32 } ` @@ -6432,7 +6432,7 @@ func TestInterpretWord64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as Word64 } ` @@ -6452,7 +6452,7 @@ func TestInterpretWord64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as Word64 + 2 as Word64 } ` @@ -6473,7 +6473,7 @@ func TestInterpretWord64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 3 as Word64 - 2 as Word64 } ` @@ -6494,7 +6494,7 @@ func TestInterpretWord64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 1 as Word64 * 2 as Word64 } ` @@ -6515,7 +6515,7 @@ func TestInterpretWord64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word64 / 2 as Word64 } ` @@ -6536,7 +6536,7 @@ func TestInterpretWord64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word64 % 2 as Word64 } ` @@ -6557,7 +6557,7 @@ func TestInterpretWord64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word64 | 2 as Word64 } ` @@ -6578,7 +6578,7 @@ func TestInterpretWord64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word64 ^ 2 as Word64 } ` @@ -6599,7 +6599,7 @@ func TestInterpretWord64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word64 & 2 as Word64 } ` @@ -6620,7 +6620,7 @@ func TestInterpretWord64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word64 << 2 as Word64 } ` @@ -6641,7 +6641,7 @@ func TestInterpretWord64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 10 as Word64 >> 2 as Word64 } ` @@ -6667,7 +6667,7 @@ func TestInterpretStorageReferenceValueMetering(t *testing.T) { script := ` resource R {} - pub fun main(account: AuthAccount) { + access(all) fun main(account: AuthAccount) { account.borrow<&R>(from: /storage/r) } ` @@ -6692,7 +6692,7 @@ func TestInterpretEphemeralReferenceValueMetering(t *testing.T) { script := ` resource R {} - pub fun main(): &Int { + access(all) fun main(): &Int { let x: Int = 1 let y = &x as &Int return y @@ -6714,7 +6714,7 @@ func TestInterpretEphemeralReferenceValueMetering(t *testing.T) { script := ` resource R {} - pub fun main(): &Int { + access(all) fun main(): &Int { let x: Int? = 1 let y = &x as &Int? return y! @@ -6740,7 +6740,7 @@ func TestInterpretStringMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = "a" } ` @@ -6758,7 +6758,7 @@ func TestInterpretStringMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = "a" let y = x } @@ -6777,7 +6777,7 @@ func TestInterpretStringMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = "İ" } ` @@ -6795,7 +6795,7 @@ func TestInterpretStringMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = "ABC".toLower() } ` @@ -6814,7 +6814,7 @@ func TestInterpretStringMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = "İ".toLower() } ` @@ -6836,7 +6836,7 @@ func TestInterpretCharacterMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Character = "a" } ` @@ -6854,7 +6854,7 @@ func TestInterpretCharacterMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Character = "a" let y = x } @@ -6873,7 +6873,7 @@ func TestInterpretCharacterMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: String = "a" let y: Character = x[0] } @@ -6895,7 +6895,7 @@ func TestInterpretAddressValueMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Address = 0x0 } ` @@ -6912,7 +6912,7 @@ func TestInterpretAddressValueMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = Address(0x0) } ` @@ -6933,7 +6933,7 @@ func TestInterpretPathValueMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = /public/bar } ` @@ -6950,7 +6950,7 @@ func TestInterpretPathValueMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = PublicPath(identifier: "bar") } ` @@ -6973,7 +6973,7 @@ func TestInterpretPathCapabilityValueMetering(t *testing.T) { script := ` resource R {} - pub fun main(account: AuthAccount) { + access(all) fun main(account: AuthAccount) { let r <- create R() account.save(<-r, to: /storage/r) let x = account.link<&R>(/public/cap, target: /storage/r) @@ -6997,7 +6997,7 @@ func TestInterpretPathCapabilityValueMetering(t *testing.T) { script := ` resource R {} - pub fun main(account: AuthAccount) { + access(all) fun main(account: AuthAccount) { let r <- create R() account.save(<-r, to: /storage/r) let x = account.link<&R>(/public/cap, target: /storage/r) @@ -7027,7 +7027,7 @@ func TestInterpretPathLinkValueMetering(t *testing.T) { script := ` resource R {} - pub fun main(account: AuthAccount) { + access(all) fun main(account: AuthAccount) { account.link<&R>(/public/cap, target: /private/p) } ` @@ -7053,7 +7053,7 @@ func TestInterpretAccountLinkValueMetering(t *testing.T) { const script = ` #allowAccountLinking - pub fun main(account: AuthAccount) { + access(all) fun main(account: AuthAccount) { account.linkAccount(/private/cap) } ` @@ -7089,7 +7089,7 @@ func TestInterpretTypeValueMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let t: Type = Type() } ` @@ -7106,7 +7106,7 @@ func TestInterpretTypeValueMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let t: Type = ConstantSizedArrayType(type: Type(), size: 2) } ` @@ -7124,7 +7124,7 @@ func TestInterpretTypeValueMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let v = 5 let t: Type = v.getType() } @@ -7149,7 +7149,7 @@ func TestInterpretVariableMetering(t *testing.T) { var a = 3 let b = false - pub fun main() { + access(all) fun main() { } ` @@ -7166,7 +7166,7 @@ func TestInterpretVariableMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(a: String, b: Bool) { + access(all) fun main(a: String, b: Bool) { } ` @@ -7187,7 +7187,7 @@ func TestInterpretVariableMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { var x = fun (x: String, y: Bool) {} } ` @@ -7204,7 +7204,7 @@ func TestInterpretVariableMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { var x = fun (x: String, y: Bool) {} x("", false) } @@ -7228,7 +7228,7 @@ func TestInterpretFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Fix64 = 1.4 } ` @@ -7248,7 +7248,7 @@ func TestInterpretFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Fix64 = 1.4 + 2.5 } ` @@ -7270,7 +7270,7 @@ func TestInterpretFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Fix64 = 1.4 let y: Fix64 = x.saturatingAdd(2.5) } @@ -7293,7 +7293,7 @@ func TestInterpretFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Fix64 = 1.4 - 2.5 } ` @@ -7315,7 +7315,7 @@ func TestInterpretFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Fix64 = 1.4 let y: Fix64 = x.saturatingSubtract(2.5) } @@ -7338,7 +7338,7 @@ func TestInterpretFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Fix64 = 1.4 * 2.5 } ` @@ -7360,7 +7360,7 @@ func TestInterpretFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Fix64 = 1.4 let y: Fix64 = x.saturatingMultiply(2.5) } @@ -7383,7 +7383,7 @@ func TestInterpretFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Fix64 = 3.4 / 2.5 } ` @@ -7405,7 +7405,7 @@ func TestInterpretFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Fix64 = 3.4 let y: Fix64 = x.saturatingMultiply(2.5) } @@ -7428,7 +7428,7 @@ func TestInterpretFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Fix64 = 3.4 % 2.5 } ` @@ -7453,7 +7453,7 @@ func TestInterpretFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Fix64 = 1.4 let y: Fix64 = -x } @@ -7477,7 +7477,7 @@ func TestInterpretFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: FixedPoint = -1.4 } ` @@ -7497,7 +7497,7 @@ func TestInterpretFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Fix64 = 1.0 x == 1.0 x != 1.0 @@ -7527,7 +7527,7 @@ func TestInterpretUFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: UFix64 = 1.4 } ` @@ -7547,7 +7547,7 @@ func TestInterpretUFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: UFix64 = 1.4 + 2.5 } ` @@ -7569,7 +7569,7 @@ func TestInterpretUFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: UFix64 = 1.4 let y: UFix64 = x.saturatingAdd(2.5) } @@ -7592,7 +7592,7 @@ func TestInterpretUFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: UFix64 = 2.5 - 1.4 } ` @@ -7614,7 +7614,7 @@ func TestInterpretUFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: UFix64 = 1.4 let y: UFix64 = x.saturatingSubtract(2.5) } @@ -7637,7 +7637,7 @@ func TestInterpretUFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: UFix64 = 1.4 * 2.5 } ` @@ -7659,7 +7659,7 @@ func TestInterpretUFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: UFix64 = 1.4 let y: UFix64 = x.saturatingMultiply(2.5) } @@ -7682,7 +7682,7 @@ func TestInterpretUFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: UFix64 = 3.4 / 2.5 } ` @@ -7704,7 +7704,7 @@ func TestInterpretUFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: UFix64 = 3.4 let y: UFix64 = x.saturatingMultiply(2.5) } @@ -7727,7 +7727,7 @@ func TestInterpretUFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: UFix64 = 3.4 % 2.5 } ` @@ -7752,7 +7752,7 @@ func TestInterpretUFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: FixedPoint = 1.4 } ` @@ -7772,7 +7772,7 @@ func TestInterpretUFix64Metering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: UFix64 = 1.0 x == 1.0 x != 1.0 @@ -7800,11 +7800,11 @@ func TestInterpretTokenMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { var x: String = "hello" } - pub struct foo { + access(all) struct foo { var x: Int init() { @@ -7818,7 +7818,7 @@ func TestInterpretTokenMetering(t *testing.T) { _, err := inter.Invoke("main") require.NoError(t, err) - assert.Equal(t, uint64(32), meter.getMemory(common.MemoryKindTypeToken)) + assert.Equal(t, uint64(38), meter.getMemory(common.MemoryKindTypeToken)) assert.Equal(t, uint64(25), meter.getMemory(common.MemoryKindSpaceToken)) assert.Equal(t, uint64(0), meter.getMemory(common.MemoryKindRawString)) }) @@ -7827,7 +7827,7 @@ func TestInterpretTokenMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { var a: [String] = [] var b = 4 + 6 var c = true && false != false @@ -7839,7 +7839,7 @@ func TestInterpretTokenMetering(t *testing.T) { _, err := inter.Invoke("main") require.NoError(t, err) - assert.Equal(t, uint64(36), meter.getMemory(common.MemoryKindTypeToken)) + assert.Equal(t, uint64(39), meter.getMemory(common.MemoryKindTypeToken)) assert.Equal(t, uint64(31), meter.getMemory(common.MemoryKindSpaceToken)) assert.Equal(t, uint64(0), meter.getMemory(common.MemoryKindRawString)) }) @@ -7853,14 +7853,14 @@ func TestInterpretTokenMetering(t *testing.T) { */ // single line comment - pub fun main() {} + access(all) fun main() {} ` meter := newTestMemoryGauge() inter := parseCheckAndInterpretWithMemoryMetering(t, script, meter) _, err := inter.Invoke("main") require.NoError(t, err) - assert.Equal(t, uint64(11), meter.getMemory(common.MemoryKindTypeToken)) + assert.Equal(t, uint64(14), meter.getMemory(common.MemoryKindTypeToken)) assert.Equal(t, uint64(7), meter.getMemory(common.MemoryKindSpaceToken)) assert.Equal(t, uint64(0), meter.getMemory(common.MemoryKindRawString)) }) @@ -7869,7 +7869,7 @@ func TestInterpretTokenMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { var a = 1 var b = 0b1 var c = 0o1 @@ -7882,7 +7882,7 @@ func TestInterpretTokenMetering(t *testing.T) { _, err := inter.Invoke("main") require.NoError(t, err) - assert.Equal(t, uint64(27), meter.getMemory(common.MemoryKindTypeToken)) + assert.Equal(t, uint64(30), meter.getMemory(common.MemoryKindTypeToken)) assert.Equal(t, uint64(26), meter.getMemory(common.MemoryKindSpaceToken)) assert.Equal(t, uint64(0), meter.getMemory(common.MemoryKindRawString)) }) @@ -7899,7 +7899,7 @@ func TestInterpreterStringLocationMetering(t *testing.T) { script := ` struct S {} - pub fun main(account: AuthAccount) { + access(all) fun main(account: AuthAccount) { let s = CompositeType("") } ` @@ -7916,7 +7916,7 @@ func TestInterpreterStringLocationMetering(t *testing.T) { script = ` struct S {} - pub fun main(account: AuthAccount) { + access(all) fun main(account: AuthAccount) { let s = CompositeType("S.test.S") } ` @@ -7945,7 +7945,7 @@ func TestInterpretIdentifierMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let foo = 4 let bar = 5 } @@ -7964,7 +7964,7 @@ func TestInterpretIdentifierMetering(t *testing.T) { t.Parallel() script := ` - pub fun main(foo: String, bar: String) { + access(all) fun main(foo: String, bar: String) { } ` meter := newTestMemoryGauge() @@ -7985,9 +7985,9 @@ func TestInterpretIdentifierMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() {} + access(all) fun main() {} - pub struct foo { + access(all) struct foo { var x: String var y: String @@ -7996,7 +7996,7 @@ func TestInterpretIdentifierMetering(t *testing.T) { self.y = "b" } - pub fun bar() {} + access(all) fun bar() {} } ` @@ -8012,7 +8012,7 @@ func TestInterpretIdentifierMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { // 2 - 'main', empty-return-type + access(all) fun main() { // 2 - 'main', empty-return-type let foo = ["a", "b"] // 1 foo.length // 3 - 'foo', 'length', constant field resolver foo.length // 3 - 'foo', 'length', constant field resolver (not re-used) @@ -8040,7 +8040,7 @@ func TestInterpretInterfaceStaticType(t *testing.T) { script := ` struct interface I {} - pub fun main() { + access(all) fun main() { let type = Type() RestrictedType( @@ -8068,7 +8068,7 @@ func TestInterpretFunctionStaticType(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { FunctionType(parameters: [], return: Type()) } ` @@ -8086,9 +8086,9 @@ func TestInterpretFunctionStaticType(t *testing.T) { t.Parallel() script := ` - pub fun hello() {} + access(all) fun hello() {} - pub fun main() { + access(all) fun main() { let a = [hello] } ` @@ -8106,11 +8106,11 @@ func TestInterpretFunctionStaticType(t *testing.T) { t.Parallel() script := ` - pub struct S { + access(all) struct S { fun naught() {} } - pub fun main() { + access(all) fun main() { let x = S() let y = x.naught } @@ -8129,11 +8129,11 @@ func TestInterpretFunctionStaticType(t *testing.T) { t.Parallel() script := ` - pub struct S { + access(all) struct S { fun naught() {} } - pub fun main() { + access(all) fun main() { let x = S() x.naught.isInstance(Type()) } @@ -8156,15 +8156,15 @@ func TestInterpretASTMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { foo(a: "hello", b: 23) bar("hello", 23) } - pub fun foo(a: String, b: Int) { + access(all) fun foo(a: String, b: Int) { } - pub fun bar(_ a: String, _ b: Int) { + access(all) fun bar(_ a: String, _ b: Int) { } ` meter := newTestMemoryGauge() @@ -8178,7 +8178,7 @@ func TestInterpretASTMetering(t *testing.T) { t.Run("blocks", func(t *testing.T) { script := ` - pub fun main() { + access(all) fun main() { var i = 0 if i != 0 { i = 0 @@ -8213,26 +8213,26 @@ func TestInterpretASTMetering(t *testing.T) { script := ` import Foo from 0x42 - pub let x = 1 - pub var y = 2 + access(all) let x = 1 + access(all) var y = 2 - pub fun main() { + access(all) fun main() { var z = 3 } - pub fun foo(_ x: String, _ y: Int) {} + access(all) fun foo(_ x: String, _ y: Int) {} - pub struct A { - pub var a: String + access(all) struct A { + access(all) var a: String init() { self.a = "hello" } } - pub struct interface B {} + access(all) struct interface B {} - pub resource C { + access(all) resource C { let a: Int init() { @@ -8240,12 +8240,12 @@ func TestInterpretASTMetering(t *testing.T) { } } - pub resource interface D {} + access(all) resource interface D {} - pub enum E: Int8 { - pub case a - pub case b - pub case c + access(all) enum E: Int8 { + access(all) case a + access(all) case b + access(all) case c } transaction {} @@ -8255,7 +8255,7 @@ func TestInterpretASTMetering(t *testing.T) { importedChecker, err := checker.ParseAndCheckWithOptions(t, ` - pub let Foo = 1 + access(all) let Foo = 1 `, checker.ParseAndCheckOptions{ Location: utils.ImportedLocation, @@ -8319,7 +8319,7 @@ func TestInterpretASTMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { var a = 5 while a < 10 { // while @@ -8347,13 +8347,13 @@ func TestInterpretASTMetering(t *testing.T) { } } - pub fun foo(): Int { + access(all) fun foo(): Int { return 5 // return } resource bar {} - pub contract Events { + access(all) contract Events { event FooEvent(x: Int, y: Int) fun events() { @@ -8407,7 +8407,7 @@ func TestInterpretASTMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { var a = 5 // integer expr var b = 1.2 + 2.3 // binary, fixed-point expr var c = !true // unary, boolean expr @@ -8471,7 +8471,7 @@ func TestInterpretASTMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { var a: Int = 5 // nominal type var b: String? = "hello" // optional type var c: [Int; 2] = [1, 2] // constant sized type @@ -8513,24 +8513,24 @@ func TestInterpretASTMetering(t *testing.T) { t.Run("position info", func(t *testing.T) { script := ` - pub let x = 1 - pub var y = 2 + access(all) let x = 1 + access(all) var y = 2 - pub fun main() { + access(all) fun main() { var z = 3 } - pub fun foo(_ x: String, _ y: Int) {} + access(all) fun foo(_ x: String, _ y: Int) {} - pub struct A { - pub var a: String + access(all) struct A { + access(all) var a: String init() { self.a = "hello" } } - pub struct interface B {} + access(all) struct interface B {} ` meter := newTestMemoryGauge() @@ -8540,8 +8540,8 @@ func TestInterpretASTMetering(t *testing.T) { _, err := inter.Invoke("main") require.NoError(t, err) - assert.Equal(t, uint64(229), meter.getMemory(common.MemoryKindPosition)) - assert.Equal(t, uint64(124), meter.getMemory(common.MemoryKindRange)) + assert.Equal(t, uint64(271), meter.getMemory(common.MemoryKindPosition)) + assert.Equal(t, uint64(145), meter.getMemory(common.MemoryKindRange)) }) t.Run("locations", func(t *testing.T) { @@ -8552,8 +8552,8 @@ func TestInterpretASTMetering(t *testing.T) { importedChecker, err := checker.ParseAndCheckWithOptions(t, ` - pub let A = 1 - pub let B = 1 + access(all) let A = 1 + access(all) let B = 1 `, checker.ParseAndCheckOptions{ Location: utils.ImportedLocation, @@ -8604,7 +8604,7 @@ func TestInterpretVariableActivationMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() {} + access(all) fun main() {} ` meter := newTestMemoryGauge() @@ -8622,11 +8622,11 @@ func TestInterpretVariableActivationMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { foo(a: "hello", b: 23) } - pub fun foo(a: String, b: Int) { + access(all) fun foo(a: String, b: Int) { } ` @@ -8645,7 +8645,7 @@ func TestInterpretVariableActivationMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { if true { let a = 1 } @@ -8670,16 +8670,16 @@ func TestInterpretStaticTypeConversionMetering(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let a: {Int: AnyStruct{Foo}} = {} // dictionary + restricted let b: [&Int] = [] // variable-sized + reference let c: [Int?; 2] = [1, 2] // constant-sized + optional let d: [Capability<&Bar>] = [] // capability + variable-sized + reference } - pub struct interface Foo {} + access(all) struct interface Foo {} - pub struct Bar: Foo {} + access(all) struct Bar: Foo {} ` meter := newTestMemoryGauge() @@ -8704,7 +8704,7 @@ func TestInterpretStorageMapMetering(t *testing.T) { script := ` resource R {} - pub fun main(account: AuthAccount) { + access(all) fun main(account: AuthAccount) { let r <- create R() account.save(<-r, to: /storage/r) account.link<&R>(/public/cap, target: /storage/r) @@ -8930,7 +8930,7 @@ func TestInterpretValueStringConversion(t *testing.T) { t.Parallel() script := fmt.Sprintf(` - pub fun main() { + access(all) fun main() { let x = %s log(x) } @@ -8951,7 +8951,7 @@ func TestInterpretValueStringConversion(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = Foo() log(x) } @@ -8971,7 +8971,7 @@ func TestInterpretValueStringConversion(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = 4 log(&x as &AnyStruct) } @@ -8984,7 +8984,7 @@ func TestInterpretValueStringConversion(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = fun(a: String, b: Bool) {} log(&x as &AnyStruct) } @@ -8997,13 +8997,13 @@ func TestInterpretValueStringConversion(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x = Foo() log(x.bar) } struct Foo { - pub fun bar(a: String, b: Bool) {} + access(all) fun bar(a: String, b: Bool) {} } ` @@ -9014,7 +9014,7 @@ func TestInterpretValueStringConversion(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { let x: Void = foo() log(x) } @@ -9029,7 +9029,7 @@ func TestInterpretValueStringConversion(t *testing.T) { t.Parallel() script := ` - pub fun main(a: Capability<&{Foo}>) { + access(all) fun main(a: Capability<&{Foo}>) { log(a) } @@ -9057,7 +9057,7 @@ func TestInterpretValueStringConversion(t *testing.T) { t.Parallel() script := ` - pub fun main(a: Capability<&{Foo}>) { + access(all) fun main(a: Capability<&{Foo}>) { log(a) } @@ -9082,7 +9082,7 @@ func TestInterpretValueStringConversion(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { log(Type()) } ` @@ -9162,7 +9162,7 @@ func TestInterpretStaticTypeStringConversion(t *testing.T) { } script := fmt.Sprintf(` - pub fun main() { + access(all) fun main() { log(Type<%s>()) }`, sema.NewTypeAnnotation(primitiveStaticType.SemaType()). @@ -9223,7 +9223,7 @@ func TestInterpretStaticTypeStringConversion(t *testing.T) { script := fmt.Sprintf(` entitlement X - pub fun main() { + access(all) fun main() { log(Type<%s>()) } `, @@ -9243,7 +9243,7 @@ func TestInterpretStaticTypeStringConversion(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { log(Type()) } @@ -9262,7 +9262,7 @@ func TestInterpretStaticTypeStringConversion(t *testing.T) { t.Parallel() script := ` - pub fun main() { + access(all) fun main() { log(Type()) } diff --git a/runtime/tests/interpreter/metering_test.go b/runtime/tests/interpreter/metering_test.go index 8929ebc74b..f7f5d303b7 100644 --- a/runtime/tests/interpreter/metering_test.go +++ b/runtime/tests/interpreter/metering_test.go @@ -38,7 +38,7 @@ func TestInterpretStatementHandler(t *testing.T) { importedChecker, err := checker.ParseAndCheckWithOptions(t, ` - pub fun a() { + access(all) fun a() { true true } @@ -165,7 +165,7 @@ func TestInterpretLoopIterationHandler(t *testing.T) { importedChecker, err := checker.ParseAndCheckWithOptions(t, ` - pub fun a() { + access(all) fun a() { var i = 1 while i <= 4 { i = i + 1 @@ -292,9 +292,9 @@ func TestInterpretFunctionInvocationHandler(t *testing.T) { importedChecker, err := checker.ParseAndCheckWithOptions(t, ` - pub fun a() {} + access(all) fun a() {} - pub fun b() { + access(all) fun b() { true true a() @@ -312,7 +312,7 @@ func TestInterpretFunctionInvocationHandler(t *testing.T) { ` import b from "imported" - pub fun c() { + access(all) fun c() { true true b() @@ -320,7 +320,7 @@ func TestInterpretFunctionInvocationHandler(t *testing.T) { true } - pub fun d() { + access(all) fun d() { true true c() diff --git a/runtime/tests/interpreter/reference_test.go b/runtime/tests/interpreter/reference_test.go index 842353456e..65da727818 100644 --- a/runtime/tests/interpreter/reference_test.go +++ b/runtime/tests/interpreter/reference_test.go @@ -100,13 +100,13 @@ func TestInterpretContainerVariance(t *testing.T) { inter := parseCheckAndInterpret(t, ` struct S1 { - pub fun getSecret(): Int { + access(all) fun getSecret(): Int { return 0 } } struct S2 { - priv fun getSecret(): Int { + access(self) fun getSecret(): Int { return 42 } } @@ -135,13 +135,13 @@ func TestInterpretContainerVariance(t *testing.T) { inter := parseCheckAndInterpret(t, ` struct S1 { - pub fun getSecret(): Int { + access(all) fun getSecret(): Int { return 0 } } struct S2 { - priv fun getSecret(): Int { + access(self) fun getSecret(): Int { return 42 } } @@ -177,7 +177,7 @@ func TestInterpretContainerVariance(t *testing.T) { } struct S2 { - priv var value: Int + access(self) var value: Int init() { self.value = 1 @@ -216,7 +216,7 @@ func TestInterpretContainerVariance(t *testing.T) { } struct S2 { - priv var value: Int + access(self) var value: Int init() { self.value = 1 @@ -255,7 +255,7 @@ func TestInterpretContainerVariance(t *testing.T) { struct S2 { // field is only publicly readable, not writeable - pub var value: Int + access(all) var value: Int init() { self.value = 0 @@ -299,7 +299,7 @@ func TestInterpretContainerVariance(t *testing.T) { struct S2 { // field is only publicly readable, not writeable - pub var value: Int + access(all) var value: Int init() { self.value = 0 @@ -564,7 +564,11 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { true, ` resource R { - pub(set) var id: Int + access(all) var id: Int + + access(all) fun setID(_ id: Int) { + self.id = id + } init() { self.id = 1 @@ -579,7 +583,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { account.save(<-r, to: /storage/r) // Update the reference - ref.id = 2 + ref.setID(2) }`, sema.Config{}, errorHandler(t), @@ -602,7 +606,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { true, ` resource R { - pub(set) var id: Int + access(all) var id: Int init() { self.id = 1 @@ -634,7 +638,11 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { inter := parseCheckAndInterpret(t, ` resource R { - pub(set) var id: Int + access(all) var id: Int + + access(all) fun setID(_ id: Int) { + self.id = id + } init() { self.id = 1 @@ -651,7 +659,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { let movedR <- target.remove(at: 0) // Update the reference - ref.id = 2 + ref.setID(2) destroy movedR } @@ -691,7 +699,11 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { t, ` resource R { - pub(set) var id: Int + access(all) var id: Int + + access(all) fun setID(_ id: Int) { + self.id = id + } init() { self.id = 1 @@ -706,7 +718,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { let r2 <- r1 // Update the reference - ref.id = 2 + ref.setID(2) destroy r2 }`, @@ -728,7 +740,11 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { inter := parseCheckAndInterpret(t, ` resource R { - pub(set) var id: Int + access(all) var id: Int + + access(all) fun setID(_ id: Int) { + self.id = id + } init() { self.id = 1 @@ -745,7 +761,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { target2.append(<- target1.remove(at: 0)) // Update the reference - ref.id = 2 + ref.setID(2) } `) @@ -800,7 +816,11 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { inter := parseCheckAndInterpret(t, ` resource R { - pub(set) var id: Int + access(all) var id: Int + + access(all) fun setID(_ id: Int) { + self.id = id + } init() { self.id = 1 @@ -824,7 +844,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { target.append(<- movedR) // Update the reference - ref.id = 2 + ref.setID(2) return target[1].id } @@ -868,7 +888,11 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { true, ` resource R { - pub(set) var id: Int + access(all) var id: Int + + access(all) fun setID(_ id: Int) { + self.id = id + } init() { self.id = 1 @@ -883,7 +907,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { let r2 <- account.load<@R>(from: /storage/r)! - r1Ref.id = 2 + r1Ref.setID(2) destroy r2 }`, sema.Config{}, @@ -900,7 +924,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { inter, err := parseCheckAndInterpretWithOptions(t, ` resource R { - pub(set) var id: Int + access(all) var id: Int init() { self.id = 5 @@ -1003,10 +1027,10 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { inter := parseCheckAndInterpret( t, ` - pub fun test() { + access(all) fun test() { let r <- create R() let s = S() - s.b = &r as &R + s.setB(&r as &R) let x = s.b! // get reference from a struct field let movedR <- r // move the resource @@ -1015,16 +1039,20 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { destroy movedR } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 } } - pub struct S { - pub(set) var b: &R? + access(all) struct S { + access(all) var b: &R? + + access(all) fun setB(_ b: &R) { + self.b = b + } init() { self.b = nil @@ -1044,28 +1072,31 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { inter := parseCheckAndInterpret( t, ` - pub fun test() { + access(all) fun test() { let r <- create R() let s = S() - s.b = &r as &R - s.b = &r as &R // assign reference to a struct field + s.setB(&r as &R) // assign reference to a struct field let movedR <- r // move the resource s.b!.a destroy movedR } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 } } - pub struct S { - pub(set) var b: &R? + access(all) struct S { + access(all) var b: &R? + + access(all) fun setB(_ b: &R) { + self.b = b + } init() { self.b = nil @@ -1086,7 +1117,11 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { t, ` resource R { - pub(set) var id: Int + access(all) var id: Int + + access(all) fun setID(_ id: Int) { + self.id = id + } init() { self.id = 1 @@ -1101,7 +1136,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { let r <- array.remove(at: 0) // Update the reference - ref.id = 2 + ref.setID(2) destroy r destroy array @@ -1121,7 +1156,11 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { t, ` resource R { - pub(set) var id: Int + access(all) var id: Int + + access(all) fun setID(_ id: Int) { + self.id = id + } init() { self.id = 1 @@ -1136,7 +1175,7 @@ func TestInterpretResourceReferenceInvalidationOnMove(t *testing.T) { let r <- dictionary.remove(key: 0) // Update the reference - ref.id = 2 + ref.setID(2) destroy r destroy dictionary @@ -1173,7 +1212,11 @@ func TestInterpretResourceReferenceInvalidationOnDestroy(t *testing.T) { true, ` resource R { - pub(set) var id: Int + access(all) var id: Int + + access(all) fun setID(_ id: Int) { + self.id = id + } init() { self.id = 1 @@ -1187,7 +1230,7 @@ func TestInterpretResourceReferenceInvalidationOnDestroy(t *testing.T) { destroy r // Update the reference - ref.id = 2 + ref.setID(2) }`, sema.Config{}, errorHandler(t), @@ -1205,26 +1248,30 @@ func TestInterpretResourceReferenceInvalidationOnDestroy(t *testing.T) { inter := parseCheckAndInterpret( t, ` - pub fun test() { + access(all) fun test() { let r <- create R() let s = S() - s.b = &r as &R + s.setB(&r as &R) let x = s.b! // get reference from a struct field destroy r // destroy the resource x.a } - pub resource R { - pub let a: Int + access(all) resource R { + access(all) let a: Int init() { self.a = 5 } } - pub struct S { - pub(set) var b: &R? + access(all) struct S { + access(all) var b: &R? + + access(all) fun setB(_ b: &R) { + self.b = b + } init() { self.b = nil diff --git a/runtime/tests/interpreter/resources_test.go b/runtime/tests/interpreter/resources_test.go index ebb7a0f081..ce2b648515 100644 --- a/runtime/tests/interpreter/resources_test.go +++ b/runtime/tests/interpreter/resources_test.go @@ -400,7 +400,16 @@ func TestInterpretImplicitResourceRemovalFromContainer(t *testing.T) { } resource R1 { - pub(set) var r2s: @{Int: R2} + access(all) var r2s: @{Int: R2} + + access(all) fun setR2(i: Int, r: @R2) { + self.r2s[i] <-! r + } + + access(all) fun move(i: Int, r: @R2?): @R2? { + let optR2 <- self.r2s[i] <- r + return <- optR2 + } init() { self.r2s <- {} @@ -416,11 +425,11 @@ func TestInterpretImplicitResourceRemovalFromContainer(t *testing.T) { } fun test(r1: &R1): String? { - r1.r2s[0] <-! create R2() + r1.setR2(i: 0, r: <- create R2()) // The second assignment should not lead to the resource being cleared, // it must be fully moved out of this container before, // not just assigned to the new variable - let optR2 <- r1.r2s[0] <- nil + let optR2 <- r1.move(i: 0, r: nil) let value = optR2?.value destroy optR2 return value @@ -2135,7 +2144,7 @@ func TestInterpreterResourcePreCondition(t *testing.T) { resource S {} struct interface Receiver { - pub fun deposit(from: @S) { + access(all) fun deposit(from: @S) { post { from != nil: "" } @@ -2143,7 +2152,7 @@ func TestInterpreterResourcePreCondition(t *testing.T) { } struct Vault: Receiver { - pub fun deposit(from: @S) { + access(all) fun deposit(from: @S) { destroy from } } @@ -2165,7 +2174,7 @@ func TestInterpreterResourcePostCondition(t *testing.T) { resource S {} struct interface Receiver { - pub fun deposit(from: @S) { + access(all) fun deposit(from: @S) { post { from != nil: "" } @@ -2173,7 +2182,7 @@ func TestInterpreterResourcePostCondition(t *testing.T) { } struct Vault: Receiver { - pub fun deposit(from: @S) { + access(all) fun deposit(from: @S) { destroy from } } @@ -2195,7 +2204,7 @@ func TestInterpreterResourcePreAndPostCondition(t *testing.T) { resource S {} struct interface Receiver { - pub fun deposit(from: @S) { + access(all) fun deposit(from: @S) { pre { from != nil: "" } @@ -2206,7 +2215,7 @@ func TestInterpreterResourcePreAndPostCondition(t *testing.T) { } struct Vault: Receiver { - pub fun deposit(from: @S) { + access(all) fun deposit(from: @S) { pre { from != nil: "" } @@ -2234,7 +2243,7 @@ func TestInterpreterResourceConditionAdditionalParam(t *testing.T) { resource S {} struct interface Receiver { - pub fun deposit(from: @S, other: UInt64) { + access(all) fun deposit(from: @S, other: UInt64) { pre { from != nil: "" } @@ -2245,7 +2254,7 @@ func TestInterpreterResourceConditionAdditionalParam(t *testing.T) { } struct Vault: Receiver { - pub fun deposit(from: @S, other: UInt64) { + access(all) fun deposit(from: @S, other: UInt64) { pre { from != nil: "" } @@ -2273,7 +2282,7 @@ func TestInterpreterResourceDoubleWrappedCondition(t *testing.T) { resource S {} struct interface A { - pub fun deposit(from: @S) { + access(all) fun deposit(from: @S) { pre { from != nil: "" } @@ -2284,7 +2293,7 @@ func TestInterpreterResourceDoubleWrappedCondition(t *testing.T) { } struct interface B { - pub fun deposit(from: @S) { + access(all) fun deposit(from: @S) { pre { from != nil: "" } @@ -2295,7 +2304,7 @@ func TestInterpreterResourceDoubleWrappedCondition(t *testing.T) { } struct Vault: A, B { - pub fun deposit(from: @S) { + access(all) fun deposit(from: @S) { pre { from != nil: "" } @@ -2327,7 +2336,7 @@ func TestInterpretOptionalResourceReference(t *testing.T) { true, ` resource R { - pub let id: Int + access(all) let id: Int init() { self.id = 1 @@ -2365,7 +2374,7 @@ func TestInterpretArrayOptionalResourceReference(t *testing.T) { true, ` resource R { - pub let id: Int + access(all) let id: Int init() { self.id = 1 @@ -2398,7 +2407,7 @@ func TestInterpretResourceDestroyedInPreCondition(t *testing.T) { _, err := parseCheckAndInterpretWithOptions(t, ` resource interface I { - pub fun receiveResource(_ r: @Bar) { + access(all) fun receiveResource(_ r: @Bar) { pre { destroyResource(<-r) } @@ -2411,7 +2420,7 @@ func TestInterpretResourceDestroyedInPreCondition(t *testing.T) { } resource Foo: I { - pub fun receiveResource(_ r: @Bar) { + access(all) fun receiveResource(_ r: @Bar) { destroy r } } diff --git a/runtime/tests/interpreter/runtimetype_test.go b/runtime/tests/interpreter/runtimetype_test.go index 65133bedfb..c9eb9416b6 100644 --- a/runtime/tests/interpreter/runtimetype_test.go +++ b/runtime/tests/interpreter/runtimetype_test.go @@ -572,7 +572,7 @@ func TestInterpretRestrictedType(t *testing.T) { struct B : S {} struct interface S2 { - pub let foo : Int + access(all) let foo : Int } let a = RestrictedType(identifier: "S.test.A", restrictions: ["S.test.R"])! diff --git a/runtime/tests/interpreter/uuid_test.go b/runtime/tests/interpreter/uuid_test.go index d1aaf27a11..ed234ebdef 100644 --- a/runtime/tests/interpreter/uuid_test.go +++ b/runtime/tests/interpreter/uuid_test.go @@ -38,9 +38,9 @@ func TestInterpretResourceUUID(t *testing.T) { importedChecker, err := checker.ParseAndCheckWithOptions(t, ` - pub resource R {} + access(all) resource R {} - pub fun createR(): @R { + access(all) fun createR(): @R { return <- create R() } `, @@ -54,9 +54,9 @@ func TestInterpretResourceUUID(t *testing.T) { ` import createR from "imported" - pub resource R2 {} + access(all) resource R2 {} - pub fun createRs(): @[AnyResource] { + access(all) fun createRs(): @[AnyResource] { return <- [ <- (createR() as @AnyResource), <- create R2() diff --git a/runtime/tests/utils/utils.go b/runtime/tests/utils/utils.go index c630385a63..abeb26bd57 100644 --- a/runtime/tests/utils/utils.go +++ b/runtime/tests/utils/utils.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/go-test/deep" + "github.com/k0kubun/pp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -34,6 +35,10 @@ import ( "github.com/onflow/cadence/runtime/common" ) +func init() { + pp.ColoringEnabled = false +} + // TestLocation is used as the default location for programs in tests. const TestLocation = common.StringLocation("test") @@ -70,8 +75,8 @@ func AssertEqualWithDiff(t *testing.T, expected, actual any) { "expected: %s\n"+ "actual : %s\n\n"+ "%s", - expected, - actual, + pp.Sprint(expected), + pp.Sprint(actual), s.String(), ) } diff --git a/runtime/type_test.go b/runtime/type_test.go index 3595790a9b..105f38b529 100644 --- a/runtime/type_test.go +++ b/runtime/type_test.go @@ -163,7 +163,7 @@ func TestRuntimeBlockFieldTypes(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub fun main(): [UFix64] { + access(all) fun main(): [UFix64] { let block = getCurrentBlock() let id = block.id diff --git a/runtime/validation_test.go b/runtime/validation_test.go index 76e3b0b922..d9f10a73bb 100644 --- a/runtime/validation_test.go +++ b/runtime/validation_test.go @@ -95,7 +95,7 @@ func TestRuntimeArgumentImportMissingType(t *testing.T) { runtime := newTestInterpreterRuntime() script := []byte(` - pub fun main(value: AnyStruct) {} + access(all) fun main(value: AnyStruct) {} `) runtimeInterface := &testRuntimeInterface{ diff --git a/semantics/tests/parser/valid/parse_structure.fpl b/semantics/tests/parser/valid/parse_structure.fpl index 05d305e575..178c13d54d 100644 --- a/semantics/tests/parser/valid/parse_structure.fpl +++ b/semantics/tests/parser/valid/parse_structure.fpl @@ -1,5 +1,5 @@ struct Test { - pub(set) var foo: Int + access(all) var foo: Int init(foo: Int) { self.foo = foo diff --git a/tools/analysis/analysis_test.go b/tools/analysis/analysis_test.go index e7cb708823..e7f1121ef9 100644 --- a/tools/analysis/analysis_test.go +++ b/tools/analysis/analysis_test.go @@ -42,7 +42,7 @@ func TestNeedSyntaxAndImport(t *testing.T) { const txCode = ` import 0x1 - pub let y = "test" as! String + access(all) let y = "test" as! String ` contractAddress := common.MustBytesToAddress([]byte{0x1}) @@ -51,7 +51,7 @@ func TestNeedSyntaxAndImport(t *testing.T) { Name: "ContractA", } const contractCode = ` - pub contract ContractA { + access(all) contract ContractA { init() { let y = true as! Bool } @@ -152,15 +152,15 @@ func TestNeedSyntaxAndImport(t *testing.T) { { location: contractLocation, Range: ast.Range{ - StartPos: ast.Position{Offset: 61, Line: 4, Column: 15}, - EndPos: ast.Position{Offset: 73, Line: 4, Column: 27}, + StartPos: ast.Position{Offset: 69, Line: 4, Column: 15}, + EndPos: ast.Position{Offset: 81, Line: 4, Column: 27}, }, }, { location: txLocation, Range: ast.Range{ - StartPos: ast.Position{Offset: 31, Line: 4, Column: 15}, - EndPos: ast.Position{Offset: 47, Line: 4, Column: 31}, + StartPos: ast.Position{Offset: 39, Line: 4, Column: 23}, + EndPos: ast.Position{Offset: 55, Line: 4, Column: 39}, }, }, }, @@ -178,7 +178,7 @@ func TestParseError(t *testing.T) { Name: "ContractA", } const contractCode = ` - pub contract ContractA { + access(all) contract ContractA { init() { ??? } @@ -224,7 +224,7 @@ func TestCheckError(t *testing.T) { Name: "ContractA", } const contractCode = ` - pub contract ContractA { + access(all) contract ContractA { init() { X } @@ -267,7 +267,7 @@ func TestStdlib(t *testing.T) { scriptLocation := common.ScriptLocation{} const code = ` - pub fun main() { + access(all) fun main() { panic("test") } ` @@ -309,7 +309,7 @@ func TestCyclicImports(t *testing.T) { } const fooContractCode = ` import 0x2 - pub contract Foo {} + access(all) contract Foo {} ` barContractAddress := common.MustBytesToAddress([]byte{0x2}) @@ -319,7 +319,7 @@ func TestCyclicImports(t *testing.T) { } const barContractCode = ` import 0x1 - pub contract Bar {} + access(all) contract Bar {} ` config := &analysis.Config{ diff --git a/tools/batch-script/address_provider.go b/tools/batch-script/address_provider.go index be7b0ac72f..2573b2d44d 100644 --- a/tools/batch-script/address_provider.go +++ b/tools/batch-script/address_provider.go @@ -46,7 +46,7 @@ type AddressProvider struct { const endOfAccountsError = "get storage used failed" const accountStorageUsageScript = ` -pub fun main(address: Address): UInt64 { +access(all) fun main(address: Address): UInt64 { return getAccount(address).storageUsed } ` diff --git a/tools/batch-script/get_contracts.cdc b/tools/batch-script/get_contracts.cdc index 6a523a211e..2d1cfef5e0 100644 --- a/tools/batch-script/get_contracts.cdc +++ b/tools/batch-script/get_contracts.cdc @@ -1,4 +1,4 @@ -pub fun main(addresses: [Address]): {Address: {String: String}} { +access(self) fun main(addresses: [Address]): {Address: {String: String}} { let accountContracts: {Address: {String: String}} = {} for address in addresses { diff --git a/tools/compatibility-check/contracts_checker_test.go b/tools/compatibility-check/contracts_checker_test.go index 95b52012e6..150f045251 100644 --- a/tools/compatibility-check/contracts_checker_test.go +++ b/tools/compatibility-check/contracts_checker_test.go @@ -34,11 +34,11 @@ func TestCyclicImport(t *testing.T) { input.Write([]byte(`location,code A.0000000000000001.Foo,"import Bar from 0x0000000000000001 -pub contract Foo {}" +access(all) contract Foo {}" A.0000000000000001.Bar,"import Baz from 0x0000000000000001 -pub contract Foo {}" +access(all) contract Foo {}" A.0000000000000001.Baz,"import Foo from 0x0000000000000001 -pub contract Foo {}" +access(all) contract Foo {}" `)) checker.CheckCSV(&input)