Repository: hyperledger/quilt
Pull request #459 (2020-05-05 21:17:40)

Make ConnectionNewAddress Frame's address optional address
This change enables backwards compatibility with the JS Interledger implementations and overall supports more Stream use-cases in a backwards compatible manner.

For more details, see https://github.com/interledger/rfcs/pull/573


Patch:
diff --git a/codecs-parent/codecs-stream/src/main/java/org/interledger/codecs/stream/frame/AsnConnectionNewAddressFrameDataCodec.java b/codecs-parent/codecs-stream/src/main/java/org/interledger/codecs/stream/frame/AsnConnectionNewAddressFrameDataCodec.java
index 9c34984..9c22a67 100644
--- a/codecs-parent/codecs-stream/src/main/java/org/interledger/codecs/stream/frame/AsnConnectionNewAddressFrameDataCodec.java
+++ b/codecs-parent/codecs-stream/src/main/java/org/interledger/codecs/stream/frame/AsnConnectionNewAddressFrameDataCodec.java
@@ -21,9 +21,12 @@ package org.interledger.codecs.stream.frame;
  */
 
 import org.interledger.codecs.ilp.AsnInterledgerAddressCodec;
+import org.interledger.core.InterledgerAddress;
 import org.interledger.encoding.asn.codecs.AsnSequenceCodec;
 import org.interledger.stream.frames.ConnectionNewAddressFrame;
 
+import java.util.Optional;
+
 public class AsnConnectionNewAddressFrameDataCodec extends AsnSequenceCodec<ConnectionNewAddressFrame> {
 
   /**
@@ -37,13 +40,14 @@ public class AsnConnectionNewAddressFrameDataCodec extends AsnSequenceCodec<Conn
 
   @Override
   public ConnectionNewAddressFrame decode() {
+    final Optional<InterledgerAddress> address = Optional.ofNullable(getValueAt(0));
     return ConnectionNewAddressFrame.builder()
-        .sourceAddress(getValueAt(0))
+        .sourceAddress(address)
         .build();
   }
 
   @Override
   public void encode(ConnectionNewAddressFrame value) {
-    setValueAt(0, value.sourceAddress());
+    setValueAt(0, value.sourceAddress().orElse(null));
   }
 }
diff --git a/pom.xml b/pom.xml
index 5ef7527..337ee1c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,20 +59,20 @@
 
   <developers>
     <developer>
-      <name>Adrian Hope-Bailie</name>
-      <organizationUrl>https://github.com/adrianhopebailie</organizationUrl>
+      <name>David Fuelling</name>
+      <organizationUrl>https://github.com/sappenin</organizationUrl>
     </developer>
     <developer>
-      <name>Andrew Gates</name>
-      <organizationUrl>https://github.com/andrew-g-za</organizationUrl>
+      <name>Neil Hartner</name>
+      <organizationUrl>https://github.com/nhartner</organizationUrl>
     </developer>
     <developer>
-      <name>Enrique Benito</name>
-      <organizationUrl>https://github.com/earizon</organizationUrl>
+      <name>Noah Kramer</name>
+      <organizationUrl>https://github.com/nkramer44</organizationUrl>
     </developer>
     <developer>
-      <name>David Fuelling</name>
-      <organizationUrl>https://github.com/sappenin</organizationUrl>
+      <name>Ian Simpson</name>
+      <organizationUrl>https://github.com/theotherian</organizationUrl>
     </developer>
   </developers>
 
diff --git a/stream-parent/stream-core/src/main/java/org/interledger/stream/frames/ConnectionNewAddressFrame.java b/stream-parent/stream-core/src/main/java/org/interledger/stream/frames/ConnectionNewAddressFrame.java
index e9b3c47..19b6f8d 100644
--- a/stream-parent/stream-core/src/main/java/org/interledger/stream/frames/ConnectionNewAddressFrame.java
+++ b/stream-parent/stream-core/src/main/java/org/interledger/stream/frames/ConnectionNewAddressFrame.java
@@ -23,6 +23,8 @@ package org.interledger.stream.frames;
 import org.interledger.core.Immutable;
 import org.interledger.core.InterledgerAddress;
 
+import java.util.Optional;
+
 /**
  * Indicates that the connection was closed.
  */
@@ -48,6 +50,6 @@ public interface ConnectionNewAddressFrame extends StreamFrame {
    *
    * @return A {@link InterledgerAddress} representing the source address of the receiver.
    */
-  InterledgerAddress sourceAddress();
+  Optional<InterledgerAddress> sourceAddress();
 
 }


Test patch:
diff --git a/codecs-parent/codecs-stream/src/test/java/org/interledger/codecs/stream/frame/AsnConnectionNewAddressFrameCodecTest.java b/codecs-parent/codecs-stream/src/test/java/org/interledger/codecs/stream/frame/AsnConnectionNewAddressFrameCodecTest.java
index 5e4fa8b..107ce74 100644
--- a/codecs-parent/codecs-stream/src/test/java/org/interledger/codecs/stream/frame/AsnConnectionNewAddressFrameCodecTest.java
+++ b/codecs-parent/codecs-stream/src/test/java/org/interledger/codecs/stream/frame/AsnConnectionNewAddressFrameCodecTest.java
@@ -76,6 +76,10 @@ public class AsnConnectionNewAddressFrameCodecTest extends AbstractAsnFrameCodec
                 .sourceAddress(InterledgerAddress.of(JUST_RIGHT))
                 .build()
         },
+        // empty address
+        {
+            ConnectionNewAddressFrame.builder().build()
+        },
     });
   }
 }
diff --git a/stream-parent/stream-core/src/test/java/org/interledger/stream/frames/StreamFrameTypeTest.java b/stream-parent/stream-core/src/test/java/org/interledger/stream/frames/StreamFrameTypeTest.java
index d62950f..fc6a6b0 100644
--- a/stream-parent/stream-core/src/test/java/org/interledger/stream/frames/StreamFrameTypeTest.java
+++ b/stream-parent/stream-core/src/test/java/org/interledger/stream/frames/StreamFrameTypeTest.java
@@ -15,7 +15,6 @@ import static org.interledger.stream.frames.StreamFrameConstants.STREAM_DATA_MAX
 import static org.interledger.stream.frames.StreamFrameConstants.STREAM_MONEY;
 import static org.interledger.stream.frames.StreamFrameConstants.STREAM_MONEY_BLOCKED;
 import static org.interledger.stream.frames.StreamFrameConstants.STREAM_MONEY_MAX;
-import static org.mockito.Mockito.spy;
 
 import org.interledger.core.InterledgerAddress;
 import org.interledger.stream.Denomination;
@@ -188,12 +187,16 @@ public class StreamFrameTypeTest {
         .build();
     assertThat(frame.streamFrameType()).isEqualTo(StreamFrameType.ConnectionNewAddress);
     // make sure interface default method is exercised
-    final ConnectionNewAddressFrame interfaceFrame = new ConnectionNewAddressFrame() {
-      @Override
-      public InterledgerAddress sourceAddress() {
-        return null;
-      }
-    };
+    final ConnectionNewAddressFrame interfaceFrame = () -> Optional.empty();
+    assertThat(interfaceFrame.streamFrameType()).isEqualTo(StreamFrameType.ConnectionNewAddress);
+  }
+
+  @Test
+  public void connectionNewAddressFrameWithEmptyAddress() {
+    ConnectionNewAddressFrame frame = ConnectionNewAddressFrame.builder().build();
+    assertThat(frame.streamFrameType()).isEqualTo(StreamFrameType.ConnectionNewAddress);
+    // make sure interface default method is exercised
+    final ConnectionNewAddressFrame interfaceFrame = () -> Optional.empty();
     assertThat(interfaceFrame.streamFrameType()).isEqualTo(StreamFrameType.ConnectionNewAddress);
   }