Skip to content

Commit

Permalink
Merge pull request #159 from ElrondNetwork/contract-test-9
Browse files Browse the repository at this point in the history
Mandos update
  • Loading branch information
andrei-marinica authored Aug 28, 2020
2 parents 9095914 + f71607a commit 888ce6e
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 36 deletions.
4 changes: 2 additions & 2 deletions arwenmandos/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ 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.
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
Expand Down
10 changes: 6 additions & 4 deletions arwenmandos/execScenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand All @@ -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 {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion arwenmandos/execTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions arwenmandos/stepCheckTxResult.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down
4 changes: 2 additions & 2 deletions arwenmandos/stepRunTx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
24 changes: 19 additions & 5 deletions arwenmandos/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 + "]"
}
4 changes: 1 addition & 3 deletions cmd/testgen/dns/genDnsTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
7 changes: 3 additions & 4 deletions fuzz/delegation/v0.3/fuzzDelegationExecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions fuzz/delegation/v0.4/fuzzDelegationExecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
4 changes: 3 additions & 1 deletion integrationTests/json/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file modified test/adder/adder.wasm
Binary file not shown.
Binary file modified test/async/alice.wasm
Binary file not shown.
Binary file modified test/async/bob.wasm
Binary file not shown.
Binary file modified test/crypto_bubbles_min_v1/crypto-bubbles.wasm
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
{
"step": "externalSteps",
"path": "../genesis/03_genesis_stake.steps.json"
"path": "03_genesis_stake.steps.json"
},
{
"step": "externalSteps",
Expand Down
Binary file modified test/erc20-rust/contracts/simple-coin.wasm
Binary file not shown.
Binary file modified test/features/features.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion test/features/storage_opt_addr_err.scen.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 888ce6e

Please sign in to comment.