Ethereum PHP
PHP interface to Ethereum JSON-RPC API.
EthSTest.php
Go to the documentation of this file.
1 <?php
2 namespace Ethereum;
6 
12 class EthSTest extends TestStatic
13 {
14 
15 
16  public function convertDataProvider()
17  {
18  return [
19  // [ABI, rlpValue, Expected type class, expected value]
20  [
21  // @see https://github.com/ethereum/web3.js/blob/cd1cfd9db6cacb494884a1824f8562c6440f85df/test/coder.decodeParam.js#L204-L206
22  'string',
23  '0000000000000000000000000000000000000000000000000000000000000009'.
24  '6761766f66796f726b0000000000000000000000000000000000000000000000'
25  ,
26  'EthS',
27  'gavofyork',
28  ],
29  [
30  // @see: https://github.com/ethereum/web3.js/blob/cd1cfd9db6cacb494884a1824f8562c6440f85df/test/coder.decodeParam.js#L207-L210
31  'string',
32  '0000000000000000000000000000000000000000000000000000000000000008'.
33  'c383c2a4c383c2a4000000000000000000000000000000000000000000000000'
34  ,
35  'EthS',
36  'ää',
37  ],
38  [
39  // @see: https://github.com/ethereum/web3.js/blob/cd1cfd9db6cacb494884a1824f8562c6440f85df/test/coder.decodeParam.js#L211-L214
40  'string',
41  '0000000000000000000000000000000000000000000000000000000000000002'.
42  'c3bc000000000000000000000000000000000000000000000000000000000000'
43  ,
44  'EthS',
45  'ü',
46  ],
47  [
48  // @see: https://github.com/ethereum/web3.js/blob/cd1cfd9db6cacb494884a1824f8562c6440f85df/test/coder.decodeParam.js#L215-L218
49  'string',
50  '0000000000000000000000000000000000000000000000000000000000000002'.
51  'c383000000000000000000000000000000000000000000000000000000000000'
52  ,
53  'EthS',
54  'Ã',
55  ],
56  [
57  // @see: https://github.com/ethereum/web3.js/blob/cd1cfd9db6cacb494884a1824f8562c6440f85df/test/coder.decodeParam.js#L215-L218
58  'string',
59  '000000000000000000000000000000000000000000000000000000000000003e'.
60  '77656c636f6d6520746f20657468657265756d2e2077656c636f6d6520746f20'.
61  '657468657265756d2e2077656c636f6d6520746f20657468657265756d2e0000'
62  ,
63  'EthS',
64  'welcome to ethereum. welcome to ethereum. welcome to ethereum.',
65  ],
66  [
67  // @see: https://github.com/ethereumjs/ethereumjs-abi/blob/71f123b676f2b2d81bc20f343670d90045a3d3d8/test/index.js#L228-L235
68  'string',
69  '000000000000000000000000000000000000000000000000000000000000000b'.
70  '68656c6c6f20776f726c64000000000000000000000000000000000000000000'
71  ,
72  'EthS',
73  'hello world',
74  ],
75  [
76  // @see: https://github.com/ethereumjs/ethereumjs-abi/blob/71f123b676f2b2d81bc20f343670d90045a3d3d8/test/index.js#L600-L605
77  'string',
78  '0000000000000000000000000000000000000000000000000000000000000017'.
79  '657468657265756d20737ac3a16dc3ad74c3b367c3a970000000000000000000'
80  ,
81  'EthS',
82  'ethereum számítógép',
83  ],
84  [
85  // @see: https://github.com/ethereumjs/ethereumjs-abi/blob/71f123b676f2b2d81bc20f343670d90045a3d3d8/test/index.js#L616-L620
86  'string',
87  '0000000000000000000000000000000000000000000000000000000000000018'.
88  'e4b8bae4bb80e4b988e982a3e4b988e8aea4e79c9fefbc9f0000000000000000'
89  ,
90  'EthS',
91  '为什么那么认真?',
92  ],
93  [
94  // @see: https://github.com/ethereumjs/ethereumjs-abi/blob/71f123b676f2b2d81bc20f343670d90045a3d3d8/test/index.js#L89-L95
95  'string',
96  '00000000000000000000000000000000000000000000000000000000000000c2'.
97  '2068656c6c6f20776f726c642068656c6c6f20776f726c642068656c6c6f2077'.
98  '6f726c642068656c6c6f20776f726c64202068656c6c6f20776f726c64206865'.
99  '6c6c6f20776f726c642068656c6c6f20776f726c642068656c6c6f20776f726c'.
100  '64202068656c6c6f20776f726c642068656c6c6f20776f726c642068656c6c6f'.
101  '20776f726c642068656c6c6f20776f726c642068656c6c6f20776f726c642068'.
102  '656c6c6f20776f726c642068656c6c6f20776f726c642068656c6c6f20776f72'.
103  '6c64000000000000000000000000000000000000000000000000000000000000'
104  ,
105  'EthS',
106  ' hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world',
107  ],
108  [
109  // @see: https://github.com/ethereumjs/ethereumjs-abi/blob/71f123b676f2b2d81bc20f343670d90045a3d3d8/test/index.js#L105-L111
110  'string',
111  '000000000000000000000000000000000000000000000000000000000000001f'.
112  '6120726573706f6e736520737472696e672028756e737570706f727465642900'
113  ,
114  'EthS',
115  'a response string (unsupported)',
116  ],
117  ];
118  }
119 
120 
121  //
122 
127  public function testEthS__types()
128  {
129 
130  $x = new EthS('Hello World');
131  $this->assertEquals($x->val(), "Hello World");
132  $this->assertEquals($x->getSchemaType(), "S");
133  }
134 
135  // THE FOLLOWING TWO TEST ARE WRONG!
136  // @depreciated
137  // -> If you implemented something like that it will not work anymore.
138  //
139  //public function testEthS__hexToString()
140  //{
141  //
142  // $x = new EthS('0x48656c6c6f20576f726c64');
143  // $this->assertEquals($x->val(), "Hello World");
144  //}
145  //public function testEthS__stringToHex()
146  //{
147  // $x = new EthS("Hello World");
148  // $this->assertEquals($x->hexVal(), '0x48656c6c6f20576f726c64');
149  //}
150 
154  public function testEthSTest__create($abi, $rlpValue, $expClass, $utf8Val)
155  {
156  $x = EthS::cretateFromRLP(EthereumStatic::ensureHexPrefix($rlpValue));
157  $this->assertEquals($utf8Val, $x->val());
158  }
159 
163  public function testEthSTest__convertHexDataToHexStr($abi, $rlpValue, $expClass, $utf8Val)
164  {
165  $x = EthBytes::cretateFromRLP(EthereumStatic::ensureHexPrefix($rlpValue));
166  $y = $x->convertByAbi($abi);
167  $this->assertEquals($utf8Val, $y->val());
168  }
169 
173  public function testEthSTest__convertUtf8ToData($abi, $rlpValue, $expClass, $utf8Val)
174  {
175  $x = new EthS($utf8Val);
176  $y = $x->convertByAbi('bytes');
177  $z = EthBytes::cretateFromRLP(EthereumStatic::ensureHexPrefix($rlpValue));
178  $this->assertEquals($y->hexVal(), $z->hexVal());
179  }
180 
181  // DOES NOT MAKE SENSE RIGHT NOW, just duplicates. DataSet has no plain Hex value.
182 // /**
183 // * @dataProvider convertDataProvider
184 // */
185 // public function testEthSTest__Utf8ToHex($abi, $rlpValue, $expClass, $utf8Val)
186 // {
187 // $x = new EthS($utf8Val);
188 // $this->assertEquals(EthereumStatic::ensureHexPrefix($rlpValue), $x->hexVal());
189 // }
190 //
191 // /**
192 // * @dataProvider convertDataProvider
193 // */
194 // public function testEthSTest__HexToUtf8($abi, $rlpValue, $expClass, $utf8Val)
195 // {
196 // $x = EthS::cretateFromRLP(EthereumStatic::ensureHexPrefix($rlpValue));
197 // $this->assertEquals($utf8Val, $x->val());
198 // }
199 
200 }
testEthSTest__create($abi, $rlpValue, $expClass, $utf8Val)
Definition: EthSTest.php:154
testEthSTest__convertHexDataToHexStr($abi, $rlpValue, $expClass, $utf8Val)
Definition: EthSTest.php:163
testEthSTest__convertUtf8ToData($abi, $rlpValue, $expClass, $utf8Val)
Definition: EthSTest.php:173
Definition: Abi.php:3