Ethereum PHP
PHP interface to Ethereum JSON-RPC API.
EthDTest.php
Go to the documentation of this file.
1 <?php
2 namespace Ethereum;
6 
12 class EthDTest extends TestStatic
13 {
18  public function testEthD__simple()
19  {
20 
21  $x = new EthD('0x4f1116b6e1a6e963efffa30c0a8541075cc51c45');
22  $this->assertSame($x->val(), '4f1116b6e1a6e963efffa30c0a8541075cc51c45');
23  $this->assertSame($x->hexVal(), '0x4f1116b6e1a6e963efffa30c0a8541075cc51c45');
24  $this->assertSame($x->getSchemaType(), "D");
25  }
26 
27  // Made to Fail.
28  public function testEthD__notHexPrefixed()
29  {
30  $a = new EthD('4f1116b6e1a6e963efffa30c0a8541075cc51c45');
31  $this->assertEquals($a->hexVal(), '0x4f1116b6e1a6e963efffa30c0a8541075cc51c45');
32  }
33 
34  public function testEthQD__notHex()
35  {
36  try {
37  $val = '0xyz116b6e1a6e963efffa30c0a8541075cc51c45';
38  $exception_message_expected = 'A non well formed hex value encountered: ' . $val;
39  new EthD($val);
40  $this->fail("Expected exception '" . $exception_message_expected . "' not thrown");
41  } catch (\Exception $exception) {
42  $this->assertEquals($exception->getMessage(), $exception_message_expected);
43  }
44  }
45 
46 
47 
48  public function convertDataProvider()
49  {
50  return [
51  // [ABI, value, Expected type class, expected value]
52  [
53  'bool',
54  '0x0000000000000000000000000000000000000000000000000000000000000001',
55  'EthB',
56  true
57  ],
58  [
59  'bool',
60  '0x0000000000000000000000000000000000000000000000000000000000000000',
61  'EthB',
62  false
63  ],
64  [
65  'uint256',
66  '0x000000000000000000000000000000000000000000000000000000000000000e',
67  'EthQ',
68  14
69  ],
70  [
71  'uint', // Should fall back to uint256
72  '0x000000000000000000000000000000000000000000000000000000000000000e',
73  'EthQ',
74  14
75  ],
76  [
77  'int256',
78  '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
79  'EthQ',
80  -1
81  ],
82  [
83  'int', // Should fall back to int256
84  '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
85  'EthQ',
86  -1
87  ],
88  [
89  'uint32',
90  '0x000000000000000000000000000000000000000000000000000000000000002a',
91  'EthQ',
92  42
93  ],
94  [
95  'int256',
96  '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc19',
97  'EthQ',
98  -999
99  ],
100  [
101  'address',
102  '0xf17f52151EbEF6C7334FAD080c5704D77216b732',
103  'EthD20',
104  'f17f52151ebef6c7334fad080c5704d77216b732'
105  ],
106 
107  // TOOO LONG FOR NOW Requires RLP.
108  // ['string', '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001f6120726573706f6e736520737472696e672028756e737570706f727465642900', 'EthQ', 'a response string (unsupported)'],
109  ];
110  }
111 
115  public function testEthD__converter($abi, $value, $expClass, $expVal)
116  {
117  $x = new EthD($value);
118  $y = $x->convertByAbi($abi);
119  $className = (new ReflectionClass($y))->getShortName();
120  $this->assertEquals($expClass, $className);
121  $this->assertEquals($expVal, $y->val());
122  }
123 }
testEthD__converter($abi, $value, $expClass, $expVal)
Definition: EthDTest.php:115
testEthD__notHexPrefixed()
Definition: EthDTest.php:28
Definition: Abi.php:3