Skip to content

Commit

Permalink
Rename mutability entitlements
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Aug 2, 2023
1 parent 5b47d1a commit 5d40cd1
Show file tree
Hide file tree
Showing 21 changed files with 163 additions and 163 deletions.
4 changes: 2 additions & 2 deletions runtime/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@ func TestRuntimePublicKey(t *testing.T) {
signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
)
var publickeyRef = &publicKey.publicKey as auth(Mutable) &[UInt8]
var publickeyRef = &publicKey.publicKey as auth(Mutate) &[UInt8]
publickeyRef[0] = 3
return publicKey
Expand Down Expand Up @@ -1909,7 +1909,7 @@ func TestAuthAccountContracts(t *testing.T) {
script := []byte(`
transaction {
prepare(signer: AuthAccount) {
var namesRef = &signer.contracts.names as auth(Mutable) &[String]
var namesRef = &signer.contracts.names as auth(Mutate) &[String]
namesRef[0] = "baz"
assert(signer.contracts.names[0] == "foo")
Expand Down
18 changes: 9 additions & 9 deletions runtime/capabilitycontrollers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
access(all) fun quickSort(_ items: auth(Mutable) &[AnyStruct], isLess: fun(Int, Int): Bool) {
access(all) fun quickSort(_ items: auth(Mutate) &[AnyStruct], isLess: fun(Int, Int): Bool) {
fun quickSortPart(leftIndex: Int, rightIndex: Int) {
Expand Down Expand Up @@ -1803,7 +1803,7 @@ func TestRuntimeCapabilityControllers(t *testing.T) {
assert(controllers1.length == 3)
Test.quickSort(
&controllers1 as auth(Mutable) &[AnyStruct],
&controllers1 as auth(Mutate) &[AnyStruct],
isLess: fun(i: Int, j: Int): Bool {
let a = controllers1[i]
let b = controllers1[j]
Expand Down Expand Up @@ -1901,7 +1901,7 @@ func TestRuntimeCapabilityControllers(t *testing.T) {
assert(controllers1.length == 3)
Test.quickSort(
&controllers1 as auth(Mutable) &[AnyStruct],
&controllers1 as auth(Mutate) &[AnyStruct],
isLess: fun(i: Int, j: Int): Bool {
let a = controllers1[i]
let b = controllers1[j]
Expand Down Expand Up @@ -2252,7 +2252,7 @@ func TestRuntimeCapabilityControllers(t *testing.T) {
assert(controllers.length == 3)
Test.quickSort(
&controllers as auth(Mutable) &[AnyStruct],
&controllers as auth(Mutate) &[AnyStruct],
isLess: fun(i: Int, j: Int): Bool {
let a = controllers[i]
let b = controllers[j]
Expand Down Expand Up @@ -2330,7 +2330,7 @@ func TestRuntimeCapabilityControllers(t *testing.T) {
assert(controllers.length == 3)
Test.quickSort(
&controllers as auth(Mutable) &[AnyStruct],
&controllers as auth(Mutate) &[AnyStruct],
isLess: fun(i: Int, j: Int): Bool {
let a = controllers[i]
let b = controllers[j]
Expand Down Expand Up @@ -2585,7 +2585,7 @@ func TestRuntimeCapabilityControllers(t *testing.T) {
let controllers1Before = signer.capabilities.storage.getControllers(forPath: storagePath1)
Test.quickSort(
&controllers1Before as auth(Mutable) &[AnyStruct],
&controllers1Before as auth(Mutate) &[AnyStruct],
isLess: fun(i: Int, j: Int): Bool {
let a = controllers1Before[i]
let b = controllers1Before[j]
Expand All @@ -2599,7 +2599,7 @@ func TestRuntimeCapabilityControllers(t *testing.T) {
let controllers2Before = signer.capabilities.storage.getControllers(forPath: storagePath2)
Test.quickSort(
&controllers2Before as auth(Mutable) &[AnyStruct],
&controllers2Before as auth(Mutate) &[AnyStruct],
isLess: fun(i: Int, j: Int): Bool {
let a = controllers2Before[i]
let b = controllers2Before[j]
Expand All @@ -2623,7 +2623,7 @@ func TestRuntimeCapabilityControllers(t *testing.T) {
let controllers1After = signer.capabilities.storage.getControllers(forPath: storagePath1)
Test.quickSort(
&controllers1After as auth(Mutable) &[AnyStruct],
&controllers1After as auth(Mutate) &[AnyStruct],
isLess: fun(i: Int, j: Int): Bool {
let a = controllers1After[i]
let b = controllers1After[j]
Expand All @@ -2636,7 +2636,7 @@ func TestRuntimeCapabilityControllers(t *testing.T) {
let controllers2After = signer.capabilities.storage.getControllers(forPath: storagePath2)
Test.quickSort(
&controllers2After as auth(Mutable) &[AnyStruct],
&controllers2After as auth(Mutate) &[AnyStruct],
isLess: fun(i: Int, j: Int): Bool {
let a = controllers2After[i]
let b = controllers2After[j]
Expand Down
4 changes: 2 additions & 2 deletions runtime/convertValues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ func TestExportReferenceValue(t *testing.T) {
var v:[AnyStruct] = []
acct.save(v, to: /storage/x)
var ref = acct.borrow<auth(Insertable) &[AnyStruct]>(from: /storage/x)!
var ref = acct.borrow<auth(Insert) &[AnyStruct]>(from: /storage/x)!
ref.append(ref)
return ref
}
Expand Down Expand Up @@ -1984,7 +1984,7 @@ func TestExportReferenceValue(t *testing.T) {
var v:[AnyStruct] = []
acct.save(v, to: /storage/x)
var ref1 = acct.borrow<auth(Insertable) &[AnyStruct]>(from: /storage/x)!
var ref1 = acct.borrow<auth(Insert) &[AnyStruct]>(from: /storage/x)!
var ref2 = acct.borrow<&[AnyStruct]>(from: /storage/x)!
ref1.append(ref2)
Expand Down
24 changes: 12 additions & 12 deletions runtime/resource_duplicate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) {
// --- this code actually makes use of the vuln ---
access(all) resource DummyResource {
access(all) var dictRef: auth(Mutable) &{Bool: AnyResource};
access(all) var arrRef: auth(Mutable) &[Vault];
access(all) var dictRef: auth(Mutate) &{Bool: AnyResource};
access(all) var arrRef: auth(Mutate) &[Vault];
access(all) var victim: @Vault;
init(dictRef: auth(Mutable) &{Bool: AnyResource}, arrRef: auth(Mutable) &[Vault], victim: @Vault) {
init(dictRef: auth(Mutate) &{Bool: AnyResource}, arrRef: auth(Mutate) &[Vault], victim: @Vault) {
self.dictRef = dictRef;
self.arrRef = arrRef;
self.victim <- victim;
Expand All @@ -85,8 +85,8 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) {
access(all) fun duplicateResource(victim1: @Vault, victim2: @Vault): @[Vault]{
let arr : @[Vault] <- [];
let dict: @{Bool: DummyResource} <- { }
let ref = &dict as auth(Mutable) &{Bool: AnyResource};
let arrRef = &arr as auth(Mutable) &[Vault];
let ref = &dict as auth(Mutate) &{Bool: AnyResource};
let arrRef = &arr as auth(Mutate) &[Vault];
var v1: @DummyResource? <- create DummyResource(dictRef: ref, arrRef: arrRef, victim: <- victim1);
dict[false] <-> v1;
Expand Down Expand Up @@ -183,9 +183,9 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) {
script := `
access(all) resource Vault {
access(all) var balance: UFix64
access(all) var dictRef: auth(Mutable) &{Bool: Vault};
access(all) var dictRef: auth(Mutate) &{Bool: Vault};
init(balance: UFix64, _ dictRef: auth(Mutable) &{Bool: Vault}) {
init(balance: UFix64, _ dictRef: auth(Mutate) &{Bool: Vault}) {
self.balance = balance
self.dictRef = dictRef;
}
Expand All @@ -208,7 +208,7 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) {
access(all) fun main(): UFix64 {
let dict: @{Bool: Vault} <- { }
let dictRef = &dict as auth(Mutable) &{Bool: Vault};
let dictRef = &dict as auth(Mutate) &{Bool: Vault};
var v1 <- create Vault(balance: 1000.0, dictRef); // This will be duplicated
var v2 <- create Vault(balance: 1.0, dictRef); // This will be lost
Expand Down Expand Up @@ -305,7 +305,7 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) {
let acc = getAuthAccount(0x1)
acc.save(<-dict, to: /storage/foo)
let ref = acc.borrow<auth(Mutable) &{Int: R}>(from: /storage/foo)!
let ref = acc.borrow<auth(Mutate) &{Int: R}>(from: /storage/foo)!
ref.forEachKey(fun(i: Int): Bool {
var r4: @R? <- create R()
Expand Down Expand Up @@ -372,9 +372,9 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) {
script := `
access(all) resource Vault {
access(all) var balance: UFix64
access(all) var arrRef: auth(Mutable) &[Vault]
access(all) var arrRef: auth(Mutate) &[Vault]
init(balance: UFix64, _ arrRef: auth(Mutable) &[Vault]) {
init(balance: UFix64, _ arrRef: auth(Mutate) &[Vault]) {
self.balance = balance
self.arrRef = arrRef;
}
Expand All @@ -397,7 +397,7 @@ func TestRuntimeResourceDuplicationUsingDestructorIteration(t *testing.T) {
access(all) fun main(): UFix64 {
let arr: @[Vault] <- []
let arrRef = &arr as auth(Mutable) &[Vault];
let arrRef = &arr as auth(Mutate) &[Vault];
var v1 <- create Vault(balance: 1000.0, arrRef); // This will be duplicated
var v2 <- create Vault(balance: 1.0, arrRef); // This will be lost
Expand Down
12 changes: 6 additions & 6 deletions runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,7 @@ func TestRuntimeStorageMultipleTransactionsResourceWithArray(t *testing.T) {
prepare(signer: AuthAccount) {
signer.save(<-createContainer(), to: /storage/container)
signer.link<auth(Insertable) &Container>(/public/container, target: /storage/container)
signer.link<auth(Insert) &Container>(/public/container, target: /storage/container)
}
}
`)
Expand All @@ -2017,7 +2017,7 @@ func TestRuntimeStorageMultipleTransactionsResourceWithArray(t *testing.T) {
prepare(signer: AuthAccount) {
let publicAccount = getAccount(signer.address)
let ref = publicAccount.getCapability(/public/container)
.borrow<auth(Insertable) &Container>()!
.borrow<auth(Insert) &Container>()!
let length = ref.values.length
ref.appendValue(1)
Expand All @@ -2034,7 +2034,7 @@ func TestRuntimeStorageMultipleTransactionsResourceWithArray(t *testing.T) {
let publicAccount = getAccount(signer.address)
let ref = publicAccount
.getCapability(/public/container)
.borrow<auth(Insertable) &Container>()!
.borrow<auth(Insert) &Container>()!
let length = ref.values.length
ref.appendValue(2)
Expand Down Expand Up @@ -7019,7 +7019,7 @@ func TestRuntimeGetCapability(t *testing.T) {
script := []byte(`
access(all) fun main(): Capability {
let dict: {Int: AuthAccount} = {}
let ref = &dict as auth(Mutable) &{Int: AnyStruct}
let ref = &dict as auth(Mutate) &{Int: AnyStruct}
ref[0] = getAccount(0x01) as AnyStruct
return dict.values[0].getCapability(/private/xxx)
}
Expand Down Expand Up @@ -7054,7 +7054,7 @@ func TestRuntimeGetCapability(t *testing.T) {
script := []byte(`
access(all) fun main(): Capability {
let dict: {Int: AuthAccount} = {}
let ref = &dict as auth(Mutable) &{Int: AnyStruct}
let ref = &dict as auth(Mutate) &{Int: AnyStruct}
ref[0] = getAccount(0x01) as AnyStruct
return dict.values[0].getCapability(/public/xxx)
}
Expand Down Expand Up @@ -7089,7 +7089,7 @@ func TestRuntimeGetCapability(t *testing.T) {
script := []byte(`
access(all) fun main(): Capability {
let dict: {Int: PublicAccount} = {}
let ref = &dict as auth(Mutable) &{Int: AnyStruct}
let ref = &dict as auth(Mutate) &{Int: AnyStruct}
ref[0] = getAccount(0x01) as AnyStruct
return dict.values[0].getCapability(/public/xxx)
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/sema/check_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,12 @@ func (checker *Checker) visitIdentifierExpressionAssignment(
}

var mutableEntitledAccess = NewEntitlementSetAccess(
[]*EntitlementType{MutableEntitlement},
[]*EntitlementType{MutateEntitlement},
Disjunction,
)

var insertableAndRemovableEntitledAccess = NewEntitlementSetAccess(
[]*EntitlementType{InsertableEntitlement, RemovableEntitlement},
[]*EntitlementType{InsertEntitlement, RemoveEntitlement},
Conjunction,
)

Expand Down
6 changes: 3 additions & 3 deletions runtime/sema/entitlements.cdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

entitlement Mutable
entitlement Mutate

entitlement Insertable
entitlement Insert

entitlement Removable
entitlement Remove
24 changes: 12 additions & 12 deletions runtime/sema/entitlements.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions runtime/sema/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -1945,12 +1945,12 @@ If either of the parameters are out of the bounds of the array, or the indices a
`

var insertableEntitledAccess = NewEntitlementSetAccess(
[]*EntitlementType{InsertableEntitlement, MutableEntitlement},
[]*EntitlementType{InsertEntitlement, MutateEntitlement},
Disjunction,
)

var removableEntitledAccess = NewEntitlementSetAccess(
[]*EntitlementType{RemovableEntitlement, MutableEntitlement},
[]*EntitlementType{RemoveEntitlement, MutateEntitlement},
Disjunction,
)

Expand Down Expand Up @@ -2516,9 +2516,9 @@ func (t *VariableSizedType) SupportedEntitlements() *EntitlementOrderedSet {

var arrayDictionaryEntitlements = func() *EntitlementOrderedSet {
set := orderedmap.New[EntitlementOrderedSet](3)
set.Set(MutableEntitlement, struct{}{})
set.Set(InsertableEntitlement, struct{}{})
set.Set(RemovableEntitlement, struct{}{})
set.Set(MutateEntitlement, struct{}{})
set.Set(InsertEntitlement, struct{}{})
set.Set(RemoveEntitlement, struct{}{})
return set
}()

Expand Down
Loading

0 comments on commit 5d40cd1

Please sign in to comment.