Fix integer overflow in StateEditor
Add StateEditorTest