Skip to content

Commit

Permalink
Merge pull request #23 from ElrondNetwork/erc20-rust-test
Browse files Browse the repository at this point in the history
Erc20 rust test
  • Loading branch information
sasurobert authored Nov 12, 2019
2 parents 27a9000 + 1acaa1d commit 31ac890
Show file tree
Hide file tree
Showing 74 changed files with 235 additions and 176 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@

/arwen/debug
/cmd/test/test

# VSCode settings
.vscode
17 changes: 0 additions & 17 deletions .vscode/launch.json

This file was deleted.

16 changes: 15 additions & 1 deletion cmd/test/debugArwen.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ import (
)

func main() {
if len(os.Args) != 2 {
panic("One argument expected - the path to the json test.")
}
jsonTestPath := os.Args[1]

err := controller.RunSingleJSONTest(
jsonTestPath,
newArwenTestExecutor())

if err == nil {
fmt.Println("SUCCESS")
} else {
fmt.Printf("ERROR: %s\n", err.Error())
}
}

func getTestRoot() string {
Expand All @@ -22,7 +36,7 @@ func getTestRoot() string {

func debugArwenTest(testFile string) {
arwenTestRoot := getTestRoot()
err := controller.RunSingleIeleTest(
err := controller.RunSingleJSONTest(
filepath.Join(arwenTestRoot, testFile),
newArwenTestExecutor())

Expand Down
24 changes: 18 additions & 6 deletions cmd/test/executorRun.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
vmi "github.com/ElrondNetwork/elrond-vm-common"
worldhook "github.com/ElrondNetwork/elrond-vm-util/mock-hook-blockchain"
cryptohook "github.com/ElrondNetwork/elrond-vm-util/mock-hook-crypto"
ij "github.com/ElrondNetwork/elrond-vm-util/test-util/ielejson"
ij "github.com/ElrondNetwork/elrond-vm-util/test-util/vmtestjson"
)

// TestVMType is the VM type argument we use in tests.
Expand All @@ -22,8 +22,9 @@ const ignoreGas = true
const ignoreAllLogs = false

type arwenTestExecutor struct {
world *worldhook.BlockchainHookMock
vm vmi.VMExecutionHandler
world *worldhook.BlockchainHookMock
vm vmi.VMExecutionHandler
contractPathReplacements map[string]string
}

func newArwenTestExecutor() *arwenTestExecutor {
Expand All @@ -37,17 +38,28 @@ func newArwenTestExecutor() *arwenTestExecutor {
panic(err)
}
return &arwenTestExecutor{
world: world,
vm: vm,
world: world,
vm: vm,
contractPathReplacements: make(map[string]string),
}
}

func (te *arwenTestExecutor) replaceCode(pathInTest, actualPath string) *arwenTestExecutor {
te.contractPathReplacements[pathInTest] = actualPath
return te
}

// ProcessCode takes the contract file path, assembles it and yields the bytecode.
func (te *arwenTestExecutor) ProcessCode(testPath string, value string) (string, error) {
if len(value) == 0 {
return "", nil
}
fullPath := filepath.Join(testPath, value)
var fullPath string
if replacement, shouldReplace := te.contractPathReplacements[value]; shouldReplace {
fullPath = replacement
} else {
fullPath = filepath.Join(testPath, value)
}
scCode, err := ioutil.ReadFile(fullPath)
if err != nil {
return "", err
Expand Down
22 changes: 0 additions & 22 deletions cmd/test/node_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/test/testRunUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
worldhook "github.com/ElrondNetwork/elrond-vm-util/mock-hook-blockchain"

vmi "github.com/ElrondNetwork/elrond-vm-common"
ij "github.com/ElrondNetwork/elrond-vm-util/test-util/ielejson"
ij "github.com/ElrondNetwork/elrond-vm-util/test-util/vmtestjson"
)

// for nicer error messages
Expand Down
61 changes: 61 additions & 0 deletions cmd/test/vm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"path/filepath"
"testing"

controller "github.com/ElrondNetwork/elrond-vm-util/test-util/testcontroller"
)

var excludedTests = []string{}

func TestErc20FromC(t *testing.T) {
testExec := newArwenTestExecutor().replaceCode(
"erc20.wasm",
filepath.Join(getTestRoot(), "contracts/erc20-c.wasm"))

err := controller.RunAllJSONTestsInDirectory(
getTestRoot(),
"erc20",
".json",
excludedTests,
testExec)

if err != nil {
t.Error(err)
}
}

func TestErc20FromRustDebug(t *testing.T) {
testExec := newArwenTestExecutor().replaceCode(
"erc20.wasm",
filepath.Join(getTestRoot(), "contracts/erc20-rust-debug.wasm"))

err := controller.RunAllJSONTestsInDirectory(
getTestRoot(),
"erc20",
".json",
excludedTests,
testExec)

if err != nil {
t.Error(err)
}
}

func TestErc20FromRustRelease(t *testing.T) {
testExec := newArwenTestExecutor().replaceCode(
"erc20.wasm",
filepath.Join(getTestRoot(), "contracts/erc20-rust-release.wasm"))

err := controller.RunAllJSONTestsInDirectory(
getTestRoot(),
"erc20",
".json",
excludedTests,
testExec)

if err != nil {
t.Error(err)
}
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/ElrondNetwork/arwen-wasm-vm
go 1.13

require (
github.com/ElrondNetwork/elrond-vm-common v0.0.9
github.com/ElrondNetwork/elrond-vm-util v0.0.6
github.com/ElrondNetwork/elrond-vm-common v0.1.1
github.com/ElrondNetwork/elrond-vm-util v0.0.7
github.com/ElrondNetwork/go-ext-wasm v0.0.7
github.com/mitchellh/mapstructure v1.1.2
github.com/stretchr/testify v1.3.0
github.com/stretchr/testify v1.4.0
)
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
github.com/ElrondNetwork/elrond-vm-common v0.0.9 h1:Ff8vEJSKChRfmp+TVo7AgciRkMXjL4+TbNin6LQ7xKw=
github.com/ElrondNetwork/elrond-vm-common v0.0.9/go.mod h1:VqCCN0cX0e4D/KDc7MGNV9ElrOsfnjuJnGvcODVjzbk=
github.com/ElrondNetwork/elrond-vm-util v0.0.6 h1:+F0UBUt9WT2l/HHFg9SxmXdoM6PU/gXe/xtJ3gt6YhA=
github.com/ElrondNetwork/elrond-vm-util v0.0.6/go.mod h1:dpR1oCiP5isV9PPcVu2gEQ+GS7DF9BqtsG1juCATmvc=
github.com/ElrondNetwork/elrond-vm-common v0.1.1 h1:QuTFNlwfhjxqTwKsByt6xPr/FFGt7nR2DoJoxX80s+8=
github.com/ElrondNetwork/elrond-vm-common v0.1.1/go.mod h1:ZakxPST/Wt8umnRtA9gobcy3Dw2bywxwkC54P5VhO9g=
github.com/ElrondNetwork/elrond-vm-util v0.0.7 h1:Q+vRwD9YAxFEB1kw3rY5P8xKCMFuzGLH3PiNoNp2IjQ=
github.com/ElrondNetwork/elrond-vm-util v0.0.7/go.mod h1:EbijIwcul0wQ9ydTN4z1dU29DnYV2vudpeuAkUo1h20=
github.com/ElrondNetwork/go-ext-wasm v0.0.7 h1:GZJXG9xCeK1oQZDyLXvSf1i4QeYpG0lxrXqSQEnfd8Y=
github.com/ElrondNetwork/go-ext-wasm v0.0.7/go.mod h1:wlns4D0OzJP+q/cLweFz1rGpoZOG8LbGYX2jD31HCgw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
Expand All @@ -13,6 +15,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand All @@ -23,3 +27,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
File renamed without changes.
Binary file added test/contracts/erc20-rust-debug.wasm
Binary file not shown.
Binary file added test/contracts/erc20-rust-release.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions test/erc20/allowance_CallerCaller.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
},
"blocks": [
Expand Down Expand Up @@ -74,7 +74,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/erc20/allowance_CallerOther.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
},
"blocks": [
Expand Down Expand Up @@ -74,7 +74,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/erc20/allowance_OtherCaller.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
},
"blocks": [
Expand Down Expand Up @@ -74,7 +74,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/erc20/allowance_OtherEqOther.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
},
"blocks": [
Expand Down Expand Up @@ -74,7 +74,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/erc20/allowance_OtherNEqOther.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
},
"blocks": [
Expand Down Expand Up @@ -74,7 +74,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/erc20/approve_Caller-Negative.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
},
"blocks": [
Expand Down Expand Up @@ -72,7 +72,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/erc20/approve_Caller-Positive.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
},
"blocks": [
Expand Down Expand Up @@ -85,7 +85,7 @@
"0x028697c15331677e6ebf0b00000000008697c15331677e6ebf0b000000000000": "0x25",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/erc20/approve_Caller-Zero.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
},
"blocks": [
Expand Down Expand Up @@ -84,7 +84,7 @@
"0x0100a94f5374fce5edbc8e2a8697c15331677e6ebf0b00000000000000000000": "0x2710",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x2710"
},
"code": "wrc20_arwen.wasm"
"code": "erc20.wasm"
}
}
}
Expand Down
Loading

0 comments on commit 31ac890

Please sign in to comment.