Skip to content

Commit e6f27ac

Browse files
authored
Merge pull request #3813 from onflow/supun/refactor-tests
Run existing interpreter tests with the compiler and VM
2 parents 2bfb934 + 8e17741 commit e6f27ac

File tree

14 files changed

+444
-38
lines changed

14 files changed

+444
-38
lines changed

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ build-compatibility-check:
6060
(cd ./tools/compatibility-check && go build .)
6161

6262
.PHONY: ci
63-
ci:
63+
ci: test-with-compiler test-tools
6464
# test all packages
6565
go test -coverprofile=coverage.txt -covermode=atomic -parallel 8 -race -coverpkg $(COVERPKGS) ./...
6666
# run interpreter smoke tests. results from run above are reused, so no tests runs are duplicated
@@ -69,7 +69,7 @@ ci:
6969
sed -i -e 's/^.* 0 0$$//' coverage.txt
7070

7171
.PHONY: test
72-
test: test-all-packages test-tools
72+
test: test-all-packages test-tools test-with-compiler
7373

7474
.PHONY: test-all-packages
7575
test-all-packages:
@@ -82,6 +82,12 @@ test-tools:
8282
(cd ./tools/constructorcheck && go test -parallel 8 ./)
8383
(cd ./tools/maprange && go test -parallel 8 ./)
8484

85+
86+
.PHONY: test-with-compiler
87+
test-with-compiler:
88+
(go test -parallel 8 ./interpreter/... -compile=true)
89+
90+
8591
.PHONY: lint-github-actions
8692
lint-github-actions: build-linter
8793
tools/golangci-lint/golangci-lint run --out-format=colored-line-number,github-actions --timeout=5m -v ./...

bbq/vm/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (c *Config) WithAccountHandler(handler stdlib.AccountHandler) *Config {
7575
}
7676

7777
// TODO: This is temporary. Remove once storing/reading is supported for VM values.
78-
func (c *Config) interpreter() *interpreter.Interpreter {
78+
func (c *Config) Interpreter() *interpreter.Interpreter {
7979
if c.inter == nil {
8080
inter, err := interpreter.NewInterpreter(
8181
nil,

bbq/vm/storage.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func ReadStored(
5353
storageDomain, _ := common.StorageDomainFromIdentifier(domain)
5454

5555
accountStorage := storage.GetDomainStorageMap(
56-
config.interpreter(),
56+
config.Interpreter(),
5757
address,
5858
storageDomain,
5959
false,
@@ -74,7 +74,7 @@ func WriteStored(
7474
value Value,
7575
) (existed bool) {
7676

77-
inter := config.interpreter()
77+
inter := config.Interpreter()
7878

7979
accountStorage := config.Storage.GetDomainStorageMap(inter, storageAddress, domain, true)
8080
interValue := VMValueToInterpreterValue(config, value)
@@ -107,7 +107,7 @@ func StoredValueExists(
107107
identifier interpreter.StorageMapKey,
108108
) bool {
109109
accountStorage := config.Storage.GetDomainStorageMap(
110-
config.interpreter(),
110+
config.Interpreter(),
111111
storageAddress,
112112
domain,
113113
false,

bbq/vm/test/utils.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,17 @@ func compileAndInvokeWithOptions(
562562
arguments ...vm.Value,
563563
) (vm.Value, error) {
564564

565+
programVM := CompileAndPrepareToInvoke(t, code, options)
566+
567+
result, err := programVM.Invoke(funcName, arguments...)
568+
if err == nil {
569+
require.Equal(t, 0, programVM.StackSize())
570+
}
571+
572+
return result, err
573+
}
574+
575+
func CompileAndPrepareToInvoke(t testing.TB, code string, options CompilerAndVMOptions) *vm.VM {
565576
programs := map[common.Location]*compiledProgram{}
566577

567578
location := common.ScriptLocation{0x1}
@@ -600,13 +611,7 @@ func compileAndInvokeWithOptions(
600611
program,
601612
vmConfig,
602613
)
603-
604-
result, err := programVM.Invoke(funcName, arguments...)
605-
if err == nil {
606-
require.Equal(t, 0, programVM.StackSize())
607-
}
608-
609-
return result, err
614+
return programVM
610615
}
611616

612617
func compileAndInvokeWithOptionsAndPrograms(

bbq/vm/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
func IsSubType(config *Config, sourceType, targetType bbq.StaticType) bool {
2727
// TODO: Avoid conversion to sema types.
28-
inter := config.interpreter()
28+
inter := config.Interpreter()
2929
return inter.IsSubType(sourceType, targetType)
3030
}
3131

bbq/vm/value_account.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func checkAndIssueStorageCapabilityControllerWithType(
259259
borrowType, ok := ty.(*interpreter.ReferenceStaticType)
260260
if !ok {
261261
// TODO: remove conversion. se static type in error
262-
semaType, err := config.interpreter().ConvertStaticToSemaType(ty)
262+
semaType, err := config.Interpreter().ConvertStaticToSemaType(ty)
263263
if err != nil {
264264
panic(err)
265265
}
@@ -376,7 +376,7 @@ func recordStorageCapabilityController(
376376
storageMapKey := interpreter.StringStorageMapKey(identifier)
377377

378378
accountStorage := config.Storage.GetDomainStorageMap(
379-
config.interpreter(),
379+
config.Interpreter(),
380380
address,
381381
common.StorageDomainPathCapability,
382382
true,
@@ -396,7 +396,7 @@ func recordStorageCapabilityController(
396396
setValue,
397397
)
398398
capabilityIDSetInterValue := VMValueToInterpreterValue(config, capabilityIDSet)
399-
accountStorage.SetValue(config.interpreter(), storageMapKey, capabilityIDSetInterValue)
399+
accountStorage.SetValue(config.Interpreter(), storageMapKey, capabilityIDSetInterValue)
400400
} else {
401401
capabilityIDSet := readValue.(*DictionaryValue)
402402
existing := capabilityIDSet.Insert(config, setKey, setValue)

bbq/vm/value_capability.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func getCapabilityController(
211211
storageMapKey := interpreter.Uint64StorageMapKey(capabilityID)
212212

213213
accountStorage := config.Storage.GetDomainStorageMap(
214-
config.interpreter(),
214+
config.Interpreter(),
215215
address,
216216
common.StorageDomainCapabilityController,
217217
false,

bbq/vm/value_composite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (v *CompositeValue) SetMember(config *Config, name string, value Value) {
139139
}
140140

141141
if existingStorable != nil {
142-
inter := config.interpreter()
142+
inter := config.Interpreter()
143143
existingValue := interpreter.StoredValue(nil, existingStorable, config.Storage)
144144

145145
existingValue.DeepRemove(inter, true) // existingValue is standalone because it was overwritten in parent container.

bbq/vm/value_conversions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func VMValueToInterpreterValue(config *Config, value Value) interpreter.Value {
173173
nil,
174174
)
175175
case *StorageReferenceValue:
176-
inter := config.interpreter()
176+
inter := config.Interpreter()
177177
semaBorrowType, err := inter.ConvertStaticToSemaType(value.BorrowedType)
178178
if err != nil {
179179
panic(err)

bbq/vm/value_dictionary.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ func (v *DictionaryValue) iterate(
433433

434434
func newValueComparator(conf *Config) atree.ValueComparator {
435435
return func(storage atree.SlabStorage, atreeValue atree.Value, otherStorable atree.Storable) (bool, error) {
436-
inter := conf.interpreter()
436+
inter := conf.Interpreter()
437437
locationRange := interpreter.EmptyLocationRange
438438
value := interpreter.MustConvertStoredValue(inter, atreeValue)
439439
otherValue := interpreter.StoredValue(inter, otherStorable, storage)
@@ -443,7 +443,7 @@ func newValueComparator(conf *Config) atree.ValueComparator {
443443

444444
func newHashInputProvider(conf *Config) atree.HashInputProvider {
445445
return func(value atree.Value, scratch []byte) ([]byte, error) {
446-
inter := conf.interpreter()
446+
inter := conf.Interpreter()
447447
locationRange := interpreter.EmptyLocationRange
448448
hashInput := interpreter.MustConvertStoredValue(inter, value).(interpreter.HashableValue).
449449
HashInput(inter, locationRange, scratch)

0 commit comments

Comments
 (0)