/
vmDummy.go
131 lines (107 loc) · 3.89 KB
/
vmDummy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package executortest
import (
"errors"
scenarioexec "github.com/Dharitri-org/drtg-scenario/scenario/executor"
scenmodel "github.com/Dharitri-org/drtg-scenario/scenario/model"
worldmock "github.com/Dharitri-org/drtg-scenario/worldmock"
"github.com/Dharitri-org/drtg-core/core"
vmcommon "github.com/Dharitri-org/drtg-vm-common"
)
var _ scenarioexec.VMInterface = (*DummyVM)(nil)
var _ scenarioexec.VMBuilder = (*DummyVMBuilder)(nil)
// DummyVM is a VM stand-in that can never be called.
// Used for tests that do not require a VM.
type DummyVM struct{}
// RunSmartContractCreate -
func (*DummyVM) RunSmartContractCreate(input *vmcommon.ContractCreateInput) (*vmcommon.VMOutput, error) {
return nil, errors.New("cannot call the DummyVM")
}
// RunSmartContractCall -
func (*DummyVM) RunSmartContractCall(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error) {
return nil, errors.New("cannot call the DummyVM")
}
// GasScheduleChange -
func (*DummyVM) GasScheduleChange(newGasSchedule map[string]map[string]uint64) {}
// GetVersion -
func (*DummyVM) GetVersion() string {
return ""
}
// IsInterfaceNil -
func (*DummyVM) IsInterfaceNil() bool {
return false
}
// Close -
func (*DummyVM) Close() error {
return nil
}
// Reset -
func (*DummyVM) Reset() {}
// SetGasTracing -
func (*DummyVM) SetGasTracing(enableGasTracing bool) {}
// GetGasTrace -
func (*DummyVM) GetGasTrace() map[string]map[string][]uint64 {
return make(map[string]map[string][]uint64)
}
// DummyVMBuilder is the builder for a DummyVM.
// Also provides a minimal gas schedule for running the builtin functions.
// Used for tests that do not require a VM.
type DummyVMBuilder struct{}
// NewMockWorld defines how the MockWorld is initialized.
func (*DummyVMBuilder) NewMockWorld() *worldmock.MockWorld {
return worldmock.NewMockWorld()
}
// GasScheduleMapFromScenarios converts the gas schedule name from a scenario into an actual gas map.
func (*DummyVMBuilder) GasScheduleMapFromScenarios(scenGasSchedule scenmodel.GasSchedule) (worldmock.GasScheduleMap, error) {
gasMap := make(map[string]map[string]uint64)
fillGasMapInternal(gasMap, 1)
return gasMap, nil
}
// GetVMType returns the configured VM type.
func (*DummyVMBuilder) GetVMType() []byte {
return []byte{0, 0}
}
// NewVM creates the execution VM host with references to the world mock and gas schedule.
func (*DummyVMBuilder) NewVM(world *worldmock.MockWorld, gasSchedule map[string]map[string]uint64) (scenarioexec.VMInterface, error) {
return &DummyVM{}, nil
}
func fillGasMapInternal(gasMap map[string]map[string]uint64, value uint64) map[string]map[string]uint64 {
gasMap[core.BaseOperationCostString] = fillGasMapBaseOperationCosts(value)
gasMap[core.BuiltInCostString] = fillGasMapBuiltInCosts(value)
return gasMap
}
func fillGasMapBaseOperationCosts(value uint64) map[string]uint64 {
gasMap := make(map[string]uint64)
gasMap["StorePerByte"] = value
gasMap["DataCopyPerByte"] = value
gasMap["ReleasePerByte"] = value
gasMap["PersistPerByte"] = value
gasMap["CompilePerByte"] = value
gasMap["AoTPreparePerByte"] = value
gasMap["GetCode"] = value
return gasMap
}
func fillGasMapBuiltInCosts(value uint64) map[string]uint64 {
gasMap := make(map[string]uint64)
gasMap["ChangeOwnerAddress"] = value
gasMap["ClaimDeveloperRewards"] = value
gasMap["SaveUserName"] = value
gasMap["SaveKeyValue"] = value
gasMap["DCTTransfer"] = value
gasMap["DCTBurn"] = value
gasMap["DCTLocalMint"] = value
gasMap["DCTLocalBurn"] = value
gasMap["DCTNFTCreate"] = value
gasMap["DCTNFTAddQuantity"] = value
gasMap["DCTNFTBurn"] = value
gasMap["DCTNFTTransfer"] = value
gasMap["DCTNFTChangeCreateOwner"] = value
gasMap["DCTNFTAddUri"] = value
gasMap["DCTNFTUpdateAttributes"] = value
gasMap["DCTNFTMultiTransfer"] = value
gasMap["SetGuardian"] = value
gasMap["GuardAccount"] = value
gasMap["UnGuardAccount"] = value
gasMap["TrieLoadPerNode"] = value
gasMap["TrieStorePerNode"] = value
return gasMap
}