Beispiel #1
0
 def test_from_data(self):
     data = {
         "id":
         "5a1ZVJTu8Y7mPA6BbkvGdfmbjvz9YSppQXPnb5MxihV5",
         "type":
         4,
         "version":
         3,
         "sender":
         "3N9ChkxWXqgdWLLErWFrSwjqARB6NtYsvZh",
         "senderPublicKey":
         "9NFb1rvMyr1k8f3wu3UP1RaEGsozBt9gF2CmPMGGA42m",
         "fee":
         100000000,
         "timestamp":
         1609639213556,
         "amount":
         100000000000,
         "recipient":
         "3NBcx7AQqDopBj3WfwCVARNYuZyt1L9xEVM",
         "attachment":
         "9Ajdvzr",
         "proofs": [
             "3ftQ2ArKKXw655WdHy2TK1MGXeyzKRqMQYwFidekkyxLpzFGsTziSFsbM5RCFxrn32EzisMgPWtQVQ4e5UqKUcES"
         ],
         "height":
         1212761
     }
     transaction = Transfer(recipient=data['recipient'],
                            amount=data['amount']).from_data(data)
     crypto.compare_data_transaction(data, transaction)
Beispiel #2
0
def from_data(data):
    if data['type'] == 4:
        return Transfer.from_data(data)
    elif data['type'] == 8:
        return Lease.from_data(data)
    elif data['type'] == 9:
        return CancelLease.from_data(data)
    elif data['type'] == 11:
        return MassTransfer.from_data(data)
    elif data['type'] == 12:
        return Data.from_data(data)
    elif data['type'] == 13:
        return SetScript.from_data(data)
    elif data['type'] == 15:
        return Anchor.from_data(data)
    elif data['type'] == 16:
        return Association.from_data(data)
    elif data['type'] == 17:
        return RevokeAssociation.from_data(data)
    elif data['type'] == 18:
        return Sponsorship.from_data(data)
    elif data['type'] == 19:
        return CancelSponsorship.from_data(data)
    elif data['type'] == 20:
        return Register.from_data(data)
    else:
        raise Exception('Incorrect transaction Type')
Beispiel #3
0
 def test_to_json(self, expected, version):
     transaction = Transfer('3N8TQ1NLN8KcwJnVZM777GUCdUnEZWZ85Rb',
                            120000000, 'hello')
     transaction.timestamp = 1326499200000
     transaction.version = version
     transaction.sign_with(self.account)
     assert transaction.to_json() == expected
Beispiel #4
0
    def test_sign_with_multi_sig(self):
        transaction = Transfer('3N8TQ1NLN8KcwJnVZM777GUCdUnEZWZ85Rb', 10000)
        transaction.timestamp = 1629883934685
        transaction.sender = '3MtHYnCkd3oFZr21yb2vEdngcSGXvuNNCq2'
        transaction.sender_public_key = '4EcSxUkMxqxBEBUBL2oKz3ARVsbyRJTivWpNrYQGdguz'
        transaction.proofs = [
            'PTEgvxqiUswaKiHoamMpTDRDS6u9msGoS2Hz56c16xSTHRfMnNPgbGBrDtonCspE9RErdsei7RQaFBbPWZgTJbj'
        ]

        transaction.sign_with(self.account2)
        assert transaction.is_signed() is True
        assert transaction.timestamp == 1629883934685
        assert transaction.sender == '3MtHYnCkd3oFZr21yb2vEdngcSGXvuNNCq2'
        assert transaction.sender_public_key == '4EcSxUkMxqxBEBUBL2oKz3ARVsbyRJTivWpNrYQGdguz'
        assert len(transaction.proofs) == 2
        assert transaction.proofs[
            0] == 'PTEgvxqiUswaKiHoamMpTDRDS6u9msGoS2Hz56c16xSTHRfMnNPgbGBrDtonCspE9RErdsei7RQaFBbPWZgTJbj'
        assert self.account2.verify_signature(transaction.to_binary(),
                                              transaction.proofs[1])
    def test_sponsor_with(self):
        transaction = Transfer('3N8TQ1NLN8KcwJnVZM777GUCdUnEZWZ85Rb', 10000)
        with pytest.raises(Exception):
            transaction.sponsor_with(self.account2)
        transaction.sign_with(self.account)

        transaction.sponsor_with(self.account2)
        assert transaction.sponsor == self.account2.address
        assert transaction.sponsor_public_key == base58.b58encode(
            self.account2.public_key.__bytes__())
        assert transaction.sponsor_key_type == 'ed25519'

        assert self.account2.verify_signature(transaction.to_binary(),
                                              transaction.proofs[1])

        json = transaction.to_json()
        assert json['sponsor'] == self.account2.address
        assert json['sponsorPublicKey'] == base58.b58encode(
            self.account2.public_key.__bytes__())
        assert json['sponsorKeyType'] == self.account2.key_type
Beispiel #6
0
 def test_sign_with(self):
     transaction = Transfer('3N8TQ1NLN8KcwJnVZM777GUCdUnEZWZ85Rb', 10000)
     assert transaction.is_signed() is False
     transaction.sign_with(self.account)
     assert transaction.is_signed() is True
     timestamp = int(time() * 1000)
     assert str(transaction.timestamp)[:-3] == str(timestamp)[:-3]
     assert transaction.sender == '3MtHYnCkd3oFZr21yb2vEdngcSGXvuNNCq2'
     assert transaction.sender_public_key == '4EcSxUkMxqxBEBUBL2oKz3ARVsbyRJTivWpNrYQGdguz'
     assert self.account.verify_signature(transaction.to_binary(),
                                          transaction.proofs[0])
Beispiel #7
0
 def test_broadcast(self, mock_Class):
     transaction = Transfer('3N8TQ1NLN8KcwJnVZM777GUCdUnEZWZ85Rb',
                            120000000, 'Hello')
     broadcastedTransaction = Transfer(
         '3N8TQ1NLN8KcwJnVZM777GUCdUnEZWZ85Rb', 120000000, 'Hello')
     broadcastedTransaction.id = '7cCeL1qwd9i6u8NgMNsQjBPxVhrME2BbfZMT1DF9p4Yi'
     mc = mock_Class.return_value
     mc.broadcast.return_value = broadcastedTransaction
     assert transaction.broadcast_to(
         node=mock_Class()) == broadcastedTransaction
 def test_broadcast(self):
     transaction = Transfer('3N6MFpSbbzTozDcfkTUT5zZ2sNbJKFyRtRj', 10000000)
     with mock.patch.object(
             PublicNode,
             "wrapper",
             return_value=
         {
             'type':
             4,
             'version':
             3,
             'id':
             '74MeWagvnJ2MZTV7wEUQVWG8mTVddS9pJuqvtyG8b5eP',
             'sender':
             '3N5PoiMisnbNPseVXcCa5WDRLLHkj7dz4Du',
             'senderKeyType':
             'ed25519',
             'senderPublicKey':
             'AneNBwCMTG1YQ5ShPErzJZETTsHEWFnPWhdkKiHG6VTX',
             'fee':
             100000000,
             'timestamp':
             1631613596742,
             'recipient':
             '3N6MFpSbbzTozDcfkTUT5zZ2sNbJKFyRtRj',
             'amount':
             10000000,
             'attachment':
             '',
             'proofs': [
                 'j2q6isq2atpXBADMZ2Vz7oRozfUKGuDkLnVMqtnXkwDhw6tyHmMMHTbaVknP4JmYiVWN5PuNp6i4f5TBhuc9QSm'
             ]
         }):
         response = PublicNode('https://tesnet.lto.network').broadcast(
             transaction)
     assert response.to_json() == {
         'type':
         4,
         'version':
         3,
         'sender':
         '3N5PoiMisnbNPseVXcCa5WDRLLHkj7dz4Du',
         'senderKeyType':
         'ed25519',
         'senderPublicKey':
         'AneNBwCMTG1YQ5ShPErzJZETTsHEWFnPWhdkKiHG6VTX',
         'fee':
         100000000,
         'timestamp':
         1631613596742,
         'amount':
         10000000,
         'height':
         '',
         'id':
         '74MeWagvnJ2MZTV7wEUQVWG8mTVddS9pJuqvtyG8b5eP',
         'recipient':
         '3N6MFpSbbzTozDcfkTUT5zZ2sNbJKFyRtRj',
         'attachment':
         '',
         'proofs': [
             'j2q6isq2atpXBADMZ2Vz7oRozfUKGuDkLnVMqtnXkwDhw6tyHmMMHTbaVknP4JmYiVWN5PuNp6i4f5TBhuc9QSm'
         ]
     }
Beispiel #9
0
 def test_construct(self):
     transaction = Transfer('3N8TQ1NLN8KcwJnVZM777GUCdUnEZWZ85Rb', 10000)
     assert transaction.amount == 10000
     assert transaction.recipient == '3N8TQ1NLN8KcwJnVZM777GUCdUnEZWZ85Rb'
     assert transaction.tx_fee == 100000000