Skip to content

Commit

Permalink
Do not export unnecessary types and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
m-Peter committed Sep 8, 2023
1 parent 767d32b commit b6814fa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
48 changes: 24 additions & 24 deletions test/emulator_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,25 @@ const helperFilePrefix = "\x00helper/"

var _ stdlib.Blockchain = &EmulatorBackend{}

type SystemClock struct {
type systemClock struct {
TimeDelta int64
}

func (sc SystemClock) Now() time.Time {
func (sc systemClock) Now() time.Time {
return time.Now().Add(time.Second * time.Duration(sc.TimeDelta)).UTC()
}

func NewSystemClock() *SystemClock {
return &SystemClock{}
func newSystemClock() *systemClock {
return &systemClock{}
}

type DeployedContractConstructorInvocation struct {
type deployedContractConstructorInvocation struct {
ConstructorArguments []interpreter.Value
ArgumentTypes []sema.Type
}

var ContractInvocations = make(
map[string]DeployedContractConstructorInvocation,
var contractInvocations = make(
map[string]deployedContractConstructorInvocation,
0,
)

Expand All @@ -96,28 +96,28 @@ type EmulatorBackend struct {

// logCollection is a hook attached in the server logger, in order
// to aggregate and expose log messages from the blockchain.
logCollection *LogCollectionHook
logCollection *logCollectionHook

// clock allows manipulating the blockchain's clock.
clock *SystemClock
clock *systemClock
}

type keyInfo struct {
accountKey *sdk.AccountKey
signer crypto.Signer
}

var Chain = flow.MonotonicEmulator.Chain()
var chain = flow.MonotonicEmulator.Chain()

var CommonContracts = emulator.NewCommonContracts(Chain)
var commonContracts = emulator.NewCommonContracts(chain)

var systemContracts = func() []common.AddressLocation {
serviceAddress := Chain.ServiceAddress().HexWithPrefix()
serviceAddress := chain.ServiceAddress().HexWithPrefix()
contracts := map[string]string{
"FlowServiceAccount": serviceAddress,
"FlowToken": fvm.FlowTokenAddress(Chain).HexWithPrefix(),
"FungibleToken": fvm.FungibleTokenAddress(Chain).HexWithPrefix(),
"FlowFees": environment.FlowFeesAddress(Chain).HexWithPrefix(),
"FlowToken": fvm.FlowTokenAddress(chain).HexWithPrefix(),
"FungibleToken": fvm.FungibleTokenAddress(chain).HexWithPrefix(),
"FlowFees": environment.FlowFeesAddress(chain).HexWithPrefix(),
"FlowStorageFees": serviceAddress,
"FlowClusterQC": serviceAddress,
"FlowDKG": serviceAddress,
Expand Down Expand Up @@ -146,7 +146,7 @@ func NewEmulatorBackend(
stdlibHandler stdlib.StandardLibraryHandler,
coverageReport *runtime.CoverageReport,
) *EmulatorBackend {
logCollectionHook := NewLogCollectionHook()
logCollectionHook := newLogCollectionHook()
var blockchain *emulator.Blockchain
if coverageReport != nil {
excludeCommonLocations(coverageReport)
Expand All @@ -157,7 +157,7 @@ func NewEmulatorBackend(
} else {
blockchain = newBlockchain(logCollectionHook)
}
clock := NewSystemClock()
clock := newSystemClock()
blockchain.SetClock(clock)

return &EmulatorBackend{
Expand Down Expand Up @@ -512,7 +512,7 @@ func (e *EmulatorBackend) DeployContract(
}
argTypes = append(argTypes, argType)
}
ContractInvocations[name] = DeployedContractConstructorInvocation{
contractInvocations[name] = deployedContractConstructorInvocation{
ConstructorArguments: args,
ArgumentTypes: argTypes,
}
Expand All @@ -527,7 +527,7 @@ func (e *EmulatorBackend) Logs() []string {

// newBlockchain returns an emulator blockchain for testing.
func newBlockchain(
hook *LogCollectionHook,
hook *logCollectionHook,
opts ...emulator.Option,
) *emulator.Blockchain {
output := zerolog.ConsoleWriter{Out: os.Stdout}
Expand All @@ -539,8 +539,8 @@ func newBlockchain(
[]emulator.Option{
emulator.WithStorageLimitEnabled(false),
emulator.WithServerLogger(logger),
emulator.Contracts(CommonContracts),
emulator.WithChainID(Chain.ChainID()),
emulator.Contracts(commonContracts),
emulator.WithChainID(chain.ChainID()),
},
opts...,
)...,
Expand Down Expand Up @@ -715,7 +715,7 @@ func excludeCommonLocations(coverageReport *runtime.CoverageReport) {
for _, location := range systemContracts {
coverageReport.ExcludeLocation(location)
}
for _, contract := range CommonContracts {
for _, contract := range commonContracts {
address, _ := common.HexToAddress(contract.Address.String())
location := common.AddressLocation{
Address: address,
Expand All @@ -729,7 +729,7 @@ func excludeCommonLocations(coverageReport *runtime.CoverageReport) {
// address mappings for system/common contracts.
func baseConfiguration() *stdlib.Configuration {
addresses := make(map[string]common.Address, 0)
serviceAddress := common.Address(Chain.ServiceAddress())
serviceAddress := common.Address(chain.ServiceAddress())
addresses["NonFungibleToken"] = serviceAddress
addresses["MetadataViews"] = serviceAddress
addresses["ViewResolver"] = serviceAddress
Expand All @@ -738,7 +738,7 @@ func baseConfiguration() *stdlib.Configuration {
address := common.Address(addressLocation.Address)
addresses[contract] = address
}
for _, contractDescription := range CommonContracts {
for _, contractDescription := range commonContracts {
contract := contractDescription.Name
address := common.Address(contractDescription.Address)
addresses[contract] = address
Expand Down
24 changes: 12 additions & 12 deletions test/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ type Result struct {
Error error
}

// LogCollectionHook can be attached to zerolog.Logger objects, in order
// logCollectionHook can be attached to zerolog.Logger objects, in order
// to aggregate the log messages in a string slice, containing only the
// string message.
type LogCollectionHook struct {
type logCollectionHook struct {
Logs []string
}

var _ zerolog.Hook = &LogCollectionHook{}
var _ zerolog.Hook = &logCollectionHook{}

// NewLogCollectionHook initializes and returns a *LogCollectionHook
func NewLogCollectionHook() *LogCollectionHook {
return &LogCollectionHook{
// newLogCollectionHook initializes and returns a *LogCollectionHook
func newLogCollectionHook() *logCollectionHook {
return &logCollectionHook{
Logs: make([]string, 0),
}
}

func (h *LogCollectionHook) Run(e *zerolog.Event, level zerolog.Level, msg string) {
func (h *logCollectionHook) Run(e *zerolog.Event, level zerolog.Level, msg string) {
if level != zerolog.NoLevel {
logMsg := strings.Replace(
msg,
Expand Down Expand Up @@ -144,7 +144,7 @@ type TestRunner struct {
// logCollection is a hook attached in the program logger of
// the script environment, in order to aggregate and expose
// log messages from test cases and contracts.
logCollection *LogCollectionHook
logCollection *logCollectionHook

// randomSeed is used for randomized test case execution.
randomSeed int64
Expand All @@ -155,7 +155,7 @@ type TestRunner struct {
}

func NewTestRunner() *TestRunner {
logCollectionHook := NewLogCollectionHook()
logCollectionHook := newLogCollectionHook()
output := zerolog.ConsoleWriter{Out: os.Stdout}
output.FormatMessage = func(i interface{}) string {
msg := i.(string)
Expand All @@ -169,8 +169,8 @@ func NewTestRunner() *TestRunner {
logger := zerolog.New(output).With().Timestamp().Logger().Hook(logCollectionHook)
blockchain, err := emulator.New(
emulator.WithStorageLimitEnabled(false),
emulator.Contracts(CommonContracts),
emulator.WithChainID(Chain.ChainID()),
emulator.Contracts(commonContracts),
emulator.WithChainID(chain.ChainID()),
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -580,7 +580,7 @@ func (r *TestRunner) interpreterContractValueHandler(

default:
if _, ok := compositeType.Location.(common.AddressLocation); ok {
invocation, found := ContractInvocations[compositeType.Identifier]
invocation, found := contractInvocations[compositeType.Identifier]
if !found {
panic(fmt.Errorf("contract invocation not found"))
}
Expand Down

0 comments on commit b6814fa

Please sign in to comment.