def test_load_transaction():
    transaction = {
        'name': 'polyswarmtransaction.transaction:Transaction',
        'from': '0x3f17f1962B36e491b30A40b2405849e597Ba5FB5',
        'data': {}
    }
    signed = SignedTransaction(json.dumps(transaction), bytes([0] * 65))
    assert isinstance(signed.transaction(), Transaction)
    assert not DeepDiff(signed.transaction().data, Transaction().data, ignore_order=True)
def test_load_transaction_non_transaction():
    transaction = {
        'name': 'polyswarmtransaction.transaction:SignedTransaction',
        'from': '0x3f17f1962B36e491b30A40b2405849e597Ba5FB5',
        'data': {}
    }
    signed = SignedTransaction(json.dumps(transaction), bytes([0] * 65))
    with pytest.raises(UnsupportedTransactionError):
        signed.transaction()
예제 #3
0
def test_load_withdrawal():
    data = {
        'name': 'polyswarmtransaction.nectar:WithdrawalTransaction',
        'from': '0x3f17f1962B36e491b30A40b2405849e597Ba5FB5',
        'data': {
            'amount': '200000000000000000'
        }
    }
    signed = SignedTransaction(json.dumps(data), bytes([0] * 65))
    assert isinstance(signed.transaction(), WithdrawalTransaction)
    assert not DeepDiff(signed.transaction().data, WithdrawalTransaction('200000000000000000').data, ignore_order=True)
예제 #4
0
def test_load_vote():
    data = {
        'name': 'polyswarmtransaction.bounty:VoteTransaction',
        'from': '0x3f17f1962B36e491b30A40b2405849e597Ba5FB5',
        'data': {
            'guid': 'test',
            'vote': True,
        }
    }
    signed = SignedTransaction(json.dumps(data), bytes([0] * 65))
    assert isinstance(signed.transaction(), VoteTransaction)
    assert not DeepDiff(signed.transaction().data,
                        VoteTransaction('test', True).data,
                        ignore_order=True)
예제 #5
0
def test_load_assertion():
    data = {
        'name': 'polyswarmtransaction.bounty:AssertionTransaction',
        'from': '0x3f17f1962B36e491b30A40b2405849e597Ba5FB5',
        'data': {
            'guid': 'test',
            'verdict': True,
            'bid': '1000000000000000000',
            'metadata': {
                'malware_family': ''
            }
        }
    }
    signed = SignedTransaction(json.dumps(data), bytes([0] * 65))
    assert isinstance(signed.transaction(), AssertionTransaction)
    assert not DeepDiff(
        signed.transaction().data,
        AssertionTransaction('test', True, '1000000000000000000',
                             ASSERTION_METADATA).data,
        ignore_order=True)
예제 #6
0
def test_load_approve_release():
    data = {
        'name': 'polyswarmtransaction.nectar:ApproveNectarReleaseTransaction',
        'from': '0x3f17f1962B36e491b30A40b2405849e597Ba5FB5',
        'data': {
            'destination': '0x0000000000000000000000000000000000000001',
            'amount': '200000000000000000',
            'transaction_hash': '0x0000000000000000000000000000000',
            'block_hash': '0x0000000000000000000000000000000',
            'block_number': '0x1',
        }
    }
    signed = SignedTransaction(json.dumps(data), bytes([0] * 65))

    approve_nct_release = ApproveNectarReleaseTransaction(destination='0x0000000000000000000000000000000000000001',
                                               amount='200000000000000000',
                                               transaction_hash='0x0000000000000000000000000000000',
                                               block_hash='0x0000000000000000000000000000000',
                                               block_number='0x1')
    assert isinstance(signed.transaction(), ApproveNectarReleaseTransaction)
    assert not DeepDiff(signed.transaction().data, approve_nct_release.data, ignore_order=True)
예제 #7
0
def test_load_bounty():
    data = {
        'name': 'polyswarmtransaction.bounty:BountyTransaction',
        'from': '0x3f17f1962B36e491b30A40b2405849e597Ba5FB5',
        'data': {
            'guid': 'test',
            'reward': '2000000000000000000',
            'artifact': 'Qm',
            'artifact_type': 0,
            'duration': 123,
            'metadata': [{
                'mimetype': ''
            }]
        }
    }
    signed = SignedTransaction(json.dumps(data), bytes([0] * 65))
    assert isinstance(signed.transaction(), BountyTransaction)
    assert not DeepDiff(
        signed.transaction().data,
        BountyTransaction('test', '2000000000000000000', 'Qm',
                          ArtifactType.FILE.value, 123, BOUNTY_METADATA).data,
        ignore_order=True)
예제 #8
0
def test_load_assertion_bad_metadata():
    data = {
        'name': 'polyswarmtransaction.bounty:AssertionTransaction',
        'from': '0x3f17f1962B36e491b30A40b2405849e597Ba5FB5',
        'data': {
            'guid': 'test',
            'verdict': True,
            'bid': '1000000000000000000',
            'metadata': {}
        }
    }
    signed = SignedTransaction(json.dumps(data), bytes([0] * 65))
    with pytest.raises(ValueError):
        assert signed.transaction()
예제 #9
0
def test_load_bounty_bad_metadata():
    data = {
        'name': 'polyswarmtransaction.bounty:BountyTransaction',
        'from': '0x3f17f1962B36e491b30A40b2405849e597Ba5FB5',
        'data': {
            'guid': 'test',
            'reward': '2000000000000000000',
            'artifact': 'Qm',
            'artifact_type': 0,
            'duration': 123,
            'metadata': []
        }
    }
    signed = SignedTransaction(json.dumps(data), bytes([0] * 65))
    with pytest.raises(ValueError):
        assert signed.transaction()
def test_load_transaction_string():
    signed = SignedTransaction('this is not json', bytes([0] * 65))
    with pytest.raises(json.JSONDecodeError):
        signed.transaction()