rewrite most of test.rs to use higher level abstraction API