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

Add specific push opcodes for different data types #7

Merged
merged 10 commits into from
Apr 8, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
*.out

.idea/
vendor/
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: go

go:
- "1.11.x"

script:
- go test -v ./... -coverprofile=coverage.out -coverpkg=./...

after_success:
- go build
14 changes: 14 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github.com/bazo-blockchain/bazo-vm

go 1.12

require (
github.com/bazo-blockchain/bazo-miner v0.0.0-20190202131416-70aeba0cc925
github.com/google/go-cmp v0.2.0 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/willf/bitset v1.1.10 // indirect
github.com/willf/bloom v2.0.3+incompatible // indirect
golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5
gotest.tools v2.2.0+incompatible
)
18 changes: 18 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
github.com/bazo-blockchain/bazo-miner v0.0.0-20190202131416-70aeba0cc925 h1:nSe2r9vdKDML8Vu6aV3T6zMkhmoOg/irdEgDSfY9PQ0=
github.com/bazo-blockchain/bazo-miner v0.0.0-20190202131416-70aeba0cc925/go.mod h1:mss6+SSsouoT/kKCIiQSONh972tLbCVORAxq/PzvCa8=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/willf/bitset v1.1.10 h1:NotGKqX0KwQ72NUzqrjZq5ipPNDQex9lo3WpaS8L2sc=
github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/willf/bloom v2.0.3+incompatible h1:QDacWdqcAUI1MPOwIQZRy9kOR7yxfyEmxX8Wdm2/JPA=
github.com/willf/bloom v2.0.3+incompatible/go.mod h1:MmAltL9pDMNTrvUkxdg0k0q5I0suxmuwp3KbyrZLOZ8=
golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5 h1:bselrhR0Or1vomJZC8ZIjWtbDmn9OYFLX5Ik9alpJpE=
golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e h1:nFYrTHrdrAOpShe27kaFHjsqYSEQ0KWqdWLu3xuZJts=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
5 changes: 3 additions & 2 deletions vm/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/bazo-blockchain/bazo-miner/protocol"
)

// Function generates random bytes, if an exception occurs, it is catched and printed out with the random bytes,
// Function generates random bytes, if an exception occurs, it is caught and printed out with the random bytes,
// so the specific failing test can be recreated
func Fuzz() {
code := protocol.RandomBytes()
Expand All @@ -25,8 +25,9 @@ func Fuzz() {
vm.Exec(false)
}

// TODO: Write proper Fuzz test
func TestFuzz(t *testing.T) {
for i := 0; i <= 5000000; i++ {
Fuzz()
// Fuzz()
}
}
2 changes: 1 addition & 1 deletion vm/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type Map []byte

func NewMap() Map {
func CreateMap() Map {
return []byte{0x01, 0x00, 0x00}
}

Expand Down
22 changes: 11 additions & 11 deletions vm/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
)

func Test_NewMap(t *testing.T) {
m := NewMap()
m := CreateMap()

if len(m) != 3 {
t.Errorf("Expected a Byte Array with size 3 but got %v", len(m))
}
}

func TestMap_IncerementSize(t *testing.T) {
m := NewMap()
m := CreateMap()

s, err := ByteArrayToUI16(m[1:3])
if s != 0 || err != nil {
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestMap_DecrementSize(t *testing.T) {
}

func TestMap_Append(t *testing.T) {
m := NewMap()
m := CreateMap()
k := []byte{0x01}
v := []byte{0x64, 0x00}
err := m.Append(k, v)
Expand All @@ -68,15 +68,15 @@ func TestMap_Append(t *testing.T) {
}

func TestMap_ContainsKey_EmptyMap(t *testing.T) {
m := NewMap()
m := CreateMap()
actual, _ := m.MapContainsKey([]byte{0x00})
if actual {
t.Errorf("Didn't expect map to contain key")
}
}

func TestMap_ContainsKey_false(t *testing.T) {
m := NewMap()
m := CreateMap()
m.Append([]byte{0x02}, []byte{0x01, 0x02})
m.Append([]byte{0x05}, []byte{0x01, 0x02})
m.Append([]byte{0x03}, []byte{0x01, 0x02})
Expand All @@ -88,7 +88,7 @@ func TestMap_ContainsKey_false(t *testing.T) {
}

func TestMap_ContainsKey_true(t *testing.T) {
m := NewMap()
m := CreateMap()
m.Append([]byte{0x02}, []byte{0x01, 0x02})
m.Append([]byte{0x05}, []byte{0x01, 0x02})
m.Append([]byte{0x00}, []byte{0x01, 0x02})
Expand All @@ -100,7 +100,7 @@ func TestMap_ContainsKey_true(t *testing.T) {
}

func TestMap_GetVal(t *testing.T) {
m := NewMap()
m := CreateMap()
m.Append([]byte{0x00}, []byte{0x00})
m.Append([]byte{0x01}, []byte{0x01, 0x01})
m.Append([]byte{0x02, 0x00}, []byte{0x02, 0x02, 0x02})
Expand All @@ -126,7 +126,7 @@ func TestMap_GetVal(t *testing.T) {
}

func TestMap_SetVal(t *testing.T) {
actual := NewMap()
actual := CreateMap()
actual.Append([]byte{0x00}, []byte{0x00})
actual.Append([]byte{0x02, 0x00}, []byte{0x02, 0x02, 0x02})

Expand All @@ -135,7 +135,7 @@ func TestMap_SetVal(t *testing.T) {
t.Errorf("Expected map size to be '4' but was '%v'", size)
}

expected := NewMap()
expected := CreateMap()
expected.Append([]byte{0x00}, []byte{0x00})
expected.Append([]byte{0x02, 0x00}, []byte{0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04})

Expand All @@ -157,7 +157,7 @@ func TestMap_SetVal(t *testing.T) {
}

func TestMap_Remove(t *testing.T) {
actual := NewMap()
actual := CreateMap()
actual.Append([]byte{0x00}, []byte{0x00})
actual.Append([]byte{0x01}, []byte{0x01, 0x01})
actual.Append([]byte{0x02, 0x00}, []byte{0x02, 0x02, 0x02})
Expand All @@ -168,7 +168,7 @@ func TestMap_Remove(t *testing.T) {
t.Errorf("Expected map size to be '4' but was '%v'", size)
}

expected := NewMap()
expected := CreateMap()
expected.Append([]byte{0x00}, []byte{0x00})
expected.Append([]byte{0x01}, []byte{0x01, 0x01})
expected.Append([]byte{0x03, 0x00, 0x00}, []byte{0x03, 0x03, 0x03, 0x03, 0x03})
Expand Down
Loading