Turning tests that were buried in client into unit tests and added test ...

Turning tests that were buried in client into unit tests and added test showing problem with grain reference in grain state.  I ended up creating these while chasing a different bug, and thought you might want the unit tests contributed as a starting point.  Basically this gets you this:

![image](https://cloud.githubusercontent.com/assets/7763701/3143373/2d9bb4f2-e9f7-11e3-8526-4ada6027b037.png)

Hope you don't mind if I contribute...