diff --git a/arwenmandos/exec.go b/arwenmandos/exec.go index 2900709ec..db443bfd3 100644 --- a/arwenmandos/exec.go +++ b/arwenmandos/exec.go @@ -9,7 +9,7 @@ import ( worldhook "github.com/ElrondNetwork/elrond-vm-util/mock-hook-blockchain" cryptohook "github.com/ElrondNetwork/elrond-vm-util/mock-hook-crypto" mc "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/controller" - mjparse "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/json/parse" + fr "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/json/fileresolver" ) // TestVMType is the VM type argument we use in tests. @@ -17,7 +17,7 @@ var TestVMType = []byte{0, 0} // ArwenTestExecutor parses, interprets and executes both .test.json tests and .scen.json scenarios with Arwen. type ArwenTestExecutor struct { - fileResolver mjparse.FileResolver + fileResolver fr.FileResolver World *worldhook.BlockchainHookMock vm vmi.VMExecutionHandler checkGas bool diff --git a/arwenmandos/execScenario.go b/arwenmandos/execScenario.go index 105a32ee9..6e2ff2711 100644 --- a/arwenmandos/execScenario.go +++ b/arwenmandos/execScenario.go @@ -3,8 +3,8 @@ package arwenmandos import ( vmi "github.com/ElrondNetwork/elrond-vm-common" mc "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/controller" + fr "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/json/fileresolver" mj "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/json/model" - mjparse "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/json/parse" ) // Reset clears state/world. @@ -14,7 +14,7 @@ func (ae *ArwenTestExecutor) Reset() { } // ExecuteScenario executes an individual test. -func (ae *ArwenTestExecutor) ExecuteScenario(scenario *mj.Scenario, fileResolver mjparse.FileResolver) error { +func (ae *ArwenTestExecutor) ExecuteScenario(scenario *mj.Scenario, fileResolver fr.FileResolver) error { ae.fileResolver = fileResolver ae.checkGas = scenario.CheckGas @@ -35,15 +35,17 @@ func (ae *ArwenTestExecutor) ExecuteScenario(scenario *mj.Scenario, fileResolver func (ae *ArwenTestExecutor) ExecuteStep(generalStep mj.Step) error { switch step := generalStep.(type) { case *mj.ExternalStepsStep: + fileResolverBackup := ae.fileResolver externalStepsRunner := mc.NewScenarioRunner( ae, - ae.fileResolver, + ae.fileResolver.Clone(), ) extAbsPth := ae.fileResolver.ResolveAbsolutePath(step.Path) err := externalStepsRunner.RunSingleJSONScenario(extAbsPth) if err != nil { return err } + ae.fileResolver = fileResolverBackup case *mj.SetStateStep: // append accounts for _, acct := range step.Accounts { @@ -53,7 +55,7 @@ func (ae *ArwenTestExecutor) ExecuteStep(generalStep mj.Step) error { // replace block info ae.World.PreviousBlockInfo = convertBlockInfo(step.PreviousBlockInfo) ae.World.CurrentBlockInfo = convertBlockInfo(step.CurrentBlockInfo) - ae.World.Blockhashes = mj.JSONBytesValues(step.BlockHashes) + ae.World.Blockhashes = mj.JSONBytesFromStringValues(step.BlockHashes) // append NewAddressMocks addressMocksToAdd := convertNewAddressMocks(step.NewAddressMocks) diff --git a/arwenmandos/execTest.go b/arwenmandos/execTest.go index 4facfe8df..1a24ea904 100644 --- a/arwenmandos/execTest.go +++ b/arwenmandos/execTest.go @@ -10,7 +10,7 @@ import ( func (ae *ArwenTestExecutor) ExecuteTest(test *mj.Test) error { // reset world ae.World.Clear() - ae.World.Blockhashes = mj.JSONBytesValues(test.BlockHashes) + ae.World.Blockhashes = mj.JSONBytesFromStringValues(test.BlockHashes) for _, acct := range test.Pre { ae.World.AcctMap.PutAccount(convertAccount(acct)) diff --git a/arwenmandos/stepCheckTxResult.go b/arwenmandos/stepCheckTxResult.go index 616fd9c59..5db0258b1 100644 --- a/arwenmandos/stepCheckTxResult.go +++ b/arwenmandos/stepCheckTxResult.go @@ -31,14 +31,14 @@ func checkTxResults( if len(output.ReturnData) != len(blResult.Out) { return fmt.Errorf("result length mismatch. Tx %s. Want: %s. Have: %s", txIndex, - mj.JSONCheckBytesString(blResult.Out), + checkBytesListPretty(blResult.Out), mj.ResultAsString(output.ReturnData)) } for i, expected := range blResult.Out { if !expected.Check(output.ReturnData[i]) { return fmt.Errorf("result mismatch. Tx %s. Want: %s. Have: %s", txIndex, - mj.JSONCheckBytesString(blResult.Out), + checkBytesListPretty(blResult.Out), mj.ResultAsString(output.ReturnData)) } } diff --git a/arwenmandos/stepRunTx.go b/arwenmandos/stepRunTx.go index 132a61ef8..208b1b246 100644 --- a/arwenmandos/stepRunTx.go +++ b/arwenmandos/stepRunTx.go @@ -155,7 +155,7 @@ func (ae *ArwenTestExecutor) scCreate(txIndex string, tx *mj.Transaction) (*vmi. ContractCode: tx.Code.Value, VMInput: vmi.VMInput{ CallerAddr: tx.From.Value, - Arguments: mj.JSONBytesValues(tx.Arguments), + Arguments: mj.JSONBytesFromTreeValues(tx.Arguments), CallValue: tx.Value.Value, GasPrice: tx.GasPrice.Value, GasProvided: tx.GasLimit.Value, @@ -181,7 +181,7 @@ func (ae *ArwenTestExecutor) scCall(txIndex string, tx *mj.Transaction) (*vmi.VM Function: tx.Function, VMInput: vmi.VMInput{ CallerAddr: tx.From.Value, - Arguments: mj.JSONBytesValues(tx.Arguments), + Arguments: mj.JSONBytesFromTreeValues(tx.Arguments), CallValue: tx.Value.Value, GasPrice: tx.GasPrice.Value, GasProvided: tx.GasLimit.Value, diff --git a/arwenmandos/util.go b/arwenmandos/util.go index e97aba27a..fbb3b2242 100644 --- a/arwenmandos/util.go +++ b/arwenmandos/util.go @@ -9,6 +9,7 @@ import ( vmi "github.com/ElrondNetwork/elrond-vm-common" mj "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/json/model" + oj "github.com/ElrondNetwork/elrond-vm-util/test-util/orderedjson" ) func convertAccount(testAcct *mj.Account) *worldhook.Account { @@ -60,13 +61,13 @@ func convertBlockInfo(testBlockInfo *mj.BlockInfo) *worldhook.BlockInfo { func convertLogToTestFormat(outputLog *vmi.LogEntry) *mj.LogEntry { testLog := mj.LogEntry{ - Address: mj.JSONBytes{Value: outputLog.Address}, - Identifier: mj.JSONBytes{Value: outputLog.Identifier}, - Data: mj.JSONBytes{Value: outputLog.Data}, - Topics: make([]mj.JSONBytes, len(outputLog.Topics)), + Address: mj.JSONBytesFromString{Value: outputLog.Address}, + Identifier: mj.JSONBytesFromString{Value: outputLog.Identifier}, + Data: mj.JSONBytesFromString{Value: outputLog.Data}, + Topics: make([]mj.JSONBytesFromString, len(outputLog.Topics)), } for i, topic := range outputLog.Topics { - testLog.Topics[i] = mj.JSONBytes{Value: topic} + testLog.Topics[i] = mj.JSONBytesFromString{Value: topic} } return &testLog @@ -111,3 +112,16 @@ func generateTxHash(txIndex string) []byte { } return txIndexBytes } + +// JSONCheckBytesString formats a list of JSONCheckBytes for printing to console. +func checkBytesListPretty(jcbs []mj.JSONCheckBytes) string { + str := "[" + for i, jcb := range jcbs { + if i > 0 { + str += ", " + } + + str += "\"" + oj.JSONString(jcb.Original) + "\"" + } + return str + "]" +} diff --git a/cmd/testgen/dns/genDnsTest.go b/cmd/testgen/dns/genDnsTest.go index 927bad3e6..e59eb70a3 100644 --- a/cmd/testgen/dns/genDnsTest.go +++ b/cmd/testgen/dns/genDnsTest.go @@ -41,9 +41,7 @@ func main() { "dns.wasm", filepath.Join(getTestRoot(), "dns/dns.wasm")) tg := &testGenerator{ - mandosParser: mjparse.Parser{ - FileResolver: fileResolver, - }, + mandosParser: mjparse.NewParser(fileResolver), generatedScenario: &mj.Scenario{ Name: "dns test", }, diff --git a/fuzz/delegation/v0.3/fuzzDelegationExecutor.go b/fuzz/delegation/v0.3/fuzzDelegationExecutor.go index 21120672a..536dd21da 100644 --- a/fuzz/delegation/v0.3/fuzzDelegationExecutor.go +++ b/fuzz/delegation/v0.3/fuzzDelegationExecutor.go @@ -10,6 +10,7 @@ import ( am "github.com/ElrondNetwork/arwen-wasm-vm/arwenmandos" vmi "github.com/ElrondNetwork/elrond-vm-common" worldhook "github.com/ElrondNetwork/elrond-vm-util/mock-hook-blockchain" + fr "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/json/fileresolver" mj "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/json/model" mjparse "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/json/parse" mjwrite "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/json/write" @@ -40,14 +41,12 @@ type fuzzDelegationExecutor struct { generatedScenario *mj.Scenario } -func newFuzzDelegationExecutor(fileResolver mjparse.FileResolver) (*fuzzDelegationExecutor, error) { +func newFuzzDelegationExecutor(fileResolver fr.FileResolver) (*fuzzDelegationExecutor, error) { arwenTestExecutor, err := am.NewArwenTestExecutor() if err != nil { return nil, err } - parser := mjparse.Parser{ - FileResolver: fileResolver, - } + parser := mjparse.NewParser(fileResolver) return &fuzzDelegationExecutor{ arwenTestExecutor: arwenTestExecutor, world: arwenTestExecutor.World, diff --git a/fuzz/delegation/v0.4/fuzzDelegationExecutor.go b/fuzz/delegation/v0.4/fuzzDelegationExecutor.go index 57342a32e..54685492d 100644 --- a/fuzz/delegation/v0.4/fuzzDelegationExecutor.go +++ b/fuzz/delegation/v0.4/fuzzDelegationExecutor.go @@ -10,6 +10,7 @@ import ( am "github.com/ElrondNetwork/arwen-wasm-vm/arwenmandos" vmi "github.com/ElrondNetwork/elrond-vm-common" worldhook "github.com/ElrondNetwork/elrond-vm-util/mock-hook-blockchain" + fr "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/json/fileresolver" mj "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/json/model" mjparse "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/json/parse" mjwrite "github.com/ElrondNetwork/elrond-vm-util/test-util/mandos/json/write" @@ -40,14 +41,12 @@ type fuzzDelegationExecutor struct { generatedScenario *mj.Scenario } -func newFuzzDelegationExecutor(fileResolver mjparse.FileResolver) (*fuzzDelegationExecutor, error) { +func newFuzzDelegationExecutor(fileResolver fr.FileResolver) (*fuzzDelegationExecutor, error) { arwenTestExecutor, err := am.NewArwenTestExecutor() if err != nil { return nil, err } - parser := mjparse.Parser{ - FileResolver: fileResolver, - } + parser := mjparse.NewParser(fileResolver) return &fuzzDelegationExecutor{ arwenTestExecutor: arwenTestExecutor, world: arwenTestExecutor.World, diff --git a/go.mod b/go.mod index 9adff08cf..6f4db86da 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/ElrondNetwork/arwen-wasm-vm go 1.13 require ( - github.com/ElrondNetwork/big-int-util v0.0.5 + github.com/ElrondNetwork/big-int-util v0.1.0 github.com/ElrondNetwork/elrond-go-logger v1.0.2 github.com/ElrondNetwork/elrond-vm-common v0.1.23 - github.com/ElrondNetwork/elrond-vm-util v0.3.6 + github.com/ElrondNetwork/elrond-vm-util v0.4.0 github.com/gin-gonic/gin v1.6.3 github.com/mitchellh/mapstructure v1.1.2 github.com/pelletier/go-toml v1.6.0 diff --git a/go.sum b/go.sum index 285adf2c7..f8cd82768 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,13 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/ElrondNetwork/big-int-util v0.0.5 h1:e/9kK++9ZH/SdIYqLSUPRFYrDZmDWDgff3/7SCydq5I= -github.com/ElrondNetwork/big-int-util v0.0.5/go.mod h1:96viBvoTXLjZOhEvE0D+QnAwg1IJLPAK6GVHMbC7Aw4= +github.com/ElrondNetwork/big-int-util v0.1.0 h1:vTMoJ5azhVmr7jhpSD3JUjQdkdyXoEPVkOvhdw1RjV4= +github.com/ElrondNetwork/big-int-util v0.1.0/go.mod h1:96viBvoTXLjZOhEvE0D+QnAwg1IJLPAK6GVHMbC7Aw4= github.com/ElrondNetwork/elrond-go-logger v1.0.2 h1:X//QtN5WEPe6yrOL2fgb3EI5IDDAmh449bXfOMgr6Fc= github.com/ElrondNetwork/elrond-go-logger v1.0.2/go.mod h1:e5D+c97lKUfFdAzFX7rrI2Igl/z4Y0RkKYKWyzprTGk= github.com/ElrondNetwork/elrond-vm-common v0.1.23 h1:4tIzzVdpAI8FonCA1BrbNb+3lukKoyHUaoSOAZWvYnY= github.com/ElrondNetwork/elrond-vm-common v0.1.23/go.mod h1:ZakxPST/Wt8umnRtA9gobcy3Dw2bywxwkC54P5VhO9g= -github.com/ElrondNetwork/elrond-vm-util v0.3.6 h1:pJdiDWfYY1SnLo8oOWlvQvtFrIn0Sduy5TGyjRVxINw= -github.com/ElrondNetwork/elrond-vm-util v0.3.6/go.mod h1:+ecDJZLTwN/yeRXXEqd+sa9WoalLsT4nFtQWCo0YKWA= +github.com/ElrondNetwork/elrond-vm-util v0.4.0 h1:TbwIdWZj7F2KNYvslw0gEUZn0wdISSWz7JQjZXvZ5DA= +github.com/ElrondNetwork/elrond-vm-util v0.4.0/go.mod h1:L/IHojCXiYSd73/5oCJTsBRPwFY7UfR0E2f+o4ztjH8= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/integrationTests/json/vm_test.go b/integrationTests/json/vm_test.go index c4156412a..be4fd2b88 100644 --- a/integrationTests/json/vm_test.go +++ b/integrationTests/json/vm_test.go @@ -162,7 +162,9 @@ func TestDelegation_v0_3(t *testing.T) { getTestRoot(), "delegation/v0_3", ".scen.json", - []string{}) + []string{ + "delegation/v0_3/test/integration/genesis/genesis.scen.json", + }) if err != nil { t.Error(err) diff --git a/test/adder/adder.wasm b/test/adder/adder.wasm index 36754ed40..baddfd301 100755 Binary files a/test/adder/adder.wasm and b/test/adder/adder.wasm differ diff --git a/test/async/alice.wasm b/test/async/alice.wasm index 9ebd77936..d5e9142a7 100755 Binary files a/test/async/alice.wasm and b/test/async/alice.wasm differ diff --git a/test/async/bob.wasm b/test/async/bob.wasm index 0e7471ece..d1bfc4110 100755 Binary files a/test/async/bob.wasm and b/test/async/bob.wasm differ diff --git a/test/crypto_bubbles_min_v1/crypto-bubbles.wasm b/test/crypto_bubbles_min_v1/crypto-bubbles.wasm index e29d20e51..304d8063b 100755 Binary files a/test/crypto_bubbles_min_v1/crypto-bubbles.wasm and b/test/crypto_bubbles_min_v1/crypto-bubbles.wasm differ diff --git a/test/delegation/v0_3/test/integration/genesis/genesis.scen.json b/test/delegation/v0_3/test/integration/genesis/genesis.scen.json index 6bcc0f25e..cf1e97b1d 100644 --- a/test/delegation/v0_3/test/integration/genesis/genesis.scen.json +++ b/test/delegation/v0_3/test/integration/genesis/genesis.scen.json @@ -23,7 +23,7 @@ }, { "step": "externalSteps", - "path": "../genesis/03_genesis_stake.steps.json" + "path": "03_genesis_stake.steps.json" }, { "step": "externalSteps", diff --git a/test/erc20-rust/contracts/simple-coin.wasm b/test/erc20-rust/contracts/simple-coin.wasm index 16ff706c3..3885680f4 100755 Binary files a/test/erc20-rust/contracts/simple-coin.wasm and b/test/erc20-rust/contracts/simple-coin.wasm differ diff --git a/test/features/features.wasm b/test/features/features.wasm index fb11c21b6..1eb6f4b03 100755 Binary files a/test/features/features.wasm and b/test/features/features.wasm differ diff --git a/test/features/storage_opt_addr_err.scen.json b/test/features/storage_opt_addr_err.scen.json index d1db1f3c1..9c0cbbfaa 100644 --- a/test/features/storage_opt_addr_err.scen.json +++ b/test/features/storage_opt_addr_err.scen.json @@ -8,7 +8,7 @@ "nonce": "0", "balance": "0", "storage": { - "``opt_addr": "1|``____________address_too_long____________" + "``opt_addr": ["1", "``____________address_too_long____________"] }, "code": "file:features.wasm" },