Ethereum PHP
PHP interface to Ethereum JSON-RPC API.
EthBytesTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Ethereum;
4 
8 
9 
15 class EthBytesTest extends TestStatic
16 {
21  public function testEthD__simple()
22  {
23 
24  $x = new EthD('0x4f1116b6e1a6e963efffa30c0a8541075cc51c45');
25  $this->assertSame($x->val(), '4f1116b6e1a6e963efffa30c0a8541075cc51c45');
26  $this->assertSame($x->hexVal(), '0x4f1116b6e1a6e963efffa30c0a8541075cc51c45');
27  $this->assertSame($x->getSchemaType(), "D");
28  }
29 
30 
31  public function convertDataProvider()
32  {
33  return [
34  // [ABI, rawValue, Expected type class, expected value]
35  [
36  // See https://github.com/ethereum/web3.js/blob/cd1cfd9db6cacb494884a1824f8562c6440f85df/test/coder.decodeParam.js#L141-L144
37  'bytes',
38  '0000000000000000000000000000000000000000000000000000000000000009'
39  .'6761766f66796f726b0000000000000000000000000000000000000000000000'
40  ,
41  'EthBytes',
42  '0x6761766f66796f726b',
43  ],
44  [
45  //See https://github.com/ethereum/web3.js/blob/cd1cfd9db6cacb494884a1824f8562c6440f85df/test/coder.decodeParam.js#L145-L148
46  'bytes',
47  '0000000000000000000000000000000000000000000000000000000000000020'
48  .'731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'
49  ,
50  'EthBytes',
51  '0x731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
52  ],
53  [
54  //See https://github.com/ethereum/web3.js/blob/cd1cfd9db6cacb494884a1824f8562c6440f85df/test/coder.decodeParam.js#L149-L156
55  'bytes',
56  '0000000000000000000000000000000000000000000000000000000000000060'
57  .'131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'
58  .'231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'
59  .'331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'
60  ,
61  'EthBytes',
62  '0x131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b231a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b331a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
63  ],
64  [
65  //See https://github.com/ethereum/web3.js/blob/cd1cfd9db6cacb494884a1824f8562c6440f85df/test/coder.decodeParam.js#L157-L162
66  'bytes',
67  '0000000000000000000000000000000000000000000000000000000000000040'
68  .'731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'
69  .'731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'
70  ,
71  'EthBytes',
72  '0x731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'
73  .'731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b',
74  ],
75  [
76  //See https://github.com/ethereum/web3.js/blob/master/test/coder.decodeParam.js
77  'bytes',
78  '000000000000000000000000000000000000000000000000000000000000009f'
79  .'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
80  .'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
81  .'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
82  .'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
83  .'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff100'
84  ,
85  'EthBytes',
86  '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
87  .'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
88  .'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
89  .'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
90  .'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1',
91  ],
92  [
93  //See https://github.com/ethereum/web3.js/blob/master/test/coder.decodeParam.js
94  'bytes',
95  '0000000000000000000000000000000000000000000000000000000000000006'
96  .'c3a40000c3a40000000000000000000000000000000000000000000000000000',
97  'EthBytes',
98  '0xc3a40000c3a4',
99  ],
100  [
101  // @see https://github.com/ethereumjs/ethereumjs-abi/blob/master/test/index.js
102  'bytes',
103  '000000000000000000000000000000000000000000000000000000000000000b'
104  .'68656c6c6f20776f726c64000000000000000000000000000000000000000000',
105  'EthBytes',
106  '0x68656c6c6f20776f726c64',
107  ],
108 
109  // @todo IS THIS TEST VALID??
110 // [
111 // 'bytes',
112 // '0x000000000000000000000000000000000000000000000000000000000000000d'
113 // .'48656c6c6f2c20776f726c642100000000000000000000000000000000000000',
114 // 'EthBytes',
115 // 'Hello, world!',
116 // ],
117 // [
118 // 'bytes',
119 // '0x0000000000000000000000000000000000000000000000000000000000000004'
120 // .'6461766500000000000000000000000000000000000000000000000000000000',
121 // 'EthBytes',
122 // 'dave',
123 // ],
124  [
125  'bytes',
126  '0000000000000000000000000000000000000000000000000000000000000009'
127  .'6761766f66796f726b0000000000000000000000000000000000000000000000'
128  ,
129  'EthBytes',
130  '0x6761766f66796f726b',
131  ],
132 // [
133 // 'string',
134 // '0x0000000000000000000000000000000000000000000000000000000000000020'
135 // .'0000000000000000000000000000000000000000000000000000000000000009'
136 // .'6761766f66796f726b0000000000000000000000000000000000000000000000'
137 // ,
138 // 'EthS',
139 // 'gavofyork',
140 // ],
141  ];
142  }
143 
144 
148  public function testEthBytesTest__createVal($abi, $rawValue, $expClass, $expVal)
149  {
150  $expClass = "\\Ethereum\DataType\\$expClass";
151  $x = $expClass::cretateFromRLP(EthereumStatic::ensureHexPrefix($rawValue));
152  $this->assertEquals($expVal, $x->hexVal());
153  }
154 
158  public function testEthBytesTest__createType($abi, $rawValue, $expClass, $expVal)
159  {
160  $class = "\\Ethereum\DataType\\" . $expClass;
161  $x = new $class($expVal);
162  $this->assertEquals($expClass, $x->getClassName());
163  }
164 
165 
169  public function testEthBytesTest__createTypeWithAbi($abi, $rawValue, $expClass, $expVal)
170  {
171  $class = "\\Ethereum\DataType\\" . $expClass;
172  $x = new $class($expVal, ['abi' => $abi]);
173  $this->assertEquals($expClass, $x->getClassName());
174  }
175 
179  public function testEthBytesTest__converter($abi, $rawValue, $expClass, $expVal)
180  {
181  $x = new EthD($expVal);
182  $y = $x->convertByAbi($abi);
183  $this->assertEquals(EthereumStatic::removeHexPrefix($expVal), $y->val());
184  }
185 
189  public function testEthBytesTest__converterType($abi, $rawValue, $expClass, $expVal)
190  {
191  $x = new EthD($expVal);
192  $y = $x->convertByAbi($abi);
193  $this->assertEquals($expClass, $y->getClassName());
194  }
195 
196 }
testEthBytesTest__createTypeWithAbi($abi, $rawValue, $expClass, $expVal)
testEthBytesTest__createType($abi, $rawValue, $expClass, $expVal)
testEthBytesTest__converter($abi, $rawValue, $expClass, $expVal)
testEthBytesTest__converterType($abi, $rawValue, $expClass, $expVal)
testEthBytesTest__createVal($abi, $rawValue, $expClass, $expVal)
Definition: Abi.php:3