-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dYdX): Add support for dYdX Cosmos chain (#3671)
* feat(dYdX): Add support for dYdX Cosmos chain * feat(dYdX): Fix Kotlin tests
- Loading branch information
1 parent
24f24c1
commit d42429b
Showing
15 changed files
with
208 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...oid/app/src/androidTest/java/com/trustwallet/core/app/blockchains/dydx/TestDydxAddress.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
package com.trustwallet.core.app.blockchains.dydx | ||
|
||
import com.trustwallet.core.app.utils.toHexByteArray | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import wallet.core.jni.* | ||
|
||
class TestDydxAddress { | ||
|
||
init { | ||
System.loadLibrary("TrustWalletCore") | ||
} | ||
|
||
@Test | ||
fun testAddress() { | ||
val key = PrivateKey("a498a9ee41af9bab5ef2a8be63d5c970135c3c109e70efc8c56c534e6636b433".toHexByteArray()) | ||
val pubKey = key.getPublicKeySecp256k1(true) | ||
val address = AnyAddress(pubKey, CoinType.DYDX) | ||
val expected = AnyAddress("dydx1mry47pkga5tdswtluy0m8teslpalkdq0hc72uz", CoinType.DYDX) | ||
|
||
assertEquals(address.description(), expected.description()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
use tw_any_coin::test_utils::address_utils::{ | ||
test_address_bech32_is_valid, test_address_create_bech32_with_public_key, | ||
test_address_get_data, test_address_invalid, test_address_normalization, test_address_valid, | ||
AddressBech32IsValid, AddressCreateBech32WithPublicKey, | ||
}; | ||
use tw_coin_registry::coin_type::CoinType; | ||
use tw_keypair::tw::PublicKeyType; | ||
|
||
#[test] | ||
fn test_dydx_address_normalization() { | ||
test_address_normalization( | ||
CoinType::Dydx, | ||
"dydx1adl7usw7z2dnysyn7wvrghu0u0q6gr7jqs4gtt", | ||
"dydx1adl7usw7z2dnysyn7wvrghu0u0q6gr7jqs4gtt", | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_dydx_address_is_valid() { | ||
test_address_valid( | ||
CoinType::Dydx, | ||
"dydxvaloper1gf9yvztyvnc3aqrkjd8hfnaf8pk56sl7mzfage", | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_dydx_address_invalid() { | ||
test_address_invalid( | ||
CoinType::Dydx, | ||
"dydxvaloper1gf9yvztyvnc3aqrkjd8hfnaf8pk56sl7mz", | ||
); | ||
// Cosmos has a different `hrp`. | ||
test_address_invalid( | ||
CoinType::Cosmos, | ||
"dydx1adl7usw7z2dnysyn7wvrghu0u0q6gr7jqs4gtt", | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_dydx_address_get_data() { | ||
test_address_get_data( | ||
CoinType::Dydx, | ||
"dydxvaloper1gf9yvztyvnc3aqrkjd8hfnaf8pk56sl7mzfage", | ||
"424a46096464f11e8076934f74cfa9386d4d43fe", | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_dydx_is_valid_bech32() { | ||
// Dydx address must be valid if its Base32 prefix passed. | ||
test_address_bech32_is_valid(AddressBech32IsValid { | ||
coin: CoinType::Dydx, | ||
address: "dydx1adl7usw7z2dnysyn7wvrghu0u0q6gr7jqs4gtt", | ||
hrp: "dydx", | ||
}); | ||
// Dydx address must be valid for the standard Cosmos hub if its Base32 prefix passed. | ||
test_address_bech32_is_valid(AddressBech32IsValid { | ||
coin: CoinType::Cosmos, | ||
address: "dydx1adl7usw7z2dnysyn7wvrghu0u0q6gr7jqs4gtt", | ||
hrp: "dydx", | ||
}); | ||
// Cosmos address must be valid with "cosmos" hrp. | ||
test_address_bech32_is_valid(AddressBech32IsValid { | ||
coin: CoinType::Dydx, | ||
address: "cosmos1hsk6jryyqjfhp5dhc55tc9jtckygx0eph6dd02", | ||
hrp: "cosmos", | ||
}); | ||
} | ||
|
||
#[test] | ||
fn test_any_address_create_bech32_with_public_key() { | ||
test_address_create_bech32_with_public_key(AddressCreateBech32WithPublicKey { | ||
coin: CoinType::Cosmos, | ||
private_key: "a498a9ee41af9bab5ef2a8be63d5c970135c3c109e70efc8c56c534e6636b433", | ||
public_key_type: PublicKeyType::Secp256k1, | ||
hrp: "dydx", | ||
expected: "dydx1mry47pkga5tdswtluy0m8teslpalkdq0hc72uz", | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
mod dydx_address; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
import WalletCore | ||
import XCTest | ||
|
||
class DydxTests: XCTestCase { | ||
func testAddress() { | ||
let key = PrivateKey(data: Data(hexString: "a498a9ee41af9bab5ef2a8be63d5c970135c3c109e70efc8c56c534e6636b433")!)! | ||
let pubkey = key.getPublicKeySecp256k1(compressed: true) | ||
let address = AnyAddress(publicKey: pubkey, coin: .dydx) | ||
let addressFromString = AnyAddress(string: "dydx1mry47pkga5tdswtluy0m8teslpalkdq0hc72uz", coin: .dydx)! | ||
|
||
XCTAssertEqual(address.description, addressFromString.description) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
#include "TestUtilities.h" | ||
#include <TrustWalletCore/TWCoinTypeConfiguration.h> | ||
#include <gtest/gtest.h> | ||
|
||
TEST(TWDydxCoinType, TWCoinType) { | ||
const auto coin = TWCoinTypeDydx; | ||
const auto symbol = WRAPS(TWCoinTypeConfigurationGetSymbol(coin)); | ||
const auto id = WRAPS(TWCoinTypeConfigurationGetID(coin)); | ||
const auto name = WRAPS(TWCoinTypeConfigurationGetName(coin)); | ||
const auto txId = WRAPS(TWStringCreateWithUTF8Bytes("F236222E4F7C92FA84711FD6451ED22DD56CBDFA319BFDAFB99A21E4E9B9EC2F")); | ||
const auto txUrl = WRAPS(TWCoinTypeConfigurationGetTransactionURL(coin, txId.get())); | ||
const auto accId = WRAPS(TWStringCreateWithUTF8Bytes("dydx1adl7usw7z2dnysyn7wvrghu0u0q6gr7jqs4gtt")); | ||
const auto accUrl = WRAPS(TWCoinTypeConfigurationGetAccountURL(coin, accId.get())); | ||
|
||
assertStringsEqual(id, "dydx"); | ||
assertStringsEqual(name, "dYdX"); | ||
assertStringsEqual(symbol, "DYDX"); | ||
ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(coin), 18); | ||
ASSERT_EQ(TWCoinTypeBlockchain(coin), TWBlockchainCosmos); | ||
ASSERT_EQ(TWCoinTypeP2pkhPrefix(coin), 0); | ||
ASSERT_EQ(TWCoinTypeP2shPrefix(coin), 0); | ||
ASSERT_EQ(TWCoinTypeStaticPrefix(coin), 0); | ||
assertStringsEqual(txUrl, "https://www.mintscan.io/dydx/tx/F236222E4F7C92FA84711FD6451ED22DD56CBDFA319BFDAFB99A21E4E9B9EC2F"); | ||
assertStringsEqual(accUrl, "https://www.mintscan.io/dydx/address/dydx1adl7usw7z2dnysyn7wvrghu0u0q6gr7jqs4gtt"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters