diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusSigner.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusSigner.kt index 5615a10361b..2cbaaf9635e 100644 --- a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusSigner.kt +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusSigner.kt @@ -5,14 +5,17 @@ package com.trustwallet.core.app.blockchains.pactus import com.google.protobuf.ByteString -import com.trustwallet.core.app.utils.Numeric import com.trustwallet.core.app.utils.toHexByteArray -import com.trustwallet.core.app.utils.toHexBytes -import com.trustwallet.core.app.utils.toHexBytesInByteString import org.junit.Assert.assertEquals import org.junit.Test -import wallet.core.jni.PactusSigner +import wallet.core.jni.PrivateKey +import wallet.core.java.AnySigner +import wallet.core.jni.CoinType +import wallet.core.jni.CoinType.PACTUS import wallet.core.jni.proto.Pactus +import wallet.core.jni.proto.Pactus.SigningOutput +import com.trustwallet.core.app.utils.Numeric +import org.junit.Assert.assertArrayEquals class TestPactusSigner { @@ -21,42 +24,36 @@ class TestPactusSigner { } @Test - fun PactusTransactionSigning() { - val privateKey = - "4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6".toHexBytesInByteString() - - val transfer = Pactus.TransferPayload.newBuilder() - .setSender("pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr") - .setReceiver("pc1r0g22ufzn8qtw0742dmfglnw73e260hep0k3yra") - .setAmount(20000) - .build() - - val transaction = Pactus.TransactionMessage.newBuilder() - .setLockTime(0x00030201) - .setFee(1000) - .setMemo("test") - .setTransfer(transfer) - .build() - + fun testPactusTransactionSigning() { val signingInput = Pactus.SigningInput.newBuilder() - .setPrivateKey(privateKey) - .setTransaction(transaction) - .build() - - val output: Pactus.SigningOutput = PactusSigner.sign(signingInput) + signingInput.apply { + privateKey = ByteString.copyFrom(PrivateKey("4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6".toHexByteArray()).data()) + transaction = Pactus.TransactionMessage.newBuilder().apply { + lockTime = 0x00030201 + fee = 1000 + memo = "test" + transfer = Pactus.TransferPayload.newBuilder().apply { + sender = "pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr" + receiver = "pc1r0g22ufzn8qtw0742dmfglnw73e260hep0k3yra" + amount = 20000 + }.build() + }.build() + } + + val output = AnySigner.sign(signingInput.build(), PACTUS, SigningOutput.parser()) assertEquals( - "34cd4656a98f7eb996e83efdc384cefbe3a9c52dca79a99245b4eacc0b0b4311", + "0x34cd4656a98f7eb996e83efdc384cefbe3a9c52dca79a99245b4eacc0b0b4311", Numeric.toHexString(output.transactionId.toByteArray()) ) assertEquals( - "50ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd09", + "0x50ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd09", Numeric.toHexString(output.signature.toByteArray()) ) assertEquals( - "000101020300e807047465737401037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21a09c0150ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd0995794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa", + "0x000101020300e807047465737401037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21a09c0150ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd0995794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa", Numeric.toHexString(output.signedTransactionData.toByteArray()) ) } diff --git a/rust/chains/tw_pactus/src/encoder/var_int.rs b/rust/chains/tw_pactus/src/encoder/var_int.rs index ab2c953ccef..aba98f95f4f 100644 --- a/rust/chains/tw_pactus/src/encoder/var_int.rs +++ b/rust/chains/tw_pactus/src/encoder/var_int.rs @@ -9,7 +9,7 @@ use byteorder::ReadBytesExt; use super::{error::Error, Decodable}; use crate::encoder::Encodable; -/// A type of variable-length integer commonly used in the Bitcoin P2P protocol and Bitcoin serialized data structures. +/// A type of variable-length integer used in the Pactus blockchain to serialize a variable-length integer. #[derive(Default, Debug, Clone, Copy, PartialEq)] pub struct VarInt(u64); @@ -105,7 +105,7 @@ mod tests { VarInt::from(0xffff_usize).encode(&mut w).unwrap(); VarInt::from(0x01_0000_usize).encode(&mut w).unwrap(); VarInt::from(0xffff_ffff_usize).encode(&mut w).unwrap(); - VarInt::from(0x01_0000_0000_usize).encode(&mut w).unwrap(); + VarInt(0x01_0000_0000_u64).encode(&mut w).unwrap(); let expected = vec![ 0x00, // 0x00 diff --git a/rust/frameworks/tw_utxo/src/encode/compact_integer.rs b/rust/frameworks/tw_utxo/src/encode/compact_integer.rs index 2bf8853145f..ec4e3ae9d2e 100644 --- a/rust/frameworks/tw_utxo/src/encode/compact_integer.rs +++ b/rust/frameworks/tw_utxo/src/encode/compact_integer.rs @@ -70,7 +70,7 @@ mod tests { .append(&CompactInteger::from(0xffff_usize)) .append(&CompactInteger::from(0x01_0000_usize)) .append(&CompactInteger::from(0xffff_ffff_usize)) - .append(&CompactInteger::from(0x01_0000_0000_usize)); + .append(&CompactInteger(0x01_0000_0000_u64)); let expected = vec![ 0x00, // 0x00 diff --git a/swift/Tests/Blockchains/PactusTests.swift b/swift/Tests/Blockchains/PactusTests.swift index 22dd425b2ba..cb0903079c8 100644 --- a/swift/Tests/Blockchains/PactusTests.swift +++ b/swift/Tests/Blockchains/PactusTests.swift @@ -2,8 +2,8 @@ // // Copyright © 2017 Trust Wallet. -import WalletCore import XCTest +import WalletCore class PactusTests: XCTestCase { @@ -18,29 +18,27 @@ class PactusTests: XCTestCase { } func testSign() { - let privateKeyData = Data(hexString: "5d996aa76b3212142792d9130796cd2e11e3c445a93118c08414df4f66bc60ec")! - let transfer = PactusTransferPayload.with { - $0.sender = "pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr" - $0.receiver = "pc1r0g22ufzn8qtw0742dmfglnw73e260hep0k3yra" - $0.amount = 20000 - } - let transaction = PactusTransactionMessage.with { - $0.lockTime(0x00030201) - $0.fee(1000) - $0.memo("test") - $0.transfer(transfer) - } let input = PactusSigningInput.with { - $0.privateKey = privateKeyData - $0.transaction = transfer + $0.privateKey = Data(hexString: "5d996aa76b3212142792d9130796cd2e11e3c445a93118c08414df4f66bc60ec")! + $0.transaction = PactusTransactionMessage.with { + $0.lockTime = 0x00030201 + $0.fee = 1000 + $0.memo = "test" + $0.transfer = PactusTransferPayload.with { + $0.sender = "pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr" + $0.receiver = "pc1r0g22ufzn8qtw0742dmfglnw73e260hep0k3yra" + $0.amount = 20000 + } + } } - let output: PactusSigningOutput = AnySigner.sign(input: input, coin: .Pactus) + let output: PactusSigningOutput = AnySigner.sign(input: input, coin: .pactus) + let expectedTransactionID = "34cd4656a98f7eb996e83efdc384cefbe3a9c52dca79a99245b4eacc0b0b4311" let expectedSignature = "50ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd09" let expectedSignedData = "000101020300e807047465737401037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21a09c0150ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd0995794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa" XCTAssertEqual(output.transactionID.hexString, expectedTransactionID) XCTAssertEqual(output.signature.hexString, expectedSignature) - XCTAssertEqual(output.signedTransactionData.hexString, expectedSiexpectedSignedDatanedTx) + XCTAssertEqual(output.signedTransactionData.hexString, expectedSignedData) } }