Fix tests and add an upgrade test