function testResettingPassword() { $email = '*****@*****.**'; $u = getUser($email); $this->followRedirects(false); # XXX: Hack to avoid being redirected to homepage upon logout. $this->logout(); $this->followRedirects(); $this->get('/account/signin'); $this->clickLink("//a[contains(text(), 'Forget your password')]"); # We specify the address using different cAsINg to make sure things aren't case-sensitive. $this->submitForm($this->getForm('lost-pass'), array('email' => '*****@*****.**')); /* TODO: Make this test more comprehensive -- but first we need a properly "stubbed-out" email for test framework... $sentEmails = $this->getSentEmails(); assertTrue(count($sentEmails) == 1); $matches = array(); preg_match('@https?://[-.a-z]+(/[^\\s]+)@', $sentEmails[0]->message, $matches); $relativeURI = $matches[1]; $this->get($relativeURI); $this->submitForm($this->getForm(), array('password' => 'nu3vo', 'confirmPassword' => 'nu3vo')); $this->logout(); $this->assertNotLoggedIn(); $this->login($email, 'nu3vo'); $this->assertLoggedIn($u->email); */ $row = DB\selectExactlyOne('confirmation_codes', 'user_id = ?', array($u->id)); $this->get('/account/pass-reset?c=' . $row['code']); $this->submitForm($this->getForm('change-password-form'), array('password' => 'n00p@ss', 'confirm-password' => 'n00p@ss')); }
function getBalance($address, \DateInterval $maxCacheAge = null) { if (empty($address) || trim($address) == '') { throw new InvalidAddress("Empty string/value is not valid"); } $satoshis = null; $updatedAt = null; $needsUpdated = false; try { $row = DB\selectExactlyOne('bitcoin_addresses', 'address = ?', array($address)); $satoshis = intval($row['satoshis']); if ($maxCacheAge) { $updatedAt = new DateTime($row['updated_at']); $expiresAt = $updatedAt->add($maxCacheAge); $now = new DateTime('now'); if ($expiresAt->getTimestamp() < $now->getTimestamp()) { $needsUpdated = true; } } } catch (DB\NoMatchingRecords $_) { $needsUpdated = true; } if ($needsUpdated) { # Since we don't want to have two or three (or more) processes all trying to query # Blockchain.info at the same time, we use a lock to assure only one attempt is made # to update the cache. $lockObtained = withLock($address, function () use($address) { $satoshis = BlockchainDotInfo\getBalanceInSatoshis($address); cacheBalance($address, $satoshis); }); if (!$lockObtained) { if ($satoshis === null) { Log\error("Failed to obtain lock for and no cached balance exists for Bitcoin address " . "{$address}; defaulting to zero"); } $oneHourAgo = new DateTime('1 hour ago'); if ($updatedAt && $updatedAt->getTimestamp() < $oneHourAgo->getTimestamp()) { Log\error("Balance for Bitcoin address {$address} has not been updated for " . "more than one hour"); } } } // $btcBalance = $satoshis / satoshisPerBTC(); // $balanceWithPrecision = $currency == 'BTC' ? $btcBalance : fromBTC($btcBalance, $currency); // return $balanceWithPrecision; return new AmountOfBitcoin($satoshis); }