ui/shared/src/test/java/com/squareup/subzero/shared/ColdWalletTest.java
@Test public void MaxSizeTest() {
    Path.Builder path = Path.newBuilder()
        .setAccount(0x7FFFFFFF)
        .setIsChange(false)
        .setIndex(0x7FFFFFFF);

    // This input is as big as possible.
    TxInput input = TxInput.newBuilder()
        .setPrevHash(ByteString.copyFrom(Hex.decode("d37365c6a3c089576b1ea1cb8bee2baa005afc96d24080515635f852c680d127")))
        .setPrevIndex(0x7FFFFFFF)
        .setAmount(0x7FFFFFFF7FFFFFFFL)
        .setPath(path)
        .build();

    TxOutput output = TxOutput.newBuilder()
        .setAmount(0x7FFFFFFF7FFFFFFFL)
        .setDestination(Destination.GATEWAY)
        .setPath(path)
        .build();

    List<TxInput> inputs = new ArrayList<>();
    for(int i = 0; i < Constants.INPUTS_COUNT_AT_LEAST; i++) {
      inputs.add(input);
    }

    List<TxOutput> outputs = new ArrayList<>();
    for(int i = 0; i < Constants.OUTPUTS_COUNT_AT_LEAST; i++) {
      outputs.add(output);
    }

    String token = "TokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenToken";
    CommandRequest request = coldWallet.startTransaction(inputs, outputs, token);
    assertThat(request.getSerializedSize()).isLessThan(Constants.MAX_QR_PROTO_BYTES);

    // The response consists of signatures.  We know bitcoin signatures are, in worst-case, 73 bytes
    // So we verify a CommandResponse.SignTxResponse with 73 byte signatures fits.
    List<Signature> signatures = new ArrayList<>();

    for(int i = 0; i < Constants.INPUTS_COUNT_AT_LEAST; i++) {
      signatures.add(Signature.newBuilder()
          .setDer(ByteString.copyFrom(Hex.decode(
                  "3045022100c822d9b754a87ef25a0c9a9ad44eba41bd00822ddab60f759e77e99e80427feb02207edc74ca82fafc6d7b42ef4815d4142ff49fca0bac533449f15543c19264c13901FF"
           ))).build());
    }

    CommandResponse response = CommandResponse.newBuilder()
        .setToken(token)
        .setSignTx(CommandResponse.SignTxResponse.newBuilder()
            .addAllSignatures(signatures))
        .build();

    System.out.println(format("the serialized size is %d (of %d)", response.getSerializedSize(), Constants.MAX_QR_PROTO_BYTES));
    assertThat(response.getSerializedSize()).isLessThan(Constants.MAX_QR_PROTO_BYTES);
  }
/**
   * MaxSizeTest verifies we can create a transaction with the documented number of inputs and
   * outputs, with the generated proto under the QR code size limit.
   */
MaxSizeTest verifies we can create a transaction with the documented number of inputs and
outputs, with the generated proto under the QR code size limit.
MaxSizeTest verifies we can create a transaction with the documented number of inputs and outputs with the generated proto under the QR code size limit .
@Test public void MaxSizeTest() {
    Path.Builder path = Path.newBuilder()
        .setAccount(0x7FFFFFFF)
        .setIsChange(false)
        .setIndex(0x7FFFFFFF);
    TxInput input = TxInput.newBuilder()
        .setPrevHash(ByteString.copyFrom(Hex.decode("d37365c6a3c089576b1ea1cb8bee2baa005afc96d24080515635f852c680d127")))
        .setPrevIndex(0x7FFFFFFF)
        .setAmount(0x7FFFFFFF7FFFFFFFL)
        .setPath(path)
        .build();
    TxOutput output = TxOutput.newBuilder()
        .setAmount(0x7FFFFFFF7FFFFFFFL)
        .setDestination(Destination.GATEWAY)
        .setPath(path)
        .build();
    List<TxInput> inputs = new ArrayList<>();
    for(int i = 0; i < Constants.INPUTS_COUNT_AT_LEAST; i++) {
      inputs.add(input);
    }
    List<TxOutput> outputs = new ArrayList<>();
    for(int i = 0; i < Constants.OUTPUTS_COUNT_AT_LEAST; i++) {
      outputs.add(output);
    }
    String token = "TokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenToken";
    CommandRequest request = coldWallet.startTransaction(inputs, outputs, token);
    assertThat(request.getSerializedSize()).isLessThan(Constants.MAX_QR_PROTO_BYTES);
    List<Signature> signatures = new ArrayList<>();
    for(int i = 0; i < Constants.INPUTS_COUNT_AT_LEAST; i++) {
      signatures.add(Signature.newBuilder()
          .setDer(ByteString.copyFrom(Hex.decode(
                  "3045022100c822d9b754a87ef25a0c9a9ad44eba41bd00822ddab60f759e77e99e80427feb02207edc74ca82fafc6d7b42ef4815d4142ff49fca0bac533449f15543c19264c13901FF"
           ))).build());
    }
    CommandResponse response = CommandResponse.newBuilder()
        .setToken(token)
        .setSignTx(CommandResponse.SignTxResponse.newBuilder()
            .addAllSignatures(signatures))
        .build();
    System.out.println(format("the serialized size is %d (of %d)", response.getSerializedSize(), Constants.MAX_QR_PROTO_BYTES));
    assertThat(response.getSerializedSize()).isLessThan(Constants.MAX_QR_PROTO_BYTES);
  }
@ Test public void MaxSizeTest ( ) { Path . Builder path = Path . newBuilder ( ) . setAccount ( 0x7FFFFFFF ) . setIsChange ( false ) . setIndex ( 0x7FFFFFFF ) ; TxInput input = TxInput . newBuilder ( ) . setPrevHash ( ByteString . copyFrom ( Hex . decode ( "d37365c6a3c089576b1ea1cb8bee2baa005afc96d24080515635f852c680d127" ) ) ) . setPrevIndex ( 0x7FFFFFFF ) . setAmount ( 0x7FFFFFFF7FFFFFFFL ) . setPath ( path ) . build ( ) ; TxOutput output = TxOutput . newBuilder ( ) . setAmount ( 0x7FFFFFFF7FFFFFFFL ) . setDestination ( Destination . GATEWAY ) . setPath ( path ) . build ( ) ; List < TxInput > inputs = new ArrayList < > ( ) ; for ( int i = 0 ; i < Constants . INPUTS_COUNT_AT_LEAST ; i ++ ) { inputs . add ( input ) ; } List < TxOutput > outputs = new ArrayList < > ( ) ; for ( int i = 0 ; i < Constants . OUTPUTS_COUNT_AT_LEAST ; i ++ ) { outputs . add ( output ) ; } String token = "TokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenToken" ; CommandRequest request = coldWallet . startTransaction ( inputs , outputs , token ) ; assertThat ( request . getSerializedSize ( ) ) . isLessThan ( Constants . MAX_QR_PROTO_BYTES ) ; List < Signature > signatures = new ArrayList < > ( ) ; for ( int i = 0 ; i < Constants . INPUTS_COUNT_AT_LEAST ; i ++ ) { signatures . add ( Signature . newBuilder ( ) . setDer ( ByteString . copyFrom ( Hex . decode ( "3045022100c822d9b754a87ef25a0c9a9ad44eba41bd00822ddab60f759e77e99e80427feb02207edc74ca82fafc6d7b42ef4815d4142ff49fca0bac533449f15543c19264c13901FF" ) ) ) . build ( ) ) ; } CommandResponse response = CommandResponse . newBuilder ( ) . setToken ( token ) . setSignTx ( CommandResponse . SignTxResponse . newBuilder ( ) . addAllSignatures ( signatures ) ) . build ( ) ; System . out . println ( format ( "the serialized size is %d (of %d)" , response . getSerializedSize ( ) , Constants . MAX_QR_PROTO_BYTES ) ) ; assertThat ( response . getSerializedSize ( ) ) . isLessThan ( Constants . MAX_QR_PROTO_BYTES ) ; }
MaxSizeTest verifies we can create a transaction with the documented number of inputs and
 outputs, with the generated proto under the QR code size limit.
MaxSizeTest verifies we can create a transaction with the documented number of inputs and outputs with the generated proto under the QR code size limit .
// This input is as big as possible. // The response consists of signatures.  We know bitcoin signatures are, in worst-case, 73 bytes // So we verify a CommandResponse.SignTxResponse with 73 byte signatures fits.