Skip to content

Commit

Permalink
[Cosmos]: Adding support for Mars (#3082)
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius authored Apr 14, 2023
1 parent 0e0e351 commit 55f9c7d
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,6 @@ class CoinAddressDerivationTests {
NEUTRON -> assertEquals("neutron142j9u5eaduzd7faumygud6ruhdwme98q5mrmv5", address)
SOMMELIER -> assertEquals("somm142j9u5eaduzd7faumygud6ruhdwme98quc948e", address)
FETCHAI -> assertEquals("fetch142j9u5eaduzd7faumygud6ruhdwme98qrera5y", address)
MARS -> assertEquals("mars142j9u5eaduzd7faumygud6ruhdwme98qdenqrg", address)
}
}
2 changes: 1 addition & 1 deletion coverage.stats
Original file line number Diff line number Diff line change
@@ -1 +1 @@
95.0
93.0
1 change: 1 addition & 0 deletions docs/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ This list is generated from [./registry.json](../registry.json)
| 10042221 | Arbitrum | ETH | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/arbitrum/info/logo.png" width="32" /> | <https://arbitrum.io> |
| 11000118 | Sommelier | SOMM | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/sommelier/info/logo.png" width="32" /> | <https://www.sommelier.finance/> |
| 12000118 | Fetch AI | FET | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/fetchai/info/logo.png" width="32" /> | <https://fetch.ai/> |
| 13000118 | Mars Hub | MARS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/mars/info/logo.png" width="32" /> | <https://marsprotocol.io/> |
| 20000118 | Stargaze | STARS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/stargaze/info/logo.png" width="32" /> | <https://www.stargaze.zone/> |
| 20000714 | BNB Smart Chain | BNB | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/smartchain/info/logo.png" width="32" /> | <https://www.binance.org/en/smartChain> |
| 20009001 | Native Evmos | EVMOS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/nativeevmos/info/logo.png" width="32" /> | <https://evmos.org/> |
Expand Down
1 change: 1 addition & 0 deletions include/TrustWalletCore/TWCoinType.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ enum TWCoinType {
TWCoinTypeNeutron = 90000118,
TWCoinTypeSommelier = 11000118,
TWCoinTypeFetchAI = 12000118,
TWCoinTypeMars = 13000118,
};

/// 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 @@ -786,6 +786,36 @@
"documentation": "https://docs.fetch.ai/"
}
},
{
"id": "mars",
"name": "Mars",
"displayName": "Mars Hub",
"coinId": 13000118,
"symbol": "MARS",
"decimals": 6,
"chainId": "mars-1",
"blockchain": "Cosmos",
"derivation": [
{
"path": "m/44'/118'/0'/0/0"
}
],
"curve": "secp256k1",
"publicKeyType": "secp256k1",
"hrp": "mars",
"addressHasher": "sha256ripemd",
"explorer": {
"url": "https://www.mintscan.io/mars-protocol",
"txPath": "/txs/",
"accountPath": "/account/",
"sampleTx": "C12120760C71189A678739E0F1FD4EFAF2C29EA660B57A359AC728F89FAA7528",
"sampleAccount": "mars1nnjy6nct405pzfaqjm3dsyw0pf0kyw72vhw4pr"
},
"info": {
"url": "https://marsprotocol.io/",
"documentation": "https://docs.marsprotocol.io/"
}
},
{
"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 @@ -311,6 +311,9 @@ class CoinAddressDerivationTests: XCTestCase {
case .fetchAI:
let expectedResult = "fetch142j9u5eaduzd7faumygud6ruhdwme98qrera5y"
assertCoinDerivation(coin, expectedResult, derivedAddress, address)
case .mars:
let expectedResult = "mars142j9u5eaduzd7faumygud6ruhdwme98qdenqrg"
assertCoinDerivation(coin, expectedResult, derivedAddress, address)
@unknown default:
fatalError()
}
Expand Down
19 changes: 19 additions & 0 deletions tests/chains/Cosmos/Mars/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 gMarsAddr = "mars1mry47pkga5tdswtluy0m8teslpalkdq0rufhfw";
static const std::string gMarsHrp = "mars";

TEST(TWMarsAnyAddress, AllMarsAddressTests) {
CosmosAddressParameters parameters{.hrp = gMarsHrp, .coinType = TWCoinTypeMars, .address = gMarsAddr};
TestCosmosAddressParameters(parameters);
}

}
38 changes: 38 additions & 0 deletions tests/chains/Cosmos/Mars/TWCoinTypeTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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>

namespace TW::Cosmos::tests {
TEST(TWMarsCoinType, TWCoinType) {
const auto coin = TWCoinTypeMars;
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("C12120760C71189A678739E0F1FD4EFAF2C29EA660B57A359AC728F89FAA7528"));
const auto txUrl = WRAPS(TWCoinTypeConfigurationGetTransactionURL(coin, txId.get()));
const auto accId = WRAPS(TWStringCreateWithUTF8Bytes("mars1nnjy6nct405pzfaqjm3dsyw0pf0kyw72vhw4pr"));
const auto accUrl = WRAPS(TWCoinTypeConfigurationGetAccountURL(coin, accId.get()));

assertStringsEqual(id, "mars");
assertStringsEqual(name, "Mars Hub");
assertStringsEqual(symbol, "MARS");
ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(coin), 6);
ASSERT_EQ(TWCoinTypeBlockchain(coin), TWBlockchainCosmos);
ASSERT_EQ(TWCoinTypeP2shPrefix(coin), 0x0);
ASSERT_EQ(TWCoinTypeStaticPrefix(coin), 0x0);
assertStringsEqual(chainId, "mars-1");
assertStringsEqual(txUrl, "https://www.mintscan.io/mars-protocol/txs/C12120760C71189A678739E0F1FD4EFAF2C29EA660B57A359AC728F89FAA7528");
assertStringsEqual(accUrl, "https://www.mintscan.io/mars-protocol/account/mars1nnjy6nct405pzfaqjm3dsyw0pf0kyw72vhw4pr");
}
}
3 changes: 3 additions & 0 deletions tests/common/CoinAddressDerivationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ TEST(Coin, DeriveAddress) {
case TWCoinTypeFetchAI:
EXPECT_EQ(address, "fetch1hkfq3zahaqkkzx5mjnamwjsfpq2jk7z02xk8wk");
break;
case TWCoinTypeMars:
EXPECT_EQ(address, "mars1hkfq3zahaqkkzx5mjnamwjsfpq2jk7z0yxx6e6");
break;
// no default branch here, intentionally, to better notice any missing coins
}
}
Expand Down

0 comments on commit 55f9c7d

Please sign in to comment.