Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multipay serde fix and additional tests #101

Merged
merged 4 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@ public HashMap toHashMap() {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("network", this.network);
map.put("id", this.id);
map.put("expiration", this.expiration);
map.put("amount", this.amount);
map.put("fee", this.fee);
map.put("amount", String.valueOf(this.amount));
map.put("fee", String.valueOf(this.fee));
map.put("recipientId", this.recipientId);
map.put("signature", this.signature);
map.put("senderPublicKey", this.senderPublicKey);
Expand All @@ -246,7 +245,7 @@ public HashMap toHashMap() {
if (this.version == 1) {
map.put("timestamp", this.timestamp);
} else {
map.put("nonce", this.nonce);
map.put("nonce", String.valueOf(this.nonce));
map.put("typeGroup", this.typeGroup);
}

Expand All @@ -258,6 +257,10 @@ public HashMap toHashMap() {
map.put("signSignature", this.signSignature);
}

if (this.expiration > 0) {
map.put("expiration", this.expiration);
}

HashMap<String, Object> asset = new HashMap<>();
if (this.type == CoreTransactionTypes.SECOND_SIGNATURE_REGISTRATION.getValue()) {
HashMap<String, String> publicKey = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public MultiPayment(ByteBuffer buffer, Transaction transaction) {

@Override
public void serialize() {
this.buffer.putInt(this.transaction.asset.multiPayment.payments.size());
this.buffer.putShort((short) this.transaction.asset.multiPayment.payments.size());
for (TransactionAsset.Payment current : this.transaction.asset.multiPayment.payments) {
this.buffer.putLong(current.amount);
this.buffer.put(Base58.decodeChecked(current.recipientId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import static org.junit.jupiter.api.Assertions.assertTrue;

import org.arkecosystem.crypto.configuration.Network;
import org.arkecosystem.crypto.networks.Devnet;
import org.arkecosystem.crypto.networks.Testnet;
import org.arkecosystem.crypto.transactions.Transaction;
import org.junit.jupiter.api.Test;

Expand All @@ -20,6 +23,41 @@ void build() {
assertTrue(actual.verify());
}

@Test
void buildDevnet() {
Network.set(new Devnet());
Transaction actual =
new MultiPayment()
.addPayment("DNA6BqdX2mYw3PtPfGmEz2bGyyCA9hbaED", 1)
.addPayment("D65rqoZU7U4FdqLVF9KsEF9GBtvwDEVTBt", 2)
.addPayment("D88ZXZ5MaeZFA6xrJPSgJ92qWVWY1462dD", 3)
.vendorField("Zan Vendor Field arghhh")
.nonce(2)
.sign(
"nurse organ hub theory mad strike desert add heavy deposit immune inform")
.transaction;

System.out.println(actual.toJson());
System.out.println(actual.serialize());
assertTrue(actual.verify());
}

@Test
void buildTestnet() {
Network.set(new Testnet());
Transaction actual =
new MultiPayment()
.addPayment("AHXtmB84sTZ9Zd35h9Y1vfFvPE2Xzqj8ri", 1)
.addPayment("AZFEPTWnn2Sn8wDZgCRF8ohwKkrmk2AZi1", 2)
.nonce(1)
.sign("this is a top secret passphrase")
.transaction;

System.out.println(actual.toJson());
System.out.println(actual.serialize());
assertTrue(actual.verify());
}

@Test
void buildSecondSignature() {
Transaction actual =
Expand Down