mirror of
https://git.wownero.com/lza_menace/wownero-python.git
synced 2024-08-15 03:25:25 +00:00
Fix encoding errors on send_transaction()
This commit is contained in:
parent
261cd342dd
commit
3ad3a6082b
6 changed files with 42 additions and 4 deletions
|
@ -5,6 +5,7 @@ import operator
|
|||
import json
|
||||
import logging
|
||||
import requests
|
||||
import six
|
||||
|
||||
from .. import exceptions
|
||||
from ..account import Account
|
||||
|
@ -67,7 +68,7 @@ class JSONRPCDaemon(object):
|
|||
|
||||
def send_transaction(self, blob, relay=True):
|
||||
res = self.raw_request('/sendrawtransaction', {
|
||||
'tx_as_hex': binascii.hexlify(blob),
|
||||
'tx_as_hex': six.ensure_text(binascii.hexlify(blob)),
|
||||
'do_not_relay': not relay})
|
||||
if res['status'] == 'OK':
|
||||
return res
|
||||
|
|
Binary file not shown.
18
tests/data/test_jsonrpcdaemon/test_send_transaction.json
Normal file
18
tests/data/test_jsonrpcdaemon/test_send_transaction.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"credits": 0,
|
||||
"double_spend": false,
|
||||
"fee_too_low": false,
|
||||
"invalid_input": false,
|
||||
"invalid_output": false,
|
||||
"low_mixin": false,
|
||||
"not_rct": false,
|
||||
"not_relayed": false,
|
||||
"overspend": false,
|
||||
"reason": "",
|
||||
"sanity_check_failed": false,
|
||||
"status": "OK",
|
||||
"too_big": false,
|
||||
"too_few_outputs": false,
|
||||
"top_hash": "",
|
||||
"untrusted": false
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
import decimal
|
||||
import os
|
||||
import responses
|
||||
|
||||
from monero.const import NET_STAGE
|
||||
from monero.daemon import Daemon
|
||||
from monero.backends.jsonrpc import JSONRPCDaemon
|
||||
from monero.transaction import Transaction
|
||||
|
||||
from .base import JSONTestCase
|
||||
|
||||
|
@ -11,6 +13,7 @@ class JSONRPCDaemonTestCase(JSONTestCase):
|
|||
jsonrpc_url = 'http://127.0.0.1:18081/json_rpc'
|
||||
mempool_url = 'http://127.0.0.1:18081/get_transaction_pool'
|
||||
transactions_url = 'http://127.0.0.1:18081/get_transactions'
|
||||
sendrawtransaction_url = 'http://127.0.0.1:18081/sendrawtransaction'
|
||||
data_subdir = 'test_jsonrpcdaemon'
|
||||
|
||||
def setUp(self):
|
||||
|
@ -110,3 +113,18 @@ class JSONRPCDaemonTestCase(JSONTestCase):
|
|||
"035a1cfadd2f80124998f5af8c7bb6703743a4f322d0a20b7f7b502956ada59d")
|
||||
self.assertIsNone(txs[3].height)
|
||||
self.assertEqual(txs[3].size, 2724)
|
||||
|
||||
@responses.activate
|
||||
def test_send_transaction(self):
|
||||
path = os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
"data",
|
||||
self.data_subdir,
|
||||
"0e8fa9202e0773333360e5b9e8fb8e94272c16a8a58b6fe7cf3b4327158e3a44.tx")
|
||||
responses.add(responses.POST, self.sendrawtransaction_url,
|
||||
json=self._read('test_send_transaction.json'),
|
||||
status=200)
|
||||
tx = Transaction(
|
||||
blob=open(path, "rb").read())
|
||||
rsp = self.daemon.send_transaction(tx)
|
||||
self.assertEqual(rsp["status"], "OK")
|
||||
|
|
|
@ -4,6 +4,7 @@ import logging
|
|||
import operator
|
||||
import re
|
||||
import sys
|
||||
import six
|
||||
|
||||
from monero.backends.jsonrpc import JSONRPCDaemon
|
||||
from monero.daemon import Daemon
|
||||
|
@ -36,9 +37,9 @@ elif args.verbosity > 1:
|
|||
level = logging.DEBUG
|
||||
logging.basicConfig(level=level, format="%(asctime)-15s %(message)s")
|
||||
if args.tx_filenames:
|
||||
blobs = [(f, open(f, 'r').read()) for f in args.tx_filenames]
|
||||
blobs = [(f, open(f, 'rb').read()) for f in args.tx_filenames]
|
||||
else:
|
||||
blobs = [('transaction', sys.stdin.read())]
|
||||
blobs = [('transaction', sys.stdin.buffer.read() if six.PY3 else sys.stdin.read())]
|
||||
d = Daemon(JSONRPCDaemon(timeout=args.timeout, proxy_url=args.proxy_url, **args.daemon_rpc_url))
|
||||
for name, blob in blobs:
|
||||
logging.debug("Sending {}".format(name))
|
||||
|
|
|
@ -63,6 +63,6 @@ for tx in txns:
|
|||
if args.outdir:
|
||||
outname = os.path.join(args.outdir, tx.hash + '.tx')
|
||||
outfile = open(outname, 'wb')
|
||||
outfile.write(tx.blob.encode())
|
||||
outfile.write(tx.blob)
|
||||
outfile.close()
|
||||
print(u"Transaction saved to {}".format(outname))
|
||||
|
|
Loading…
Reference in a new issue