@Test
  public void extensions() throws Exception {
    myWallet.addExtension(new FooWalletExtension("com.whatever.required", true));
    Protos.Wallet proto = new WalletProtobufSerializer().walletToProto(myWallet);
    // Initial extension is mandatory: try to read it back into a wallet that doesn't know about it.
    try {
      new WalletProtobufSerializer().readWallet(params, null, proto);
      fail();
    } catch (UnreadableWalletException e) {
      assertTrue(e.getMessage().contains("mandatory"));
    }
    Wallet wallet =
        new WalletProtobufSerializer()
            .readWallet(
                params,
                new WalletExtension[] {new FooWalletExtension("com.whatever.required", true)},
                proto);
    assertTrue(wallet.getExtensions().containsKey("com.whatever.required"));

    // Non-mandatory extensions are ignored if the wallet doesn't know how to read them.
    Wallet wallet2 = new Wallet(params);
    wallet2.addExtension(new FooWalletExtension("com.whatever.optional", false));
    Protos.Wallet proto2 = new WalletProtobufSerializer().walletToProto(wallet2);
    Wallet wallet5 = new WalletProtobufSerializer().readWallet(params, null, proto2);
    assertEquals(0, wallet5.getExtensions().size());
  }
  @Test
  public void extensionsWithError() throws Exception {
    WalletExtension extension =
        new WalletExtension() {
          @Override
          public String getWalletExtensionID() {
            return "test";
          }

          @Override
          public boolean isWalletExtensionMandatory() {
            return false;
          }

          @Override
          public byte[] serializeWalletExtension() {
            return new byte[0];
          }

          @Override
          public void deserializeWalletExtension(Wallet containingWallet, byte[] data)
              throws Exception {
            throw new NullPointerException(); // Something went wrong!
          }
        };
    myWallet.addExtension(extension);
    Protos.Wallet proto = new WalletProtobufSerializer().walletToProto(myWallet);
    Wallet wallet =
        new WalletProtobufSerializer().readWallet(params, new WalletExtension[] {extension}, proto);
    assertEquals(0, wallet.getExtensions().size());
  }