Skip to content

Commit

Permalink
add reproducer
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed May 8, 2024
1 parent ee20f86 commit e0c7a79
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10750,3 +10750,90 @@ func TestRuntimeMoveSelfVariable(t *testing.T) {
require.ErrorAs(t, err, &interpreter.NonTransferableValueError{})
})
}

func TestRuntimeContractWithInvalidCapability(t *testing.T) {

t.Parallel()

runtime := NewTestInterpreterRuntimeWithAttachments()

address := common.MustBytesToAddress([]byte{0x1})

contract := []byte(`
access(all)
contract Test {
access(all) var invalidCap: Capability
access(all) var unrelatedStoragePath: StoragePath
init() {
self.invalidCap = self.account.capabilities.get<&AnyResource>(/public/path)
self.unrelatedStoragePath = /storage/validPath
}
}
`)

script := []byte(`
import Test from 0x1
access(all) fun main() {
log(Test.unrelatedStoragePath)
log(Test.invalidCap)
}
`)

deploy := DeploymentTransaction("Test", contract)

accountCodes := map[Location][]byte{}
var events []cadence.Event

runtimeInterface := &TestRuntimeInterface{
OnGetCode: func(location Location) (bytes []byte, err error) {
return accountCodes[location], nil
},
Storage: NewTestLedger(nil, nil),
OnGetSigningAccounts: func() ([]Address, error) {
return []Address{address}, nil
},
OnResolveLocation: NewSingleIdentifierLocationResolver(t),
OnGetAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
return accountCodes[location], nil
},
OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error {
accountCodes[location] = code
return nil
},
OnEmitEvent: func(event cadence.Event) error {
events = append(events, event)
return nil
},
}

nextTransactionLocation := NewTransactionLocationGenerator()

// Deploy contract

err := runtime.ExecuteTransaction(
Script{
Source: deploy,
},
Context{
Interface: runtimeInterface,
Location: nextTransactionLocation(),
},
)
require.NoError(t, err)

// Run script

_, err = runtime.ExecuteScript(
Script{
Source: script,
},
Context{
Interface: runtimeInterface,
Location: nextTransactionLocation(),
},
)
require.NoError(t, err)
}

0 comments on commit e0c7a79

Please sign in to comment.