add transaction unit test and fix bugs