From dda2353ed52ac6bb25ccb1458761ae9e0ccd8a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 22 Jun 2023 09:57:33 -0700 Subject: [PATCH] adjust tests --- encoding/ccf/ccf_test.go | 17 +-- runtime/coverage_test.go | 14 +-- .../imported_values_memory_metering_test.go | 2 +- runtime/resource_duplicate_test.go | 48 ++++----- runtime/runtime_test.go | 102 +++++++++--------- runtime/stdlib/test_test.go | 48 ++++----- runtime/tests/checker/entrypoint_test.go | 6 +- runtime/tests/checker/reference_test.go | 6 +- runtime/tests/interpreter/reference_test.go | 6 +- runtime/tests/interpreter/resources_test.go | 62 ++++++----- 10 files changed, 158 insertions(+), 153 deletions(-) diff --git a/encoding/ccf/ccf_test.go b/encoding/ccf/ccf_test.go index 934ed4de66..a3b4b3cbf6 100644 --- a/encoding/ccf/ccf_test.go +++ b/encoding/ccf/ccf_test.go @@ -9237,7 +9237,6 @@ func TestEncodeType(t *testing.T) { 0xd8, ccf.CBORTagReferenceTypeValue, // array, 2 elements follow 0x82, - // authorized // nil 0xf6, // tag @@ -14646,7 +14645,7 @@ func TestCyclicReferenceValue(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 @@ -14660,12 +14659,14 @@ func TestCyclicReferenceValue(t *testing.T) { nil, }).WithType(&cadence.VariableSizedArrayType{ ElementType: &cadence.ReferenceType{ - Type: cadence.AnyStructType{}, + Authorization: cadence.Unauthorized{}, + Type: cadence.AnyStructType{}, }, }), }).WithType(&cadence.VariableSizedArrayType{ ElementType: &cadence.ReferenceType{ - Type: cadence.AnyStructType{}, + Authorization: cadence.Unauthorized{}, + Type: cadence.AnyStructType{}, }, }) @@ -14693,8 +14694,8 @@ func TestCyclicReferenceValue(t *testing.T) { 0xd8, ccf.CBORTagReferenceType, // array, 2 items follow 0x82, - // false - 0xf4, + // nil + 0xf6, // tag 0xd8, ccf.CBORTagSimpleType, // AnyStruct type ID (39) @@ -14713,8 +14714,8 @@ func TestCyclicReferenceValue(t *testing.T) { 0xd8, ccf.CBORTagReferenceType, // array, 2 items follow 0x82, - // false - 0xf4, + // nil + 0xf6, // tag 0xd8, ccf.CBORTagSimpleType, // AnyStruct type ID (39) diff --git a/runtime/coverage_test.go b/runtime/coverage_test.go index e46cba7c6e..c28c55574d 100644 --- a/runtime/coverage_test.go +++ b/runtime/coverage_test.go @@ -1654,15 +1654,15 @@ func TestRuntimeCoverageWithNoStatements(t *testing.T) { t.Parallel() importedScript := []byte(` - pub contract FooContract { - pub resource interface Receiver { + access(all) contract FooContract { + access(all) resource interface Receiver { } } `) script := []byte(` import "FooContract" - pub fun main(): Int { + access(all) fun main(): Int { Type<@{FooContract.Receiver}>().identifier return 42 } @@ -1731,17 +1731,17 @@ func TestCoverageReportLCOVFormat(t *testing.T) { t.Parallel() integerTraits := []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 { @@ -1765,7 +1765,7 @@ func TestCoverageReportLCOVFormat(t *testing.T) { script := []byte(` import "IntegerTraits" - pub fun main(): Int { + access(all) fun main(): Int { let testInputs: {Int: String} = { -1: "Negative", 0: "Zero", diff --git a/runtime/imported_values_memory_metering_test.go b/runtime/imported_values_memory_metering_test.go index 763b8e9670..998179b922 100644 --- a/runtime/imported_values_memory_metering_test.go +++ b/runtime/imported_values_memory_metering_test.go @@ -338,7 +338,7 @@ func TestImportedValueMemoryMetering(t *testing.T) { t.Parallel() script := []byte(` - pub fun main(x: Word256) {} + access(all) fun main(x: Word256) {} `) meter := make(map[common.MemoryKind]uint64) diff --git a/runtime/resource_duplicate_test.go b/runtime/resource_duplicate_test.go index 2c43aec4b4..743cf198bf 100644 --- a/runtime/resource_duplicate_test.go +++ b/runtime/resource_duplicate_test.go @@ -44,32 +44,32 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) { script := ` // This Vault class is from Flow docs, used as our "victim" in this example - pub resource Vault { + access(all) resource Vault { // Balance of a user's Vault // we use unsigned fixed point numbers for balances // because they can represent decimals and do not allow negative values - pub var balance: UFix64 + access(all) var balance: UFix64 init(balance: UFix64) { self.balance = balance } - pub fun withdraw(amount: UFix64): @Vault { + access(all) fun withdraw(amount: UFix64): @Vault { self.balance = self.balance - amount return <-create Vault(balance: amount) } - pub fun deposit(from: @Vault) { + access(all) fun deposit(from: @Vault) { self.balance = self.balance + from.balance destroy from } } // --- this code actually makes use of the vuln --- - pub resource DummyResource { - pub var dictRef: &{Bool: AnyResource}; - pub var arrRef: &[Vault]; - pub var victim: @Vault; + access(all) resource DummyResource { + access(all) var dictRef: &{Bool: AnyResource}; + access(all) var arrRef: &[Vault]; + access(all) var victim: @Vault; init(dictRef: &{Bool: AnyResource}, arrRef: &[Vault], victim: @Vault) { self.dictRef = dictRef; self.arrRef = arrRef; @@ -82,7 +82,7 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) { } } - pub fun duplicateResource(victim1: @Vault, victim2: @Vault): @[Vault]{ + access(all) fun duplicateResource(victim1: @Vault, victim2: @Vault): @[Vault]{ let arr : @[Vault] <- []; let dict: @{Bool: DummyResource} <- { } let ref = &dict as &{Bool: AnyResource}; @@ -102,7 +102,7 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) { // --- end of vuln code --- - pub fun main() { + access(all) fun main() { var v1 <- create Vault(balance: 1000.0); // This will be duplicated var v2 <- create Vault(balance: 1.0); // This will be lost @@ -176,21 +176,21 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) { t.Parallel() script := ` - pub resource Vault { - pub var balance: UFix64 - pub var dictRef: &{Bool: Vault}; + access(all) resource Vault { + access(all) var balance: UFix64 + access(all) var dictRef: &{Bool: Vault}; init(balance: UFix64, _ dictRef: &{Bool: Vault}) { self.balance = balance self.dictRef = dictRef; } - pub fun withdraw(amount: UFix64): @Vault { + access(all) fun withdraw(amount: UFix64): @Vault { self.balance = self.balance - amount return <-create Vault(balance: amount, self.dictRef) } - pub fun deposit(from: @Vault) { + access(all) fun deposit(from: @Vault) { self.balance = self.balance + from.balance destroy from } @@ -200,7 +200,7 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) { } } - pub fun main(): UFix64 { + access(all) fun main(): UFix64 { let dict: @{Bool: Vault} <- { } let dictRef = &dict as &{Bool: Vault}; @@ -279,9 +279,9 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) { t.Parallel() script := ` - pub resource R{} + access(all) resource R{} - pub fun main() { + access(all) fun main() { var dict: @{Int: R} <- {} var r1: @R? <- create R() @@ -363,21 +363,21 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) { t.Parallel() script := ` - pub resource Vault { - pub var balance: UFix64 - pub var arrRef: &[Vault] + access(all) resource Vault { + access(all) var balance: UFix64 + access(all) var arrRef: &[Vault] init(balance: UFix64, _ arrRef: &[Vault]) { self.balance = balance self.arrRef = arrRef; } - pub fun withdraw(amount: UFix64): @Vault { + access(all) fun withdraw(amount: UFix64): @Vault { self.balance = self.balance - amount return <-create Vault(balance: amount, self.arrRef) } - pub fun deposit(from: @Vault) { + access(all) fun deposit(from: @Vault) { self.balance = self.balance + from.balance destroy from } @@ -387,7 +387,7 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) { } } - pub fun main(): UFix64 { + access(all) fun main(): UFix64 { let arr: @[Vault] <- [] let arrRef = &arr as &[Vault]; diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index b4a40ad00d..9176ab2fcf 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -8118,32 +8118,32 @@ func TestRuntimeDestructorReentrancyPrevention(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub resource Vault { + access(all) resource Vault { // Balance of a user's Vault // we use unsigned fixed point numbers for balances // because they can represent decimals and do not allow negative values - pub var balance: UFix64 + access(all) var balance: UFix64 init(balance: UFix64) { self.balance = balance } - pub fun withdraw(amount: UFix64): @Vault { + access(all) fun withdraw(amount: UFix64): @Vault { self.balance = self.balance - amount return <-create Vault(balance: amount) } - pub fun deposit(from: @Vault) { + access(all) fun deposit(from: @Vault) { self.balance = self.balance + from.balance destroy from } } // --- this code actually makes use of the vuln --- - pub resource InnerResource { - pub var victim: @Vault; - pub var here: Bool; - pub var parent: &OuterResource; + access(all) resource InnerResource { + access(all) var victim: @Vault; + access(all) var here: Bool; + access(all) var parent: &OuterResource; init(victim: @Vault, parent: &OuterResource) { self.victim <- victim; self.here = false; @@ -8159,18 +8159,18 @@ func TestRuntimeDestructorReentrancyPrevention(t *testing.T) { } } - pub resource OuterResource { - pub var inner: @InnerResource?; - pub var collector: &Vault; + access(all) resource OuterResource { + access(all) var inner: @InnerResource?; + access(all) var collector: &Vault; init(victim: @Vault, collector: &Vault) { self.collector = collector; self.inner <- create InnerResource(victim: <- victim, parent: &self as &OuterResource); } - pub fun reenter() { + access(all) fun reenter() { let inner <- self.inner <- nil; destroy inner; } - pub fun collect(from: @Vault) { + access(all) fun collect(from: @Vault) { self.collector.deposit(from: <- from); } @@ -8179,7 +8179,7 @@ func TestRuntimeDestructorReentrancyPrevention(t *testing.T) { } } - pub fun doubleBalanceOfVault(vault: @Vault): @Vault { + access(all) fun doubleBalanceOfVault(vault: @Vault): @Vault { var collector <- vault.withdraw(amount: 0.0); var r <- create OuterResource(victim: <- vault, collector: &collector as &Vault); destroy r; @@ -8188,7 +8188,7 @@ func TestRuntimeDestructorReentrancyPrevention(t *testing.T) { // --- end of vuln code --- - pub fun main(): UFix64 { + access(all) fun main(): UFix64 { var v1 <- create Vault(balance: 1000.0); var v2 <- doubleBalanceOfVault(vault: <- v1); var v3 <- doubleBalanceOfVault(vault: <- v2); @@ -8223,7 +8223,7 @@ func TestRuntimeFlowEventTypes(t *testing.T) { rt := newTestInterpreterRuntime() script := []byte(` - pub fun main(): Type? { + access(all) fun main(): Type? { return CompositeType("flow.AccountContractAdded") } `) @@ -8298,18 +8298,18 @@ func TestInvalidatedResourceUse(t *testing.T) { attacker := []byte(fmt.Sprintf(` import VictimContract from %s - pub contract AttackerContract { + access(all) contract AttackerContract { - pub resource AttackerResource { - pub var vault: @VictimContract.Vault - pub var firstCopy: @VictimContract.Vault + access(all) resource AttackerResource { + access(all) var vault: @VictimContract.Vault + access(all) var firstCopy: @VictimContract.Vault init(vault: @VictimContract.Vault) { self.vault <- vault self.firstCopy <- self.vault.withdraw(amount: 0.0) } - pub fun shenanigans(): UFix64{ + access(all) fun shenanigans(): UFix64{ let fullBalance = self.vault.balance var withdrawn <- self.vault.withdraw(amount: 0.0) @@ -8323,7 +8323,7 @@ func TestInvalidatedResourceUse(t *testing.T) { return fullBalance } - pub fun fetchfirstCopy(): @VictimContract.Vault { + access(all) fun fetchfirstCopy(): @VictimContract.Vault { var withdrawn <- self.firstCopy.withdraw(amount: 0.0) self.firstCopy <-> withdrawn return <- withdrawn @@ -8335,7 +8335,7 @@ func TestInvalidatedResourceUse(t *testing.T) { } } - pub fun doubleBalanceOfVault(_ victim: @VictimContract.Vault): @VictimContract.Vault { + access(all) fun doubleBalanceOfVault(_ victim: @VictimContract.Vault): @VictimContract.Vault { var r <- create AttackerResource(vault: <- victim) // The magic happens during the execution of the following line of code @@ -8349,7 +8349,7 @@ func TestInvalidatedResourceUse(t *testing.T) { return <- secondCopy } - pub fun attack() { + access(all) fun attack() { var v1 <- VictimContract.faucet() var v2<- AttackerContract.doubleBalanceOfVault(<- v1) destroy v2 @@ -8359,30 +8359,30 @@ func TestInvalidatedResourceUse(t *testing.T) { )) victim := []byte(` - pub contract VictimContract { - pub resource Vault { + access(all) contract VictimContract { + access(all) resource Vault { // Balance of a user's Vault // we use unsigned fixed point numbers for balances // because they can represent decimals and do not allow negative values - pub var balance: UFix64 + access(all) var balance: UFix64 init(balance: UFix64) { self.balance = balance } - pub fun withdraw(amount: UFix64): @Vault { + access(all) fun withdraw(amount: UFix64): @Vault { self.balance = self.balance - amount return <-create Vault(balance: amount) } - pub fun deposit(from: @Vault) { + access(all) fun deposit(from: @Vault) { self.balance = self.balance + from.balance destroy from } } - pub fun faucet(): @VictimContract.Vault { + access(all) fun faucet(): @VictimContract.Vault { return <- create VictimContract.Vault(balance: 5.0) } } @@ -8490,12 +8490,12 @@ func TestInvalidatedResourceUse2(t *testing.T) { attacker := []byte(fmt.Sprintf(` import VictimContract from %s - pub contract AttackerContract { + access(all) contract AttackerContract { - pub resource InnerResource { - pub var name: String - pub var parent: &OuterResource? - pub var vault: @VictimContract.Vault? + access(all) resource InnerResource { + access(all) var name: String + access(all) var parent: &OuterResource? + access(all) var vault: @VictimContract.Vault? init(_ name: String) { self.name = name @@ -8503,11 +8503,11 @@ func TestInvalidatedResourceUse2(t *testing.T) { self.vault <- nil } - pub fun setParent(_ parent: &OuterResource) { + access(all) fun setParent(_ parent: &OuterResource) { self.parent = parent } - pub fun setVault(_ vault: @VictimContract.Vault) { + access(all) fun setVault(_ vault: @VictimContract.Vault) { self.vault <-! vault } @@ -8518,10 +8518,10 @@ func TestInvalidatedResourceUse2(t *testing.T) { } } - pub resource OuterResource { - pub var inner1: @InnerResource - pub var inner2: @InnerResource - pub var collector: &VictimContract.Vault + access(all) resource OuterResource { + access(all) var inner1: @InnerResource + access(all) var inner2: @InnerResource + access(all) var collector: &VictimContract.Vault init(_ victim: @VictimContract.Vault, _ collector: &VictimContract.Vault) { self.collector = collector @@ -8534,11 +8534,11 @@ func TestInvalidatedResourceUse2(t *testing.T) { self.inner2.setParent(&self as &OuterResource) } - pub fun shenanigans() { + access(all) fun shenanigans() { self.inner1 <-> self.inner2 } - pub fun collect(_ from: @VictimContract.Vault) { + access(all) fun collect(_ from: @VictimContract.Vault) { self.collector.deposit(from: <- from) } @@ -8549,14 +8549,14 @@ func TestInvalidatedResourceUse2(t *testing.T) { } } - pub fun doubleBalanceOfVault(_ vault: @VictimContract.Vault): @VictimContract.Vault { + access(all) fun doubleBalanceOfVault(_ vault: @VictimContract.Vault): @VictimContract.Vault { var collector <- vault.withdraw(amount: 0.0) var outer <- create OuterResource(<- vault, &collector as &VictimContract.Vault) destroy outer return <- collector } - pub fun attack() { + access(all) fun attack() { var v1 <- VictimContract.faucet() var v2 <- AttackerContract.doubleBalanceOfVault(<- v1) destroy v2 @@ -8566,30 +8566,30 @@ func TestInvalidatedResourceUse2(t *testing.T) { )) victim := []byte(` - pub contract VictimContract { - pub resource Vault { + access(all) contract VictimContract { + access(all) resource Vault { // Balance of a user's Vault // we use unsigned fixed point numbers for balances // because they can represent decimals and do not allow negative values - pub var balance: UFix64 + access(all) var balance: UFix64 init(balance: UFix64) { self.balance = balance } - pub fun withdraw(amount: UFix64): @Vault { + access(all) fun withdraw(amount: UFix64): @Vault { self.balance = self.balance - amount return <-create Vault(balance: amount) } - pub fun deposit(from: @Vault) { + access(all) fun deposit(from: @Vault) { self.balance = self.balance + from.balance destroy from } } - pub fun faucet(): @VictimContract.Vault { + access(all) fun faucet(): @VictimContract.Vault { return <- create VictimContract.Vault(balance: 5.0) } } diff --git a/runtime/stdlib/test_test.go b/runtime/stdlib/test_test.go index 69541e05f9..730cb9a117 100644 --- a/runtime/stdlib/test_test.go +++ b/runtime/stdlib/test_test.go @@ -679,7 +679,7 @@ func TestAssertEqual(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { Test.assertEqual("this string", "this string") } ` @@ -697,7 +697,7 @@ func TestAssertEqual(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { Test.assertEqual(15, 21) } ` @@ -721,7 +721,7 @@ func TestAssertEqual(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { Test.assertEqual(true, 1) } ` @@ -745,13 +745,13 @@ func TestAssertEqual(t *testing.T) { script := ` import Test - pub fun testEqual() { + access(all) fun testEqual() { let expected = Address(0xf8d6e0586b0a20c7) let actual = Address(0xf8d6e0586b0a20c7) Test.assertEqual(expected, actual) } - pub fun testNotEqual() { + access(all) fun testNotEqual() { let expected = Address(0xf8d6e0586b0a20c7) let actual = Address(0xee82856bf20e2aa6) Test.assertEqual(expected, actual) @@ -780,21 +780,21 @@ func TestAssertEqual(t *testing.T) { script := ` import Test - pub struct Foo { - pub let answer: Int + access(all) struct Foo { + access(all) let answer: Int init(answer: Int) { self.answer = answer } } - pub fun testEqual() { + access(all) fun testEqual() { let expected = Foo(answer: 42) let actual = Foo(answer: 42) Test.assertEqual(expected, actual) } - pub fun testNotEqual() { + access(all) fun testNotEqual() { let expected = Foo(answer: 42) let actual = Foo(answer: 420) Test.assertEqual(expected, actual) @@ -823,13 +823,13 @@ func TestAssertEqual(t *testing.T) { script := ` import Test - pub fun testEqual() { + access(all) fun testEqual() { let expected = [1, 2, 3] let actual = [1, 2, 3] Test.assertEqual(expected, actual) } - pub fun testNotEqual() { + access(all) fun testNotEqual() { let expected = [1, 2, 3] let actual = [1, 2] Test.assertEqual(expected, actual) @@ -858,13 +858,13 @@ func TestAssertEqual(t *testing.T) { script := ` import Test - pub fun testEqual() { + access(all) fun testEqual() { let expected = {1: true, 2: false, 3: true} let actual = {1: true, 2: false, 3: true} Test.assertEqual(expected, actual) } - pub fun testNotEqual() { + access(all) fun testNotEqual() { let expected = {1: true, 2: false} let actual = {1: true, 2: true} Test.assertEqual(expected, actual) @@ -893,13 +893,13 @@ func TestAssertEqual(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let f1 <- create Foo() let f2 <- create Foo() Test.assertEqual(<-f1, <-f2) } - pub resource Foo {} + access(all) resource Foo {} ` _, err := newTestContractInterpreter(t, script) @@ -915,14 +915,14 @@ func TestAssertEqual(t *testing.T) { script := ` import Test - pub fun test() { + access(all) fun test() { let foo <- create Foo() let bar = Bar() Test.assertEqual(<-foo, bar) } - pub resource Foo {} - pub struct Bar {} + access(all) resource Foo {} + access(all) struct Bar {} ` _, err := newTestContractInterpreter(t, script) @@ -937,14 +937,14 @@ func TestAssertEqual(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) @@ -1958,7 +1958,7 @@ func TestBlockchain(t *testing.T) { script := ` import Test - pub fun test(): [AnyStruct] { + access(all) fun test(): [AnyStruct] { var blockchain = Test.newEmulatorBlockchain() return blockchain.events() } @@ -1994,7 +1994,7 @@ func TestBlockchain(t *testing.T) { script := ` import Test - pub fun test(): [AnyStruct] { + access(all) fun test(): [AnyStruct] { var blockchain = Test.newEmulatorBlockchain() // 'Foo' is not an event-type. @@ -2004,7 +2004,7 @@ func TestBlockchain(t *testing.T) { return blockchain.eventsOfType(typ) } - pub struct Foo {} + access(all) struct Foo {} ` eventsInvoked := false diff --git a/runtime/tests/checker/entrypoint_test.go b/runtime/tests/checker/entrypoint_test.go index fd3193ef4a..4bea123456 100644 --- a/runtime/tests/checker/entrypoint_test.go +++ b/runtime/tests/checker/entrypoint_test.go @@ -199,8 +199,8 @@ func TestEntryPointParameters(t *testing.T) { t.Parallel() checker, err := ParseAndCheck(t, ` - pub contract SimpleContract { - pub let v: Int + access(all) contract SimpleContract { + access(all) let v: Int init(a: Int) { self.v = a } @@ -228,7 +228,7 @@ func TestEntryPointParameters(t *testing.T) { t.Parallel() checker, err := ParseAndCheck(t, ` - pub contract SimpleContract { + access(all) contract SimpleContract { init() {} } `) diff --git a/runtime/tests/checker/reference_test.go b/runtime/tests/checker/reference_test.go index 36ac72c5d1..4cb952c402 100644 --- a/runtime/tests/checker/reference_test.go +++ b/runtime/tests/checker/reference_test.go @@ -2775,15 +2775,15 @@ func TestCheckResourceReferenceMethodInvocationAfterMove(t *testing.T) { t.Parallel() _, err := ParseAndCheck(t, ` - pub resource Foo { + resource Foo { - pub let id: UInt8 + let id: UInt8 init() { self.id = 12 } - pub fun something() {} + access(all) fun something() {} } fun main() { diff --git a/runtime/tests/interpreter/reference_test.go b/runtime/tests/interpreter/reference_test.go index 65da727818..cad8d1892e 100644 --- a/runtime/tests/interpreter/reference_test.go +++ b/runtime/tests/interpreter/reference_test.go @@ -1290,15 +1290,15 @@ func TestInterpretReferenceTrackingOnInvocation(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - pub resource Foo { + access(all) resource Foo { - pub let id: UInt8 + access(all) let id: UInt8 init() { self.id = 12 } - pub fun something() {} + access(all) fun something() {} } fun returnSameRef(_ ref: &Foo): &Foo { diff --git a/runtime/tests/interpreter/resources_test.go b/runtime/tests/interpreter/resources_test.go index ce2b648515..a74b00b14b 100644 --- a/runtime/tests/interpreter/resources_test.go +++ b/runtime/tests/interpreter/resources_test.go @@ -2601,18 +2601,18 @@ func TestInterpretResourceFunctionInvocationAfterDestruction(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - pub resource Vault { - pub fun foo(_ ignored: Bool) {} + access(all) resource Vault { + access(all) fun foo(_ ignored: Bool) {} } - pub resource Attacker { - pub var vault: @Vault + access(all) resource Attacker { + access(all) var vault: @Vault init() { self.vault <- create Vault() } - pub fun shenanigans(): Bool { + access(all) fun shenanigans(): Bool { var temp <- create Vault() self.vault <-> temp destroy temp @@ -2624,7 +2624,7 @@ func TestInterpretResourceFunctionInvocationAfterDestruction(t *testing.T) { } } - pub fun main() { + access(all) fun main() { let a <- create Attacker() a.vault.foo(a.shenanigans()) destroy a @@ -2642,25 +2642,25 @@ func TestInterpretResourceFunctionReferenceValidity(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - pub resource Vault { - pub fun foo(_ ref: &Vault): &Vault { + access(all) resource Vault { + access(all) fun foo(_ ref: &Vault): &Vault { return ref } } - pub resource Attacker { - pub var vault: @Vault + access(all) resource Attacker { + access(all) var vault: @Vault init() { self.vault <- create Vault() } - pub fun shenanigans1(): &Vault { + access(all) fun shenanigans1(): &Vault { // Create a reference in a nested call return &self.vault as &Vault } - pub fun shenanigans2(_ ref: &Vault): &Vault { + access(all) fun shenanigans2(_ ref: &Vault): &Vault { return ref } @@ -2669,7 +2669,7 @@ func TestInterpretResourceFunctionReferenceValidity(t *testing.T) { } } - pub fun main() { + access(all) fun main() { let a <- create Attacker() // A reference to receiver get created inside the nested call 'shenanigans1()'. @@ -2697,20 +2697,20 @@ func TestInterpretResourceFunctionResourceFunctionValidity(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - pub resource Vault { - pub fun foo(_ dummy: Bool): Bool { + access(all) resource Vault { + access(all) fun foo(_ dummy: Bool): Bool { return dummy } } - pub resource Attacker { - pub var vault: @Vault + access(all) resource Attacker { + access(all) var vault: @Vault init() { self.vault <- create Vault() } - pub fun shenanigans(_ n: Int): Bool { + access(all) fun shenanigans(_ n: Int): Bool { if n > 0 { return self.vault.foo(self.shenanigans(n - 1)) } @@ -2722,7 +2722,7 @@ func TestInterpretResourceFunctionResourceFunctionValidity(t *testing.T) { } } - pub fun main() { + access(all) fun main() { let a <- create Attacker() a.vault.foo(a.shenanigans(10)) @@ -2740,33 +2740,37 @@ func TestInterpretInnerResourceDestruction(t *testing.T) { t.Parallel() inter := parseCheckAndInterpret(t, ` - pub resource InnerResource { - pub var name: String - pub(set) var parent: &OuterResource? + access(all) resource InnerResource { + access(all) var name: String + access(all) var parent: &OuterResource? init(_ name: String) { self.name = name self.parent = nil } + access(all) fun setParent(_ parent: &OuterResource) { + self.parent = parent + } + destroy() { self.parent!.shenanigans() } } - pub resource OuterResource { - pub var inner1: @InnerResource - pub var inner2: @InnerResource + access(all) resource OuterResource { + access(all) var inner1: @InnerResource + access(all) var inner2: @InnerResource init() { self.inner1 <- create InnerResource("inner1") self.inner2 <- create InnerResource("inner2") - self.inner1.parent = &self as &OuterResource - self.inner2.parent = &self as &OuterResource + self.inner1.setParent(&self as &OuterResource) + self.inner2.setParent(&self as &OuterResource) } - pub fun shenanigans() { + access(all) fun shenanigans() { self.inner1 <-> self.inner2 } @@ -2776,7 +2780,7 @@ func TestInterpretInnerResourceDestruction(t *testing.T) { } } - pub fun main() { + access(all) fun main() { let a <- create OuterResource() destroy a }`,