From f48df7d2c787621b52b2908bb289be790c17816b Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Thu, 14 Dec 2017 18:22:55 +0800 Subject: [PATCH] eth_getBlockByNumber --- src/Eth.php | 11 +++++++++++ test/unit/EthTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/Eth.php b/src/Eth.php index a26b000..1dc9ffb 100644 --- a/src/Eth.php +++ b/src/Eth.php @@ -171,6 +171,17 @@ class Eth 'validators' => BooleanValidator::class ] ] + ], + 'eth_getBlockByNumber' => [ + 'params' => [ + [ + 'validators' => [ + QuantityValidator::class, TagValidator::class + ] + ], [ + 'validators' => BooleanValidator::class + ] + ] ] ]; diff --git a/test/unit/EthTest.php b/test/unit/EthTest.php index 0277803..6842661 100644 --- a/test/unit/EthTest.php +++ b/test/unit/EthTest.php @@ -557,6 +557,32 @@ class EthTest extends TestCase }); } + /** + * testGetBlockByNumber + * + * @return void + */ + public function testGetBlockByNumber() + { + $eth = $this->eth; + + $eth->getBlockByNumber('latest', false, function ($err, $block) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + if (isset($block->result)) { + // weired behavior, see https://github.com/sc0Vu/web3.php/issues/16 + $this->assertTrue($block->result !== null); + } else { + if (isset($block->error)) { + $this->fail($block->error->message); + } else { + $this->assertTrue(true); + } + } + }); + } + /** * testUnallowedMethod *