function testJSendFailure() { $json = array("status" => "status", "message" => "Something happened"); try { Fetch::checkJSend($json); $this->fail("Expected failure"); } catch (JSendException $e) { // expected } }
function getDifficulty(Logger $logger) { if (!$this->info_url) { throw new DifficultyException("No known difficulty URL for currency '" . $this->currency->getCode() . "'"); } $url = $this->info_url; $logger->info($url); $json = Fetch::jsonDecode(Fetch::get($url)); try { $data = Fetch::checkJSend($json); } catch (JSendException $e) { throw new BlockException($e->getMessage(), $e); } $value = $data['last_block']['difficulty']; $logger->info("Difficulty: " . number_format($value)); return $value; }