Example #1
0
    def setUp(self):
        """
        Method called to prepare the test fixture.

        1. Start Bitcoin Core Daemon and get a default Bitcoin address.
        2. Attempt to try a connection to a node once in our host list.
        3. Get fixed(default) and some normal addresses in core wallet.
        """
        result = {}

        role = BaseRole(env.host)
        if RESET_BLOCKCHAIN:
            role.reset_and_restart()
        else:
            role.start()

        result['default'] = role.getfixedaddress()

        # Try a connection with each other
        for host in env.hosts:
            if host == env.host:
                continue
            role.addnode(host.split('_')[0], host.split('_')[1])

        result['wallet'] = role.listwalletaddress(config.NUM_ADDRESS_PER_NODE)
        return result
Example #2
0
    def setUp(self):
        """
        Method called to prepare the test fixture.

        1. Start Bitcoin Core Daemon and get a default Bitcoin address.
        2. Attempt to try a connection to a node once in our host list.
        3. Get fixed(default) and some normal addresses in core wallet.
        """
        result = {}

        role = BaseRole(env.host)
        if RESET_BLOCKCHAIN:
            role.reset_and_restart()
        else:
            role.start()

        result['default'] = role.getfixedaddress()

        # Try a connection with each other
        for host in env.hosts:
            if host == env.host:
                continue
            role.addnode(host, config.port)

        result['wallet'] = role.listwalletaddress(config.NUM_ADDRESS_PER_NODE)
        return result
Example #3
0
 def mint_all_i_can_mint_after_become_issuer(self):
     role = BaseRole(env.host)
     licenseinfo = role.getlicenseinfo()
     for color, info in licenseinfo.iteritems():
         if int(color) == 1:
             # already minted in apply_license_1()
             # skip this case otherwise coins may overflow
             continue
         issuer = Issuer(env.host, info['address'], color)
         # TODO: if mint MAX_COINS = 10^10
         # sendfrom rpc error: The transaction was rejected  will happen
         issuer.mint(config.INITIAL_AMOUNT_PER_ISSUER)
Example #4
0
 def mint_all_i_can_mint_after_become_issuer(self):
     role = BaseRole(env.host)
     licenseinfo = role.getlicenseinfo()
     for color, info in licenseinfo.iteritems():
         if int(color) == 1:
             # already minted in apply_license_1()
             # skip this case otherwise coins may overflow
             continue
         issuer = Issuer(env.host, info['address'], color)
         # TODO: if mint MAX_COINS = 10^10
         # sendfrom rpc error: The transaction was rejected  will happen
         issuer.mint(config.INITIAL_AMOUNT_PER_ISSUER)
Example #5
0
    def create_payment(self, from_address, to_address, amount, color):
        role = BaseRole(env.host)
        balances = role.getaddressbalance(from_address)
        if not balances.has_key(str(color)) or not balances.has_key("1") or int(balances[color]) < amount:
            # insufficient funds
            return

        role.send_coins(from_address, to_address, amount, color)
        msg = "{from_addr} send {amount} of color: {color} TO {to_addr}".format(from_addr=from_address,
                                                                                amount=amount,
                                                                                color=color,
                                                                                to_addr=to_address)
        print green(msg)
Example #6
0
    def create_payment(self, from_address, to_address, amount, color):
        role = BaseRole(env.host)
        balances = role.getaddressbalance(from_address)
        if not balances.has_key(str(color)) or not balances.has_key("1") or int(balances[color]) < amount:
            f = open(env.host.split('_')[0] + env.host.split('_')[1] + '.txt','a')
            if not balances.has_key("1"):
                f.write('color 1 not enough\n')
            else :
                f.write('color ' + str(color) + ' not enough\n')
            f.close()
            # insufficient funds
            return

        role.send_coins(from_address, to_address, amount, color, False)
        msg = "{from_addr} send {amount} of color: {color} TO {to_addr}".format(from_addr=from_address,
                                                                                amount=amount,
                                                                                color=color,
                                                                                to_addr=to_address)
        print green(msg)
Example #7
0
    def random_apply_member(self):
        result = {}

        role = BaseRole(env.host)
        licenseinfo = role.getlicenseinfo()
        for color, info in licenseinfo.iteritems():
            if int(color) == 1:
                # for the use of fee
                continue

            members = []
            issuer = Issuer(env.host, info['address'], color)
            for idx in xrange(config.MAX_NUM_MEMBERS_PER_ISSUER):
                member_address = self._random_choose_an_address('others')
                if member_address in members:
                    continue
                issuer.activate(member_address, config.INITIAL_AMOUNT_PER_ISSUER / config.MAX_NUM_MEMBERS_PER_ISSUER)
                members.append(member_address)

            result[color] = members

        return result
Example #8
0
    def random_apply_member(self):
        result = {}

        role = BaseRole(env.host)
        licenseinfo = role.getlicenseinfo()
        for color, info in licenseinfo.iteritems():
            if int(color) == 1:
                # for the use of fee
                continue

            members = []
            issuer = Issuer(env.host, info['address'], color)
            for idx in xrange(config.MAX_NUM_MEMBERS_PER_ISSUER):
                member_address = self._random_choose_an_address('others')
                if member_address in members:
                    continue
                issuer.activate(member_address, config.INITIAL_AMOUNT_PER_ISSUER / config.MAX_NUM_MEMBERS_PER_ISSUER)
                members.append(member_address)

            result[color] = members

        return result