Skip to content

Commit

Permalink
Add derive address test cases (#172)
Browse files Browse the repository at this point in the history
* Add derive address test cases

* Use binance test as main coin
  • Loading branch information
vikmeup authored Mar 17, 2019
1 parent a569836 commit 05b5ad1
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ DerivationPath TW::derivationPath(TWCoinType coin) {
std::string TW::deriveAddress(TWCoinType coin, const PrivateKey& privateKey) {
switch (coin) {
case TWCoinTypeBinance:
return Tendermint::Address(HRP_BINANCE, privateKey.getPublicKey(PublicKeyType::secp256k1)).string();
return Tendermint::Address(HRP_BINANCE_TEST, privateKey.getPublicKey(PublicKeyType::secp256k1)).string();

case TWCoinTypeBitcoin:
return Bitcoin::Bech32Address(privateKey.getPublicKey(PublicKeyType::secp256k1), 0, HRP_BITCOIN).string();
Expand Down
74 changes: 74 additions & 0 deletions swift/Tests/CoinAddressDerivationTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright © 2017-2019 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.

import XCTest
import TrustWalletCore

class CoinAddressDerivationTests: XCTestCase {

func testDerive() {
let wallet = HDWallet(mnemonic: "shoot island position soft burden budget tooth cruel issue economy destroy above", passphrase: "")

for _ in 0..<4 {
for coin in CoinType.allCases {
let privateKey = wallet.getKeyForCoin(coin: coin)
let address = coin.deriveAddress(privateKey: privateKey)
switch coin {
case .aion:
XCTAssertEqual("0xa0629f34c9ea4757ad0b275628d4d02e3db6c9009ba2ceeba76a5b55fb2ca42e", address)
case .binance:
XCTAssertEqual("tbnb12vtaxl9952zm6rwf7v8jerq74pvaf77fkw9xhl", address)
case .bitcoin:
XCTAssertEqual("bc1quvuarfksewfeuevuc6tn0kfyptgjvwsvrprk9d", address)
case .bitcoinCash:
XCTAssertEqual("bitcoincash:qpzl3jxkzgvfd9flnd26leud5duv795fnv7vuaha70", address)
case .callisto:
XCTAssertEqual("0x3E6FFC80745E6669135a76F4A7ce6BCF02436e04", address)
case .dash:
XCTAssertEqual("XqHiz8EXYbTAtBEYs4pWTHh7ipEDQcNQeT", address)
case .ethereum:
XCTAssertEqual("0x8f348F300873Fd5DA36950B2aC75a26584584feE", address)
case .ethereumClassic:
XCTAssertEqual("0x078bA3228F3E6C08bEEac9A005de0b7e7089aD1c", address)
case .go:
XCTAssertEqual("0x5940ce4A14210d4Ccd0ac206CE92F21828016aC2", address)
case .icon:
XCTAssertEqual("hx18b380b53c23dc4ee9f6666bc20d1be02f3fe106", address)
case .litecoin:
XCTAssertEqual("ltc1qhd8fxxp2dx3vsmpac43z6ev0kllm4n53t5sk0u", address)
case .poa:
XCTAssertEqual("0xe8a3e8bE17E172B6926130eAfB521e9D2849aca9", address)
case .ripple:
XCTAssertEqual("rPwE3gChNKtZ1mhH3Ko8YFGqKmGRWLWXV3", address)
case .tezos:
XCTAssertEqual("tz1acnY9VbMagps26Kj3RfoGRWD9nYG5qaRX", address)
case .thunderToken:
XCTAssertEqual("0x4b92b3ED6d8b24575Bf5ce4C6a86ED261DA0C8d7", address)
case .tomoChain:
XCTAssertEqual("0xC74b6D8897cBa9A4b659d43fEF73C9cA852cE424", address)
case .tron:
XCTAssertEqual("TQ5NMqJjhpQGK7YJbESKtNCo86PJ89ujio", address)
case .veChain:
XCTAssertEqual("0x1a553275dF34195eAf23942CB7328AcF9d48c160", address)
case .wanChain:
XCTAssertEqual("0xD5ca90b928279FE5D06144136a25DeD90127aC15", address)
case .xdai:
XCTAssertEqual("0x364d0551599B97EAf997bc06c8c40Aaf73124402", address)
case .zcash:
XCTAssertEqual("t3ZEo7WrSBB1o1DCUytPsnUfoEoZn2qL5er", address)
case .zcoin:
XCTAssertEqual("aEd5XFChyXobvEics2ppAqgK3Bgusjxtik", address)
case .nimiq:
XCTAssertEqual("NQ76 7AVR EHDA N05U X7SY XB14 XJU7 8ERV GM6H", address)
case .stellar:
XCTAssertEqual("GA3H6I4C5XUBYGVB66KXR27JV5KS3APSTKRUWOIXZ5MVWZKVTLXWKZ2P", address)
case .neo:
XCTAssertEqual("AUa3rzbGJe7MbHf8Kra9em8oaLBL1MDYKF", address)
}
}
}
}
}
4 changes: 4 additions & 0 deletions swift/TrustWalletCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
14FDB4B82236BC9B002FC058 /* Signer.h in Headers */ = {isa = PBXBuildFile; fileRef = 14FDB4B62236BC9B002FC058 /* Signer.h */; };
14FDB4BB2236BDBD002FC058 /* Stellar.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 14FDB4B92236BDBC002FC058 /* Stellar.pb.cc */; };
14FDB4BC2236BDBD002FC058 /* Stellar.pb.h in Headers */ = {isa = PBXBuildFile; fileRef = 14FDB4BA2236BDBD002FC058 /* Stellar.pb.h */; };
29587DC8223E08B300BAD800 /* CoinAddressDerivationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29587DC6223E08A600BAD800 /* CoinAddressDerivationTests.swift */; };
34339D36023473D76FAF18EE /* Pods_TrustWalletCore_TrustWalletCoreTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B3B8FA185E5408ACD70CFB5 /* Pods_TrustWalletCore_TrustWalletCoreTests.framework */; };
467181FB9EFC0E4C01DDB460 /* Pods_TrustWalletCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36F25C48C7A120965C189BCE /* Pods_TrustWalletCore.framework */; };
4E8BBE8C2230998600F98E04 /* RLP.h in Headers */ = {isa = PBXBuildFile; fileRef = 4E8BBE852230998500F98E04 /* RLP.h */; };
Expand Down Expand Up @@ -632,6 +633,7 @@
14FDB4B62236BC9B002FC058 /* Signer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Signer.h; sourceTree = "<group>"; };
14FDB4B92236BDBC002FC058 /* Stellar.pb.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Stellar.pb.cc; sourceTree = "<group>"; };
14FDB4BA2236BDBD002FC058 /* Stellar.pb.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Stellar.pb.h; sourceTree = "<group>"; };
29587DC6223E08A600BAD800 /* CoinAddressDerivationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoinAddressDerivationTests.swift; sourceTree = "<group>"; };
36F25C48C7A120965C189BCE /* Pods_TrustWalletCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TrustWalletCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4E8BBE852230998500F98E04 /* RLP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RLP.h; path = Aion/RLP.h; sourceTree = "<group>"; };
4E8BBE862230998500F98E04 /* Transaction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Transaction.cpp; path = Aion/Transaction.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1717,6 +1719,7 @@
61E813EF2227585900D4D2C9 /* PublicKeyTests.swift */,
61E813F12227586800D4D2C9 /* PurposeTests.swift */,
61E813F32227587600D4D2C9 /* SlipTests.swift */,
29587DC6223E08A600BAD800 /* CoinAddressDerivationTests.swift */,
61C4E904222613DC0020A917 /* Addresses */,
61C4E905222613E70020A917 /* Blockchains */,
61A6250D2236DA1A009C450C /* Keystore */,
Expand Down Expand Up @@ -2782,6 +2785,7 @@
6198EA8021B6BFC9008CB60A /* DataTests.swift in Sources */,
61E813E62227535A00D4D2C9 /* BinanceChainTests.swift in Sources */,
61C4E920222615120020A917 /* BitcoinAddressTests.swift in Sources */,
29587DC8223E08B300BAD800 /* CoinAddressDerivationTests.swift in Sources */,
61C4E91E2226150F0020A917 /* WanchainTests.swift in Sources */,
61E81434222758E100D4D2C9 /* PublicKeyTests.swift in Sources */,
61E81432222758E100D4D2C9 /* PrivateKeyTests.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion tests/CoinTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TEST(Coin, validateAddressZcash) {
TEST(Coin, DeriveAddress) {
const auto privateKey = PrivateKey(parse_hex("0x4646464646464646464646464646464646464646464646464646464646464646"));
EXPECT_EQ(TW::deriveAddress(TWCoinTypeAion, privateKey), "0xa0010b0ea04ba4d76ca6e5e9900bacf19bc4402eaec7e36ea7ddd8eed48f60f3");
EXPECT_EQ(TW::deriveAddress(TWCoinTypeBinance, privateKey), "bnb1hkfq3zahaqkkzx5mjnamwjsfpq2jk7z0mlq0d0");
EXPECT_EQ(TW::deriveAddress(TWCoinTypeBinance, privateKey), "tbnb1hkfq3zahaqkkzx5mjnamwjsfpq2jk7z042ftd7");
EXPECT_EQ(TW::deriveAddress(TWCoinTypeBitcoin, privateKey), "bc1qhkfq3zahaqkkzx5mjnamwjsfpq2jk7z00ppggv");
EXPECT_EQ(TW::deriveAddress(TWCoinTypeBitcoinCash, privateKey), "bitcoincash:qz7eyzytkl5z6cg6nw20hd62pyyp22mcfuardfd2vn");
EXPECT_EQ(TW::deriveAddress(TWCoinTypeCallisto, privateKey), "0x9d8A62f656a8d1615C1294fd71e9CFb3E4855A4F");
Expand Down

0 comments on commit 05b5ad1

Please sign in to comment.