Ethereum PHP
PHP interface to Ethereum JSON-RPC API.
EthD20Test.php
Go to the documentation of this file.
1 <?php
2 namespace Ethereum;
3 
5 
6 
12 class EthD20Test extends TestStatic
13 {
18  public function testEthD20__simple()
19  {
20 
21  $x = new EthD20('0x3facfa472e86e3edaeaa837f6ba038ac01f7f539');
22  $this->assertSame($x->val(), '3facfa472e86e3edaeaa837f6ba038ac01f7f539');
23  $this->assertSame($x->hexVal(), '0x3facfa472e86e3edaeaa837f6ba038ac01f7f539');
24  $this->assertSame($x->getSchemaType(), "D20");
25  }
26 
27  // Made to Fail.
29  {
30  try {
31  new EthD20('0x3facfa472e86e3edaeaa837f6ba038ac01f7f53989');
32  $this->fail("Expected exception '" . $exception_message_expected . "' not thrown");
33  } catch (\Exception $exception) {
34  $this->assertTrue(strpos($exception->getMessage(), "Invalid length") !== false);
35  }
36  }
37 
38  public function testEthQ__invalidLengthShort()
39  {
40 
41  try {
42  new EthD20('0x0');
43  $this->fail("Expected exception '" . $exception_message_expected . "' not thrown");
44  } catch (\Exception $exception) {
45  $this->assertTrue(strpos($exception->getMessage(), "Invalid length") !== false);
46  }
47  }
48 
49  public function testEthQ__notHexPrefixed()
50  {
51  // Change note: Now you can use unprefixed values again.
52  $a = new EthD20('4f1116b6e1a6e963efffa30c0a8541075cc51c45');
53  $this->assertEquals($a->hexVal(), '0x4f1116b6e1a6e963efffa30c0a8541075cc51c45');
54  }
55 
56  public function testEthQ__notHex()
57  {
58  try {
59  $val = '0xyz116b6e1a6e963efffa30c0a8541075cc51c45';
60  $exception_message_expected = 'A non well formed hex value encountered: ' . $val;
61  new EthD20($val);
62  $this->fail("Expected exception '" . $exception_message_expected . "' not thrown");
63  } catch (\Exception $exception) {
64  $this->assertEquals($exception->getMessage(), $exception_message_expected);
65  }
66  }
67 }
Definition: Abi.php:3