@Test
public void getToAddress() throws Exception {

    // pay to pubkey
    ECKey toKey = new ECKey();
    Address toAddress = toKey.toAddress(PARAMS);
    assertEquals(toAddress, ScriptBuilder.createOutputScript(toKey).getToAddress(PARAMS, true));
    // pay to pubkey hash
    assertEquals(toAddress, ScriptBuilder.createOutputScript(toAddress).getToAddress(PARAMS, true));
    // pay to script hash
    Script p2shScript = ScriptBuilder.createP2SHOutputScript(new byte[20]);
    Address scriptAddress = Address.fromP2SHScript(PARAMS, p2shScript);
    assertEquals(scriptAddress, p2shScript.getToAddress(PARAMS, true));
}