First test
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package vm
|
||||
|
||||
import "bytes"
|
||||
import "encoding/hex"
|
||||
47
state_test.go
Normal file
47
state_test.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package vm
|
||||
|
||||
import "encoding/hex"
|
||||
import "strings"
|
||||
import "testing"
|
||||
|
||||
func TestFirst(t *testing.T) {
|
||||
asm := [][]string{
|
||||
[]string{
|
||||
"0000020000000000010000000000000000000000000000000000000000000001",
|
||||
"0000000100000000000000000000000000000001000000000000000000000000",
|
||||
"0000030100000000010000000000000000000000000000000000000000000003",
|
||||
"000004010000000000000000fffffffffffffffd000000000000000000000000",
|
||||
},
|
||||
[]string{
|
||||
"0000020000000000020000000000000000000000000000000000000000000001",
|
||||
},
|
||||
}
|
||||
|
||||
functionByteCode := [][]byte{}
|
||||
|
||||
for _, fnc := range asm {
|
||||
fncString := strings.Join(fnc, "")
|
||||
|
||||
byteCode, err := hex.DecodeString(fncString)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
functionByteCode = append(functionByteCode, byteCode)
|
||||
}
|
||||
|
||||
state, err := NewState(functionByteCode)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
state.Execute()
|
||||
|
||||
if state.Error != nil {
|
||||
t.Fatal(state)
|
||||
}
|
||||
|
||||
if state.GlobalMemory[0] != 3 {
|
||||
t.Fatal(state.GlobalMemory[0])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user