Files
subcoding/vm/state_test.go
2021-11-16 20:41:57 -10:00

48 lines
1014 B
Go

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 := NewStateFromByteCode(functionByteCode)
if err != nil {
t.Fatal(err)
}
state.Execute()
if state.err != nil {
t.Fatal(state)
}
if state.globalMemory.mustReadUnsigned(0) != 3 {
t.Fatal(state.globalMemory.mustReadUnsigned(0))
}
}