Ejemplo n.º 1
0
def test_invalid_syscoin_address():
    from syscoinlib import is_valid_syscoin_address

    main = invalid_syscoin_address()
    test = invalid_syscoin_address('testnet')

    assert is_valid_syscoin_address(main) is False
    assert is_valid_syscoin_address(main, 'mainnet') is False
    assert is_valid_syscoin_address(main, 'testnet') is False

    assert is_valid_syscoin_address(test) is False
    assert is_valid_syscoin_address(test, 'mainnet') is False
    assert is_valid_syscoin_address(test, 'testnet') is False
Ejemplo n.º 2
0
    def is_valid(self):
        import syscoinlib
        import decimal

        printdbg("In Superblock#is_valid, for SB: %s" % self.__dict__)

        # it's a string from the DB...
        addresses = self.payment_addresses.split('|')
        for addr in addresses:
            if not syscoinlib.is_valid_syscoin_address(addr, config.network):
                printdbg("\tInvalid address [%s], returning False" % addr)
                return False

        amounts = self.payment_amounts.split('|')
        for amt in amounts:
            if not misc.is_numeric(amt):
                printdbg("\tAmount [%s] is not numeric, returning False" % amt)
                return False

            # no negative or zero amounts allowed
            damt = decimal.Decimal(amt)
            if not damt > 0:
                printdbg("\tAmount [%s] is zero or negative, returning False" %
                         damt)
                return False

        # verify proposal hashes correctly formatted...
        if len(self.proposal_hashes) > 0:
            hashes = self.proposal_hashes.split('|')
            for object_hash in hashes:
                if not misc.is_hash(object_hash):
                    printdbg("\tInvalid proposal hash [%s], returning False" %
                             object_hash)
                    return False

        # ensure number of payment addresses matches number of payments
        if len(addresses) != len(amounts):
            printdbg(
                "\tNumber of payment addresses [%s] != number of payment amounts [%s], returning False"
                % (len(addresses), len(amounts)))
            return False

        printdbg("Leaving Superblock#is_valid, Valid = True")
        return True
Ejemplo n.º 3
0
    def is_valid(self):
        import syscoinlib

        printdbg("In Proposal#is_valid, for Proposal: %s" % self.__dict__)

        try:
            # proposal name exists and is not null/whitespace
            if (len(self.name.strip()) == 0):
                printdbg("\tInvalid Proposal name [%s], returning False" %
                         self.name)
                return False

            # proposal name is normalized (something like "[a-zA-Z0-9-_]+")
            if not re.match(r'^[-_a-zA-Z0-9]+$', self.name):
                printdbg(
                    "\tInvalid Proposal name [%s] (does not match regex), returning False"
                    % self.name)
                return False

            # end date < start date
            if (self.end_epoch <= self.start_epoch):
                printdbg(
                    "\tProposal end_epoch [%s] <= start_epoch [%s] , returning False"
                    % (self.end_epoch, self.start_epoch))
                return False

            # amount must be numeric
            if misc.is_numeric(self.payment_amount) is False:
                printdbg(
                    "\tProposal amount [%s] is not valid, returning False" %
                    self.payment_amount)
                return False

            # amount can't be negative or 0
            if (float(self.payment_amount) <= 0):
                printdbg(
                    "\tProposal amount [%s] is negative or zero, returning False"
                    % self.payment_amount)
                return False

            # payment address is valid base58 syscoin addr, non-multisig
            if not syscoinlib.is_valid_syscoin_address(self.payment_address,
                                                       config.network):
                printdbg(
                    "\tPayment address [%s] not a valid Syscoin address for network [%s], returning False"
                    % (self.payment_address, config.network))
                return False

            # URL
            if (len(self.url.strip()) < 4):
                printdbg("\tProposal URL [%s] too short, returning False" %
                         self.url)
                return False

            # proposal URL has any whitespace
            if (re.search(r'\s', self.url)):
                printdbg(
                    "\tProposal URL [%s] has whitespace, returning False" %
                    self.name)
                return False

            # Syscoin Core restricts proposals to 512 bytes max
            if len(self.serialise()) > (self.MAX_DATA_SIZE * 2):
                printdbg("\tProposal [%s] is too big, returning False" %
                         self.name)
                return False

            try:
                parsed = urlparse.urlparse(self.url)
            except Exception as e:
                printdbg(
                    "\tUnable to parse Proposal URL, marking invalid: %s" % e)
                return False

        except Exception as e:
            printdbg(
                "Unable to validate in Proposal#is_valid, marking invalid: %s"
                % e.message)
            return False

        printdbg("Leaving Proposal#is_valid, Valid = True")
        return True
def test_valid_syscoin_address():
    from syscoinlib import is_valid_syscoin_address

    main = valid_syscoin_address()
    test = valid_syscoin_address('testnet')
    main_btc = valid_bitcoin_address()
    test_btc = valid_bitcoin_address('testnet')

    assert is_valid_syscoin_address(main) is True
    assert is_valid_syscoin_address(main, 'mainnet') is True
    assert is_valid_syscoin_address(main, 'testnet') is False

    assert is_valid_syscoin_address(test) is False
    assert is_valid_syscoin_address(test, 'mainnet') is False
    assert is_valid_syscoin_address(test, 'testnet') is True

    assert is_valid_syscoin_address(main_btc) is True
    assert is_valid_syscoin_address(main_btc, 'mainnet') is True
    assert is_valid_syscoin_address(main_btc, 'testnet') is False

    assert is_valid_syscoin_address(test_btc) is False
    assert is_valid_syscoin_address(test_btc, 'mainnet') is False
    assert is_valid_syscoin_address(test_btc, 'testnet') is True