From 125f48a6e5ad76b5145c1a6d802f9772b4ceda7a Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Tue, 19 Dec 2017 16:05:02 +0800 Subject: [PATCH] personal_sendTransaction --- src/Personal.php | 10 ++++++++++ test/unit/PersonalApiTest.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/Personal.php b/src/Personal.php index 7683b00..3b049dd 100644 --- a/src/Personal.php +++ b/src/Personal.php @@ -18,6 +18,7 @@ use Web3\RequestManagers\HttpRequestManager; use Web3\Validators\AddressValidator; use Web3\Validators\StringValidator; use Web3\Validators\QuantityValidator; +use Web3\Validators\TransactionValidator; class Personal { @@ -54,6 +55,15 @@ class Personal ] ] ], + 'personal_sendTransaction' => [ + 'params' => [ + [ + 'validators' => TransactionValidator::class + ], [ + 'validators' => StringValidator::class + ] + ] + ] ]; /** diff --git a/test/unit/PersonalApiTest.php b/test/unit/PersonalApiTest.php index 243161a..ed08083 100644 --- a/test/unit/PersonalApiTest.php +++ b/test/unit/PersonalApiTest.php @@ -92,6 +92,40 @@ class PersonalApiTest extends TestCase }); } + /** + * testSendTransaction + * + * @return void + */ + public function testSendTransaction() + { + $personal = $this->personal; + + $personal->sendTransaction([ + 'from' => "0xb60e8dd61c5d32be8058bb8eb970870f07233155", + 'to' => "0xd46e8dd67c5d32be8058bb8eb970870f07244567", + 'gas' => "0x76c0", + 'gasPrice' => "0x9184e72a000", + 'value' => "0x9184e72a", + 'data' => "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675" + ], '123456', function ($err, $transaction) { + if ($err !== null) { + // infura banned us to use send transaction + return $this->assertTrue($err->getCode() === 405); + } + if (isset($transaction->result)) { + $this->assertTrue(is_string($transaction->result)); + } else { + if (isset($transaction->error)) { + // it's just test hex. + $this->assertTrue(is_string($transaction->error->message)); + } else { + $this->assertTrue(true); + } + } + }); + } + /** * testUnallowedMethod *