Skip to content

Commit

Permalink
Fix waves output json (#530)
Browse files Browse the repository at this point in the history
* Fix waves output json

* compare whole json

* Fix codacy warnigns

* Fix codacy
  • Loading branch information
hewigovens authored and vikmeup committed Jun 25, 2019
1 parent 3f77d9c commit 9e3dbbe
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Waves/Transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ json Transaction::buildJson(Data signature) const {
jsonTx["fee"] = fee;
jsonTx["senderPublicKey"] = Base58::bitcoin.encode(pub_key);
jsonTx["timestamp"] = timestamp;
jsonTx["proofs"] = json::array({Base58::bitcoin.encode(signature)}).dump();
jsonTx["proofs"] = json::array({Base58::bitcoin.encode(signature)});
jsonTx["recipient"] = Address(to).string();
if (asset != WAVES) {
jsonTx["assetId"] = asset;
Expand All @@ -72,4 +72,4 @@ json Transaction::buildJson(Data signature) const {
jsonTx["attachment"] = Base58::bitcoin.encode(attachment);

return jsonTx;
}
}
2 changes: 1 addition & 1 deletion swift/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: cbcc5bab5b64fa9f7863e62cc106d25d3fc1dfc5

COCOAPODS: 1.7.1
COCOAPODS: 1.7.2
38 changes: 38 additions & 0 deletions swift/Tests/Blockchains/WavesTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 WavesTests: XCTestCase {

func testSigner() throws {

let privateKey = PrivateKey(data: Data(hexString: "68b7a9adb4a655b205f43dac413803785921e22cd7c4d05857b203a62621075f")!)!

let input = WavesSigningInput.with {
$0.amount = 100_000_000
$0.asset = "DacnEpaUVFRCYk8Fcd1F3cqUZuT4XG7qW9mRyoZD81zq"
$0.fee = 100_000
$0.feeAsset = "DacnEpaUVFRCYk8Fcd1F3cqUZuT4XG7qW9mRyoZD81zq"
$0.to = "3PPCZQkvdMJpmx7Zrz1cnYsPe9Bt1XT2Ckx"
$0.attachment = Data(hexString: "0x68656c6c6f")!
$0.timestamp = 1559146613
$0.privateKey = privateKey.data
}

let output = WavesSigner.sign(input: input)
guard let json = try JSONSerialization.jsonObject(with: output.json.data(using: .utf8)!, options: []) as? [String: Any] else {
XCTFail("unable to decode json")
return
}
XCTAssertNotNil(json["proofs"] as? [String])
// swiftlint:disable line_length
XCTAssertEqual(output.json, "{\"amount\":100000000,\"assetId\":\"DacnEpaUVFRCYk8Fcd1F3cqUZuT4XG7qW9mRyoZD81zq\",\"attachment\":\"Cn8eVZg\",\"fee\":100000,\"feeAssetId\":\"DacnEpaUVFRCYk8Fcd1F3cqUZuT4XG7qW9mRyoZD81zq\",\"proofs\":[\"2sKtLEXdvK3Yy94S7ypdVyCkUc7BT7RgG6xzLd8qr1NUE24iXcnu1MYF4HKMXRsxnP3akgVS25V3Xet9auv1evte\"],\"recipient\":\"3PPCZQkvdMJpmx7Zrz1cnYsPe9Bt1XT2Ckx\",\"senderPublicKey\":\"9AXmkhYSNGev6iUfR1oJ9X1SjqKsqp518TriHiLLHuKA\",\"timestamp\":1559146613,\"type\":4,\"version\":2}")
XCTAssertEqual(output.signature.hexString, "5d6a77b1fd9b53d9735cd2543ba94215664f2b07d6c7befb081221fcd49f5b6ad6b9ac108582e8d3e74943bdf35fd80d985edf4b4de1fb1c5c427e84d0879f8f")
// swiftlint:enable line_length
}
}
3 changes: 2 additions & 1 deletion swift/Tests/Blockchains/ZilliqaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// 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

Expand Down Expand Up @@ -49,6 +50,6 @@ class ZilliqaTests: XCTestCase {

let signature = ZilliqaSigner.sign(input: input).signature

XCTAssertEqual(signature.hexString, "001fa4df08c11a4a79e96e69399ee48eeecc78231a78b0355a8ca783c77c139436e37934fecc2252ed8dac00e235e22d18410461fb896685c4270642738ed268");
XCTAssertEqual(signature.hexString, "001fa4df08c11a4a79e96e69399ee48eeecc78231a78b0355a8ca783c77c139436e37934fecc2252ed8dac00e235e22d18410461fb896685c4270642738ed268")
}
}
4 changes: 2 additions & 2 deletions tests/Waves/TransactionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ TEST(WavesTransaction, jsonSerialize) {
ASSERT_EQ(json["fee"], 100000000);
ASSERT_EQ(json["senderPublicKey"], "6mA8eQjie53kd4jbZrwL3ZhMBqCX6nzit1k55tR2X7zU");
ASSERT_EQ(json["timestamp"], 1526641218066);
ASSERT_EQ(json["proofs"], "[\"5ynN2NUiFHkQzw9bK8R7dZcNfTWMAtcWRJsrMvFFM6dUT3fSnPCCX7CTajNU8bJCB"
ASSERT_EQ(json["proofs"].dump(), "[\"5ynN2NUiFHkQzw9bK8R7dZcNfTWMAtcWRJsrMvFFM6dUT3fSnPCCX7CTajNU8bJCB"
"H69vU1mnwfx4zpDtF1SkzKg\"]");
ASSERT_EQ(json["recipient"], "3P2uzAzX9XTu1t32GkWw68YFFLwtapWvDds");
ASSERT_EQ(json["assetId"], "DacnEpaUVFRCYk8Fcd1F3cqUZuT4XG7qW9mRyoZD81zq");
ASSERT_EQ(json["feeAssetId"], "DacnEpaUVFRCYk8Fcd1F3cqUZuT4XG7qW9mRyoZD82zq");
ASSERT_EQ(json["amount"], 10000000);
ASSERT_EQ(json["attachment"], "4t2Xazb2SX");
ASSERT_EQ(json.dump(), "{\"amount\":10000000,\"assetId\":\"DacnEpaUVFRCYk8Fcd1F3cqUZuT4XG7qW9mRyoZD81zq\",\"attachment\":\"4t2Xazb2SX\",\"fee\":100000000,\"feeAssetId\":\"DacnEpaUVFRCYk8Fcd1F3cqUZuT4XG7qW9mRyoZD82zq\",\"proofs\":\"[\\\"5ynN2NUiFHkQzw9bK8R7dZcNfTWMAtcWRJsrMvFFM6dUT3fSnPCCX7CTajNU8bJCBH69vU1mnwfx4zpDtF1SkzKg\\\"]\",\"recipient\":\"3P2uzAzX9XTu1t32GkWw68YFFLwtapWvDds\",\"senderPublicKey\":\"6mA8eQjie53kd4jbZrwL3ZhMBqCX6nzit1k55tR2X7zU\",\"timestamp\":1526641218066,\"type\":4,\"version\":2}");
ASSERT_EQ(json.dump(), "{\"amount\":10000000,\"assetId\":\"DacnEpaUVFRCYk8Fcd1F3cqUZuT4XG7qW9mRyoZD81zq\",\"attachment\":\"4t2Xazb2SX\",\"fee\":100000000,\"feeAssetId\":\"DacnEpaUVFRCYk8Fcd1F3cqUZuT4XG7qW9mRyoZD82zq\",\"proofs\":[\"5ynN2NUiFHkQzw9bK8R7dZcNfTWMAtcWRJsrMvFFM6dUT3fSnPCCX7CTajNU8bJCBH69vU1mnwfx4zpDtF1SkzKg\"],\"recipient\":\"3P2uzAzX9XTu1t32GkWw68YFFLwtapWvDds\",\"senderPublicKey\":\"6mA8eQjie53kd4jbZrwL3ZhMBqCX6nzit1k55tR2X7zU\",\"timestamp\":1526641218066,\"type\":4,\"version\":2}");
}

0 comments on commit 9e3dbbe

Please sign in to comment.