def test_broadcast_transaction_thenBroadcastsToAllNodes(self):
with patch.object(FullNode, '__init__', return_value=None) as patched_init, \
patch.object(FullNode, 'request_nodes_from_all') as patched_request_nodes_from_all, \
patch("crankycoin.time.time", return_value="1508823223") as patched_time_time, \
patch("crankycoin.requests.post") as patched_requests:
transaction = Transaction("source", "destination", 0, 0)
node = FullNode("127.0.0.1", "reward_address")
node.full_nodes = {"127.0.0.1", "127.0.0.2", "127.0.0.3"}
node.broadcast_transaction(transaction)
patched_request_nodes_from_all.assert_called_once()
patched_requests.assert_has_calls([
call("http://127.0.0.1:30013/transactions", json={'transaction': '{"amount": 0, "destination": "destination", "fee": 0, "signature": null, "source": "source", "timestamp": 1508823223, "tx_hash": null}'}),
call("http://127.0.0.2:30013/transactions", json={'transaction': '{"amount": 0, "destination": "destination", "fee": 0, "signature": null, "source": "source", "timestamp": 1508823223, "tx_hash": null}'}),
call("http://127.0.0.3:30013/transactions", json={'transaction': '{"amount": 0, "destination": "destination", "fee": 0, "signature": null, "source": "source", "timestamp": 1508823223, "tx_hash": null}'})
], True)
评论列表
文章目录