Skip to content

Commit

Permalink
[Cosmos]: add Sommelier support (#3076)
Browse files Browse the repository at this point in the history
  • Loading branch information
Milerius committed Apr 13, 2023
1 parent 78bc410 commit ca7bd5a
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:

jobs:
build:
runs-on: macos-latest-xl
runs-on: macos-latest
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ios-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:

jobs:
build:
runs-on: macos-latest-xl
runs-on: macos-latest
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/kotlin-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:

jobs:
build:
runs-on: macos-latest-xl
runs-on: macos-latest
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,6 @@ class CoinAddressDerivationTests {
NATIVECANTO -> assertEquals("canto13u6g7vqgw074mgmf2ze2cadzvkz9snlwqua5pd", address)
COMDEX -> assertEquals("comdex142j9u5eaduzd7faumygud6ruhdwme98qhtgm0y", address)
NEUTRON -> assertEquals("neutron142j9u5eaduzd7faumygud6ruhdwme98q5mrmv5", address)
SOMMELIER -> assertEquals("somm142j9u5eaduzd7faumygud6ruhdwme98quc948e", address)
}
}
1 change: 1 addition & 0 deletions docs/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ This list is generated from [./registry.json](../registry.json)
| 10009000 | Avalanche C-Chain | AVAX | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/avalanchec/info/logo.png" width="32" /> | <https://www.avalabs.org/> |
| 10009001 | Evmos | EVMOS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/evmos/info/logo.png" width="32" /> | <https://evmos.org/> |
| 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/> |
| 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 @@ -142,6 +142,7 @@ enum TWCoinType {
TWCoinTypeNativeCanto = 10007700,
TWCoinTypeComdex = 80000118,
TWCoinTypeNeutron = 90000118,
TWCoinTypeSommelier = 11000118,
};

/// Returns the blockchain for a coin type.
Expand Down
29 changes: 29 additions & 0 deletions registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,35 @@
"documentation": "https://docs.neutron.org/"
}
},
{
"id": "sommelier",
"name": "Sommelier",
"displayName": "Sommelier",
"coinId": 11000118,
"symbol": "SOMM",
"decimals": 6,
"chainId": "sommelier-3",
"blockchain": "Cosmos",
"derivation": [
{
"path": "m/44'/118'/0'/0/0"
}
],
"curve": "secp256k1",
"publicKeyType": "secp256k1",
"hrp": "somm",
"addressHasher": "sha256ripemd",
"explorer": {
"url": "https://www.mintscan.io/sommelier",
"txPath": "/txs/",
"accountPath": "/account/",
"sampleTx": "E73A9E5E534777DDADF7F69A5CB41972894B862D1763FA4081FE913D8D3A5E80",
"sampleAccount": "somm10d5wmqvezwtj20u5hg3wuvwucce2nhsy0tzqgn"
},
"info": {
"url": "https://www.sommelier.finance/"
}
},
{
"id": "zcash",
"name": "Zcash",
Expand Down
3 changes: 0 additions & 3 deletions src/Cosmos/Address.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class Address: public Bech32Address {
public:
Address() : Bech32Address("") {}

/// Initializes an address with a key hash, with prefix of the given coin.
Address(TWCoinType coin, const Data& keyHash) : Bech32Address(stringForHRP(TW::hrp(coin)), keyHash) {}

/// Initializes an address with a key hash, with given prefix.
Address(const std::string& hrp, const Data& keyHash) : Bech32Address(hrp, keyHash) {}

Expand Down
3 changes: 3 additions & 0 deletions swift/Tests/CoinAddressDerivationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ class CoinAddressDerivationTests: XCTestCase {
case .neutron:
let expectedResult = "neutron142j9u5eaduzd7faumygud6ruhdwme98q5mrmv5"
assertCoinDerivation(coin, expectedResult, derivedAddress, address)
case .sommelier:
let expectedResult = "somm142j9u5eaduzd7faumygud6ruhdwme98quc948e"
assertCoinDerivation(coin, expectedResult, derivedAddress, address)
@unknown default:
fatalError()
}
Expand Down
4 changes: 4 additions & 0 deletions tests/chains/Cosmos/AddressTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

namespace TW::Cosmos {

TEST(CosmosAddressAddressToData, Invalid) {
ASSERT_TRUE(addressToData(TWCoinTypeCosmos, "fake").empty());
}

TEST(CosmosAddress, Valid) {
ASSERT_TRUE(Address::isValid(TWCoinTypeBinance, "bnb1grpf0955h0ykzq3ar5nmum7y6gdfl6lxfn46h2"));
}
Expand Down
19 changes: 19 additions & 0 deletions tests/chains/Cosmos/Sommelier/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 gSommelierAddr = "somm1mry47pkga5tdswtluy0m8teslpalkdq0jalzdl";
static const std::string gSommelierHrp = "somm";

TEST(TWSommelierAnyAddress, AllSommelierAddressTests) {
CosmosAddressParameters parameters{.hrp = gSommelierHrp, .coinType = TWCoinTypeSommelier, .address = gSommelierAddr};
TestCosmosAddressParameters(parameters);
}

}
37 changes: 37 additions & 0 deletions tests/chains/Cosmos/Sommelier/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(TWSommelierCoinType, TWCoinType) {
const auto coin = TWCoinTypeSommelier;
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("E73A9E5E534777DDADF7F69A5CB41972894B862D1763FA4081FE913D8D3A5E80"));
const auto txUrl = WRAPS(TWCoinTypeConfigurationGetTransactionURL(coin, txId.get()));
const auto accId = WRAPS(TWStringCreateWithUTF8Bytes("somm10d5wmqvezwtj20u5hg3wuvwucce2nhsy0tzqgn"));
const auto accUrl = WRAPS(TWCoinTypeConfigurationGetAccountURL(coin, accId.get()));

assertStringsEqual(id, "sommelier");
assertStringsEqual(name, "Sommelier");
assertStringsEqual(symbol, "SOMM");
ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(coin), 6);
ASSERT_EQ(TWCoinTypeBlockchain(coin), TWBlockchainCosmos);
ASSERT_EQ(TWCoinTypeP2shPrefix(coin), 0x0);
ASSERT_EQ(TWCoinTypeStaticPrefix(coin), 0x0);
assertStringsEqual(chainId, "sommelier-3");
assertStringsEqual(txUrl, "https://www.mintscan.io/sommelier/txs/E73A9E5E534777DDADF7F69A5CB41972894B862D1763FA4081FE913D8D3A5E80");
assertStringsEqual(accUrl, "https://www.mintscan.io/sommelier/account/somm10d5wmqvezwtj20u5hg3wuvwucce2nhsy0tzqgn");
}
3 changes: 3 additions & 0 deletions tests/common/CoinAddressDerivationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ TEST(Coin, DeriveAddress) {
case TWCoinTypeNeutron:
EXPECT_EQ(address, "neutron1hkfq3zahaqkkzx5mjnamwjsfpq2jk7z0aykpkx");
break;
case TWCoinTypeSommelier:
EXPECT_EQ(address, "somm1hkfq3zahaqkkzx5mjnamwjsfpq2jk7z048s0at");
break;
// no default branch here, intentionally, to better notice any missing coins
}
}
Expand Down

0 comments on commit ca7bd5a

Please sign in to comment.