示例#1
0
class TestMinterSendTx(unittest.TestCase):
    def setUp(self):
        self.PRIVATE_KEY = '07bc17abdcee8b971bb8723e36fe9d2523306d5ab2d683631693238e0f9df142'
        self.TO = 'Mx1b685a7c1e78726c48f619c497a07ed75fe00483'
        self.FROM = 'Mx31e61a05adbd13c6b625262704bc305bf7725026'
        self.SIGNED_TX = 'f8840102018a4d4e540000000000000001aae98a4d4e5400000000000000941b685a7c1e78726c48f619c497a07ed75fe00483880de0b6b3a7640000808001b845f8431ca01f36e51600baa1d89d2bee64def9ac5d88c518cdefe45e3de66a3cf9fe410de4a01bc2228dc419a97ded0efe6848de906fbe6c659092167ef0e7dcb8d15024123a'
        self.TX = MinterSendCoinTx(
            **{
                'nonce': 1,
                'chain_id': MinterTx.TESTNET_CHAIN_ID,
                'gas_coin': 'MNT',
                'to': self.TO,
                'coin': 'MNT',
                'value': 1
            })

    def test_valid_tx(self):
        """
        Is tx instance of needed TX class.
        """

        self.assertIsInstance(self.TX, MinterSendCoinTx)

    def test_sign_tx(self):
        """
        Sign transaction and check signed transaction
        """
        self.TX.sign(self.PRIVATE_KEY)

        self.assertEqual(self.TX.signed_tx, self.SIGNED_TX)

    def test_sign_with_signature(self):
        self.TX.signature_type = MinterTx.SIGNATURE_SINGLE_TYPE
        signature = self.TX.generate_signature(self.PRIVATE_KEY)
        self.TX.sign(signature=signature)

        self.assertEqual(self.TX.signed_tx, self.SIGNED_TX)

    def test_from_raw(self):
        tx = MinterTx.from_raw(self.SIGNED_TX)

        self.assertEqual(tx.from_mx, self.FROM)
        self.assertEqual(tx.to, self.TX.to)
        self.assertEqual(tx.coin, self.TX.coin)
        self.assertEqual(tx.value, self.TX.value)
示例#2
0
class TestMinterSendMultisigTx(unittest.TestCase):
    def setUp(self):
        self.PRIVATE_KEYS = [
            'b354c3d1d456d5a1ddd65ca05fd710117701ec69d82dac1858986049a0385af9',
            '38b7dfb77426247aed6081f769ed8f62aaec2ee2b38336110ac4f7484478dccb',
            '94c0915734f92dd66acfdc48f82b1d0b208efd544fe763386160ec30c968b4af'
        ]
        self.TO = 'Mxd82558ea00eb81d35f2654953598f5d51737d31d'
        self.FROM = 'Mxdb4f4b6942cb927e8d7e3a1f602d0f1fb43b5bd2'
        self.SIGNED_TX = 'f901270102018a4d4e540000000000000001aae98a4d4e540000000000000094d82558ea00eb81d35f2654953598f5d51737d31d880de0b6b3a7640000808002b8e8f8e694db4f4b6942cb927e8d7e3a1f602d0f1fb43b5bd2f8cff8431ca0a116e33d2fea86a213577fc9dae16a7e4cadb375499f378b33cddd1d4113b6c1a021ee1e9eb61bbd24233a0967e1c745ab23001cf8816bb217d01ed4595c6cb2cdf8431ca0f7f9c7a6734ab2db210356161f2d012aa9936ee506d88d8d0cba15ad6c84f8a7a04b71b87cbbe7905942de839211daa984325a15bdeca6eea75e5d0f28f9aaeef8f8431ba0d8c640d7605034eefc8870a6a3d1c22e2f589a9319288342632b1c4e6ce35128a055fe3f93f31044033fe7b07963d547ac50bccaac38a057ce61665374c72fb454'
        self.TX = MinterSendCoinTx(
            **{
                'nonce': 1,
                'chain_id': MinterTx.TESTNET_CHAIN_ID,
                'gas_coin': 'MNT',
                'to': self.TO,
                'coin': 'MNT',
                'value': 1
            })

    def test_valid_tx(self):
        """
        Is tx instance of needed TX class.
        """

        self.assertIsInstance(self.TX, MinterSendCoinTx)

    def test_sign_tx(self):
        """
        Sign transaction and check signed transaction
        """
        self.TX.sign(private_key=self.PRIVATE_KEYS, ms_address=self.FROM)

        self.assertEqual(self.TX.signed_tx, self.SIGNED_TX)

    def test_from_raw(self):
        tx = MinterTx.from_raw(self.SIGNED_TX)

        self.assertEqual(tx.from_mx, self.FROM)
        self.assertEqual(tx.to, self.TX.to)
        self.assertEqual(tx.coin, self.TX.coin)
        self.assertEqual(tx.value, self.TX.value)

    def test_add_signature(self):
        # Sign tx with 2 of 3 private keys
        self.TX.sign(private_key=self.PRIVATE_KEYS[:2], ms_address=self.FROM)
        # Add signature by 3rd private key
        self.TX = MinterTx.add_signature(self.TX.signed_tx,
                                         self.PRIVATE_KEYS[2])

        self.assertEqual(self.TX.signed_tx, self.SIGNED_TX)

    def test_sign_with_signature(self):
        # Set signature type for transaction
        self.TX.signature_type = MinterTx.SIGNATURE_MULTI_TYPE

        # Generate signatures
        signatures = []
        for pk in self.PRIVATE_KEYS:
            signature = self.TX.generate_signature(private_key=pk)
            signatures.append(signature)

        # Sign transaction with signatures
        self.TX.sign(signature=signatures, ms_address=self.FROM)

        self.assertEqual(self.TX.signed_tx, self.SIGNED_TX)

    def test_sign_with_pk_and_signature(self):
        # Set signature type for transaction
        self.TX.signature_type = MinterTx.SIGNATURE_MULTI_TYPE

        # Generate 1 signature
        signatures = []
        for pk in self.PRIVATE_KEYS:
            signatures.append(self.TX.generate_signature(private_key=pk))

        # Sign transaction with pks and signature
        self.TX.sign(private_key=self.PRIVATE_KEYS[:2],
                     signature=signatures[2],
                     ms_address=self.FROM)
        self.assertEqual(self.TX.signed_tx, self.SIGNED_TX)

        self.TX.sign(private_key=self.PRIVATE_KEYS[0],
                     signature=signatures[1:],
                     ms_address=self.FROM)
        self.assertEqual(self.TX.signed_tx, self.SIGNED_TX)