From e9daff6b366e997ed42e7b2db562ef51e773bd95 Mon Sep 17 00:00:00 2001 From: fjchen7 Date: Wed, 1 Dec 2021 17:12:15 +0800 Subject: [PATCH] fix: replace short address with bech32m full address in test cases (#511) --- .../java/constant/AddressWithKeyHolder.java | 20 +++++++++----- .../test/java/org/nervos/api/CkbApiTest.java | 4 ++- .../api/mercury/QueryTransactionsTest.java | 3 ++- .../constant/AddressWithKeyHolder.java | 20 +++++++++----- .../test/java/transaction/LockUtilsTest.java | 3 ++- .../ckb/utils/address/AddressGenerator.java | 15 ++++++----- .../ckb/utils/address/AddressTools.java | 27 ++++++++++--------- .../src/test/java/utils/AddressToolsTest.java | 15 +++++++---- .../org/nervos/ckb/address/AddressUtils.java | 8 +++--- 9 files changed, 70 insertions(+), 45 deletions(-) diff --git a/ckb-api/src/test/java/constant/AddressWithKeyHolder.java b/ckb-api/src/test/java/constant/AddressWithKeyHolder.java index c8ec0b799..0fd041ac1 100644 --- a/ckb-api/src/test/java/constant/AddressWithKeyHolder.java +++ b/ckb-api/src/test/java/constant/AddressWithKeyHolder.java @@ -10,30 +10,36 @@ public class AddressWithKeyHolder { private static Map addressWithPubKey = new HashMap<>(8); //// 0xa3b8598e1d53e6c5e89e8acb6b4c34d3adb13f2b - private static String TEST_ADDRESS0 = "ckt1qyq28wze3cw48ek9az0g4jmtfs6d8td38u4s6hp2s0"; + private static String TEST_ADDRESS0 = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqdrhpvcu82numz73852ed45cdxn4kcn72cr4338a"; private static String TEST_PUBKEY0 = "0xa3b8598e1d53e6c5e89e8acb6b4c34d3adb13f2b"; //// 0xaf0b41c627807fbddcee75afa174d5a7e5135ebd - private static String TEST_ADDRESS1 = "ckt1qyq27z6pccncqlaamnh8ttapwn260egnt67ss2cwvz"; + private static String TEST_ADDRESS1 = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqd0pdquvfuq077aemn447shf4d8u5f4a0glzz2g4"; private static String TEST_PUBKEY1 = "0xaf0b41c627807fbddcee75afa174d5a7e5135ebd"; //// 0x05a1fabfa84db9e538e2e7fe3ca9adf849f55ce0 - private static String TEST_ADDRESS2 = "ckt1qyqqtg06h75ymw098r3w0l3u4xklsj04tnsqctqrmc"; + private static String TEST_ADDRESS2 = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf"; private static String TEST_PUBKEY2 = "0x05a1fabfa84db9e538e2e7fe3ca9adf849f55ce0"; //// 0x202647fecc5b9d8cbdb4ae7167e40f5ab1e4baaf - private static String TEST_ADDRESS3 = "ckt1qyqzqfj8lmx9h8vvhk62uut8us844v0yh2hsnqvvgc"; + private static String TEST_ADDRESS3 = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqfqyerlanzmnkxtmd9ww9n7gr66k8jt4tclm9jnk"; private static String TEST_PUBKEY3 = "0x202647fecc5b9d8cbdb4ae7167e40f5ab1e4baaf"; //// 0x839f1806e85b40c13d3c73866045476cc9a8c214 - private static String TEST_ADDRESS4 = "ckt1qyqg88ccqm59ksxp85788pnqg4rkejdgcg2qxcu2qf"; + private static String TEST_ADDRESS4 = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvrnuvqd6zmgrqn60rnsesy23mvex5vy9q0g8hfd"; private static String TEST_PUBKEY4 = "0x839f1806e85b40c13d3c73866045476cc9a8c214"; - private static String CEX_ADDRESS = "ckt1qyqz50qxup4cw2dvg0exg8y9m5e90dykuh6q72rj0h"; + private static String CEX_ADDRESS = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqf28srwq6u89xky8unyrjza6vjhkjtwtaqm5z887"; private static String CEX_PUBKEY = "0x2a3c06e06b8729ac43f2641c85dd3257b496e5f4"; private static String QUERY_TRANSACTION_ADDRESS = - "ckt1qyqp5nlkxkvwgwhee4pryj4mwetl4pyut0psq2h92t"; + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg6flmrtx8y8tuu6s3jf2ahv4l6sjw9hsc3t4tqv"; private static String QUERY_TRANSACTION_PUBKEY = "0x1a4ff63598e43af9cd42324abb7657fa849c5bc3"; static { diff --git a/ckb-api/src/test/java/org/nervos/api/CkbApiTest.java b/ckb-api/src/test/java/org/nervos/api/CkbApiTest.java index 87c5b2bc1..21b589497 100644 --- a/ckb-api/src/test/java/org/nervos/api/CkbApiTest.java +++ b/ckb-api/src/test/java/org/nervos/api/CkbApiTest.java @@ -90,7 +90,9 @@ private void mercuryApi(MercuryApi api) { try { GetBalancePayloadBuilder builder = new GetBalancePayloadBuilder(); - builder.item(ItemFactory.newAddressItem("ckt1qyq28wze3cw48ek9az0g4jmtfs6d8td38u4s6hp2s0")); + builder.item( + ItemFactory.newAddressItem( + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqdrhpvcu82numz73852ed45cdxn4kcn72cr4338a")); System.out.println(g.toJson(builder.build())); diff --git a/ckb-api/src/test/java/org/nervos/api/mercury/QueryTransactionsTest.java b/ckb-api/src/test/java/org/nervos/api/mercury/QueryTransactionsTest.java index 062bbc860..00f82571f 100644 --- a/ckb-api/src/test/java/org/nervos/api/mercury/QueryTransactionsTest.java +++ b/ckb-api/src/test/java/org/nervos/api/mercury/QueryTransactionsTest.java @@ -132,7 +132,8 @@ void testQueryTransactionsCellbase() { try { - String minerAddress = "ckt1qyqd5eyygtdmwdr7ge736zw6z0ju6wsw7rssu8fcve"; + String minerAddress = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqw6vjzy9kahx3lyvlgap8dp8ewd8g80pcgcexzrj"; QueryTransactionsPayloadBuilder builder = new QueryTransactionsPayloadBuilder(); builder.item(ItemFactory.newAddressItem(minerAddress)); builder.addAssetInfo(AssetInfo.newCkbAsset()); diff --git a/ckb-mercury-sdk/src/test/java/mercury/constant/AddressWithKeyHolder.java b/ckb-mercury-sdk/src/test/java/mercury/constant/AddressWithKeyHolder.java index fd6bebbd5..061abe3dc 100644 --- a/ckb-mercury-sdk/src/test/java/mercury/constant/AddressWithKeyHolder.java +++ b/ckb-mercury-sdk/src/test/java/mercury/constant/AddressWithKeyHolder.java @@ -10,30 +10,36 @@ public class AddressWithKeyHolder { private static Map addressWithPubKey = new HashMap<>(8); //// 0xa3b8598e1d53e6c5e89e8acb6b4c34d3adb13f2b - private static String TEST_ADDRESS0 = "ckt1qyq28wze3cw48ek9az0g4jmtfs6d8td38u4s6hp2s0"; + private static String TEST_ADDRESS0 = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqdrhpvcu82numz73852ed45cdxn4kcn72cr4338a"; private static String TEST_PUBKEY0 = "0xa3b8598e1d53e6c5e89e8acb6b4c34d3adb13f2b"; //// 0xaf0b41c627807fbddcee75afa174d5a7e5135ebd - private static String TEST_ADDRESS1 = "ckt1qyq27z6pccncqlaamnh8ttapwn260egnt67ss2cwvz"; + private static String TEST_ADDRESS1 = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqd0pdquvfuq077aemn447shf4d8u5f4a0glzz2g4"; private static String TEST_PUBKEY1 = "0xaf0b41c627807fbddcee75afa174d5a7e5135ebd"; //// 0x05a1fabfa84db9e538e2e7fe3ca9adf849f55ce0 - private static String TEST_ADDRESS2 = "ckt1qyqqtg06h75ymw098r3w0l3u4xklsj04tnsqctqrmc"; + private static String TEST_ADDRESS2 = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf"; private static String TEST_PUBKEY2 = "0x05a1fabfa84db9e538e2e7fe3ca9adf849f55ce0"; //// 0x202647fecc5b9d8cbdb4ae7167e40f5ab1e4baaf - private static String TEST_ADDRESS3 = "ckt1qyqzqfj8lmx9h8vvhk62uut8us844v0yh2hsnqvvgc"; + private static String TEST_ADDRESS3 = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqfqyerlanzmnkxtmd9ww9n7gr66k8jt4tclm9jnk"; private static String TEST_PUBKEY3 = "0x202647fecc5b9d8cbdb4ae7167e40f5ab1e4baaf"; //// 0x839f1806e85b40c13d3c73866045476cc9a8c214 - private static String TEST_ADDRESS4 = "ckt1qyqg88ccqm59ksxp85788pnqg4rkejdgcg2qxcu2qf"; + private static String TEST_ADDRESS4 = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvrnuvqd6zmgrqn60rnsesy23mvex5vy9q0g8hfd"; private static String TEST_PUBKEY4 = "0x839f1806e85b40c13d3c73866045476cc9a8c214"; - private static String CEX_ADDRESS = "ckt1qyqz50qxup4cw2dvg0exg8y9m5e90dykuh6q72rj0h"; + private static String CEX_ADDRESS = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqf28srwq6u89xky8unyrjza6vjhkjtwtaqm5z887"; private static String CEX_PUBKEY = "0x2a3c06e06b8729ac43f2641c85dd3257b496e5f4"; private static String QUERY_TRANSACTION_ADDRESS = - "ckt1qyqp5nlkxkvwgwhee4pryj4mwetl4pyut0psq2h92t"; + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg6flmrtx8y8tuu6s3jf2ahv4l6sjw9hsc3t4tqv"; private static String QUERY_TRANSACTION_PUBKEY = "0x1a4ff63598e43af9cd42324abb7657fa849c5bc3"; static { diff --git a/ckb/src/test/java/transaction/LockUtilsTest.java b/ckb/src/test/java/transaction/LockUtilsTest.java index f1aea57b6..31947ca89 100644 --- a/ckb/src/test/java/transaction/LockUtilsTest.java +++ b/ckb/src/test/java/transaction/LockUtilsTest.java @@ -22,7 +22,8 @@ public void testGenerateLockScriptWithPrivateKey() { @Test public void testGenerateLockScriptWithAddress() { Script lock = - LockUtils.generateLockScriptWithAddress("ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83"); + LockUtils.generateLockScriptWithAddress( + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqdrhpvcu82numz73852ed45cdxn4kcn72cr4338a"); Assertions.assertEquals( "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", lock.codeHash); Assertions.assertEquals("0x36c329ed630d6ce750712a477543672adab57f4c", lock.args); diff --git a/core/src/main/java/org/nervos/ckb/utils/address/AddressGenerator.java b/core/src/main/java/org/nervos/ckb/utils/address/AddressGenerator.java index d3c9d6877..cc0207377 100644 --- a/core/src/main/java/org/nervos/ckb/utils/address/AddressGenerator.java +++ b/core/src/main/java/org/nervos/ckb/utils/address/AddressGenerator.java @@ -25,9 +25,10 @@ public static String generate(Network network, Script script) { } /** - * Short address format is deprecated because it is limited (only supports secp256k1_blake160, secp256k1_multisig, anyone_can_pay) - * and a flaw has been found in its encoding method bech32, which could enable attackers to generate valid but unexpected addresses. - * For more please check https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md + * Short address format is deprecated because it is limited (only supports secp256k1_blake160, + * secp256k1_multisig, anyone_can_pay) and a flaw has been found in its encoding method bech32, + * which could enable attackers to generate valid but unexpected addresses. For more please check + * https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md */ @Deprecated public static String generateShortAddress(Network network, Script script) { @@ -65,9 +66,10 @@ public static String generateShortAddress(Network network, Script script) { } /** - * Old full address format is deprecated because a flaw has been found in its encoding method bech32, which could enable - * attackers to generate valid but unexpected addresses. - * For more please check https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md + * Old full address format is deprecated because a flaw has been found in its encoding method + * bech32, which could enable attackers to generate valid but unexpected addresses. For more + * please check + * https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md */ @Deprecated public static String generateFullAddress(Network network, Script script) { @@ -80,7 +82,6 @@ public static String generateFullAddress(Network network, Script script) { prefix(network), convertBits(com.google.common.primitives.Bytes.asList(data), 8, 5, true)); } - public static String generateBech32mFullAddress(Network network, Script script) { // Payload: type(00) | code hash | hash type | args diff --git a/core/src/main/java/org/nervos/ckb/utils/address/AddressTools.java b/core/src/main/java/org/nervos/ckb/utils/address/AddressTools.java index aabfdefc8..482898a12 100644 --- a/core/src/main/java/org/nervos/ckb/utils/address/AddressTools.java +++ b/core/src/main/java/org/nervos/ckb/utils/address/AddressTools.java @@ -30,9 +30,10 @@ public static AddressGenerateResult generateAddress(Network network) } /** - * Short address format is deprecated because it is limited (only support secp256k1_blake160, secp256k1_multisig, anyone_can_pay) - * and a flaw has been found in its encoding method bech32, which could enable attackers to generate valid but unexpected addresses. - * For more please check https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md + * Short address format is deprecated because it is limited (only support secp256k1_blake160, + * secp256k1_multisig, anyone_can_pay) and a flaw has been found in its encoding method bech32, + * which could enable attackers to generate valid but unexpected addresses. For more please check + * https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md */ @Deprecated public static AddressGenerateResult generateShortAddress(Network network) @@ -55,9 +56,10 @@ public static AddressGenerateResult generateShortAddress(Network network) } /** - * Old full address format is deprecated because a flaw has been found in its encoding method bech32, which could enable - * attackers to generate valid but unexpected addresses. - * For more please check https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md + * Old full address format is deprecated because a flaw has been found in its encoding method + * bech32, which could enable attackers to generate valid but unexpected addresses. For more + * please check + * https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md */ @Deprecated public static AddressGenerateResult generateFullAddress(Network network) @@ -100,9 +102,10 @@ public static String convertPublicKeyToAddress(Network network, String publicKey } /** - * Short address format deprecated because it is limited (only support secp256k1_blake160, secp256k1_multisig, anyone_can_pay) - * and a flaw has been found in its encoding method bech32, which could enable attackers to generate valid but unexpected addresses. - * For more please check https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md + * Short address format deprecated because it is limited (only support secp256k1_blake160, + * secp256k1_multisig, anyone_can_pay) and a flaw has been found in its encoding method bech32, + * which could enable attackers to generate valid but unexpected addresses. For more please check + * https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md */ @Deprecated public static String convertPublicKeyToShortAddress(Network network, String publicKey) { @@ -115,9 +118,9 @@ public static String convertPublicKeyToShortAddress(Network network, String publ } /** - * Old full address format deprecated because a flaw has been found in its encoding method bech32, which could enable - * attackers to generate valid but unexpected addresses. - * For more please check https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md + * Old full address format deprecated because a flaw has been found in its encoding method bech32, + * which could enable attackers to generate valid but unexpected addresses. For more please check + * https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md */ @Deprecated public static String convertPublicKeyToFullAddress(Network network, String publicKey) { diff --git a/core/src/test/java/utils/AddressToolsTest.java b/core/src/test/java/utils/AddressToolsTest.java index 90aa6019d..8f15aa0b7 100644 --- a/core/src/test/java/utils/AddressToolsTest.java +++ b/core/src/test/java/utils/AddressToolsTest.java @@ -97,7 +97,8 @@ void testConvertPublicKeyToAddress() { @Test void testGenerateAcpAddress() { String expected = "ckt1qypqtg06h75ymw098r3w0l3u4xklsj04tnsqkm65q6"; - String address = "ckt1qyqqtg06h75ymw098r3w0l3u4xklsj04tnsqctqrmc"; + String address = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf"; String actual = AddressTools.generateAcpAddress(address); @@ -108,8 +109,10 @@ void testGenerateAcpAddress() { void testGenerateChequeAddress() { String expected = "ckt1qpsdtuu7lnjqn3v8ew02xkwwlh4dv5x2z28shkwt8p2nfruccux4kq2je6sm0zczgrepc8y547zvuu6zpshfvvjh7h2ln2w035d2lnh32ylk5ydmjq5ypwq24ftzt"; - String senderAddress = "ckt1qyq27z6pccncqlaamnh8ttapwn260egnt67ss2cwvz"; - String receiverAddress = "ckt1qyqqtg06h75ymw098r3w0l3u4xklsj04tnsqctqrmc"; + String senderAddress = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqd0pdquvfuq077aemn447shf4d8u5f4a0glzz2g4"; + String receiverAddress = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf"; String actual = AddressTools.generateChequeAddress(senderAddress, receiverAddress); @@ -118,14 +121,16 @@ void testGenerateChequeAddress() { @Test void testParseAddress() { - String address = "ckt1qyqqtg06h75ymw098r3w0l3u4xklsj04tnsqctqrmc"; + String address = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf"; AddressParseResult script = AddressTools.parse(address); System.out.println(new Gson().toJson(script)); } @Test void testParseNetwork() { - String address = "ckt1qyqqtg06h75ymw098r3w0l3u4xklsj04tnsqctqrmc"; + String address = + "ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf"; Assertions.assertEquals(Network.TESTNET, AddressTools.parseNetwork(address)); } } diff --git a/utils/src/main/java/org/nervos/ckb/address/AddressUtils.java b/utils/src/main/java/org/nervos/ckb/address/AddressUtils.java index 968466588..71a4f4853 100644 --- a/utils/src/main/java/org/nervos/ckb/address/AddressUtils.java +++ b/utils/src/main/java/org/nervos/ckb/address/AddressUtils.java @@ -16,10 +16,10 @@ * and [Common Address Format](https://github.com/nervosnetwork/ckb/wiki/Common-Address-Format). * Currently we implement the predefined format for type 0x01 and code hash index 0x00. * - * Deprecated: - * Short address and old full address format are deprecated because a flaw has been found in its encoding method bech32, which could enable - * attackers to generate valid but unexpected addresses. - * For more please check https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md + *

Deprecated: Short address and old full address format are deprecated because a flaw has been + * found in its encoding method bech32, which could enable attackers to generate valid but + * unexpected addresses. For more information please check + * https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md */ @Deprecated public class AddressUtils {