Fixing memo toJsonObject test and deserializing memo's nonce only as a decimal number

This commit is contained in:
Nelson R. Perez 2017-11-02 17:57:15 -05:00
parent 0192728bd5
commit 3d4b2719bb
2 changed files with 7 additions and 8 deletions

View file

@ -294,13 +294,12 @@ public class Memo implements ByteSerializable, JsonSerializable {
JsonObject jsonObject = json.getAsJsonObject(); JsonObject jsonObject = json.getAsJsonObject();
String fromAddress = jsonObject.get(KEY_FROM).getAsString(); String fromAddress = jsonObject.get(KEY_FROM).getAsString();
String toAddress = jsonObject.get(KEY_TO).getAsString(); String toAddress = jsonObject.get(KEY_TO).getAsString();
BigInteger nonce;
System.out.println("Trying to deserialize memo with nonce: <"+jsonObject.get(KEY_NONCE).getAsString()+">"); // Apparently the nonce is always coming from the full node as a string containing a
try{ // decimal number. This is at odds with the result of the #toJsonObject method
nonce = new BigInteger(jsonObject.get(KEY_NONCE).getAsString(), 10); // which encodes this data in hexadecimal.
}catch(NumberFormatException e){ BigInteger nonce = new BigInteger(jsonObject.get(KEY_NONCE).getAsString(), 10);
nonce = new BigInteger(jsonObject.get(KEY_NONCE).getAsString(), 16);
}
String msg = jsonObject.get(KEY_MESSAGE).getAsString(); String msg = jsonObject.get(KEY_MESSAGE).getAsString();
Memo memo = null; Memo memo = null;
try{ try{

View file

@ -132,7 +132,7 @@ public class MemoTest {
JsonObject expected = new JsonObject(); JsonObject expected = new JsonObject();
expected.addProperty("from", new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, TestAccounts.Bilthon16.WIF).getKey().getPrivKeyBytes()).getPubKey())).toString()); expected.addProperty("from", new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, TestAccounts.Bilthon16.WIF).getKey().getPrivKeyBytes()).getPubKey())).toString());
expected.addProperty("to", new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, TestAccounts.Bilthon7.WIF).getKey().getPrivKeyBytes()).getPubKey())).toString()); expected.addProperty("to", new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, TestAccounts.Bilthon7.WIF).getKey().getPrivKeyBytes()).getPubKey())).toString());
expected.addProperty("nonce", String.format("%d", shortEncryptedMessageNonce)); expected.addProperty("nonce", String.format("%x", shortEncryptedMessageNonce));
expected.addProperty("message", "93c398e05f2a36a535f82880032a062d"); expected.addProperty("message", "93c398e05f2a36a535f82880032a062d");
assertEquals("Memo instance should generate a valid JsonObject",expected, jsonObject); assertEquals("Memo instance should generate a valid JsonObject",expected, jsonObject);
} }