Beispiel #1
0
 def create_asset(self, is_issue=True, secondary=0):
     '''
     issue asset to the main address.
     secondary:   The rate of secondaryissue. Default to 0, means the
                  asset is not allowed to secondary issue forever;
                  otherwise, -1 means the asset can be secondary issue
                  freely; otherwise, the valid rate is in range of 1
                  to 100, means the asset can be secondary issue when
                  own percentage greater than or equal to the rate
                  value.
     '''
     self.domain_symbol = (self.name + common.get_random_str()).upper()
     self.asset_symbol = (self.domain_symbol + ".AST." +
                          common.get_random_str()).upper()
     result, message = mvs_rpc.create_asset(self.name,
                                            self.password,
                                            self.asset_symbol,
                                            300000,
                                            self.did_symbol,
                                            description="%s's Asset" %
                                            self.name,
                                            rate=secondary)
     assert (result == 0)
     if is_issue:
         result, message = mvs_rpc.issue_asset(self.name, self.password,
                                               self.asset_symbol)
         assert (result == 0)
Beispiel #2
0
 def create(self):
     '''
     create account by importkeyfile
     '''
     #auto create a new asset name for each time create_asset is called
     self.domain_symbol = (self.name + common.get_random_str()).upper()
     self.asset_symbol = (self.domain_symbol + ".AST." + common.get_random_str()).upper()
     return mvs_rpc.import_keyfile(self.name, self.password, self.keystore_file)
    def test_0_boundary(self):

        test_symbol = common.get_random_str()

        #account password error
        ec, message = mvs_rpc.register_mit(Alice.name, Alice.password + '1',
                                           Alice.did_symbol, test_symbol)
        self.assertEqual(ec, 1000, message)

        # check symbol length
        ec, message = mvs_rpc.register_mit(Alice.name, Alice.password,
                                           Alice.did_symbol, "X" * 61)
        self.assertEqual(ec, code.asset_symbol_length_exception, message)

        # check invalid char in symbol
        spec_char_lst = "`~!#$%^&*()+[{]}\\|;:'\",<>/?"
        for char in spec_char_lst:
            ec, message = mvs_rpc.register_mit(Alice.name, Alice.password,
                                               Alice.did_symbol,
                                               test_symbol + char)
            self.assertEqual(ec, code.asset_symbol_name_exception, message)

        # check content length
        ec, message = mvs_rpc.register_mit(Alice.name, Alice.password,
                                           Alice.did_symbol, test_symbol,
                                           "X" * 257)
        self.assertEqual(ec, code.argument_size_invalid_exception, message)

        # check to did not exist
        ec, message = mvs_rpc.register_mit(Alice.name, Alice.password,
                                           Alice.did_symbol + "1", test_symbol)
        self.assertEqual(ec, code.did_symbol_notfound_exception, message)

        # check to did not owned
        ec, message = mvs_rpc.register_mit(Alice.name, Alice.password,
                                           Bob.did_symbol, test_symbol)
        self.assertEqual(ec, code.address_dismatch_account_exception, message)

        # check symbol already exist
        ec, message = mvs_rpc.register_mit(Alice.name, Alice.password,
                                           Alice.did_symbol, test_symbol)
        self.assertEqual(ec, code.success, message)
        Alice.mining()

        ec, message = mvs_rpc.register_mit(Alice.name, Alice.password,
                                           Alice.did_symbol, test_symbol)
        self.assertEqual(ec, code.asset_symbol_existed_exception, message)

        # check max length of content 256
        test_symbol = common.get_random_str()
        ec, message = mvs_rpc.register_mit(Alice.name, Alice.password,
                                           Alice.did_symbol, test_symbol,
                                           "X" * 256)
        self.assertEqual(ec, code.success, message)
Beispiel #4
0
    def test_4_fork_at_issuecert(self):
        self.make_partion()

        cert_symbol = None
        try:
            domain = (u'Not2Exist' + common.get_random_str()).upper()
            domain_symbol, asset_symbol = Alice.create_random_asset(domain_symbol=domain)
            Alice.mining()

            cert_symbol = (domain_symbol + ".NAMING").upper();
            ec, message = mvs_rpc.issue_cert(Alice.name, Alice.password, Alice.did_symbol, cert_symbol, "NAMING")
            self.assertEqual(ec, 0, message)
            Alice.mining()

            # check naming cert
            certs = Alice.get_addressasset(Alice.didaddress(), True)


            cert = filter(lambda a: a.symbol == cert_symbol, certs)
            self.assertEqual(len(cert), 1)

        finally:
            self.fork()

        # check cert
        certs = Alice.get_addressasset(Alice.didaddress(), True)
        cert = filter(lambda a: a.symbol == cert_symbol, certs)
        self.assertEqual(len(cert), 0)
    def test_0_registerdid(self):
        group = [Alice, Bob, Zac]
        did_symbol = "Alice.Bob.Zac.DIID." + common.get_random_str()

        for i, role in enumerate(group):
            addr = role.new_multisigaddress("Alice & Bob & Zac's Multisig-DID",
                                            group[:i] + group[i + 1:], 2)

        Alice.send_etp(addr, (10**8))
        Alice.mining()

        ec, tx = mvs_rpc.register_did(group[0].name, group[0].password, addr,
                                      did_symbol)
        self.assertEqual(ec, 0, tx)

        ec, tx = mvs_rpc.sign_multisigtx(group[1].name, group[1].password, tx,
                                         True)
        self.assertEqual(ec, 0, tx)

        Alice.mining()

        ec, message = mvs_rpc.list_dids()
        self.assertEqual(ec, 0, message)

        for did_ in message:
            if did_['symbol'] == did_symbol and did_["address"] == addr:
                break
        else:
            self.assertEqual(0, 1, "did -> multi-sig addr not found error")
Beispiel #6
0
 def issue_cert(self, to_):
     cert_symbol = (self.name + ".2%s." % to_.name + common.get_random_str()).upper()
     result, message = mvs_rpc.issue_cert(self.name, self.password, to_.did_symbol, cert_symbol, "NAMING")
     if result != 0:
         print("failed to issue_cert: {}".format(message))
     assert (result == 0)
     return cert_symbol
Beispiel #7
0
 def issue_naming_cert(self, domain_symbol):
     cert_symbol = (domain_symbol + "." + common.get_random_str()).upper()
     result, message = mvs_rpc.issue_cert(self.name, self.password, self.did_symbol, cert_symbol, "NAMING")
     if result != 0:
         print("failed to issue_cert: {}".format(message))
     assert (result == 0)
     return cert_symbol
Beispiel #8
0
    def create(self):
        '''
        create account by getnewaccount
        '''
        #auto create a new asset name for each time create_asset is called
        self.asset_symbol = (self.name + ".AST." +
                             common.get_random_str()).upper()

        result, self.mnemonic = mvs_rpc.new_account(self.name, self.password)
        if result != 0:
            print("create_new_account: {}".format(self.mnemonic))
        assert (result == 0)

        f = open('./Zac.txt', 'w')
        print >> f, self.lastword()
        f.close()

        result, _ = mvs_rpc.new_address(self.name, self.password, 9)
        assert (result == 0)
        result, self.addresslist = mvs_rpc.list_addresses(
            self.name, self.password)
        assert (result == 0)
        assert (len(self.addresslist) == 10)
        self.addresslist.reverse()
        return 0, "success"
    def test_2_transfer_mit(self):
        symbol = ("MIT." + common.get_random_str()).upper()
        content = "MIT of Alice: " + symbol

        # not enough mit
        ec, message = Alice.transfer_mit(Bob.did_symbol, symbol)
        self.assertEqual(ec, code.asset_lack_exception, message)

        # register mit
        ec, message = mvs_rpc.register_mit(Alice.name, Alice.password,
                                           Alice.did_symbol, symbol, content)
        self.assertEqual(ec, code.success, message)
        Alice.mining()

        # transfer mit
        ec, message = Alice.transfer_mit(Bob.did_symbol, symbol)
        self.assertEqual(ec, code.success, message)
        Alice.mining()

        # test get_mit with symbol
        ec, message = Bob.get_mit(symbol)
        self.assertEqual(ec, code.success, message)
        self.assertEqual(message["symbol"], symbol)
        self.assertEqual(message["content"], content)
        self.assertEqual(message["status"], "registered")

        # test get_mit with symbol and history
        ec, message = Bob.get_mit("", True)
        self.assertEqual(ec, code.argument_legality_exception, message)

        ec, message = Bob.get_mit(symbol, True, 0, 100)
        self.assertEqual(ec, code.argument_legality_exception, message)

        ec, message = Bob.get_mit(symbol, True, 1, 101)
        self.assertEqual(ec, code.argument_legality_exception, message)

        # success
        ec, message = Bob.get_mit(symbol, True)
        self.assertEqual(ec, code.success, message)

        mits = message['mits']
        self.assertGreater(len(mits), 0)
        found_mits = filter(lambda a: a["symbol"] == symbol, mits)
        self.assertEqual(len(found_mits), 2)

        mit = found_mits[0]
        self.assertEqual(mit["symbol"], symbol)
        self.assertEqual(mit["status"], "transfered")

        # root
        mit = found_mits[1]
        self.assertEqual(mit["symbol"], symbol)
        self.assertEqual(mit["status"], "registered")

        # not enough mit
        ec, message = Alice.transfer_mit(Bob.did_symbol, symbol)
        self.assertEqual(ec, code.asset_lack_exception, message)
Beispiel #10
0
 def register_mit(self, to_did, symbol=None, content=None, fee=None):
     if None == symbol:
         symbol = common.get_random_str()
     if None == to_did:
         to_did = self.did_symbol
     ec, message = mvs_rpc.register_mit(self.name, self.password, to_did,
                                        symbol, content, fee)
     assert (ec == 0)
     return symbol
Beispiel #11
0
 def create_random_asset(self,
                         domain_symbol=None,
                         did_symbol=None,
                         is_issue=True,
                         secondary=0):
     if None == domain_symbol:
         domain_symbol = (self.name + common.get_random_str()).upper()
     asset_symbol = domain_symbol + ".AST"
     self.create_asset_with_symbol(asset_symbol, is_issue, secondary,
                                   did_symbol)
     return domain_symbol, asset_symbol
    def test_1_register_mit(self):
        symbol = ("MIT." + common.get_random_str()).upper()
        content = "MIT of Alice: " + symbol
        ec, message = mvs_rpc.register_mit(Alice.name, Alice.password,
                                           Alice.did_symbol, symbol, content)
        self.assertEqual(ec, code.success, message)
        Alice.mining()

        # test list_mits with account
        ec, message = Alice.list_mits(Alice.name, Alice.password)
        self.assertEqual(ec, code.success, message)

        mits = message['mits']
        self.assertGreater(len(mits), 0)
        found_mits = filter(lambda a: a["symbol"] == symbol, mits)
        self.assertEqual(len(found_mits), 1)

        mit = found_mits[0]
        self.assertEqual(mit["symbol"], symbol)
        self.assertEqual(mit["content"], content)
        self.assertEqual(mit["status"], "registered")

        # test list_mits without account
        ec, message = Alice.list_mits()
        self.assertEqual(ec, code.success, message)

        mits = message['mits']
        self.assertGreater(len(mits), 0)
        found_mits = filter(lambda a: a["symbol"] == symbol, mits)
        self.assertEqual(len(found_mits), 1)

        mit = found_mits[0]
        self.assertEqual(mit["symbol"], symbol)
        self.assertEqual(mit["content"], content)
        self.assertEqual(mit["status"], "registered")

        # test get_mit with symbol
        ec, message = Alice.get_mit(symbol)
        self.assertEqual(ec, code.success, message)
        self.assertEqual(message["symbol"], symbol)
        self.assertEqual(message["content"], content)
        self.assertEqual(message["status"], "registered")

        # test get_mit without symbol
        ec, message = Alice.get_mit()
        self.assertEqual(ec, code.success, message)

        mits = message['mits']
        self.assertGreater(len(mits), 0)
        found_mits = filter(lambda a: a == symbol, mits)
        self.assertEqual(len(found_mits), 1)
    def test_1_register_mits(self):
        # set max_paramters in Mongoose.hpp to 208
        max_mit_count = 100

        mits = []
        for i in range(0, max_mit_count):
            mits.append("{}@{}:content of {}".format(common.get_random_str(),
                                                     i, i))
        ec, message = mvs_rpc.register_mit(Alice.name,
                                           Alice.password,
                                           Alice.did_symbol,
                                           mits=mits)
        self.assertEqual(ec, code.success, message)
        Alice.mining()
Beispiel #14
0
    def test_2_fork_at_issueasset(self):
        self.make_partion()

        asset_symbol = None
        domain_symbol = None
        try:
            domain = (u'Not1Exist' + common.get_random_str()).upper()
            domain_symbol, asset_symbol = Alice.create_random_asset(
                domain_symbol=domain)
            Alice.mining()

            # check asset
            ec, message = mvs_rpc.get_asset()
            self.assertEqual(ec, 0, message)
            self.assertIn(asset_symbol, message["assets"])

            addressassets = Alice.get_addressasset(Alice.mainaddress())
            addressasset = filter(lambda a: a.symbol == asset_symbol,
                                  addressassets)
            self.assertEqual(len(addressasset), 1)

            # check domain cert
            certs = Alice.get_addressasset(Alice.mainaddress(), True)
            cert = filter(lambda a: a.symbol == domain_symbol, certs)
            self.assertEqual(len(cert), 1)

        finally:
            self.fork()

        # check asset
        ec, message = mvs_rpc.get_asset()
        self.assertEqual(ec, 0, message)
        self.assertNotIn(asset_symbol, message["assets"])

        addressassets = Alice.get_addressasset(Alice.mainaddress())
        addressasset = filter(lambda a: a.symbol == asset_symbol,
                              addressassets)
        self.assertEqual(len(addressasset), 0)

        # check domain cert
        certs = Alice.get_addressasset(Alice.mainaddress(), True)
        cert = filter(lambda a: a.symbol == domain_symbol, certs)
        self.assertEqual(len(cert), 0)
    def test_1_register_did(self):
        '''
        this test case will create did for all roles. If not created before.
        '''

        #address in use
        random_did_symbol = common.get_random_str()
        ec, message = mvs_rpc.register_did(Alice.name, Alice.password,
                                           Alice.mainaddress(),
                                           random_did_symbol)
        self.assertEqual(ec, 7002, message)

        Alice.send_etp(Zac.mainaddress(), 10**8)
        Alice.mining()
        #symbol contain special symbol
        special_symbol = '''~`!#$%^&*()=+|\:;'"?/>'''
        for chr in special_symbol:
            ec, message = mvs_rpc.register_did(
                Zac.name, Zac.password, Zac.mainaddress(),
                "%s%stest" % (Zac.did_symbol, chr))
            self.assertEqual(ec, 7001, "did symol contains:" + chr)
Beispiel #16
0
    def test_3_burn_mit(self):
        symbol = ("MIT." + common.get_random_str()).upper()
        content = "MIT of Alice: " + symbol

        # register mit
        ec, message = mvs_rpc.register_mit(
            Alice.name, Alice.password, Alice.did_symbol, symbol, content)
        self.assertEqual(ec, code.success, message)
        Alice.mining()

        # burn mit
        ec, message = mvs_rpc.burn(
            Alice.name, Alice.password, symbol, is_mit=True)
        self.assertEqual(ec, code.success, message)
        Alice.mining()

        # test get_mit with symbol
        ec, message = Alice.get_mit(symbol, trace=True)
        self.assertEqual(ec, code.success, message)
        self.assertEqual(len(message), 2)
        self.assertEqual(message[0]["to_did"], "BLACKHOLE")
Beispiel #17
0
    def test_5_fork_at_did(self):
        #
        did_symbol = "test_fork_registerdiid"+common.get_random_str()
        rmtName = Zac.name+common.get_random_str()
        print rmtName
        mvs_rpc.new_address(Zac.name,Zac.password, 2)
        mvs_rpc.remote_call(self.remote_ip, mvs_rpc.import_account)(rmtName, "123456", ' '.join(Zac.mnemonic),2)
        receivers={}
        receivers[Zac.addresslist[0]] = (9**10)
        receivers[Zac.addresslist[1]] = (9**10)
        Alice.sendmore_etp(receivers)
        Alice.mining()

        # asset
        domain_symbol = ("Zacfork" + common.get_random_str()).upper()
        asset_symbol = domain_symbol + ".AST"

        # mit
        mit_symbol = ("MIT." + common.get_random_str()).upper()

        ec, message = mvs_rpc.get_info()
        self.assertEqual(ec, 0, message)
        pre_height = message[0]
        print "pre_height:"+str(pre_height)

        self.make_partion()
        import time
        try:
            # fork chain
            Alice.mining()
            ec, message = Zac.register_did(Zac.addresslist[0], did_symbol)
            self.assertEqual(ec, 0, message)
            Alice.mining()

            ec, message = mvs_rpc.change_did(Zac.name, Zac.password, Zac.addresslist[1], did_symbol)
            self.assertEqual(ec, 0, message)
            Alice.mining()

            Zac.create_asset_with_symbol(asset_symbol, True, 0, did_symbol)
            self.assertEqual(ec, 0, message)
            Alice.mining()

            Zac.send_asset(Zac.addresslist[1], 100 ,asset_symbol)
            self.assertEqual(ec, 0, message)
            Alice.mining()

            mvs_rpc.transfer_cert(Zac.name, Zac.password, Alice.did_symbol, domain_symbol, "DOMAIN")
            self.assertEqual(ec, 0, message)
            Alice.mining()

            mvs_rpc.transfer_cert(Alice.name, Alice.password, "BLACKHOLE", domain_symbol, "DOMAIN")
            self.assertEqual(ec, 0, message)
            Alice.mining()

            ec, message = mvs_rpc.register_mit(Zac.name, Zac.password, did_symbol, mit_symbol, "test fork mit")
            self.assertEqual(ec, code.success, message)
            Alice.mining(5)

            ec, message = mvs_rpc.transfer_mit(Zac.name, Zac.password, "BLACKHOLE", mit_symbol)
            self.assertEqual(ec, code.success, message)
            Alice.mining(5)

        finally:
            # main chain
            self.remote_ming(2)
            ec, message = mvs_rpc.remote_call(self.remote_ip,mvs_rpc.register_did)(rmtName, "123456", Zac.addresslist[1],did_symbol)
            self.assertEqual(ec, 0, message)
            self.remote_ming(1)

            ec, message = mvs_rpc.remote_call(self.remote_ip,mvs_rpc.change_did)(rmtName, "123456", Zac.addresslist[0], did_symbol)
            self.assertEqual(ec, 0, message)
            self.remote_ming(1)

            ec, message = self.create_asset_with_symbol_rmt(rmtName, "123456", asset_symbol, True, 0, did_symbol)
            self.assertEqual(ec, 0, message)
            self.remote_ming(1)

            ec, message = mvs_rpc.remote_call(self.remote_ip, mvs_rpc.send_asset)(rmtName, "123456",Zac.addresslist[1], asset_symbol,100)
            self.assertEqual(ec, 0, message)
            self.remote_ming(1)

            ec, message = mvs_rpc.remote_call(self.remote_ip, mvs_rpc.transfer_cert)(rmtName, "123456", "BLACKHOLE", domain_symbol, "DOMAIN")
            self.assertEqual(ec, 0, message)
            self.remote_ming(1)

            ec, message = mvs_rpc.remote_call(self.remote_ip, mvs_rpc.register_mit)(rmtName, "123456", did_symbol, mit_symbol)
            self.assertEqual(ec, code.success, message)
            self.remote_ming(1)

            ec, message = mvs_rpc.remote_call(self.remote_ip,mvs_rpc.transfer_mit)(rmtName, "123456", "BLACKHOLE", mit_symbol)
            self.assertEqual(ec, code.success, message)
            self.remote_ming(20)






        ec, message = mvs_rpc.add_node( self.remote_ip+':5251')
        self.assertEqual(ec, 0, message)

        ec, message = mvs_rpc.remote_call(self.remote_ip, mvs_rpc.get_info)()
        self.assertEqual(ec, 0, message)
        main_height = message[0]

        ec, message = mvs_rpc.get_info()
        self.assertEqual(ec, 0, message)
        fork_height = message[0]
        while  fork_height < main_height:
            time.sleep(1)
            ec, message = mvs_rpc.get_info()
            self.assertEqual(ec, 0, message)
            fork_height = message[0]
            print "fork_height:"+str(fork_height) + ",main_height:"+str(main_height)

        ec, message = mvs_rpc.list_didaddresses(did_symbol)
        self.assertEqual(ec, 0, message)
        self.assertEqual(message[0]["address"], Zac.addresslist[0], message)
    def test_0_issuecert(self):
        Alice.ensure_balance()
        '''
        Alice create asset and cert
        '''
        domain_symbol, asset_symbol = Alice.create_random_asset()
        Alice.mining()

        exist_asset = asset_symbol
        exist_domain_cert = domain_symbol

        test_cert_symbol = domain_symbol + ".CERT.TO.BOB"
        invalid_naming_cert = common.get_random_str()

        #account password error
        ec, message = mvs_rpc.issue_cert(Alice.name, Alice.password + '1',
                                         Alice.did_symbol, test_cert_symbol,
                                         'naming')
        self.assertEqual(ec, 1000, message)
        Alice.mining()

        #symbol check
        # 1 -- length
        ec, message = mvs_rpc.issue_cert(Alice.name, Alice.password,
                                         Alice.did_symbol, "X" * 65, 'naming')
        self.assertEqual(ec, 5011, message)

        # 2 -- invalid char
        spec_char_lst = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<>/?"
        for char in spec_char_lst:
            ec, message = mvs_rpc.issue_cert(Alice.name, Alice.password,
                                             Alice.did_symbol,
                                             test_cert_symbol + char, 'naming')
            self.assertEqual(ec, 1000, message)
            self.assertEqual(message, "symbol must be alpha or number or dot",
                             message)

        # check cert symbol -- invalid format
        ec, message = mvs_rpc.issue_cert(Alice.name,
                                         Alice.password,
                                         Alice.did_symbol,
                                         invalid_naming_cert,
                                         'naming',
                                         fee=None)
        self.assertEqual(ec, 5012, message)

        # did not exist
        ec, message = mvs_rpc.issue_cert(Alice.name, Alice.password,
                                         Alice.did_symbol + "d",
                                         test_cert_symbol, 'naming')
        self.assertEqual(ec, 7006, message)

        # did not owned
        ec, message = mvs_rpc.issue_cert(Alice.name, Alice.password,
                                         Bob.did_symbol, test_cert_symbol,
                                         'naming')
        self.assertEqual(ec, 4003, message)

        # cert type error
        ec, message = mvs_rpc.issue_cert(Alice.name, Alice.password,
                                         Alice.did_symbol, test_cert_symbol,
                                         "naming1")
        self.assertEqual(ec, 5017, message)

        # no domain cert owned
        ec, message = mvs_rpc.issue_cert(Alice.name, Alice.password,
                                         Alice.did_symbol,
                                         invalid_naming_cert + ".2BOB2",
                                         'naming')
        self.assertEqual(ec, 5019, message)

        # issue cert success
        ec, message = mvs_rpc.issue_cert(Alice.name, Alice.password,
                                         Alice.did_symbol, test_cert_symbol,
                                         "naming")
        self.assertEqual(ec, 0, message)
        Alice.mining()

        # cert already exist error
        ec, message = mvs_rpc.issue_cert(Alice.name, Alice.password,
                                         Alice.did_symbol, test_cert_symbol,
                                         "naming")
        self.assertEqual(ec, 5018, message)
    def test_2_transfercert(self):
        '''
        Alice create asset and cert
        '''
        domain_symbol, asset_symbol = Alice.create_random_asset()
        Alice.mining()

        naming_cert_symbol = Alice.issue_naming_cert(domain_symbol)
        Alice.mining()

        ec, message = mvs_rpc.transfer_cert(Alice.name,
                                            Alice.password,
                                            Bob.did_symbol,
                                            naming_cert_symbol,
                                            'naming',
                                            fee=None)
        self.assertEqual(ec, 0, message)
        Alice.mining()
        '''
        '''

        not_issued_symbol = domain_symbol + '.2ND' + common.get_random_str()

        # account password match error
        ec, message = mvs_rpc.transfer_cert(Alice.name,
                                            Alice.password + '1',
                                            Bob.did_symbol,
                                            domain_symbol,
                                            'naming',
                                            fee=None)
        self.assertEqual(ec, 1000, message)

        # did_symbol not exist
        ec, message = mvs_rpc.transfer_cert(Alice.name,
                                            Alice.password,
                                            "InvalidDID",
                                            domain_symbol,
                                            'naming',
                                            fee=None)
        self.assertEqual(ec, 7006, message)

        # check cert symbol -- length error
        ec, message = mvs_rpc.transfer_cert(Alice.name,
                                            Alice.password,
                                            Bob.did_symbol,
                                            "X" * 65,
                                            'naming',
                                            fee=None)
        self.assertEqual(ec, 5011, message)

        # check cert symbol -- not issued
        ec, message = mvs_rpc.transfer_cert(Alice.name,
                                            Alice.password,
                                            Bob.did_symbol,
                                            not_issued_symbol,
                                            'naming',
                                            fee=None)
        self.assertEqual(ec, 5019, message)

        # check cert symbol -- owned by some other
        ec, message = mvs_rpc.transfer_cert(Alice.name,
                                            Alice.password,
                                            Bob.did_symbol,
                                            naming_cert_symbol,
                                            'naming',
                                            fee=None)
        self.assertEqual(ec, 5020, message)

        # check fee
        ec, message = mvs_rpc.transfer_cert(Alice.name,
                                            Alice.password,
                                            Bob.did_symbol,
                                            domain_symbol,
                                            'domain',
                                            fee=0)
        self.assertEqual(ec, 5005, message)
Beispiel #20
0
    def test_0_transfer_multisig_cert(self):
        # Alice create asset
        domain_symbol, asset_symbol = Alice.create_random_asset(secondary=-1)
        Alice.mining()

        # create multisig
        #
        description = "Alice & Zac's multi-sig address"

        multisig_address = Alice.new_multisigaddress(description, [Zac], 2)
        multisig_address2 = Zac.new_multisigaddress(description, [Alice], 2)
        self.assertEqual(multisig_address, multisig_address2,
                         "multisig addresses dismatch.")

        # send etp to multisig_address
        #
        result, message = mvs_rpc.sendfrom(Alice.name, Alice.password,
                                           Alice.mainaddress(),
                                           multisig_address, 3 * 10**8)
        assert (result == 0)
        Alice.mining()

        # register did to multisig_address
        #
        multisig_did_symbol = "Multisig" + common.get_random_str()
        ec, tx = mvs_rpc.register_did(Alice.name, Alice.password,
                                      multisig_address, multisig_did_symbol)
        self.assertEqual(ec, code.success, tx)

        # sign multisig rawtx
        ec, tx2 = mvs_rpc.sign_multisigtx(Zac.name, Zac.password, tx, True)
        self.assertEqual(ec, 0, tx2)
        Alice.mining()

        # transfer cert to multisig_did_symbol
        #
        ec, message = mvs_rpc.transfer_cert(Alice.name, Alice.password,
                                            multisig_did_symbol, asset_symbol,
                                            'issue')
        self.assertEqual(ec, code.success, message)
        Alice.mining()

        # check cert
        certs = Zac.get_addressasset(multisig_address, True)
        self.assertGreater(len(certs), 0,
                           "not cert found at " + multisig_address)
        exist_symbols = filter(
            lambda a: a.symbol == asset_symbol and a.cert == "issue", certs)
        self.assertEqual(len(exist_symbols), 1,
                         "not cert found at " + multisig_address)

        # transfer cert to Cindy
        #
        ec, tx = mvs_rpc.transfer_cert(Alice.name, Alice.password,
                                       Cindy.did_symbol, asset_symbol, 'issue')
        self.assertEqual(ec, code.success, tx)

        # sign multisig rawtx
        ec, tx2 = mvs_rpc.sign_multisigtx(Zac.name, Zac.password, tx, True)
        self.assertEqual(ec, 0, tx2)
        Alice.mining()

        # check cert
        certs = Cindy.get_addressasset(Cindy.didaddress(), True)
        self.assertGreater(len(certs), 0,
                           "not cert found at " + Cindy.didaddress())
        exist_symbols = filter(
            lambda a: a.symbol == asset_symbol and a.cert == "issue", certs)
        self.assertEqual(len(exist_symbols), 1,
                         "not cert found at " + Cindy.didaddress())
    def test_1_modifydid(self):
        #import pdb; pdb.set_trace()
        group = [Alice, Cindy, Zac]

        did_symbol = '@'.join(r.name for r in group) + common.get_random_str()
        for i, role in enumerate(group):
            addr = role.new_multisigaddress(
                "Alice & Cindy & Zac's Multisig-DID",
                group[:i] + group[i + 1:], 2)

        Alice.send_etp(addr, (10**9))
        Alice.mining()

        ec, tx = mvs_rpc.register_did(group[0].name, group[0].password, addr,
                                      did_symbol)
        self.assertEqual(ec, 0, tx)

        ec, tx = mvs_rpc.sign_multisigtx(group[1].name, group[1].password, tx,
                                         True)
        self.assertEqual(ec, 0, tx)
        Alice.mining()

        group_new = [Bob, Dale, Zac]
        for i, role in enumerate(group_new):
            addr_new = role.new_multisigaddress(
                "Bob & Dale & Zac's Multisig-DID",
                group_new[:i] + group_new[i + 1:], 2)

        Alice.send_etp(addr_new, (10**6))
        Alice.mining()

        normal_new = Zac.mainaddress()
        Alice.send_etp(normal_new, 123456789)
        Alice.mining()

        ec, tx = mvs_rpc.change_did(Zac.name, Zac.password, normal_new,
                                    did_symbol)
        self.assertEqual(ec, 0, tx)

        ec, tx = mvs_rpc.sign_multisigtx(group[1].name, group[1].password, tx,
                                         True)
        self.assertEqual(ec, 0, tx)
        Alice.mining()

        did_address = group[0].get_didaddress(did_symbol)
        self.assertEqual(
            did_address, normal_new,
            "Failed where modify did address from multi_signature to normal ")

        normal_new = Zac.addresslist[1]
        Alice.send_etp(normal_new, (10**6))
        Alice.mining()
        ec, tx = mvs_rpc.change_did(Zac.name, Zac.password, normal_new,
                                    did_symbol)
        self.assertEqual(ec, 0, tx)
        Alice.mining()

        did_address = group[0].get_didaddress(did_symbol)
        self.assertEqual(
            did_address, normal_new,
            "Failed where modify did address from normal to normal")

        ec, tx = mvs_rpc.change_did(Zac.name, Zac.password, addr_new,
                                    did_symbol)
        self.assertEqual(ec, 0, tx)

        ec, tx = mvs_rpc.sign_multisigtx(group_new[0].name,
                                         group_new[0].password, tx, True)
        self.assertEqual(ec, 0, tx)
        Alice.mining()

        did_address = group[0].get_didaddress(did_symbol)
        self.assertEqual(
            did_address, addr_new,
            "Failed where modify did address from normal to multi_signature address"
        )
    def test_0_scenario_did_modified(self):

        # prepare address
        #
        Zac.mining()
        Zac.mining()
        Zac.mining()
        result, addresslist = mvs_rpc.list_addresses(Zac.name, Zac.password)

        used_addresses = []
        ec, message = mvs_rpc.list_dids(Zac.name, Zac.password)
        self.assertEqual(ec, code.success, message)

        if message['dids']:
            dids = [MOCs.Did.init(i) for i in message["dids"] if i]
            used_addresses = [did.address for did in dids if did]

        addresslist = list(set(addresslist) ^ set(used_addresses))
        length = len(addresslist)
        assert (length > 3)

        # create first did
        fst_did_address = addresslist[length - 1]
        fst_did_symbol = u"zacfirstdiid." + common.get_random_str()

        result, message = mvs_rpc.send(Alice.name, Alice.password,
                                       fst_did_address, 22 * 10**8)
        self.assertEqual(result, code.success, message)
        Zac.mining()

        ec, message = Zac.register_did(fst_did_address, fst_did_symbol)
        self.assertEqual(ec, code.success, message)
        Zac.mining()

        # create second did
        snd_did_address = addresslist[length - 2]
        snd_did_symbol = u"zacmodifydiid." + common.get_random_str()

        result, message = mvs_rpc.send(Alice.name, Alice.password,
                                       snd_did_address, 12 * 10**8)
        self.assertEqual(result, code.success, message)
        Zac.mining()

        ec, message = Zac.register_did(snd_did_address, snd_did_symbol)
        self.assertEqual(ec, code.success, message)
        Zac.mining()

        # prepare third address
        #
        trd_address = addresslist[length - 3]

        result, message = mvs_rpc.send(Alice.name, Alice.password, trd_address,
                                       12 * 10**8)
        self.assertEqual(result, code.success, message)
        Zac.mining()

        # create asset and cert
        #
        domain_symbol, fst_asset_symbol = Zac.create_random_asset(
            did_symbol=snd_did_symbol, secondary=-1)
        Zac.mining()

        # change address of did
        ec, message = mvs_rpc.change_did(Zac.name, Zac.password, trd_address,
                                         snd_did_symbol)
        self.assertEqual(ec, code.success, message)
        Zac.mining()

        # test send asset
        ec, message = mvs_rpc.didsend_asset(Zac.name, Zac.password,
                                            snd_did_symbol, fst_asset_symbol,
                                            3000)
        self.assertEqual(ec, code.success, message)
        Zac.mining()

        # test secondary_issue
        ec, message = mvs_rpc.secondary_issue(Zac.name,
                                              Zac.password,
                                              to_did=fst_did_symbol,
                                              symbol=fst_asset_symbol,
                                              volume=3000)
        self.assertEqual(ec, code.success, message)
        Zac.mining()

        # test issue cert
        naming_cert_symbol = domain_symbol + ".NAMING." + common.get_random_str(
        )
        ec, message = mvs_rpc.issue_cert(Zac.name, Zac.password,
                                         fst_did_symbol, naming_cert_symbol,
                                         "naming")
        self.assertEqual(ec, code.success, message)
        Zac.mining()

        # test transfer cert
        ec, message = mvs_rpc.transfer_cert(Zac.name, Zac.password,
                                            fst_did_symbol, fst_asset_symbol,
                                            'issue')
        self.assertEqual(ec, code.success, message)
        Zac.mining()

        # test issue new asset
        #
        snd_asset_symbol = domain_symbol + ".ASSEET." + common.get_random_str()
        ec, message = mvs_rpc.create_asset(Zac.name,
                                           Zac.password,
                                           snd_asset_symbol,
                                           volume=8000000,
                                           issuer=fst_did_symbol,
                                           rate=-1)
        self.assertEqual(ec, code.success, message)

        ec, message = mvs_rpc.issue_asset(Zac.name, Zac.password,
                                          snd_asset_symbol)
        self.assertEqual(ec, code.success, message)
        Zac.mining()

        # test secondary_issue
        ec, message = mvs_rpc.secondary_issue(Zac.name,
                                              Zac.password,
                                              to_did=fst_did_symbol,
                                              symbol=snd_asset_symbol,
                                              volume=3000)
        self.assertEqual(ec, code.success, message)
        Zac.mining()
    def test_0_boundary(self):
        test_symbol = common.get_random_str()

        # check symbol length
        mits = ["X" * 61 + ":invalid"]
        ec, message = mvs_rpc.register_mit(Alice.name,
                                           Alice.password,
                                           Alice.did_symbol,
                                           mits=mits)
        self.assertEqual(ec, code.asset_symbol_length_exception, message)

        # check invalid char in symbol
        spec_char_lst = "`~!#$%^&*()+[{]}\\|;'\",<>/?"
        for char in spec_char_lst:
            mits = [test_symbol + char + ":invalid"]
            ec, message = mvs_rpc.register_mit(Alice.name,
                                               Alice.password,
                                               Alice.did_symbol,
                                               mits=mits)
            self.assertEqual(ec, code.asset_symbol_name_exception, message)

        # check content length
        mits = [test_symbol + ":" + "X" * 257]
        ec, message = mvs_rpc.register_mit(Alice.name,
                                           Alice.password,
                                           Alice.did_symbol,
                                           mits=mits)
        self.assertEqual(ec, code.argument_size_invalid_exception, message)

        # check duplicate symbols
        mits = [
            test_symbol + ":" + "M" * 256,
            test_symbol + ":" + "Duplicate symbol"
        ]
        ec, message = mvs_rpc.register_mit(Alice.name,
                                           Alice.password,
                                           Alice.did_symbol,
                                           mits=mits)
        self.assertEqual(ec, code.asset_symbol_existed_exception, message)

        # check empty symbol
        mits = []
        ec, message = mvs_rpc.register_mit(Alice.name,
                                           Alice.password,
                                           Alice.did_symbol,
                                           mits=mits)
        self.assertEqual(ec, code.argument_legality_exception, message)

        # check to did not exist
        mits = [test_symbol + ":" + "M" * 256]
        ec, message = mvs_rpc.register_mit(Alice.name,
                                           Alice.password,
                                           Alice.did_symbol + "1",
                                           mits=mits)
        self.assertEqual(ec, code.did_symbol_notfound_exception, message)

        # check to did not owned
        ec, message = mvs_rpc.register_mit(Alice.name,
                                           Alice.password,
                                           Bob.did_symbol,
                                           mits=mits)
        self.assertEqual(ec, code.address_dismatch_account_exception, message)

        # check symbol already exist
        ec, message = mvs_rpc.register_mit(Alice.name,
                                           Alice.password,
                                           Alice.did_symbol,
                                           mits=mits)
        self.assertEqual(ec, code.success, message)
        Alice.mining()

        ec, message = mvs_rpc.register_mit(Alice.name,
                                           Alice.password,
                                           Alice.did_symbol,
                                           mits=mits)
        self.assertEqual(ec, code.asset_symbol_existed_exception, message)