Add coinbase and fix unit test of personal api.
This commit is contained in:
parent
0a4060e6dd
commit
0e71553343
@ -28,6 +28,13 @@ class TestCase extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
protected $testHost = 'http://localhost:8545';
|
protected $testHost = 'http://localhost:8545';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* coinbase
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $coinbase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setUp
|
* setUp
|
||||||
*
|
*
|
||||||
@ -37,6 +44,13 @@ class TestCase extends BaseTestCase
|
|||||||
{
|
{
|
||||||
$web3 = new Web3($this->testHost);
|
$web3 = new Web3($this->testHost);
|
||||||
$this->web3 = $web3;
|
$this->web3 = $web3;
|
||||||
|
|
||||||
|
$web3->eth->coinbase(function ($err, $coinbase) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
$this->coinbase = $coinbase;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,7 +75,7 @@ class EthApiTest extends TestCase
|
|||||||
if ($err !== null) {
|
if ($err !== null) {
|
||||||
return $this->fail($err->getMessage());
|
return $this->fail($err->getMessage());
|
||||||
}
|
}
|
||||||
$this->assertEquals($coinbase, '0x561a2aa10f9a8589c93665554c871106342f70af');
|
$this->assertEquals($coinbase, $this->coinbase);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,19 +104,37 @@ class PersonalApiTest extends TestCase
|
|||||||
{
|
{
|
||||||
$personal = $this->personal;
|
$personal = $this->personal;
|
||||||
|
|
||||||
$personal->sendTransaction([
|
// create account
|
||||||
'from' => "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
|
$personal->newAccount('123456', function ($err, $account) {
|
||||||
'to' => "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
|
|
||||||
'gas' => "0x76c0",
|
|
||||||
'gasPrice' => "0x9184e72a000",
|
|
||||||
'value' => "0x9184e72a",
|
|
||||||
'data' => "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
|
|
||||||
], '123456', function ($err, $transaction) {
|
|
||||||
if ($err !== null) {
|
if ($err !== null) {
|
||||||
// infura banned us to use send transaction
|
return $this->fail($e->getMessage());
|
||||||
return $this->assertTrue($err->getCode() === 405);
|
}
|
||||||
|
$this->newAccount = $account;
|
||||||
|
$this->assertTrue(is_string($account));
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->web3->eth->sendTransaction([
|
||||||
|
'from' => $this->coinbase,
|
||||||
|
'to' => $this->newAccount,
|
||||||
|
'value' => '0xfffffffff',
|
||||||
|
], function ($err, $transaction) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
}
|
}
|
||||||
$this->assertTrue(is_string($transaction));
|
$this->assertTrue(is_string($transaction));
|
||||||
|
$this->assertTrue(mb_strlen($transaction) === 66);
|
||||||
|
});
|
||||||
|
|
||||||
|
$personal->sendTransaction([
|
||||||
|
'from' => $this->newAccount,
|
||||||
|
'to' => $this->coinbase,
|
||||||
|
'value' => '0x01',
|
||||||
|
], '123456', function ($err, $transaction) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
$this->assertTrue(is_string($transaction));
|
||||||
|
$this->assertTrue(mb_strlen($transaction) === 66);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user