Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrated mx-chain-scenario-go v1.4.1 #99

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cmd/testgen/dns/.gitignore

This file was deleted.

136 changes: 0 additions & 136 deletions cmd/testgen/dns/genDnsTest.go

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/multiversx/mx-chain-core-go v1.2.18
github.com/multiversx/mx-chain-crypto-go v1.2.9
github.com/multiversx/mx-chain-logger-go v1.0.13
github.com/multiversx/mx-chain-scenario-go v1.3.0
github.com/multiversx/mx-chain-scenario-go v1.4.1
github.com/multiversx/mx-chain-vm-common-go v1.5.11
github.com/multiversx/mx-components-big-int v1.0.0
github.com/pelletier/go-toml v1.9.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ github.com/multiversx/mx-chain-crypto-go v1.2.9 h1:OEfF2kOQrtzUl273Z3DEcshjlTVUf
github.com/multiversx/mx-chain-crypto-go v1.2.9/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8=
github.com/multiversx/mx-chain-logger-go v1.0.13 h1:eru/TETo0MkO4ZTnXsQDKf4PBRpAXmqjT02klNT/JnY=
github.com/multiversx/mx-chain-logger-go v1.0.13/go.mod h1:MZJhTAtZTJxT+yK2EHc4ZW3YOHUc1UdjCD0iahRNBZk=
github.com/multiversx/mx-chain-scenario-go v1.3.0 h1:Vm6jYipJuIcJt8kamgXkePtKkwXaF5Lv5DglZjE5o8I=
github.com/multiversx/mx-chain-scenario-go v1.3.0/go.mod h1:Sdgz8nzA9Ki/pdY/e2a4k90LALBKQB1Eo8HeCV3Bkzo=
github.com/multiversx/mx-chain-scenario-go v1.4.1 h1:CrVXb1aNBRiFfSfpoMAUoGUy2aNXke5WnoesLdFxC2g=
github.com/multiversx/mx-chain-scenario-go v1.4.1/go.mod h1:Sdgz8nzA9Ki/pdY/e2a4k90LALBKQB1Eo8HeCV3Bkzo=
github.com/multiversx/mx-chain-vm-common-go v1.5.11 h1:rAQR00ALKOmWAuNA8XW8hR02M9gmrAE4WZwyJH4dMMU=
github.com/multiversx/mx-chain-vm-common-go v1.5.11/go.mod h1:T04rZt/VdwjPXcXVxltMmDmrhxNXsqlByYbWNWcNLYA=
github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqdhV1m/aJhaP1EMaiS8=
Expand Down
2 changes: 2 additions & 0 deletions integrationTests/json/scenariosTestCommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func runTestsInFolder(t *testing.T, folder string, exclusions []string) {
runner := scenio.NewScenarioController(
executor,
scenio.NewDefaultFileResolver(),
vmBuilder.GetVMType(),
)

err := runner.RunAllJSONScenariosInDirectory(
Expand All @@ -60,6 +61,7 @@ func runSingleTestReturnError(folder string, filename string) error {
runner := scenio.NewScenarioController(
executor,
scenio.NewDefaultFileResolver(),
vmBuilder.GetVMType(),
)

fullPath := path.Join(getTestRoot(), folder)
Expand Down
16 changes: 12 additions & 4 deletions scenario/vmBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ import (

var _ scenexec.VMBuilder = (*ScenarioVMHostBuilder)(nil)

// TestVMType is the VM type argument we use in tests.
var TestVMType = []byte{0, 0}
// DefaultVMType is the VM type argument we use in tests.
var DefaultVMType = []byte{5, 0}

// VMTestExecutor parses, interprets and executes both .test.json tests and .scen.json scenarios with VM.
type ScenarioVMHostBuilder struct {
VMType []byte
}

// NewScenarioVMHostBuilder creates a default ScenarioVMHostBuilder.
func NewScenarioVMHostBuilder() *ScenarioVMHostBuilder {
return &ScenarioVMHostBuilder{}
return &ScenarioVMHostBuilder{
VMType: DefaultVMType,
}
}

// NewMockWorld defines how the MockWorld is initialized.
Expand All @@ -51,6 +54,11 @@ func (svb *ScenarioVMHostBuilder) GasScheduleMapFromScenarios(scenGasSchedule sc
}
}

// GetVMType returns the configured VM type.
func (svb *ScenarioVMHostBuilder) GetVMType() []byte {
return svb.VMType
}

// NewVM will create a new VM instance with pointers to a mock world and given gas schedule.
func (svb *ScenarioVMHostBuilder) NewVM(
world *worldmock.MockWorld,
Expand All @@ -62,7 +70,7 @@ func (svb *ScenarioVMHostBuilder) NewVM(
return hostCore.NewVMHost(
world,
&vmhost.VMHostParameters{
VMType: TestVMType,
VMType: svb.VMType,
BlockGasLimit: blockGasLimit,
GasSchedule: gasSchedule,
BuiltInFuncContainer: world.BuiltinFuncs.Container,
Expand Down
4 changes: 2 additions & 2 deletions test/erc20-c/create.scen.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"id": "2",
"tx": {
"from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b000000000000000000001234",
"to": "0x00000000000000000f0f11111111a94f5374fce5edbc8e2a8697c15331001234",
"to": "0x0000000000000000050011111111a94f5374fce5edbc8e2a8697c15331001234",
"function": "balanceOf",
"arguments": [
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b000000000000000000001234"
Expand All @@ -63,7 +63,7 @@
"storage": {},
"code": ""
},
"0x00000000000000000f0f11111111a94f5374fce5edbc8e2a8697c15331001234": {
"0x0000000000000000050011111111a94f5374fce5edbc8e2a8697c15331001234": {
"nonce": "0",
"balance": "0",
"storage": {
Expand Down
10 changes: 5 additions & 5 deletions test/timelocks/timelocks.scen.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"step": "scCall",
"tx": {
"from": "0xacc1000000000000000000000000000000000000000000000000000000001234",
"to": "0x00000000000000000f0f11111111acc100000000000000000000000000051234",
"to": "0x0000000000000000050011111111acc100000000000000000000000000051234",
"function": "incrementCounter",
"arguments": [],
"gasLimit": "0x100000",
Expand All @@ -53,7 +53,7 @@
"step": "scCall",
"tx": {
"from": "0xacc1000000000000000000000000000000000000000000000000000000001234",
"to": "0x00000000000000000f0f11111111acc100000000000000000000000000051234",
"to": "0x0000000000000000050011111111acc100000000000000000000000000051234",
"function": "lockCounter",
"arguments": [],
"gasLimit": "0x100000",
Expand All @@ -71,7 +71,7 @@
"step": "scCall",
"tx": {
"from": "0xacc1000000000000000000000000000000000000000000000000000000001234",
"to": "0x00000000000000000f0f11111111acc100000000000000000000000000051234",
"to": "0x0000000000000000050011111111acc100000000000000000000000000051234",
"function": "incrementCounter",
"arguments": [],
"gasLimit": "0x100000",
Expand All @@ -91,7 +91,7 @@
"step": "scCall",
"tx": {
"from": "0xacc1000000000000000000000000000000000000000000000000000000001234",
"to": "0x00000000000000000f0f11111111acc100000000000000000000000000051234",
"to": "0x0000000000000000050011111111acc100000000000000000000000000051234",
"function": "releaseCounter",
"arguments": [],
"gasLimit": "0x100000",
Expand All @@ -109,7 +109,7 @@
"step": "scCall",
"tx": {
"from": "0xacc1000000000000000000000000000000000000000000000000000000001234",
"to": "0x00000000000000000f0f11111111acc100000000000000000000000000051234",
"to": "0x0000000000000000050011111111acc100000000000000000000000000051234",
"function": "incrementCounter",
"arguments": [],
"gasLimit": "0x100000",
Expand Down
5 changes: 3 additions & 2 deletions vmserver/facade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
var databasePath = "./testdata/db"
var wasmCounterPath = "../test/contracts/counter/output/counter.wasm"
var wasmErc20Path = "../test/contracts/erc20/output/erc20.wasm"
var vmType = []byte{5, 0}

func init() {
_ = os.RemoveAll(databasePath)
Expand All @@ -31,7 +32,7 @@ func TestFacade_RunContract_Counter(t *testing.T) {
deployResponse := context.deployContract(wasmCounterPath, alice.hex)
contractAddress := deployResponse.ContractAddress
contractAddressHex := deployResponse.ContractAddressHex
require.Equal(t, worldmock.GenerateMockAddress(worldmock.DefaultVMType, alice.raw, 0), contractAddress)
require.Equal(t, worldmock.GenerateMockAddress(alice.raw, 0, vmType), contractAddress)
require.True(t, context.accountExists(contractAddress))

context.runContract(contractAddressHex, alice.hex, "increment")
Expand All @@ -56,7 +57,7 @@ func TestFacade_RunContract_ERC20(t *testing.T) {
deployResponse := context.deployContract(wasmErc20Path, alice.hex, "64")
contractAddress := deployResponse.ContractAddress
contractAddressHex := deployResponse.ContractAddressHex
require.Equal(t, worldmock.GenerateMockAddress(worldmock.DefaultVMType, alice.raw, 0), contractAddress)
require.Equal(t, worldmock.GenerateMockAddress(alice.raw, 0, vmType), contractAddress)

// Initial state
totalSupply := context.queryContract(contractAddressHex, alice.hex, "totalSupply").getFirstResultAsInt64()
Expand Down
Loading