Skip to content

Commit

Permalink
Merge pull request #1243 from onflow/supun/storage-ref-test
Browse files Browse the repository at this point in the history
Add test for casting storage ref to an invalid type
  • Loading branch information
SupunS authored Nov 16, 2021
2 parents 26b1c7c + 5b56d32 commit 91c67f5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions runtime/tests/interpreter/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,13 @@ func TestInterpretAuthAccount_borrow(t *testing.T) {
return ref.foo
}
fun invalidBorrowS(): &S2? {
let s = S()
account.save(s, to: /storage/another_s)
let borrowedS = account.borrow<auth &AnyStruct>(from: /storage/another_s)
return borrowedS as! auth &S2?
}
`,
)

Expand Down Expand Up @@ -735,6 +742,12 @@ func TestInterpretAuthAccount_borrow(t *testing.T) {

require.ErrorAs(t, err, &interpreter.DereferenceError{})
})

t.Run("borrow as invalid type", func(t *testing.T) {
_, err = inter.Invoke("invalidBorrowS")
require.Error(t, err)
require.ErrorAs(t, err, &interpreter.ForceCastTypeMismatchError{})
})
})
}

Expand Down

0 comments on commit 91c67f5

Please sign in to comment.