diff --git a/CHANGELOG.md b/CHANGELOG.md index c1068e92b..ce0913c84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# 1.21.1 + +## What's Changed +### Bugfixes +* SDK: Fix transaction decoding with boxes by @jasonpaulos in https://github.com/algorand/java-algorand-sdk/pull/422 + +**Full Changelog**: https://github.com/algorand/java-algorand-sdk/compare/1.21.0...1.21.1 + # 1.21.0 ## What's Changed diff --git a/README.md b/README.md index e5ecf8067..d072cfaa9 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Maven: com.algorand algosdk - 1.21.0 + 1.21.1 ``` diff --git a/pom.xml b/pom.xml index b7c0fbf66..242704d8b 100755 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.algorand algosdk - 1.21.0 + 1.21.1 jar ${project.groupId}:${project.artifactId} diff --git a/src/main/java/com/algorand/algosdk/transaction/Transaction.java b/src/main/java/com/algorand/algosdk/transaction/Transaction.java index d08f2b0af..9b514de53 100644 --- a/src/main/java/com/algorand/algosdk/transaction/Transaction.java +++ b/src/main/java/com/algorand/algosdk/transaction/Transaction.java @@ -1585,7 +1585,7 @@ public BoxReference( @JsonProperty("i") int appIndex, @JsonProperty("n") byte[] name) { this.appIndex = appIndex; - this.name = Arrays.copyOf(name, name.length); + this.name = name == null ? new byte[]{} : Arrays.copyOf(name, name.length); } // Foreign apps start from index 1. Index 0 is the called App ID. diff --git a/src/test/java/com/algorand/algosdk/transaction/TestTransaction.java b/src/test/java/com/algorand/algosdk/transaction/TestTransaction.java index 88801ef18..35701da03 100644 --- a/src/test/java/com/algorand/algosdk/transaction/TestTransaction.java +++ b/src/test/java/com/algorand/algosdk/transaction/TestTransaction.java @@ -157,6 +157,31 @@ public void testSerializationMsgpack() throws Exception { assertEqual(o, tx); } + @Test + public void testEmptyBoxReferenceSerializationMsgpack() throws Exception { + Transaction.BoxReference boxReference = new Transaction.BoxReference(0, new byte[]{}); + + byte[] encoded = Encoder.encodeToMsgPack(boxReference); + byte[] expectedEncoded = {(byte) 128}; + assertThat(encoded).isEqualTo(expectedEncoded); + + Transaction.BoxReference decoded = Encoder.decodeFromMsgPack(encoded, Transaction.BoxReference.class); + assertThat(decoded).isEqualTo(boxReference); + } + + @Test + public void testEmptyBoxReferenceSerializationJson() throws Exception { + Transaction.BoxReference boxReference = new Transaction.BoxReference(0, new byte[]{}); + + ObjectMapper objectMapper = new ObjectMapper(); + String encoded = objectMapper.writeValueAsString(boxReference); + String expectedEncoded = "{}"; + assertThat(encoded).isEqualTo(expectedEncoded); + + Transaction.BoxReference decoded = objectMapper.readValue(encoded, Transaction.BoxReference.class); + assertThat(decoded).isEqualTo(boxReference); + } + @Test public void testMetadaHashBuilderMethods() throws Exception { // Test that the following 3 builder methods returns the same transaction