[tw] [tx] add the test cases and refactoring