Example #1
0
    def test_recognition_and_comparisons(self):
        a = Address(self.addr)
        a2 = address(self.addr)
        self.assertIsInstance(a2, Address)
        self.assertEqual(a, a2)
        self.assertEqual(a, self.addr)
        self.assertEqual(self.addr, a)
        self.assertEqual(hash(a), hash(self.addr))
        self.assertEqual(a.is_mainnet(), self.mainnet)
        self.assertEqual(a.is_testnet(), self.testnet)
        self.assertEqual(a.is_stagenet(), self.stagenet)
        self.assertEqual(a2.is_mainnet(), self.mainnet)
        self.assertEqual(a2.is_testnet(), self.testnet)
        self.assertEqual(a2.is_stagenet(), self.stagenet)

        ia = IntegratedAddress(self.iaddr)
        ia2 = address(self.iaddr)
        self.assertIsInstance(ia, IntegratedAddress)
        self.assertEqual(ia, ia2)
        self.assertEqual(ia, self.iaddr)
        self.assertEqual(self.iaddr, ia)
        self.assertEqual(hash(ia), hash(self.iaddr))
        self.assertEqual(ia.is_mainnet(), self.mainnet)
        self.assertEqual(ia.is_testnet(), self.testnet)
        self.assertEqual(ia.is_stagenet(), self.stagenet)
        self.assertEqual(ia2.is_mainnet(), self.mainnet)
        self.assertEqual(ia2.is_testnet(), self.testnet)
        self.assertEqual(ia2.is_stagenet(), self.stagenet)
        self.assertEqual(ia2.base_address(), a)

        self.assertEqual(ia.view_key(), a.view_key())
        self.assertEqual(ia.spend_key(), a.spend_key())

        sa = SubAddress(self.subaddr)
        sa2 = address(self.subaddr)
        self.assertIsInstance(sa2, SubAddress)
        self.assertEqual(sa, sa2)
        self.assertEqual(sa, self.subaddr)
        self.assertEqual(self.subaddr, sa)
        self.assertEqual(hash(sa), hash(self.subaddr))
        self.assertEqual(sa.is_mainnet(), self.mainnet)
        self.assertEqual(sa.is_testnet(), self.testnet)
        self.assertEqual(sa.is_stagenet(), self.stagenet)
        self.assertEqual(sa2.is_mainnet(), self.mainnet)
        self.assertEqual(sa2.is_testnet(), self.testnet)
        self.assertEqual(sa2.is_stagenet(), self.stagenet)

        self.assertNotEqual(a, 0)
Example #2
0
def validate_monero_address(value):
    try:
        address = Address(value)
    except ValueError as e:
        raise ValidationError(_("%(value)s is not a valid address"),
                              params={"value": value})

    network = getattr(settings, "DJCL_MONERO_NETWORK", None)
    if not network:
        raise ValidationError(
            _("Please configure the monero network in the settings file"))
    if network == "mainnet" and not address.is_mainnet():
        raise ValidationError(_("Invalid address for mainnet"))
    elif network == "stagenet" and not address.is_stagenet():
        raise ValidationError(_("Invalid address for stagenet"))
    elif network == "testnet" and not address.is_testnet():
        raise ValidationError(_("Invalid address for testnet"))
Example #3
0
    def test_recognition_and_comparisons(self):
        a = Address(self.addr)
        a2 = address(self.addr)
        self.assertIsInstance(a2, Address)
        self.assertEqual(a, a2)
        self.assertEqual(a, self.addr)
        self.assertEqual(self.addr, a)
        self.assertEqual(hash(a), hash(self.addr))
        self.assertEqual(a.net, self.net)
        with pytest.deprecated_call():
            self.assertEqual(a.is_mainnet(), self.net == const.NET_MAIN)
        with pytest.deprecated_call():
            self.assertEqual(a.is_testnet(), self.net == const.NET_TEST)
        with pytest.deprecated_call():
            self.assertEqual(a.is_stagenet(), self.net == const.NET_STAGE)
        self.assertEqual(a2.net, self.net)
        with pytest.deprecated_call():
            self.assertEqual(a2.is_mainnet(), self.net == const.NET_MAIN)
        with pytest.deprecated_call():
            self.assertEqual(a2.is_testnet(), self.net == const.NET_TEST)
        with pytest.deprecated_call():
            self.assertEqual(a2.is_stagenet(), self.net == const.NET_STAGE)

        ia = IntegratedAddress(self.iaddr)
        ia2 = address(self.iaddr)
        self.assertIsInstance(ia, IntegratedAddress)
        self.assertEqual(ia, ia2)
        self.assertEqual(ia, self.iaddr)
        self.assertEqual(self.iaddr, ia)
        self.assertEqual(hash(ia), hash(self.iaddr))
        self.assertEqual(ia.net, self.net)
        with pytest.deprecated_call():
            self.assertEqual(ia.is_mainnet(), self.net == const.NET_MAIN)
        with pytest.deprecated_call():
            self.assertEqual(ia.is_testnet(), self.net == const.NET_TEST)
        with pytest.deprecated_call():
            self.assertEqual(ia.is_stagenet(), self.net == const.NET_STAGE)
        self.assertEqual(ia2.net, self.net)
        with pytest.deprecated_call():
            self.assertEqual(ia2.is_mainnet(), self.net == const.NET_MAIN)
        with pytest.deprecated_call():
            self.assertEqual(ia2.is_testnet(), self.net == const.NET_TEST)
        with pytest.deprecated_call():
            self.assertEqual(ia2.is_stagenet(), self.net == const.NET_STAGE)
        self.assertEqual(ia2.base_address(), a)

        self.assertEqual(ia.view_key(), a.view_key())
        self.assertEqual(ia.spend_key(), a.spend_key())

        sa = SubAddress(self.subaddr)
        sa2 = address(self.subaddr)
        self.assertIsInstance(sa2, SubAddress)
        self.assertEqual(sa, sa2)
        self.assertEqual(sa, self.subaddr)
        self.assertEqual(self.subaddr, sa)
        self.assertEqual(hash(sa), hash(self.subaddr))
        self.assertEqual(sa.net, self.net)
        with pytest.deprecated_call():
            self.assertEqual(sa.is_mainnet(), self.net == const.NET_MAIN)
        with pytest.deprecated_call():
            self.assertEqual(sa.is_testnet(), self.net == const.NET_TEST)
        with pytest.deprecated_call():
            self.assertEqual(sa.is_stagenet(), self.net == const.NET_STAGE)
        self.assertEqual(sa2.net, self.net)
        with pytest.deprecated_call():
            self.assertEqual(sa2.is_mainnet(), self.net == const.NET_MAIN)
        with pytest.deprecated_call():
            self.assertEqual(sa2.is_testnet(), self.net == const.NET_TEST)
        with pytest.deprecated_call():
            self.assertEqual(sa2.is_stagenet(), self.net == const.NET_STAGE)

        self.assertNotEqual(a, 0)