Beispiel #1
0
    def setUp(self):
        MVSTestCaseBase.setUp(self)
        self.group_ABC = [Alice, Bob, Cindy]
        self.group_DEF = [Dale, Eric, Frank]
        self.addr_ABC = common.create_multisig_address(self.group_ABC, 2)
        self.addr_DEF = common.create_multisig_address(self.group_DEF, 2)

        # register did if not registered
        self.did_ABC = "Alice.Bob.Cindy@DIID"
        self.did_DEF = "Dale.Eric.Frank@DIID"

        for roles, addr, attr_name in [
            (self.group_ABC, self.addr_ABC, "did_ABC"),
            (self.group_DEF, self.addr_DEF, "did_DEF")
        ]:
            ec, message = mvs_rpc.list_dids(roles[-1].name, roles[-1].password)
            self.assertEqual(ec, 0, message)
            for did_info in message['dids']:
                if did_info["address"] == addr:
                    setattr(self, attr_name, did_info["symbol"])
                    break
            else:
                # not issued
                Alice.send_etp(addr, 10**8)
                Alice.mining()

                did_symbol = getattr(self, attr_name)

                ec, tx = mvs_rpc.register_did(roles[0].name, roles[0].password,
                                              addr, did_symbol)
                self.assertEqual(ec, 0, tx)
                ec, tx = mvs_rpc.sign_multisigtx(roles[1].name,
                                                 roles[1].password, tx, True)
                self.assertEqual(ec, 0, tx)
                Alice.mining()
    def test_9_change_did_multisig(self):
        did_normal_symbal = "Zac@" + common.get_timestamp()
        Alice.send_etp(Zac.mainaddress(), 10**8)
        Alice.mining()

        ec, message = mvs_rpc.register_did(Zac.name, Zac.password,
                                           Zac.mainaddress(),
                                           did_normal_symbal)
        self.assertEqual(ec, 0, message)
        Alice.mining()

        group = [Alice, Cindy, Dale, Frank, Zac]

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

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

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

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

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

        # did not find
        ec, message = mvs_rpc.change_did(Zac.name, Zac.password,
                                         Zac.mainaddress(),
                                         common.get_timestamp())
        self.assertEqual(ec, 7006, message)

        #did not owner by account
        ec, message = mvs_rpc.change_did(Bob.name, Bob.password,
                                         Bob.mainaddress(), did_symbol)
        self.assertEqual(ec, 7009, message)

        #did address invalid
        ec, message = mvs_rpc.change_did(Zac.name, Zac.password, "Test" * 20,
                                         did_symbol)
        self.assertEqual(ec, 4012, message)

        #address didn't owned by the account
        ec, message = mvs_rpc.change_did(Zac.name, Zac.password,
                                         Bob.mainaddress(), did_symbol)
        self.assertEqual(ec, 4003, message)

        #address is already binded with did
        ec, message = mvs_rpc.change_did(Zac.name, Zac.password,
                                         Zac.mainaddress(), did_symbol)
        self.assertEqual(ec, 7002, message)

        # no enough balance, unspent = 0, payment = 10000
        ec, message = mvs_rpc.change_did(Zac.name, Zac.password,
                                         Zac.addresslist[1], did_symbol)
        self.assertEqual(ec, 3302, message)

        Alice.send_etp(Zac.addresslist[1], 10**5)
        Alice.mining()

        #signature must be large than 3
        ec, message = mvs_rpc.change_did(Zac.name, Zac.password,
                                         Zac.addresslist[1], did_symbol)
        self.assertEqual(ec, 0, message)

        #cannot transfer to another multi-signature
        ec, message = mvs_rpc.sign_multisigtx(group[0].name, group[0].password,
                                              message, True)
        self.assertEqual(ec, 5304, message)

        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()
        ec, message = mvs_rpc.change_did(Zac.name, Zac.password, addr_new,
                                         did_symbol)
        self.assertEqual(ec, 7010, message)

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

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

        ec, message = mvs_rpc.sign_multisigtx(group[1].name, group[1].password,
                                              message, True)
        self.assertEqual(ec, 0, message)
        self.assertNotEqual(
            Zac.get_didaddress(symbol=did_symbol), Zac.addresslist[1],
            "Failed where modify did address from multi_signature to multi_signature address"
        )