Skip to content

Commit

Permalink
[Cosmos]: add neutron support (#3074)
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius committed Apr 12, 2023
1 parent c4ed980 commit b8d3462
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,6 @@ class CoinAddressDerivationTests {
KUJIRA -> assertEquals("kujira142j9u5eaduzd7faumygud6ruhdwme98qpvgpme", address)
NATIVECANTO -> assertEquals("canto13u6g7vqgw074mgmf2ze2cadzvkz9snlwqua5pd", address)
COMDEX -> assertEquals("comdex142j9u5eaduzd7faumygud6ruhdwme98qhtgm0y", address)
NEUTRON -> assertEquals("neutron142j9u5eaduzd7faumygud6ruhdwme98q5mrmv5", address)
}
}
1 change: 1 addition & 0 deletions docs/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,5 @@ This list is generated from [./registry.json](../registry.json)
| 60000118 | Crescent | CRE | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/crescent/info/logo.png" width="32" /> | <https://crescent.network/> |
| 70000118 | Kujira | KUJI | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/kujira/info/logo.png" width="32" /> | <https://kujira.app/> |
| 80000118 | Comdex | CMDX | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/comdex/info/logo.png" width="32" /> | <https://comdex.one/> |
| 90000118 | Neutron | NTRN | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/neutron/info/logo.png" width="32" /> | <https://neutron.org/> |
| 1323161554 | Aurora | ETH | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/aurora/info/logo.png" width="32" /> | <https://aurora.dev/> |
1 change: 1 addition & 0 deletions include/TrustWalletCore/TWCoinType.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ enum TWCoinType {
TWCoinTypeIoTeXEVM = 10004689,
TWCoinTypeNativeCanto = 10007700,
TWCoinTypeComdex = 80000118,
TWCoinTypeNeutron = 90000118,
};

/// Returns the blockchain for a coin type.
Expand Down
30 changes: 30 additions & 0 deletions registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,36 @@
"documentation": "https://docs.comdex.one/"
}
},
{
"id": "neutron",
"name": "Neutron",
"displayName": "Neutron",
"coinId": 90000118,
"symbol": "NTRN",
"decimals": 6,
"chainId": "baryon-1",
"blockchain": "Cosmos",
"derivation": [
{
"path": "m/44'/118'/0'/0/0"
}
],
"curve": "secp256k1",
"publicKeyType": "secp256k1",
"hrp": "neutron",
"addressHasher": "sha256ripemd",
"explorer": {
"url": "https://testnet.mintscan.io/neutron-testnet",
"txPath": "/txs/",
"accountPath": "/account/",
"sampleTx": "E18BA087009A05EB6A15A22FE30BA99379B909F74A74120E6F92B9882C45F0D7",
"sampleAccount": "neutron1pm4af8pcurxssdxztqw9rexx5f8zfq7uzqfmy8"
},
"info": {
"url": "https://neutron.org/",
"documentation": "https://docs.neutron.org/"
}
},
{
"id": "zcash",
"name": "Zcash",
Expand Down
3 changes: 3 additions & 0 deletions swift/Tests/CoinAddressDerivationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ class CoinAddressDerivationTests: XCTestCase {
case .comdex:
let expectedResult = "comdex142j9u5eaduzd7faumygud6ruhdwme98qhtgm0y"
assertCoinDerivation(coin, expectedResult, derivedAddress, address)
case .neutron:
let expectedResult = "neutron142j9u5eaduzd7faumygud6ruhdwme98q5mrmv5"
assertCoinDerivation(coin, expectedResult, derivedAddress, address)
@unknown default:
fatalError()
}
Expand Down
19 changes: 19 additions & 0 deletions tests/chains/Cosmos/Neutron/TWAnyAddressTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 "../CosmosTestHelpers.h"

namespace TW::Cosmos::tests {

static const std::string gNeutronAddr = "neutron1mry47pkga5tdswtluy0m8teslpalkdq067evxj";
static const std::string gNeutronHrp = "neutron";

TEST(TWNeutronAnyAddress, AllNeutronAddressTests) {
CosmosAddressParameters parameters{.hrp = gNeutronHrp, .coinType = TWCoinTypeNeutron, .address = gNeutronAddr};
TestCosmosAddressParameters(parameters);
}

}
37 changes: 37 additions & 0 deletions tests/chains/Cosmos/Neutron/TWCoinTypeTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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.
//
// This is a GENERATED FILE, changes made here MAY BE LOST.
// Generated one-time (codegen/bin/cointests)
//

#include "TestUtilities.h"
#include <TrustWalletCore/TWCoinTypeConfiguration.h>
#include <gtest/gtest.h>


TEST(TWNeutronCoinType, TWCoinType) {
const auto coin = TWCoinTypeNeutron;
const auto symbol = WRAPS(TWCoinTypeConfigurationGetSymbol(coin));
const auto id = WRAPS(TWCoinTypeConfigurationGetID(coin));
const auto name = WRAPS(TWCoinTypeConfigurationGetName(coin));
const auto chainId = WRAPS(TWCoinTypeChainId(coin));
const auto txId = WRAPS(TWStringCreateWithUTF8Bytes("E18BA087009A05EB6A15A22FE30BA99379B909F74A74120E6F92B9882C45F0D7"));
const auto txUrl = WRAPS(TWCoinTypeConfigurationGetTransactionURL(coin, txId.get()));
const auto accId = WRAPS(TWStringCreateWithUTF8Bytes("neutron1pm4af8pcurxssdxztqw9rexx5f8zfq7uzqfmy8"));
const auto accUrl = WRAPS(TWCoinTypeConfigurationGetAccountURL(coin, accId.get()));

assertStringsEqual(id, "neutron");
assertStringsEqual(name, "Neutron");
assertStringsEqual(symbol, "NTRN");
ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(coin), 6);
ASSERT_EQ(TWCoinTypeBlockchain(coin), TWBlockchainCosmos);
ASSERT_EQ(TWCoinTypeP2shPrefix(coin), 0x0);
ASSERT_EQ(TWCoinTypeStaticPrefix(coin), 0x0);
assertStringsEqual(chainId, "baryon-1");
assertStringsEqual(txUrl, "https://testnet.mintscan.io/neutron-testnet/txs/E18BA087009A05EB6A15A22FE30BA99379B909F74A74120E6F92B9882C45F0D7");
assertStringsEqual(accUrl, "https://testnet.mintscan.io/neutron-testnet/account/neutron1pm4af8pcurxssdxztqw9rexx5f8zfq7uzqfmy8");
}
3 changes: 3 additions & 0 deletions tests/common/CoinAddressDerivationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ TEST(Coin, DeriveAddress) {
case TWCoinTypeComdex:
EXPECT_EQ(address, "comdex1hkfq3zahaqkkzx5mjnamwjsfpq2jk7z075ap4k");
break;
case TWCoinTypeNeutron:
EXPECT_EQ(address, "neutron1hkfq3zahaqkkzx5mjnamwjsfpq2jk7z0aykpkx");
break;
// no default branch here, intentionally, to better notice any missing coins
}
}
Expand Down

0 comments on commit b8d3462

Please sign in to comment.