From a97ecc0429e5810a93210c7356e8c690ba82d57f Mon Sep 17 00:00:00 2001 From: Milerius Date: Thu, 20 Apr 2023 17:10:33 +0200 Subject: [PATCH 1/3] feat(neutron): finalize neutron airdrop example --- registry.json | 2 +- .../Cosmos/Neutron/TWAnySignerTests.cpp | 99 +++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 tests/chains/Cosmos/Neutron/TWAnySignerTests.cpp diff --git a/registry.json b/registry.json index 011d4fd4c51..cfd091a77fc 100644 --- a/registry.json +++ b/registry.json @@ -704,7 +704,7 @@ "coinId": 90000118, "symbol": "NTRN", "decimals": 6, - "chainId": "baryon-1", + "chainId": "pion-1", "blockchain": "Cosmos", "derivation": [ { diff --git a/tests/chains/Cosmos/Neutron/TWAnySignerTests.cpp b/tests/chains/Cosmos/Neutron/TWAnySignerTests.cpp new file mode 100644 index 00000000000..af1de7832dc --- /dev/null +++ b/tests/chains/Cosmos/Neutron/TWAnySignerTests.cpp @@ -0,0 +1,99 @@ +// Copyright © 2017-2023 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. + +#include "Cosmos/Address.h" +#include "HexCoding.h" +#include "proto/Cosmos.pb.h" +#include + +#include "TestUtilities.h" +#include + +namespace TW::Cosmos::tests { + +TEST(TWAnySignerNeutron, SignAirdropNeutron) { + auto privateKey = parse_hex("37f0af5bc20adb6832d39368a15492cd1e9e0cc1556d4317a5f75f9ccdf525ee"); + Proto::SigningInput input; + input.set_signing_mode(Proto::Protobuf); + input.set_account_number(336); + input.set_chain_id("pion-1"); + input.set_memo(""); + input.set_sequence(0); + input.set_private_key(privateKey.data(), privateKey.size()); + + auto msg = input.add_messages(); + auto& message = *msg->mutable_wasm_execute_contract_generic(); + + const auto tokenContractAddress = "neutron1465d8udjudl6cd8kgdlh2s37p7q0cf9x7yveumqwqk6ng94qwnmq7n79qn"; + const auto txMessage = R"({"claim":{"address":"neutron19h42zjnls2tpmg6yylcg6nr56cjxcx35q6xt57", "proof":["404ae2093edcca979ccb6ae4a36689cebc9c2c6a2b00b106c5396b079bf6dcf5","282fee30a25a60904f54d4f74aee8fcf8dd2822799c43be733e18e15743d4ece","e10de4202fe6532329d0d463d9669f1b659920868b9ea87d6715bfd223a86a40","564b4122c6f98653153d8e09d5a5f659fa7ebea740aa6b689c94211f8a11cc4b"], "amount":"2000000"}})"; + + message.set_sender_address("neutron19h42zjnls2tpmg6yylcg6nr56cjxcx35q6xt57"); + message.set_contract_address(tokenContractAddress); + message.set_execute_msg(txMessage); + + auto& fee = *input.mutable_fee(); + fee.set_gas(666666); + auto amountOfFee = fee.add_amounts(); + amountOfFee->set_denom("untrn"); + amountOfFee->set_amount("1000"); + + Proto::SigningOutput output; + ANY_SIGN(input, TWCoinTypeNeutron); + + // https://www.mintscan.io/stargaze/txs/300836A5BF9002CF38EE34A8C56E8E7E6854FA64F1DEB3AE108F381A48150F7C + auto expectedJson = R"( + { + "mode":"BROADCAST_MODE_BLOCK", + "tx_bytes":"CpQECpEECiQvY29zbXdhc20ud2FzbS52MS5Nc2dFeGVjdXRlQ29udHJhY3QS6AMKLm5ldXRyb24xOWg0MnpqbmxzMnRwbWc2eXlsY2c2bnI1NmNqeGN4MzVxNnh0NTcSQm5ldXRyb24xNDY1ZDh1ZGp1ZGw2Y2Q4a2dkbGgyczM3cDdxMGNmOXg3eXZldW1xd3FrNm5nOTRxd25tcTduNzlxbhrxAnsiY2xhaW0iOnsiYWRkcmVzcyI6Im5ldXRyb24xOWg0MnpqbmxzMnRwbWc2eXlsY2c2bnI1NmNqeGN4MzVxNnh0NTciLCAicHJvb2YiOlsiNDA0YWUyMDkzZWRjY2E5NzljY2I2YWU0YTM2Njg5Y2ViYzljMmM2YTJiMDBiMTA2YzUzOTZiMDc5YmY2ZGNmNSIsIjI4MmZlZTMwYTI1YTYwOTA0ZjU0ZDRmNzRhZWU4ZmNmOGRkMjgyMjc5OWM0M2JlNzMzZTE4ZTE1NzQzZDRlY2UiLCJlMTBkZTQyMDJmZTY1MzIzMjlkMGQ0NjNkOTY2OWYxYjY1OTkyMDg2OGI5ZWE4N2Q2NzE1YmZkMjIzYTg2YTQwIiwiNTY0YjQxMjJjNmY5ODY1MzE1M2Q4ZTA5ZDVhNWY2NTlmYTdlYmVhNzQwYWE2YjY4OWM5NDIxMWY4YTExY2M0YiJdLCAiYW1vdW50IjoiMjAwMDAwMCJ9fRJlCk4KRgofL2Nvc21vcy5jcnlwdG8uc2VjcDI1NmsxLlB1YktleRIjCiECqPwhojhpWpB3vDr8R+qyUnDkcK3BPxS35F8OrHPq5WwSBAoCCAESEwoNCgV1bnRybhIEMTAwMBCq2CgaQMIEXC8zyuuXWuIeX7dZBBzxMjmheOP1ONitBrVZdwmuQUgClmwhOdW0JwRe8CJ5NUKqtDYZjKFAPKGEWQ2veDs=" + })"; + assertJSONEqual(output.serialized(), expectedJson); + EXPECT_EQ(hex(output.signature()), "c2045c2f33caeb975ae21e5fb759041cf13239a178e3f538d8ad06b5597709ae414802966c2139d5b427045ef022793542aab436198ca1403ca184590daf783b"); + EXPECT_EQ(output.json(), ""); + EXPECT_EQ(output.error(), ""); +} + +TEST(TWAnySignerNeutron, SignWithdrawAirdropNeutron) { + auto privateKey = parse_hex("37f0af5bc20adb6832d39368a15492cd1e9e0cc1556d4317a5f75f9ccdf525ee"); + Proto::SigningInput input; + input.set_signing_mode(Proto::Protobuf); + input.set_account_number(336); + input.set_chain_id("pion-1"); + input.set_memo(""); + input.set_sequence(1); + input.set_private_key(privateKey.data(), privateKey.size()); + + auto msg = input.add_messages(); + auto& message = *msg->mutable_wasm_execute_contract_generic(); + + const auto tokenContractAddress = "neutron1dv49y7afpq573yyk6zj2z4rn7gqh689plhtrf6223kqs8ee3tq9spqpuf2"; + const auto txMessage = R"({"withdraw":{"amount":"313468"}})"; + + message.set_sender_address("neutron19h42zjnls2tpmg6yylcg6nr56cjxcx35q6xt57"); + message.set_contract_address(tokenContractAddress); + message.set_execute_msg(txMessage); + + auto& fee = *input.mutable_fee(); + fee.set_gas(666666); + auto amountOfFee = fee.add_amounts(); + amountOfFee->set_denom("untrn"); + amountOfFee->set_amount("1000"); + + Proto::SigningOutput output; + ANY_SIGN(input, TWCoinTypeNeutron); + + // Successfully broadcasted: https://explorer.rs-testnet.polypore.xyz/pion-1/tx/28F25164B1E2556844C227819B1D5437960B7E91181B37460EC6792588FF7E4E + auto expectedJson = R"( + { + "mode":"BROADCAST_MODE_BLOCK", + "tx_bytes":"CsIBCr8BCiQvY29zbXdhc20ud2FzbS52MS5Nc2dFeGVjdXRlQ29udHJhY3QSlgEKLm5ldXRyb24xOWg0MnpqbmxzMnRwbWc2eXlsY2c2bnI1NmNqeGN4MzVxNnh0NTcSQm5ldXRyb24xZHY0OXk3YWZwcTU3M3l5azZ6ajJ6NHJuN2dxaDY4OXBsaHRyZjYyMjNrcXM4ZWUzdHE5c3BxcHVmMhogeyJ3aXRoZHJhdyI6eyJhbW91bnQiOiIzMTM0NjgifX0SZwpQCkYKHy9jb3Ntb3MuY3J5cHRvLnNlY3AyNTZrMS5QdWJLZXkSIwohAqj8IaI4aVqQd7w6/EfqslJw5HCtwT8Ut+RfDqxz6uVsEgQKAggBGAESEwoNCgV1bnRybhIEMTAwMBCq2CgaQN/zzFyDC2i/lvQUNJ9Y24sWlDsAx2pa+p7KPAIiya+TNrsVrgW9jq83gi8OPhS/+/47hPH8LYOR41TijWnLgDA=" + })"; + assertJSONEqual(output.serialized(), expectedJson); + EXPECT_EQ(hex(output.signature()), "dff3cc5c830b68bf96f414349f58db8b16943b00c76a5afa9eca3c0222c9af9336bb15ae05bd8eaf37822f0e3e14bffbfe3b84f1fc2d8391e354e28d69cb8030"); + EXPECT_EQ(output.json(), ""); + EXPECT_EQ(output.error(), ""); +} + +} // namespace TW::Cosmos::tests From a903081a3a23332142658e388165cfdd5bf0bea6 Mon Sep 17 00:00:00 2001 From: Milerius Date: Thu, 20 Apr 2023 17:12:01 +0200 Subject: [PATCH 2/3] feat(neutron): update cointype --- tests/chains/Cosmos/Neutron/TWCoinTypeTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/chains/Cosmos/Neutron/TWCoinTypeTests.cpp b/tests/chains/Cosmos/Neutron/TWCoinTypeTests.cpp index 3dfb7e34cdf..12108bf6668 100644 --- a/tests/chains/Cosmos/Neutron/TWCoinTypeTests.cpp +++ b/tests/chains/Cosmos/Neutron/TWCoinTypeTests.cpp @@ -31,7 +31,7 @@ TEST(TWNeutronCoinType, TWCoinType) { ASSERT_EQ(TWCoinTypeBlockchain(coin), TWBlockchainCosmos); ASSERT_EQ(TWCoinTypeP2shPrefix(coin), 0x0); ASSERT_EQ(TWCoinTypeStaticPrefix(coin), 0x0); - assertStringsEqual(chainId, "baryon-1"); + assertStringsEqual(chainId, "pion-1"); assertStringsEqual(txUrl, "https://testnet.mintscan.io/neutron-testnet/txs/E18BA087009A05EB6A15A22FE30BA99379B909F74A74120E6F92B9882C45F0D7"); assertStringsEqual(accUrl, "https://testnet.mintscan.io/neutron-testnet/account/neutron1pm4af8pcurxssdxztqw9rexx5f8zfq7uzqfmy8"); } From b3a410d25e77dcfadba7cb607ea9aa2b66239278 Mon Sep 17 00:00:00 2001 From: Milerius Date: Thu, 20 Apr 2023 17:13:06 +0200 Subject: [PATCH 3/3] feat(neutron): update broadcasted url --- tests/chains/Cosmos/Neutron/TWAnySignerTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/chains/Cosmos/Neutron/TWAnySignerTests.cpp b/tests/chains/Cosmos/Neutron/TWAnySignerTests.cpp index af1de7832dc..0724f191629 100644 --- a/tests/chains/Cosmos/Neutron/TWAnySignerTests.cpp +++ b/tests/chains/Cosmos/Neutron/TWAnySignerTests.cpp @@ -43,7 +43,7 @@ TEST(TWAnySignerNeutron, SignAirdropNeutron) { Proto::SigningOutput output; ANY_SIGN(input, TWCoinTypeNeutron); - // https://www.mintscan.io/stargaze/txs/300836A5BF9002CF38EE34A8C56E8E7E6854FA64F1DEB3AE108F381A48150F7C + // Successfully broadcasted: https://explorer.rs-testnet.polypore.xyz/pion-1/tx/28F25164B1E2556844C227819B1D5437960B7E91181B37460EC6792588FF7E4E auto expectedJson = R"( { "mode":"BROADCAST_MODE_BLOCK",