Skip to content

Commit

Permalink
Fix reference invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Apr 20, 2023
1 parent 19019ff commit 46b6996
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion encoding/json/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const (
typeParametersKey = "typeParameters"
returnKey = "return"
typeBoundKey = "typeBound"
purityKey = "purity"
purityKey = "purity"
)

func (d *Decoder) decodeJSON(v any) cadence.Value {
Expand Down
2 changes: 1 addition & 1 deletion encoding/json/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ func prepareType(typ cadence.Type, results typePreparationResults) jsonValue {
Initializers: prepareInitializers(typ.Initializers, results),
}
case *cadence.FunctionType:
typeJson := jsonFunctionType{
typeJson := jsonFunctionType{
Kind: "Function",
TypeParameters: prepareTypeParameters(typ.TypeParameters, results),
Parameters: prepareParameters(typ.Parameters, results),
Expand Down
10 changes: 3 additions & 7 deletions runtime/attachments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,8 @@ func TestAccountAttachmentExportFailure(t *testing.T) {
import Test from 0x1
pub fun main(): &Test.A? {
let r <- Test.makeRWithA()
let acc = getAuthAccount(0x1)
acc.save(<-r, to: /storage/r)
var rRef = acc.borrow<&Test.R>(from: /storage/r)!
let a = rRef[Test.A]
let a = r[Test.A]
destroy r
return a
}
`)
Expand Down Expand Up @@ -227,7 +223,7 @@ func TestAccountAttachmentExportFailure(t *testing.T) {
},
)
require.Error(t, err)
require.ErrorAs(t, err, &interpreter.InvalidatedResourceError{})
require.ErrorAs(t, err, &interpreter.DestroyedResourceError{})
}

func TestAccountAttachmentExport(t *testing.T) {
Expand Down
9 changes: 9 additions & 0 deletions runtime/convertValues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5341,7 +5341,16 @@ func TestDestroyedResourceReferenceExport(t *testing.T) {
pub fun main(): &S {
var s <- create S()
var ref = &s as &S
// Just to trick the checker,
// and get pass the static referenced resource invalidation analysis.
var ref2 = getRef(ref)
destroy s
return ref2!
}
pub fun getRef(_ ref: &S): &S {
return ref
}
`)
Expand Down
4 changes: 2 additions & 2 deletions runtime/tests/interpreter/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
package interpreter_test

import (
"github.com/onflow/cadence/runtime/sema"
"github.com/onflow/cadence/runtime/tests/checker"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/interpreter"
"github.com/onflow/cadence/runtime/sema"
"github.com/onflow/cadence/runtime/tests/checker"
"github.com/onflow/cadence/runtime/tests/utils"
)

Expand Down
3 changes: 2 additions & 1 deletion runtime/tests/interpreter/uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ func TestInterpretResourceUUID(t *testing.T) {
interpreter.ProgramFromChecker(importingChecker),
importingChecker.Location,
&interpreter.Config{
Storage: storage,
InvalidatedResourceValidationEnabled: true,
Storage: storage,
UUIDHandler: func() (uint64, error) {
defer func() { uuid++ }()
return uuid, nil
Expand Down

0 comments on commit 46b6996

Please sign in to comment.