diff --git a/main.go b/state.go similarity index 99% rename from main.go rename to state.go index 6472a30..170eb21 100644 --- a/main.go +++ b/state.go @@ -1,4 +1,4 @@ -package main +package vm import "bytes" import "encoding/hex" diff --git a/state_test.go b/state_test.go new file mode 100644 index 0000000..83f9935 --- /dev/null +++ b/state_test.go @@ -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]) + } +}