-
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(ZetaChain): Add support for NativeZetaChain (#3669)
* feat(ZetaChain): Add `new-cosmos-chain` command * feat(ZetaChain): Add `NativeZetaChain` mainnet * feat(ZetaChain): Add support for custom Cosmos chain * feat(ZetaChain): Add `SignerInfo` to the Cosmos.proto protocol * feat(ZetaChain): Fix zetachain params in registry.json * feat(ZetaChain): Add mobile tests * [CI] Trigger CI * feat(ZetaChain): Update JSON Public Key Type * feat(ZetaChain): Fix `accountPath` in `registry.json` * feat(ZetaChain): Fix rustfmt * feat(ZetaChain): Slightly refactor NativeEvmos and NativeInjective public key types
- Loading branch information
1 parent
43bf58c
commit d02cb7d
Showing
62 changed files
with
991 additions
and
289 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
28 changes: 28 additions & 0 deletions
28
...t/java/com/trustwallet/core/app/blockchains/nativezetachain/TestNativeZetaChainAddress.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,28 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
package com.trustwallet.core.app.blockchains.nativezetachain | ||
|
||
import com.trustwallet.core.app.utils.toHex | ||
import com.trustwallet.core.app.utils.toHexByteArray | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import wallet.core.jni.* | ||
|
||
class TestNativeZetaChainAddress { | ||
|
||
init { | ||
System.loadLibrary("TrustWalletCore") | ||
} | ||
|
||
@Test | ||
fun testAddress() { | ||
val key = PrivateKey("8d2a3bd62d300a148c89dc8635f87b7a24a951bd1c4e78675fe40e1a640d46ed".toHexByteArray()) | ||
val pubKey = key.getPublicKeySecp256k1(false) | ||
val address = AnyAddress(pubKey, CoinType.NATIVEZETACHAIN) | ||
val expected = AnyAddress("zeta14py36sx57ud82t9yrks9z6hdsrpn5x6kmxs0ne", CoinType.NATIVEZETACHAIN) | ||
|
||
assertEquals(address.description(), expected.description()) | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...st/java/com/trustwallet/core/app/blockchains/nativezetachain/TestNativeZetaChainSigner.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,71 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
package com.trustwallet.core.app.blockchains.nativezetachain | ||
|
||
import com.google.protobuf.ByteString | ||
import com.trustwallet.core.app.utils.toHexByteArray | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import wallet.core.java.AnySigner | ||
import wallet.core.jni.AnyAddress | ||
import wallet.core.jni.CoinType | ||
import wallet.core.jni.PrivateKey | ||
import wallet.core.jni.proto.Cosmos | ||
|
||
class TestNativeZetaChainSigner { | ||
|
||
init { | ||
System.loadLibrary("TrustWalletCore") | ||
} | ||
|
||
@Test | ||
fun NativeZetaChainTransactionSigning() { | ||
val key = PrivateKey("8d2a3bd62d300a148c89dc8635f87b7a24a951bd1c4e78675fe40e1a640d46ed".toHexByteArray()) | ||
val publicKey = key.getPublicKeySecp256k1(false) | ||
val from = AnyAddress(publicKey, CoinType.NATIVEZETACHAIN).description() | ||
|
||
val transferAmount = Cosmos.Amount.newBuilder().apply { | ||
// 0.3 ZETA | ||
amount = "300000000000000000" | ||
denom = "azeta" | ||
}.build() | ||
|
||
val message = Cosmos.Message.newBuilder().apply { | ||
sendCoinsMessage = Cosmos.Message.Send.newBuilder().apply { | ||
fromAddress = from | ||
toAddress = "zeta1cscf4ldnkkz7f0wpveur6dpd0d6p2zxnsuu70y" | ||
addAllAmounts(listOf(transferAmount)) | ||
}.build() | ||
}.build() | ||
|
||
val transferFee = Cosmos.Fee.newBuilder().apply { | ||
gas = 200000 | ||
}.build() | ||
|
||
val signingInput = Cosmos.SigningInput.newBuilder().apply { | ||
signingMode = Cosmos.SigningMode.Protobuf | ||
accountNumber = 2726346 | ||
chainId = "athens_7001-1" | ||
sequence = 2 | ||
fee = transferFee | ||
privateKey = ByteString.copyFrom(key.data()) | ||
txHasher = Cosmos.TxHasher.Keccak256 | ||
signerInfo = Cosmos.SignerInfo.newBuilder().apply { | ||
// Zetachain requires a compressed public key to sign a transaction, | ||
// however an uncompressed public key is used to generate address. | ||
publicKeyType = Cosmos.SignerPublicKeyType.Secp256k1 | ||
jsonType = "ethermint/PubKeyEthSecp256k1" | ||
protobufType = "/ethermint.crypto.v1.ethsecp256k1.PubKey" | ||
}.build() | ||
addAllMessages(listOf(message)) | ||
}.build() | ||
|
||
val output = AnySigner.sign(signingInput, CoinType.NATIVEZETACHAIN, Cosmos.SigningOutput.parser()) | ||
|
||
// Successfully broadcasted (testnet): | ||
// https://explorer.zetachain.com/cosmos/tx/A2FC8816657856ED274C4418C3CAEAEE645561275F6C63AB5F8B1DCFB37341A0 | ||
assertEquals(output.serialized, "{\"mode\":\"BROADCAST_MODE_BLOCK\",\"tx_bytes\":\"CpoBCpcBChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEncKK3pldGExNHB5MzZzeDU3dWQ4MnQ5eXJrczl6Nmhkc3JwbjV4NmtteHMwbmUSK3pldGExY3NjZjRsZG5ra3o3ZjB3cHZldXI2ZHBkMGQ2cDJ6eG5zdXU3MHkaGwoFYXpldGESEjMwMDAwMDAwMDAwMDAwMDAwMBJhClkKTwooL2V0aGVybWludC5jcnlwdG8udjEuZXRoc2VjcDI1NmsxLlB1YktleRIjCiECho5+FjRBfbKt/Z/jggW/oP6gGJin/TBWXRP3BWo3wGUSBAoCCAEYAhIEEMCaDBpAgGvqca0w2N9wnHnnxS9HiVud4aQ9lNCumzgNIW6wOR4kvPScacGS1G3kwCw7wyI2NJL8M1eVYjafFIt2FpKl3w==\"}") | ||
} | ||
} |
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,20 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
use crate::codegen::cpp::tw_coin_address_derivation_tests_generator::CoinAddressDerivationTestsGenerator; | ||
use crate::codegen::cpp::tw_coin_type_generator::TWCoinTypeGenerator; | ||
use crate::codegen::cpp::tw_coin_type_tests_generator::TWCoinTypeTestsGenerator; | ||
use crate::registry::CoinItem; | ||
use crate::Result; | ||
|
||
pub fn new_cosmos_chain(coin: &CoinItem) -> Result<()> { | ||
// Add the new coin type to the `TWCoinType` enum. | ||
TWCoinTypeGenerator::generate_coin_type_variant(coin)?; | ||
|
||
// Add integration tests. | ||
TWCoinTypeTestsGenerator::generate(coin)?; | ||
CoinAddressDerivationTestsGenerator::generate_new_coin_type_case(coin)?; | ||
|
||
Ok(()) | ||
} |
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,16 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
use crate::codegen::rust::coin_address_derivation_test_generator::CoinAddressDerivationTestGenerator; | ||
use crate::codegen::rust::coin_integration_tests::CoinIntegrationTests; | ||
use crate::registry::CoinItem; | ||
use crate::Result; | ||
|
||
pub fn new_cosmos_chain(coin: &CoinItem) -> Result<()> { | ||
// Create integration tests. | ||
CoinIntegrationTests::new(coin.clone()).create_cosmos()?; | ||
CoinAddressDerivationTestGenerator::generate_new_coin_type_case(coin)?; | ||
|
||
Ok(()) | ||
} |
69 changes: 69 additions & 0 deletions
69
codegen-v2/src/codegen/rust/templates/integration_tests/cosmos_address_tests.rs
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,69 @@ | ||
// 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_{COIN_ID}_address_normalization() { | ||
test_address_normalization(CoinType::{COIN_TYPE}, "DENORMALIZED", "EXPECTED"); | ||
} | ||
|
||
#[test] | ||
fn test_{COIN_ID}_address_is_valid() { | ||
test_address_valid(CoinType::{COIN_TYPE}, "VALID {COIN_TYPE} ADDRESS"); | ||
} | ||
|
||
#[test] | ||
fn test_{COIN_ID}_address_invalid() { | ||
test_address_invalid(CoinType::{COIN_TYPE}, "INVALID ADDRESS"); | ||
// Cosmos has a different `hrp`. | ||
test_address_invalid(CoinType::Cosmos, "VALID {COIN_TYPE} ADDRESS"); | ||
} | ||
|
||
#[test] | ||
fn test_{COIN_ID}_address_get_data() { | ||
test_address_get_data(CoinType::{COIN_TYPE}, "ADDRESS", "HEX(DATA)"); | ||
} | ||
|
||
#[test] | ||
fn test_{COIN_ID}_is_valid_bech32() { | ||
// {COIN_TYPE} address must be valid if its Base32 prefix passed. | ||
test_address_bech32_is_valid(AddressBech32IsValid { | ||
coin: CoinType::{COIN_TYPE}, | ||
address: "{COIN_TYPE} ADDRESS", | ||
hrp: "{HRP}", | ||
}); | ||
// {COIN_TYPE} address must be valid for the standard Cosmos hub if its Base32 prefix passed. | ||
test_address_bech32_is_valid(AddressBech32IsValid { | ||
coin: CoinType::Cosmos, | ||
address: "{COIN_TYPE} ADDRESS", | ||
hrp: "{HRP}", | ||
}); | ||
// Cosmos address must be valid with "cosmos" hrp. | ||
test_address_bech32_is_valid(AddressBech32IsValid { | ||
coin: CoinType::{COIN_TYPE}, | ||
address: "cosmos1hsk6jryyqjfhp5dhc55tc9jtckygx0eph6dd02", | ||
hrp: "cosmos", | ||
}); | ||
} | ||
|
||
#[test] | ||
fn test_any_address_create_bech32_with_public_key() { | ||
test_address_create_bech32_with_public_key(AddressCreateBech32WithPublicKey { | ||
// TODO consider using `CoinType::{COIN_TYPE}` if the chain's `addressHasher` is different from Cosmos's. | ||
coin: CoinType::Cosmos, | ||
private_key: "PRIVATE_KEY", | ||
// TODO consider using another `PublicKeyType` if the chain's `publicKeyType` is different from Cosmos's. | ||
public_key_type: PublicKeyType::Secp256k1, | ||
hrp: "{HRP}", | ||
expected: "{COIN_TYPE} ADDRESS", | ||
}); | ||
} | ||
|
5 changes: 5 additions & 0 deletions
5
codegen-v2/src/codegen/rust/templates/integration_tests/mod_address.rs
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 {COIN_ID}_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
Oops, something went wrong.