Skip to content

Commit

Permalink
Merge pull request #2800 from onflow/bastian/refactor-runtime-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Sep 21, 2023
2 parents e857884 + d70dd4b commit f5846e6
Show file tree
Hide file tree
Showing 41 changed files with 3,682 additions and 3,634 deletions.
329 changes: 163 additions & 166 deletions runtime/account_test.go

Large diffs are not rendered by default.

183 changes: 89 additions & 94 deletions runtime/attachments_test.go

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions runtime/capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
* limitations under the License.
*/

package runtime
package runtime_test

import (
"testing"

"github.com/stretchr/testify/require"

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

Expand All @@ -35,25 +37,25 @@ func TestRuntimeCapability_borrowAndCheck(t *testing.T) {

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

newRuntime := func() (testInterpreterRuntime, *testRuntimeInterface) {
runtime := newTestInterpreterRuntime()
newRuntime := func() (TestInterpreterRuntime, *TestRuntimeInterface) {
runtime := NewTestInterpreterRuntime()
accountCodes := map[common.Location][]byte{}

runtimeInterface := &testRuntimeInterface{
storage: newTestLedger(nil, nil),
getSigningAccounts: func() ([]Address, error) {
runtimeInterface := &TestRuntimeInterface{
Storage: NewTestLedger(nil, nil),
OnGetSigningAccounts: func() ([]Address, error) {
return []Address{address}, nil
},
resolveLocation: singleIdentifierLocationResolver(t),
updateAccountContractCode: func(location common.AddressLocation, code []byte) error {
OnResolveLocation: NewSingleIdentifierLocationResolver(t),
OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error {
accountCodes[location] = code
return nil
},
getAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
OnGetAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
code = accountCodes[location]
return code, nil
},
emitEvent: func(event cadence.Event) error {
OnEmitEvent: func(event cadence.Event) error {
return nil
},
}
Expand All @@ -66,7 +68,7 @@ func TestRuntimeCapability_borrowAndCheck(t *testing.T) {

runtime, runtimeInterface := newRuntime()

nextTransactionLocation := newTransactionLocationGenerator()
nextTransactionLocation := NewTransactionLocationGenerator()

// Deploy contract

Expand Down Expand Up @@ -318,7 +320,7 @@ func TestRuntimeCapability_borrowAndCheck(t *testing.T) {

runtime, runtimeInterface := newRuntime()

nextTransactionLocation := newTransactionLocationGenerator()
nextTransactionLocation := NewTransactionLocationGenerator()

// Deploy contract

Expand Down Expand Up @@ -569,7 +571,7 @@ func TestRuntimeCapability_borrowAndCheck(t *testing.T) {

runtime, runtimeInterface := newRuntime()

nextTransactionLocation := newTransactionLocationGenerator()
nextTransactionLocation := NewTransactionLocationGenerator()

// Deploy contract

Expand Down
44 changes: 23 additions & 21 deletions runtime/capabilitycontrollers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

package runtime
package runtime_test

import (
"fmt"
Expand All @@ -25,10 +25,12 @@ import (
"github.com/stretchr/testify/require"

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

Expand All @@ -40,7 +42,7 @@ func TestRuntimeCapabilityControllers(t *testing.T) {
storage *Storage,
) {

rt := newTestInterpreterRuntime()
rt := NewTestInterpreterRuntime()

accountCodes := map[Location][]byte{}

Expand Down Expand Up @@ -122,30 +124,30 @@ func TestRuntimeCapabilityControllers(t *testing.T) {

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

runtimeInterface := &testRuntimeInterface{
storage: newTestLedger(nil, nil),
log: func(message string) {
runtimeInterface := &TestRuntimeInterface{
Storage: NewTestLedger(nil, nil),
OnProgramLog: func(message string) {
// NO-OP
},
emitEvent: func(event cadence.Event) error {
OnEmitEvent: func(event cadence.Event) error {
// NO-OP
return nil
},
getSigningAccounts: func() ([]Address, error) {
OnGetSigningAccounts: func() ([]Address, error) {
return []Address{signer}, nil
},
resolveLocation: singleIdentifierLocationResolver(t),
updateAccountContractCode: func(location common.AddressLocation, code []byte) error {
OnResolveLocation: NewSingleIdentifierLocationResolver(t),
OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error {
accountCodes[location] = code
return nil
},
getAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
OnGetAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
code = accountCodes[location]
return code, nil
},
}

nextTransactionLocation := newTransactionLocationGenerator()
nextTransactionLocation := NewTransactionLocationGenerator()

// Deploy contract

Expand Down Expand Up @@ -2604,7 +2606,7 @@ func TestRuntimeCapabilityBorrowAsInheritedInterface(t *testing.T) {

t.Parallel()

runtime := newTestInterpreterRuntime()
runtime := NewTestInterpreterRuntime()

contract := []byte(`
access(all) contract Test {
Expand Down Expand Up @@ -2643,28 +2645,28 @@ func TestRuntimeCapabilityBorrowAsInheritedInterface(t *testing.T) {

var accountCode []byte

runtimeInterface := &testRuntimeInterface{
getCode: func(_ Location) (bytes []byte, err error) {
runtimeInterface := &TestRuntimeInterface{
OnGetCode: func(_ Location) (bytes []byte, err error) {
return accountCode, nil
},
storage: newTestLedger(nil, nil),
getSigningAccounts: func() ([]Address, error) {
Storage: NewTestLedger(nil, nil),
OnGetSigningAccounts: func() ([]Address, error) {
return []Address{address}, nil
},
resolveLocation: singleIdentifierLocationResolver(t),
getAccountContractCode: func(_ common.AddressLocation) (code []byte, err error) {
OnResolveLocation: NewSingleIdentifierLocationResolver(t),
OnGetAccountContractCode: func(_ common.AddressLocation) (code []byte, err error) {
return accountCode, nil
},
updateAccountContractCode: func(_ common.AddressLocation, code []byte) error {
OnUpdateAccountContractCode: func(_ common.AddressLocation, code []byte) error {
accountCode = code
return nil
},
emitEvent: func(event cadence.Event) error {
OnEmitEvent: func(event cadence.Event) error {
return nil
},
}

nextTransactionLocation := newTransactionLocationGenerator()
nextTransactionLocation := NewTransactionLocationGenerator()

// Deploy

Expand Down
Loading

0 comments on commit f5846e6

Please sign in to comment.