Graphon based Clustering and Testing of Networks: Algorithms and Theory