示例#1
0
    def setUp(self):
        self.PRIVATE_KEY = '6e1df6ec69638d152f563c5eca6c13cdb5db4055861efc11ec1cdd578afd96bf'
        self.PUBLIC_KEY = 'Mp0eb98ea04ae466d8d38f490db3c99b3996a90e24243952ce9822c6dc1e2c1a43'
        self.SIGNED_TX = 'f8900102018a4d4e540000000000000007b6f5a00eb98ea04ae466d8d38f490db3c99b3996a90e24243952ce9822c6dc1e2c1a438a4d4e5400000000000000888ac7230489e80000808001b845f8431ba01c2c8f702d80cf64da1e9bf1f07a52e2fee8721aebe419aa9f62260a98983f89a07ed297d71d9dc37a57ffe9bb16915dccc703d8c09f30da8aadb9d5dbab8c7da9'

        self.TX = MinterDelegateTx(
            **{
                'nonce': 1,
                'chain_id': MinterTx.TESTNET_CHAIN_ID,
                'gas_coin': 'MNT',
                'pub_key': self.PUBLIC_KEY,
                'coin': 'MNT',
                'stake': 10
            })
示例#2
0
class TestMinterDelegateTx(unittest.TestCase):
    def setUp(self):
        self.PRIVATE_KEY = '6e1df6ec69638d152f563c5eca6c13cdb5db4055861efc11ec1cdd578afd96bf'
        self.PUBLIC_KEY = 'Mp0eb98ea04ae466d8d38f490db3c99b3996a90e24243952ce9822c6dc1e2c1a43'
        self.SIGNED_TX = 'f8900102018a4d4e540000000000000007b6f5a00eb98ea04ae466d8d38f490db3c99b3996a90e24243952ce9822c6dc1e2c1a438a4d4e5400000000000000888ac7230489e80000808001b845f8431ba01c2c8f702d80cf64da1e9bf1f07a52e2fee8721aebe419aa9f62260a98983f89a07ed297d71d9dc37a57ffe9bb16915dccc703d8c09f30da8aadb9d5dbab8c7da9'

        self.TX = MinterDelegateTx(
            **{
                'nonce': 1,
                'chain_id': MinterTx.TESTNET_CHAIN_ID,
                'gas_coin': 'MNT',
                'pub_key': self.PUBLIC_KEY,
                'coin': 'MNT',
                'stake': 10
            })

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

        self.assertIsInstance(self.TX, MinterDelegateTx)

    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(raw_tx=self.SIGNED_TX)

        self.assertEqual(tx.pub_key, self.PUBLIC_KEY)
        self.assertEqual(tx.coin, self.TX.coin)
        self.assertEqual(tx.stake, self.TX.stake)