Skip to content

Commit

Permalink
adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Jun 22, 2023
1 parent 5bded4b commit dda2353
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 153 deletions.
17 changes: 9 additions & 8 deletions encoding/ccf/ccf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9237,7 +9237,6 @@ func TestEncodeType(t *testing.T) {
0xd8, ccf.CBORTagReferenceTypeValue,
// array, 2 elements follow
0x82,
// authorized
// nil
0xf6,
// tag
Expand Down Expand Up @@ -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
Expand All @@ -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{},
},
})

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions runtime/coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion runtime/imported_values_memory_metering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 24 additions & 24 deletions runtime/resource_duplicate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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};
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand All @@ -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];
Expand Down
Loading

0 comments on commit dda2353

Please sign in to comment.