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

SDK: Fix transaction decoding with boxes #422

Merged
merged 2 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion .test-env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configs for testing repo download:
SDK_TESTING_URL="https://github.com/algorand/algorand-sdk-testing"
SDK_TESTING_BRANCH="master"
SDK_TESTING_BRANCH="app-txn-decode"
jasonpaulos marked this conversation as resolved.
Show resolved Hide resolved
SDK_TESTING_HARNESS="test-harness"

INSTALL_ONLY=0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down