Merge pull request #131 from sc0Vu/add-test

Add test for personal_lockAccount
This commit is contained in:
Peter Lai 2018-12-13 18:35:48 +09:00 committed by GitHub
commit d579535485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;
});
// 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;
use InvalidArgumentException;
use Web3\Methods\EthMethod;
use Web3\Validators\AddressValidator;
use Web3\Validators\StringValidator;
use Web3\Validators\QuantityValidator;
use Web3\Formatters\AddressFormatter;
use Web3\Formatters\StringFormatter;
use Web3\Formatters\NumberFormatter;
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
*