def setUp(self):
        super(AddressGeneratorTestCase, self).setUp()

        self.seed_1 =\
          Seed(
            b'TESTVALUE9DONTUSEINPRODUCTION999999GFDDC'
            b'PFIIEHBCWFN9KHRBEIHHREFCKBVGUGEDXCFHDFPAL',
          )

        self.seed_2 =\
          Seed(
            b'TESTVALUE9DONTUSEINPRODUCTION99999DCZGVE'
            b'JIZEKEGEEHYE9DOHCHLHMGAFDGEEQFUDVGGDGHRDR',
          )
Beispiel #2
0
    def test_fail_inputs_contents_invalid(self):
        """
    ``inputs`` is a non-empty array, but it contains invalid values.
    """
        self.assertFilterErrors(
            {
                'inputs': [
                    b'',
                    True,
                    None,
                    b'not valid trytes',

                    # This is actually valid; I just added it to make sure the
                    #   filter isn't cheating!
                    TryteString(self.trytes4),
                    2130706433,
                    b'9' * 82,
                ],
                'depth':
                100,
                'minWeightMagnitude':
                18,
                'seed':
                Seed(self.trytes1),
                'transfers': [self.transfer1],
            },
            {
                'inputs.0': [f.Required.CODE_EMPTY],
                'inputs.1': [f.Type.CODE_WRONG_TYPE],
                'inputs.2': [f.Required.CODE_EMPTY],
                'inputs.3': [Trytes.CODE_NOT_TRYTES],
                'inputs.5': [f.Type.CODE_WRONG_TYPE],
                'inputs.6': [Trytes.CODE_WRONG_FORMAT],
            },
        )
Beispiel #3
0
    def test_pass_compatible_types(self):
        """
    The request contains values that can be converted to the expected
    types.
    """
        filter_ = self._filter({
            # ``seed`` can be any TrytesCompatible value.
            'seed': bytearray(self.seed.encode('ascii')),

            # These values must still be integers/bools, however.
            'start': 42,
            'stop': 86,
            'inclusionStates': True,
        })

        self.assertFilterPasses(filter_)
        self.assertDictEqual(
            filter_.cleaned_data,
            {
                'seed': Seed(self.seed),
                'start': 42,
                'stop': 86,
                'inclusionStates': True,
            },
        )
    def test_pass_compatible_types(self):
        """
    The request contains values that can be converted to the expected
    types.
    """
        filter_ = self._filter({
            # ``seed`` can be any value that is convertible into a
            # TryteString.
            'seed': binary_type(self.seed),

            # These values must still be integers/bools, however.
            'start': 42,
            'stop': 86,
            'inclusionStates': True,
            'security_level': 2
        })

        self.assertFilterPasses(filter_)
        self.assertDictEqual(
            filter_.cleaned_data,
            {
                'seed': Seed(self.seed),
                'start': 42,
                'stop': 86,
                'inclusionStates': True,
                'security_level': 2
            },
        )
Beispiel #5
0
    def test_fail_transfers_contents_invalid(self):
        """
    ``transfers`` is a non-empty array, but it contains invalid values.
    """
        self.assertFilterErrors(
            {
                'transfers': [
                    None,

                    # This value is valid; just adding it to make sure the filter
                    # doesn't cheat!
                    ProposedTransaction(address=Address(self.trytes2),
                                        value=42),
                    {
                        'address': Address(self.trytes2),
                        'value': 42
                    },
                ],
                'depth':
                100,
                'minWeightMagnitude':
                18,
                'seed':
                Seed(self.trytes1),
            },
            {
                'transfers.0': [f.Required.CODE_EMPTY],
                'transfers.2': [f.Type.CODE_WRONG_TYPE],
            },
        )
Beispiel #6
0
    def test_pass_optional_parameters_excluded(self):
        """
    The request contains only required parameters.
    """
        filter_ = self._filter({
            'seed': Seed(self.seed),
        })

        self.assertFilterPasses(filter_)
        self.assertDictEqual(
            filter_.cleaned_data, {
                'seed': Seed(self.seed),
                'start': 0,
                'stop': None,
                'inclusionStates': False,
            })
Beispiel #7
0
  def test_pass_compatible_types(self):
    """
    Request contains values that can be converted to the expected
    types.
    """
    filter_ = self._filter({
      # ``seed`` can be any value that is convertible to TryteString.
      'seed': binary_type(self.seed),

      # These values must be integers, however.
      'index':          100,
      'count':          8,
      'securityLevel':  1,
    })

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

      {
        'seed':           Seed(self.seed),
        'index':          100,
        'count':          8,
        'securityLevel':  1,
      },
    )
Beispiel #8
0
  def test_pass_compatible_types(self):
    """
    Request contains values that can be converted to the expected
    types.
    """
    filter_ = self._filter({
      # ``seed`` can be any TrytesCompatible value.
      'seed': bytearray(self.seed.encode('ascii')),

      # These values must be integers, however.
      'index':          100,
      'count':          8,
      'securityLevel':  2,

      # ``checksum`` must be boolean.
      'checksum':       False,
    })

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

      {
        'seed':           Seed(self.seed),
        'index':          100,
        'count':          8,
        'securityLevel':  2,
        'checksum':       False,
      },
    )
Beispiel #9
0
  def setUp(self):
    super(GetNewAddressesCommandTestCase, self).setUp()

    self.adapter = MockAdapter()
    self.command = GetNewAddressesCommand(self.adapter)

    self.seed =\
      Seed(
        b'TESTVALUE9DONTUSEINPRODUCTION99999ZDCCUF'
        b'CBBIQCLGMEXAVFQEOF9DRAB9VCEBAGXAF9VF9FLHP',
      )

    self.addy_1 =\
      Address(
        b'NYMWLBUJEISSACZZBRENC9HEHYQXHCGQHSNHVCEA'
        b'ZDCTEVNGSDUEKTSYBSQGMVJRIEDHWDYSEYCFAZAH9',
      )

    self.addy_2 =\
      Address(
        b'NTPSEVZHQITARYWHIRTSIFSERINLRYVXLGIQKKHY'
        b'IWYTLQUUHDWSOVXLIKVJTYZBFKLABWRBFYVSMD9NB',
      )

    self.addy_1_checksum =\
      Address(
        b'NYMWLBUJEISSACZZBRENC9HEHYQXHCGQHSNHVCEA'
        b'ZDCTEVNGSDUEKTSYBSQGMVJRIEDHWDYSEYCFAZAH'
        b'9T9FPJROTW',
      )
    def test_pass_compatible_types(self):
        """
    The request contains values that can be converted to the expected
    types.
    """
        filter_ = self._filter({
            # ``seed`` can be any value that is convertible into an ASCII
            # representation of a TryteString.
            'seed': bytearray(self.seed.encode('ascii')),

            # These values must still be integers, however.
            'start': 42,
            'stop': 86,
            'threshold': 99,
            "securityLevel": 3,
        })

        self.assertFilterPasses(filter_)
        self.assertDictEqual(
            filter_.cleaned_data,
            {
                'seed': Seed(self.seed),
                'start': 42,
                'stop': 86,
                'threshold': 99,
                "securityLevel": 3,
            },
        )
    def test_pass_optional_parameters_excluded(self):
        """
    The request contains only required parameters.
    """
        filter_ = self._filter({
            'seed': Seed(self.seed),
        })

        self.assertFilterPasses(filter_)
        self.assertDictEqual(
            filter_.cleaned_data, {
                'seed': Seed(self.seed),
                'start': 0,
                'stop': None,
                'threshold': None,
                "securityLevel": AddressGenerator.DEFAULT_SECURITY_LEVEL,
            })
Beispiel #12
0
    def seed_from_filepath(filepath):
        # type: (Text) -> Seed
        """
        Reads a seed from the first line of a text file.

        Any lines after the first are ignored.
        """
        with open(filepath, 'rb') as f_:
            return Seed(f_.readline().strip())
Beispiel #13
0
  def test_pass_optional_parameters_excluded(self):
    """
    Request omits optional parameters.
    """
    filter_ = self._filter({
      'seed': Seed(self.seed),
    })

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

      {
        'seed':           Seed(self.seed),
        'index':          0,
        'count':          1,
        'securityLevel':  AddressGenerator.DEFAULT_SECURITY_LEVEL,
      },
    )
Beispiel #14
0
    def __init__(
            self,
            seed,
            security_level=DEFAULT_SECURITY_LEVEL,
            checksum=False,
    ):
        # type: (TrytesCompatible, int, bool) -> None
        super(AddressGenerator, self).__init__()

        self.security_level = security_level
        self.checksum = checksum
        self.seed = Seed(seed)
 def test_fail_security_level_wrong_type(self):
     """
 ``securityLevel`` is not an int.
 """
     self.assertFilterErrors(
         {
             'securityLevel': '2',
             'seed': Seed(self.seed),
         },
         {
             'securityLevel': [f.Type.CODE_WRONG_TYPE],
         },
     )
 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],
         },
     )
 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],
         },
     )
 def test_fail_security_level_too_big(self):
     """
 ``securityLevel`` is > 3.
 """
     self.assertFilterErrors(
         {
             'securityLevel': 4,
             'seed': Seed(self.seed),
         },
         {
             'securityLevel': [f.Max.CODE_TOO_BIG],
         },
     )
 def test_fail_security_level_too_small(self):
     """
 ``securityLevel`` is < 1.
 """
     self.assertFilterErrors(
         {
             'securityLevel': 0,
             'seed': Seed(self.seed),
         },
         {
             'securityLevel': [f.Min.CODE_TOO_SMALL],
         },
     )
Beispiel #20
0
    def prompt_for_seed():
        # type: () -> Seed
        """
        Prompts the user to enter their seed via stdin.
        """
        seed = secure_input(
            'Enter seed and press return (typing will not be shown).\n'
            'If no seed is specified, a random one will be used instead.\n')

        if isinstance(seed, text_type):
            seed = seed.encode('ascii')

        return Seed(seed) if seed else Seed.random()
 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],
         },
     )
Beispiel #22
0
    def __init__(self, adapter, seed=None, testnet=False):
        # type: (AdapterSpec, Optional[TrytesCompatible], bool) -> None
        """
        :param seed:
            Seed used to generate new addresses.
            If not provided, a random one will be generated.

            .. note::
                This value is never transferred to the node/network.
        """
        super(Iota, self).__init__(adapter, testnet)

        self.seed = Seed(seed) if seed else Seed.random()
        self.helpers = Helpers(self)
Beispiel #23
0
    def test_pass_optional_parameters_omitted(self):
        """
    Request omits optional parameters.
    """
        filter_ = self._filter({
            'depth': 100,
            'minWeightMagnitude': 13,
            'seed': Seed(self.trytes2),
            'transfers': [self.transfer1, self.transfer2],
        })

        self.assertFilterPasses(filter_)
        self.assertDictEqual(
            filter_.cleaned_data, {
                'changeAddress': None,
                'inputs': None,
                'reference': None,
                'depth': 100,
                'minWeightMagnitude': 13,
                'securityLevel': AddressGenerator.DEFAULT_SECURITY_LEVEL,
                'seed': Seed(self.trytes2),
                'transfers': [self.transfer1, self.transfer2],
            })
Beispiel #24
0
  def test_fail_securityLevel_float(self):
    """
    ``securityLevel`` is a float value.
    """
    self.assertFilterErrors(
      {
        'securityLevel':  1.0,
        'seed':           Seed(self.seed),
      },

      {
        'securityLevel': [f.Type.CODE_WRONG_TYPE],
      },
    )
 def test_fail_start_string(self):
     """
 ``start`` is a string.
 """
     self.assertFilterErrors(
         {
             # Not valid; it must be an int.
             'start': '0',
             'seed': Seed(self.seed),
         },
         {
             'start': [f.Type.CODE_WRONG_TYPE],
         },
     )
Beispiel #26
0
  def test_fail_securityLevel_string(self):
    """
    ``securityLevel`` is a string value.
    """
    self.assertFilterErrors(
      {
        'securityLevel':  '1',
        'seed':           Seed(self.seed),
      },

      {
        'securityLevel': [f.Type.CODE_WRONG_TYPE],
      },
    )
Beispiel #27
0
  def test_fail_count_too_small(self):
    """
    ``count`` is less than 1.
    """
    self.assertFilterErrors(
      {
        'count':  0,
        'seed':   Seed(self.seed),
      },

      {
        'count': [f.Min.CODE_TOO_SMALL],
      },
    )
 def test_fail_stop_occurs_before_start(self):
     """
 ``stop`` is less than ``start``.
 """
     self.assertFilterErrors(
         {
             'start': 1,
             'stop': 0,
             'seed': Seed(self.seed),
         },
         {
             'start': [GetInputsRequestFilter.CODE_INTERVAL_INVALID],
         },
     )
 def test_fail_interval_too_large(self):
     """
 ``stop`` is way more than ``start``.
 """
     self.assertFilterErrors(
         {
             'start': 0,
             'stop': GetInputsRequestFilter.MAX_INTERVAL + 1,
             'seed': Seed(self.seed),
         },
         {
             'stop': [GetInputsRequestFilter.CODE_INTERVAL_TOO_BIG],
         },
     )
 def test_fail_threshold_string(self):
     """
 ``threshold`` is a string.
 """
     self.assertFilterErrors(
         {
             # Not valid; it must be an int.
             'threshold': '0',
             'seed': Seed(self.seed),
         },
         {
             'threshold': [f.Type.CODE_WRONG_TYPE],
         },
     )