Skip to content

Commit

Permalink
Remove entirely the 'Test.useConfiguration' function
Browse files Browse the repository at this point in the history
  • Loading branch information
m-Peter committed Sep 19, 2023
1 parent 0f9ba5d commit 23dbe7c
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 103 deletions.
12 changes: 0 additions & 12 deletions runtime/stdlib/contracts/test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,6 @@ pub contract Test {
)
}

/// Set the configuration to be used by the blockchain.
/// Overrides any existing configuration.
///
pub fun useConfiguration(_ configuration: Configuration) {
self.backend.useConfiguration(configuration)
}

/// Returns all the logs from the blockchain, up to the calling point.
///
pub fun logs(): [String] {
Expand Down Expand Up @@ -324,11 +317,6 @@ pub contract Test {
arguments: [AnyStruct]
): Error?

/// Set the configuration to be used by the blockchain.
/// Overrides any existing configuration.
///
pub fun useConfiguration(_ configuration: Configuration)

/// Returns all the logs from the blockchain, up to the calling point.
///
pub fun logs(): [String]
Expand Down
6 changes: 0 additions & 6 deletions runtime/stdlib/test-framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ type Blockchain interface {
arguments []interpreter.Value,
) error

UseConfiguration(configuration *Configuration)

StandardLibraryHandler() StandardLibraryHandler

Logs() []string
Expand Down Expand Up @@ -99,7 +97,3 @@ type Account struct {
PublicKey *PublicKey
Address common.Address
}

type Configuration struct {
Addresses map[string]common.Address
}
76 changes: 0 additions & 76 deletions runtime/stdlib/test_emulatorbackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type testEmulatorBackendType struct {
executeNextTransactionFunctionType *sema.FunctionType
commitBlockFunctionType *sema.FunctionType
deployContractFunctionType *sema.FunctionType
useConfigFunctionType *sema.FunctionType
logsFunctionType *sema.FunctionType
serviceAccountFunctionType *sema.FunctionType
eventsFunctionType *sema.FunctionType
Expand Down Expand Up @@ -87,11 +86,6 @@ func newTestEmulatorBackendType(
testEmulatorBackendTypeDeployContractFunctionName,
)

useConfigFunctionType := interfaceFunctionType(
blockchainBackendInterfaceType,
testEmulatorBackendTypeUseConfigFunctionName,
)

logsFunctionType := interfaceFunctionType(
blockchainBackendInterfaceType,
testEmulatorBackendTypeLogsFunctionName,
Expand Down Expand Up @@ -178,12 +172,6 @@ func newTestEmulatorBackendType(
deployContractFunctionType,
testEmulatorBackendTypeDeployContractFunctionDocString,
),
sema.NewUnmeteredPublicFunctionMember(
compositeType,
testEmulatorBackendTypeUseConfigFunctionName,
useConfigFunctionType,
testEmulatorBackendTypeUseConfigFunctionDocString,
),
sema.NewUnmeteredPublicFunctionMember(
compositeType,
testEmulatorBackendTypeLogsFunctionName,
Expand Down Expand Up @@ -245,7 +233,6 @@ func newTestEmulatorBackendType(
executeNextTransactionFunctionType: executeNextTransactionFunctionType,
commitBlockFunctionType: commitBlockFunctionType,
deployContractFunctionType: deployContractFunctionType,
useConfigFunctionType: useConfigFunctionType,
logsFunctionType: logsFunctionType,
serviceAccountFunctionType: serviceAccountFunctionType,
eventsFunctionType: eventsFunctionType,
Expand Down Expand Up @@ -589,65 +576,6 @@ func (t *testEmulatorBackendType) newDeployContractFunction(
)
}

// 'EmulatorBackend.useConfiguration' function

const testEmulatorBackendTypeUseConfigFunctionName = "useConfiguration"

const testEmulatorBackendTypeUseConfigFunctionDocString = `
Set the configuration to be used by the blockchain.
Overrides any existing configuration.
`

func (t *testEmulatorBackendType) newUseConfigFunction(
blockchain Blockchain,
) *interpreter.HostFunctionValue {
return interpreter.NewUnmeteredHostFunctionValue(
t.useConfigFunctionType,
func(invocation interpreter.Invocation) interpreter.Value {
inter := invocation.Interpreter

// configurations
configsValue, ok := invocation.Arguments[0].(*interpreter.CompositeValue)
if !ok {
panic(errors.NewUnreachableError())
}

addresses, ok := configsValue.GetMember(
inter,
invocation.LocationRange,
addressesFieldName,
).(*interpreter.DictionaryValue)
if !ok {
panic(errors.NewUnreachableError())
}

mapping := make(map[string]common.Address, addresses.Count())

addresses.Iterate(inter, func(locationValue, addressValue interpreter.Value) bool {
location, ok := locationValue.(*interpreter.StringValue)
if !ok {
panic(errors.NewUnreachableError())
}

address, ok := addressValue.(interpreter.AddressValue)
if !ok {
panic(errors.NewUnreachableError())
}

mapping[location.Str] = common.Address(address)

return true
})

blockchain.UseConfiguration(&Configuration{
Addresses: mapping,
})

return interpreter.Void
},
)
}

// 'EmulatorBackend.logs' function

const testEmulatorBackendTypeLogsFunctionName = "logs"
Expand Down Expand Up @@ -893,10 +821,6 @@ func (t *testEmulatorBackendType) newEmulatorBackend(
Name: testEmulatorBackendTypeDeployContractFunctionName,
Value: t.newDeployContractFunction(blockchain),
},
{
Name: testEmulatorBackendTypeUseConfigFunctionName,
Value: t.newUseConfigFunction(blockchain),
},
{
Name: testEmulatorBackendTypeLogsFunctionName,
Value: t.newLogsFunction(blockchain),
Expand Down
9 changes: 0 additions & 9 deletions runtime/stdlib/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2679,7 +2679,6 @@ type mockedBlockchain struct {
executeTransaction func() *stdlib.TransactionResult
commitBlock func() error
deployContract func(inter *interpreter.Interpreter, name string, path string, arguments []interpreter.Value) error
useConfiguration func(configuration *stdlib.Configuration)
stdlibHandler func() stdlib.StandardLibraryHandler
logs func() []string
serviceAccount func() (*stdlib.Account, error)
Expand Down Expand Up @@ -2763,14 +2762,6 @@ func (m mockedBlockchain) DeployContract(
return m.deployContract(inter, name, path, arguments)
}

func (m mockedBlockchain) UseConfiguration(configuration *stdlib.Configuration) {
if m.useConfiguration == nil {
panic("'UseConfiguration' is not implemented")
}

m.useConfiguration(configuration)
}

func (m mockedBlockchain) StandardLibraryHandler() stdlib.StandardLibraryHandler {
if m.stdlibHandler == nil {
panic("'StandardLibraryHandler' is not implemented")
Expand Down

0 comments on commit 23dbe7c

Please sign in to comment.