def test_sign_transaction(ethereum_accounts):
    expected = '0xed2e8602439eec57a84bb372c6de718d88d2c27f265d7c01fe59a940f9c44eb25f849639669897e376dca6b3e745f4d9667' \
               '32f731b6ec20d908673ad882aeed301'
    data = {
        'name': 'polyswarmtransaction.transaction:Transaction',
        'from': '0x3f17f1962B36e491b30A40b2405849e597Ba5FB5',
        'data': {}
    }
    transaction = Transaction()
    signed = transaction.sign(ethereum_accounts[0].key)
    assert json.loads(signed.raw_transaction) == data
    assert signed.signature.hex() == expected
def test_sign_none():
    transaction = Transaction()
    with pytest.raises(InvalidKeyError):
        transaction.sign(None)
def test_recover_signed_transaction_from_payload(ethereum_accounts):
    transaction = Transaction()
    signed = transaction.sign(ethereum_accounts[0].key)
    signed = SignedTransaction(**signed.payload)
    assert signed.ecrecover() == '0x3f17f1962B36e491b30A40b2405849e597Ba5FB5'
def test_recover_signed_transaction_from_signed_output(ethereum_accounts):
    transaction = Transaction()
    signed = transaction.sign(ethereum_accounts[0].key)
    signed = SignedTransaction(signed.raw_transaction, signed.signature)
    assert signed.ecrecover() == '0x3f17f1962B36e491b30A40b2405849e597Ba5FB5'