diff --git a/test/TestCase.php b/test/TestCase.php index 780e377..51593d8 100644 --- a/test/TestCase.php +++ b/test/TestCase.php @@ -28,6 +28,13 @@ class TestCase extends BaseTestCase */ protected $testHost = 'http://localhost:8545'; + /** + * coinbase + * + * @var string + */ + protected $coinbase; + /** * setUp * @@ -37,6 +44,13 @@ class TestCase extends BaseTestCase { $web3 = new Web3($this->testHost); $this->web3 = $web3; + + $web3->eth->coinbase(function ($err, $coinbase) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + $this->coinbase = $coinbase; + }); } /** diff --git a/test/unit/EthApiTest.php b/test/unit/EthApiTest.php index db8c094..0d4cc4b 100644 --- a/test/unit/EthApiTest.php +++ b/test/unit/EthApiTest.php @@ -75,7 +75,7 @@ class EthApiTest extends TestCase if ($err !== null) { return $this->fail($err->getMessage()); } - $this->assertEquals($coinbase, '0x561a2aa10f9a8589c93665554c871106342f70af'); + $this->assertEquals($coinbase, $this->coinbase); }); } diff --git a/test/unit/PersonalApiTest.php b/test/unit/PersonalApiTest.php index 055bbf6..9924b0a 100644 --- a/test/unit/PersonalApiTest.php +++ b/test/unit/PersonalApiTest.php @@ -104,19 +104,37 @@ class PersonalApiTest extends TestCase { $personal = $this->personal; - $personal->sendTransaction([ - 'from' => "0xb60e8dd61c5d32be8058bb8eb970870f07233155", - 'to' => "0xd46e8dd67c5d32be8058bb8eb970870f07244567", - 'gas' => "0x76c0", - 'gasPrice' => "0x9184e72a000", - 'value' => "0x9184e72a", - 'data' => "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675" - ], '123456', function ($err, $transaction) { + // create account + $personal->newAccount('123456', function ($err, $account) { if ($err !== null) { - // infura banned us to use send transaction - return $this->assertTrue($err->getCode() === 405); + return $this->fail($e->getMessage()); + } + $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(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); }); }