Ethereum PHP
PHP interface to Ethereum JSON-RPC API.
Sha3JsonRpcTest.php
Go to the documentation of this file.
1 <?php
2 namespace Ethereum;
3 use Exception;
6 
13 
14  protected function setUp()
15  {
16  $this->markTestSkipped(
17  'sha3() in JsonRPC has a wrong schema type. It actually does not expect EthS (which is RLP encoded), '
18  .'but a hex encoded UTF8 string (like returned by EthS::hexToStr($hex)). For now skipping this test. '
19  . 'We might remove sha3() in schema (there is now a PHP native kessac256) or "invent" a new data type just for this case.'
20  );
21  }
22 
23  public function kessacStringProvider() {
24  // UTF8 text, Kessac256
25  return [
26  ['Hello world!', '0xecd0e108a98e192af1d2c25055f4e3bed784b5c877204e73219a5203251feaab'],
27  ["\n", '0x0ef9d8f8804d174666011a394cab7901679a8944d24249fd148a6a36071151f8'],
28  ['1', '0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6'],
29  ['-1', '0x798272c22de7de1bbb41d9d76b5240e67bb83e9ece1afeb940834536b3646693'],
30  ['testing', '0x5f16f4c7f149ac4f9510d9cf8cf384038ad348b3bcdc01915f95de12df9d1b02'],
31  ];
32  }
33 
34  public function testEmptyString()
35  {
36  $x = EthereumStatic::sha3('');
37  $this->assertSame('0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470', $x);
38  }
39 
41  {
42  $eth = new Ethereum('http://localhost:7545');
43  $x = $eth->web3_sha3(new EthS(''));
44  $this->assertSame(
45  '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',
46  $x->hexVal()
47  );
48  }
49 
50 
58  public function testManyStrings($text, $sha3)
59  {
60  $this->assertSame($sha3, EthereumStatic::sha3($text));
61  }
62 
69  public function testManyWithEthereumSha3($text, $sha3)
70  {
71  if (defined('SERVER_URL')) {
72  $eth = new Ethereum(SERVER_URL);
73  $val = new EthS($text);
74  $x = $eth->web3_sha3($val);
75  $this->assertSame($sha3, $x->hexVal());
76  }
77  else {
78  $this->markTestSkipped('Ethereum web3_sha3 can only be tested if SERVER_URL is defined.');
79  }
80 
81  }
82 }
testManyWithEthereumSha3($text, $sha3)
Definition: Abi.php:3