Ethereum PHP
PHP interface to Ethereum JSON-RPC API.
FunctionSignatureTest.php
Go to the documentation of this file.
1 <?php
2 namespace Ethereum;
3 
10 {
11  public function functionSignatureProvider() {
12  // UTF8 text, Kessac256
13  return [
14  ['multiply(uint256)', '0xc6888fa1'],
15  ['test()', '0xf8a8fd6d'],
16  ['test(uint256)', '0x29e99f07'],
17  ];
18  }
19 
20 
21  // Following would work, as uint is a alias of int256,
22  // but it is not recommended (mandatory?) to use short names for function signatures.
23  public function functionSignatureFailProvider() {
24  // UTF8 text, Kessac256
25  return [
26  ['test(uint)', '0x29e99f07'],
27  ['test(uint, uint)', '0xeb8ac921'],
28  ];
29  }
30 
36  public function testFunctionSignature($signature, $ethSignatureHash)
37  {
38  $x = EthereumStatic::getMethodSignature($signature);
39  $this->assertSame($ethSignatureHash, $x);
40  }
41 
47  public function testFunctionSignatureFail($signature, $ethSignatureHash)
48  {
49  $exception_message_expected = 'No valid (solidity) signature string provided.';
50  try {
51  EthereumStatic::getMethodSignature($signature);
52  } catch (\Exception $exception) {
53  $this->assertEquals($exception->getMessage(), $exception_message_expected);
54  }
55  }
56 }
testFunctionSignatureFail($signature, $ethSignatureHash)
testFunctionSignature($signature, $ethSignatureHash)
Definition: Abi.php:3