Add test for personal_lockAccount

Change:
* Add test for personal_lockAccount
This commit is contained in:
sc0Vu 2018-12-13 17:27:52 +08:00
parent 28627c5ecf
commit f3259100ec
3 changed files with 46 additions and 5 deletions

View File

@ -38,3 +38,16 @@ $web3->eth->getBalance($newAccount, function ($err, $balance) {
} }
echo 'Balance: ' . $balance->toString() . PHP_EOL; echo 'Balance: ' . $balance->toString() . PHP_EOL;
}); });
// remember to lock account after transaction
$personal->lockAccount($newAccount, function ($err, $locked) {
if ($err !== null) {
echo 'Error: ' . $err->getMessage();
return;
}
if ($locked) {
echo 'New account is locked!' . PHP_EOL;
} else {
echo 'New account isn\'t locked' . PHP_EOL;
}
});

View File

@ -11,14 +11,9 @@
namespace Web3\Methods\Personal; namespace Web3\Methods\Personal;
use InvalidArgumentException;
use Web3\Methods\EthMethod; use Web3\Methods\EthMethod;
use Web3\Validators\AddressValidator; use Web3\Validators\AddressValidator;
use Web3\Validators\StringValidator;
use Web3\Validators\QuantityValidator;
use Web3\Formatters\AddressFormatter; use Web3\Formatters\AddressFormatter;
use Web3\Formatters\StringFormatter;
use Web3\Formatters\NumberFormatter;
class LockAccount extends EthMethod class LockAccount extends EthMethod
{ {

View File

@ -121,6 +121,39 @@ class PersonalApiTest extends TestCase
}); });
} }
/**
* testLockAccount
*
* @return void
*/
public function testLockAccount()
{
$personal = $this->personal;
// create account
$personal->newAccount('123456', function ($err, $account) {
if ($err !== null) {
return $this->fail($err->getMessage());
}
$this->newAccount = $account;
$this->assertTrue(is_string($account));
});
$personal->unlockAccount($this->newAccount, '123456', function ($err, $unlocked) {
if ($err !== null) {
return $this->fail($err->getMessage());
}
$this->assertTrue($unlocked);
});
$personal->lockAccount($this->newAccount, function ($err, $locked) {
if ($err !== null) {
return $this->fail($err->getMessage());
}
$this->assertTrue($locked);
});
}
/** /**
* testSendTransaction * testSendTransaction
* *