/**
  * Make sure a new transaction is created if no one exists.
  */
 public function testTransactionCreated()
 {
     $user_id = $this->factory->user->create();
     $account = bca_user_account($user_id);
     $address = $account->getDepositAddress();
     $this->assertTrue(strlen($address) > 4);
     $data = array("type" => "address", "data" => array("address" => $address, "txid" => "12345678", "balance_change" => "0.05000000", "confirmations" => 0));
     BlockIoController::instance()->process($data);
     $transaction = Transaction::findOneBy("transactionHash", "12345678");
     $this->assertEquals(0.05, $transaction->getAmount("btc"));
     $this->assertEquals($transaction->getState(), Transaction::CONFIRMING);
     $account = bca_user_account($user_id);
     $this->assertEquals(0, $account->getBalance("btc"));
     $this->assertEquals(0.05, $account->getConfirmingBalance("btc"));
     $data = array("type" => "address", "data" => array("address" => $address, "txid" => "12345678", "balance_change" => "0.05000000", "confirmations" => "3"));
     BlockIoController::instance()->process($data);
     $account = bca_user_account($user_id);
     $this->assertEquals(0.05, $account->getBalance("btc"));
 }
 /**
  *
  */
 public function testGetTransactions()
 {
     $user1_id = $this->factory->user->create();
     $user1 = get_user_by("id", $user1_id);
     $user2_id = $this->factory->user->create();
     $user2 = get_user_by("id", $user2_id);
     $account1 = bca_user_account($user1_id);
     $account1->balance = 100;
     $account1->save();
     $account1 = bca_user_account($user1_id);
     $this->assertEquals(100, $account1->getBalance("satoshi"));
     $account2 = bca_user_account($user2_id);
     bca_make_transaction("satoshi", $account1, $account2, 100);
     $account2 = bca_user_account($user2_id);
     $this->assertEquals(100, $account2->getBalance("satoshi"));
     $transactions = $account2->getTransactions();
     $this->assertCount(1, $transactions);
     $transaction = $transactions[0];
     $this->assertCount(1, $account2->getTransactions(array("newerThan" => $transaction->timestamp - 1)));
     $this->assertCount(0, $account2->getTransactions(array("newerThan" => $transaction->timestamp)));
     $this->assertCount(0, $account2->getTransactions(array("newerThan" => $transaction->timestamp + 1)));
 }