Ejemplo n.º 1
0
 def test_fail_stop_occurs_before_start(self):
     """
 ``stop`` is less than ``start``.
 """
     self.assertFilterErrors(
         {
             'start': 1,
             'stop': 0,
             'seed': Seed(self.seed),
         },
         {
             'start': [GetTransfersRequestFilter.CODE_INTERVAL_INVALID],
         },
     )
Ejemplo n.º 2
0
 def test_fail_interval_too_large(self):
     """
 ``stop`` is way more than ``start``.
 """
     self.assertFilterErrors(
         {
             'start': 0,
             'stop': GetTransfersRequestFilter.MAX_INTERVAL + 1,
             'seed': Seed(self.seed),
         },
         {
             'stop': [GetTransfersRequestFilter.CODE_INTERVAL_TOO_BIG],
         },
     )
Ejemplo n.º 3
0
 def test_fail_stop_string(self):
     """
 ``stop`` is a string.
 """
     self.assertFilterErrors(
         {
             # Not valid; it must be an int.
             'stop': '0',
             'seed': Seed(self.seed),
         },
         {
             'stop': [f.Type.CODE_WRONG_TYPE],
         },
     )
Ejemplo n.º 4
0
    def test_pass_happy_path(self):
        """
    Request is valid.
    """
        request = {
            'seed': Seed(self.seed),
            'start': 0,
            'stop': 10,
            'inclusionStates': True,
        }

        filter_ = self._filter(request)

        self.assertFilterPasses(filter_)
        self.assertDictEqual(filter_.cleaned_data, request)
Ejemplo n.º 5
0
  def test_fail_inclusion_states_wrong_type(self):
    """
    ``inclusionStates`` is not a boolean.
    """
    self.assertFilterErrors(
      {
        'inclusionStates': '1',

        'seed': Seed(self.seed),
      },

      {
        'inclusionStates': [f.Type.CODE_WRONG_TYPE],
      },
    )
Ejemplo n.º 6
0
    def test_pass_happy_path(self):
        """
    Request is valid.
    """
        request = {
            'seed': Seed(self.seed),
            'index': 1,
            'count': 1,
            'securityLevel': 1,
        }

        filter_ = self._filter(request)

        self.assertFilterPasses(filter_)
        self.assertDictEqual(filter_.cleaned_data, request)
Ejemplo n.º 7
0
    def test_fail_unexpected_parameters(self):
        """
    The request contains unexpected parameters.
    """
        self.assertFilterErrors(
            {
                'seed': Seed(self.seed),

                # Told you I did. Reckless is he. Now, matters are worse.
                'foo': 'bar',
            },
            {
                'foo': [f.FilterMapper.CODE_EXTRA_KEY],
            },
        )
Ejemplo n.º 8
0
 def test_fail_transfers_empty(self):
     """
 ``transfers`` is an array, but it is empty.
 """
     self.assertFilterErrors(
         {
             'transfers': [],
             'depth': 100,
             'minWeightMagnitude': 18,
             'seed': Seed(self.trytes1),
         },
         {
             'transfers': [f.Required.CODE_EMPTY],
         },
     )
Ejemplo n.º 9
0
 def test_fail_min_weight_magnitude_null(self):
     """
 ``minWeightMagnitude`` is null.
 """
     self.assertFilterErrors(
         {
             'minWeightMagnitude': None,
             'depth': 100,
             'seed': Seed(self.trytes1),
             'transfers': [self.transfer1],
         },
         {
             'minWeightMagnitude': [f.Required.CODE_EMPTY],
         },
     )
Ejemplo n.º 10
0
    def test_fail_unexpected_parameters(self):
        """
    The request contains unexpected parameters.
    """
        self.assertFilterErrors(
            {
                'seed': Seed(self.seed),

                # Your rules are really beginning to annoy me.
                'foo': 'bar',
            },
            {
                'foo': [f.FilterMapper.CODE_EXTRA_KEY],
            },
        )
Ejemplo n.º 11
0
 def test_fail_transfers_wrong_type(self):
     """
 ``transfers`` is not an array.
 """
     self.assertFilterErrors(
         {
             'transfers': self.transfer1,
             'depth': 100,
             'minWeightMagnitude': 18,
             'seed': Seed(self.trytes1),
         },
         {
             'transfers': [f.Type.CODE_WRONG_TYPE],
         },
     )
Ejemplo n.º 12
0
 def test_fail_stop_float(self):
     """
 ``stop`` is a float.
 """
     self.assertFilterErrors(
         {
             # Even with an empty fpart, floats are not valid.
             # It's gotta be an int.
             'stop': 8.0,
             'seed': Seed(self.seed),
         },
         {
             'stop': [f.Type.CODE_WRONG_TYPE],
         },
     )
Ejemplo n.º 13
0
  def test_fail_threshold_too_small(self):
    """
    ``threshold`` is less than 0.
    """
    self.assertFilterErrors(
      {
        'threshold': -1,

        'seed': Seed(self.seed),
      },

      {
        'threshold': [f.Min.CODE_TOO_SMALL],
      },
    )
Ejemplo n.º 14
0
  def test_fail_stop_too_small(self):
    """
    ``stop`` is less than 0.
    """
    self.assertFilterErrors(
      {
        'stop': -1,

        'seed': Seed(self.seed),
      },

      {
        'stop': [f.Min.CODE_TOO_SMALL],
      },
    )
Ejemplo n.º 15
0
 def test_fail_min_weight_magnitude_too_small(self):
     """
 ``minWeightMagnitude`` is < 1.
 """
     self.assertFilterErrors(
         {
             'minWeightMagnitude': 0,
             'depth': 100,
             'seed': Seed(self.trytes1),
             'transfers': [self.transfer1],
         },
         {
             'minWeightMagnitude': [f.Min.CODE_TOO_SMALL],
         },
     )
Ejemplo n.º 16
0
 def test_fail_reference_wrong_type(self):
     """
 ``reference`` is not a TrytesCompatible value.
 """
     self.assertFilterErrors(
         {
             'reference': 42,
             'seed': Seed(self.trytes1),
             'depth': 100,
             'minWeightMagnitude': 18,
             'transfers': [self.transfer1],
         },
         {
             'reference': [f.Type.CODE_WRONG_TYPE],
         },
     )
Ejemplo n.º 17
0
    def setUp(self):
        super(IterUsedAddressesTestCase, self).setUp()

        self.adapter = MockAdapter()
        self.seed = Seed(trytes='S' * 81)
        self.address0 = 'A' * 81
        self.address1 = 'B' * 81
        self.address2 = 'C' * 81
        self.address3 = 'D' * 81

        # To speed up the tests, we will mock the address generator.
        def address_generator(ag, start, step=1):
            for addy in [self.address0, self.address1, self.address2,
                         self.address3][start::step]:
                yield addy
        self.mock_address_generator = address_generator
Ejemplo n.º 18
0
 def test_fail_min_weight_magnitude_float(self):
     """
 ``minWeightMagnitude`` is a float.
 """
     self.assertFilterErrors(
         {
             # Even with an empty fpart, floats are invalid.
             'minWeightMagnitude': 18.0,
             'depth': 100,
             'seed': Seed(self.trytes1),
             'transfers': [self.transfer1],
         },
         {
             'minWeightMagnitude': [f.Type.CODE_WRONG_TYPE],
         },
     )
Ejemplo n.º 19
0
 def test_fail_min_weight_magnitude_string(self):
     """
 ``minWeightMagnitude`` is a string.
 """
     self.assertFilterErrors(
         {
             # Nope; it's gotta be an int.
             'minWeightMagnitude': '18',
             'depth': 100,
             'seed': Seed(self.trytes1),
             'transfers': [self.transfer1],
         },
         {
             'minWeightMagnitude': [f.Type.CODE_WRONG_TYPE],
         },
     )
Ejemplo n.º 20
0
 def test_fail_depth_string(self):
     """
 ``depth`` is a string.
 """
     self.assertFilterErrors(
         {
             # Too ambiguous; it must be an int.
             'depth': '2',
             'minWeightMagnitude': 18,
             'seed': Seed(self.trytes1),
             'transfers': [self.transfer1],
         },
         {
             'depth': [f.Type.CODE_WRONG_TYPE],
         },
     )
Ejemplo n.º 21
0
 def test_fail_reference_not_trytes(self):
     """
 ``reference`` contains invalid characters.
 """
     self.assertFilterErrors(
         {
             'reference': b'not valid; must contain only uppercase and "9"',
             'seed': Seed(self.trytes1),
             'depth': 100,
             'minWeightMagnitude': 18,
             'transfers': [self.transfer1],
         },
         {
             'reference': [Trytes.CODE_NOT_TRYTES],
         },
     )
Ejemplo n.º 22
0
    def test_fail_index_float(self):
        """
    ``index`` is a float value.
    """
        self.assertFilterErrors(
            {
                # Not valid, even with an empty fpart; it must be an int.
                'index': 42.0,

                'seed': Seed(self.seed),
            },

            {
                'index': [f.Type.CODE_WRONG_TYPE],
            },
        )
Ejemplo n.º 23
0
    def test_fail_index_string(self):
        """
    ``index`` is a string value.
    """
        self.assertFilterErrors(
            {
                # Not valid; it must be an int.
                'index': '42',

                'seed': Seed(self.seed),
            },

            {
                'index': [f.Type.CODE_WRONG_TYPE],
            },
        )
Ejemplo n.º 24
0
 def test_fail_inputs_wrong_type(self):
     """
 ``inputs`` is not an array.
 """
     self.assertFilterErrors(
         {
             # Must be an array, even if there's only one input.
             'inputs': Address(self.trytes4),
             'depth': 100,
             'minWeightMagnitude': 18,
             'seed': Seed(self.trytes1),
             'transfers': [self.transfer1],
         },
         {
             'inputs': [f.Type.CODE_WRONG_TYPE],
         },
     )
Ejemplo n.º 25
0
    def test_fail_unexpected_parameters(self):
        """
    Request contains unexpected parameters.
    """
        self.assertFilterErrors(
            {
                'seed': Seed(self.seed),
                'index': None,
                'count': 1,

                # Some men just want to watch the world burn.
                'foo': 'bar',
            },
            {
                'foo': [f.FilterMapper.CODE_EXTRA_KEY],
            },
        )
Ejemplo n.º 26
0
  def test_pass_compatible_types(self):
    """
    Request contains values that can be converted to the expected
    types.
    """
    filter_ = self._filter({
      # Any TrytesCompatible values will work here.
      'changeAddress':  binary_type(self.trytes1),
      'seed':           bytearray(self.trytes2),

      'inputs': [
        binary_type(self.trytes3),
        bytearray(self.trytes4),
      ],

      # These values must have the correct type, however.
      'transfers': [
        self.transfer1,
        self.transfer2
      ],

      'depth':              100,
      'minWeightMagnitude': 18,
    })

    self.assertFilterPasses(filter_)
    self.assertDictEqual(
      filter_.cleaned_data,

      {
        'changeAddress':      Address(self.trytes1),
        'depth':              100,
        'minWeightMagnitude': 18,
        'seed':               Seed(self.trytes2),

        'inputs': [
          Address(self.trytes3),
          Address(self.trytes4),
        ],

        'transfers': [
          self.transfer1,
          self.transfer2
        ],
      }
    )
Ejemplo n.º 27
0
  def test_fail_change_address_wrong_type(self):
    """
    ``changeAddress`` is not a TrytesCompatible value.
    """
    self.assertFilterErrors(
      {
        'changeAddress': text_type(self.trytes3, 'ascii'),

        'depth':              100,
        'minWeightMagnitude': 18,
        'seed':               Seed(self.trytes1),
        'transfers':          [self.transfer1],
      },

      {
        'changeAddress': [f.Type.CODE_WRONG_TYPE],
      },
    )
Ejemplo n.º 28
0
    def test_fail_unexpected_parameters(self):
        """
    Request contains unexpected parameters.
    """
        self.assertFilterErrors(
            {
                'depth': 100,
                'minWeightMagnitude': 18,
                'seed': Seed(self.trytes1),
                'transfers': [self.transfer1],

                # Maybe he's not that smart; maybe he's like a worker bee who
                # only knows how to push buttons or something.
                'foo': 'bar',
            },
            {
                'foo': [f.FilterMapper.CODE_EXTRA_KEY],
            },
        )
Ejemplo n.º 29
0
    def test_fail_wrong_security_level_type(self):
        """
    ``security_level`` is not one of integers 1, 2 or 3.
    """
        self.assertFilterErrors(
            {
                'depth': 100,
                'minWeightMagnitude': 18,
                'seed': Seed(self.trytes1),
                'transfers': [self.transfer1],

                # Maybe he's not that smart; maybe he's like a worker bee who
                # only knows how to push buttons or something.
                'securityLevel': "2",
            },
            {
                'securityLevel': [f.Type.CODE_WRONG_TYPE],
            },
        )
Ejemplo n.º 30
0
    def test_pass_compatible_types(self):
        """
    Request contains values that can be converted to the expected
    types.
    """
        filter_ = self._filter({
            # Any TrytesCompatible values will work here.
            'changeAddress':
            bytes(self.trytes1),
            'seed':
            bytearray(self.trytes2),
            'reference':
            bytes(self.trytes1),
            'inputs': [
                bytes(self.trytes3),
                bytearray(self.trytes4),
            ],

            # These values must have the correct type, however.
            'transfers': [self.transfer1, self.transfer2],
            'depth':
            100,
            'minWeightMagnitude':
            18,
            'securityLevel':
            None,
        })

        self.assertFilterPasses(filter_)
        self.assertDictEqual(
            filter_.cleaned_data, {
                'changeAddress': Address(self.trytes1),
                'depth': 100,
                'minWeightMagnitude': 18,
                'seed': Seed(self.trytes2),
                'reference': TransactionHash(self.trytes1),
                'inputs': [
                    Address(self.trytes3),
                    Address(self.trytes4),
                ],
                'transfers': [self.transfer1, self.transfer2],
                'securityLevel': AddressGenerator.DEFAULT_SECURITY_LEVEL
            })