Ejemplo n.º 1
0
  /**
   * Handles unknown fields (required and not required)
   *
   * @throws FeathercoinURIParseException If something goes wrong
   */
  @Test
  public void testUnknown() throws FeathercoinURIParseException {
    // Unknown not required field
    testObject =
        new FeathercoinURI(
            NetworkParameters.prodNet(),
            FeathercoinURI.LITECOIN_SCHEME + ":" + PRODNET_GOOD_ADDRESS + "?aardvark=true");
    assertEquals(
        "FeathercoinURI['address'='LQz2pJYaeqntA9BFB8rDX5AL2TTKGd5AuN','aardvark'='true']",
        testObject.toString());

    assertEquals("true", (String) testObject.getParameterByName("aardvark"));

    // Unknown not required field (isolated)
    try {
      testObject =
          new FeathercoinURI(
              NetworkParameters.prodNet(),
              FeathercoinURI.LITECOIN_SCHEME + ":" + PRODNET_GOOD_ADDRESS + "?aardvark");
      fail("Expecting FeathercoinURIParseException");
    } catch (FeathercoinURIParseException e) {
      assertTrue(e.getMessage().contains("cannot parse name value pair"));
    }

    // Unknown and required field
    try {
      testObject =
          new FeathercoinURI(
              NetworkParameters.prodNet(),
              FeathercoinURI.LITECOIN_SCHEME + ":" + PRODNET_GOOD_ADDRESS + "?req-aardvark=true");
      fail("Expecting FeathercoinURIParseException");
    } catch (FeathercoinURIParseException e) {
      assertTrue(e.getMessage().contains("req-aardvark"));
    }
  }
Ejemplo n.º 2
0
 /**
  * Handles duplicated fields (sneaky address overwrite attack)
  *
  * @throws FeathercoinURIParseException If something goes wrong
  */
 @Test
 public void testBad_Duplicated() throws FeathercoinURIParseException {
   try {
     testObject =
         new FeathercoinURI(
             NetworkParameters.prodNet(),
             FeathercoinURI.LITECOIN_SCHEME + ":" + PRODNET_GOOD_ADDRESS + "?address=aardvark");
     fail("Expecting FeathercoinURIParseException");
   } catch (FeathercoinURIParseException e) {
     assertTrue(e.getMessage().contains("address"));
   }
 }
Ejemplo n.º 3
0
 /** Test a broken URI (bad address type) */
 @Test
 public void testBad_IncorrectAddressType() {
   try {
     testObject =
         new FeathercoinURI(
             NetworkParameters.testNet(),
             FeathercoinURI.LITECOIN_SCHEME + ":" + PRODNET_GOOD_ADDRESS);
     fail("Expecting FeathercoinURIParseException");
   } catch (FeathercoinURIParseException e) {
     assertTrue(e.getMessage().contains("Bad address"));
   }
 }
Ejemplo n.º 4
0
 /**
  * Handles case when there are too many question marks
  *
  * @throws FeathercoinURIParseException If something goes wrong
  */
 @Test
 public void testBad_TooManyQuestionMarks() throws FeathercoinURIParseException {
   try {
     testObject =
         new FeathercoinURI(
             NetworkParameters.prodNet(),
             FeathercoinURI.LITECOIN_SCHEME
                 + ":"
                 + PRODNET_GOOD_ADDRESS
                 + "?label=aardvark?message=zebra");
     fail("Expecting FeathercoinURIParseException");
   } catch (FeathercoinURIParseException e) {
     assertTrue(e.getMessage().contains("Too many question marks"));
   }
 }
Ejemplo n.º 5
0
  /** Test a broken URI (bad syntax) */
  @Test
  public void testBad_BadSyntax() {
    // Various illegal characters
    try {
      testObject =
          new FeathercoinURI(
              NetworkParameters.prodNet(),
              FeathercoinURI.LITECOIN_SCHEME + "|" + PRODNET_GOOD_ADDRESS);
      fail("Expecting FeathercoinURIParseException");
    } catch (FeathercoinURIParseException e) {
      assertTrue(e.getMessage().contains("Bad URI syntax"));
    }

    try {
      testObject =
          new FeathercoinURI(
              NetworkParameters.prodNet(),
              FeathercoinURI.LITECOIN_SCHEME + ":" + PRODNET_GOOD_ADDRESS + "\\");
      fail("Expecting FeathercoinURIParseException");
    } catch (FeathercoinURIParseException e) {
      assertTrue(e.getMessage().contains("Bad URI syntax"));
    }

    // Separator without field
    try {
      testObject =
          new FeathercoinURI(NetworkParameters.prodNet(), FeathercoinURI.LITECOIN_SCHEME + ":");
      fail("Expecting FeathercoinURIParseException");
    } catch (FeathercoinURIParseException e) {
      assertTrue(e.getMessage().contains("Bad URI syntax"));
    }
  }
Ejemplo n.º 6
0
  /**
   * Handles a badly formatted amount field
   *
   * @throws FeathercoinURIParseException If something goes wrong
   */
  @Test
  public void testBad_Amount() throws FeathercoinURIParseException {
    // Missing
    try {
      testObject =
          new FeathercoinURI(
              NetworkParameters.prodNet(),
              FeathercoinURI.LITECOIN_SCHEME + ":" + PRODNET_GOOD_ADDRESS + "?amount=");
      fail("Expecting FeathercoinURIParseException");
    } catch (FeathercoinURIParseException e) {
      assertTrue(e.getMessage().contains("amount"));
    }

    // Non-decimal (BIP 21)
    try {
      testObject =
          new FeathercoinURI(
              NetworkParameters.prodNet(),
              FeathercoinURI.LITECOIN_SCHEME + ":" + PRODNET_GOOD_ADDRESS + "?amount=12X4");
      fail("Expecting FeathercoinURIParseException");
    } catch (FeathercoinURIParseException e) {
      assertTrue(e.getMessage().contains("amount"));
    }
  }