From 9521b2d167c5e5d588391d4a07ed9bd137668a43 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Mon, 28 May 2018 15:21:18 +0800 Subject: [PATCH 1/6] Check output name is empty --- src/Contracts/Ethabi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Contracts/Ethabi.php b/src/Contracts/Ethabi.php index 419186e..12ee067 100644 --- a/src/Contracts/Ethabi.php +++ b/src/Contracts/Ethabi.php @@ -249,7 +249,7 @@ class Ethabi $param = mb_strtolower(Utils::stripZero($param)); for ($i=0; $i<$typesLength; $i++) { - if (isset($outputTypes['outputs'][$i]['name'])) { + if (isset($outputTypes['outputs'][$i]['name']) && empty($outputTypes['outputs'][$i]['name']) === false) { $result[$outputTypes['outputs'][$i]['name']] = $solidityTypes[$i]->decode($param, $offsets[$i], $types[$i]); } else { $result[$i] = $solidityTypes[$i]->decode($param, $offsets[$i], $types[$i]); From ee9855fcbfad32989867d6eeefa39035f169e770 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Mon, 18 Jun 2018 23:24:29 +0800 Subject: [PATCH 2/6] Change isType regex --- src/Contracts/Types/Address.php | 2 +- src/Contracts/Types/Boolean.php | 2 +- src/Contracts/Types/Bytes.php | 2 +- src/Contracts/Types/DynamicBytes.php | 2 +- src/Contracts/Types/Integer.php | 2 +- src/Contracts/Types/Str.php | 2 +- src/Contracts/Types/Uinteger.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Contracts/Types/Address.php b/src/Contracts/Types/Address.php index 3559e04..d366ad7 100644 --- a/src/Contracts/Types/Address.php +++ b/src/Contracts/Types/Address.php @@ -37,7 +37,7 @@ class Address extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/address(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^address(\[([0-9]*)\])*/', $name) === 1); } /** diff --git a/src/Contracts/Types/Boolean.php b/src/Contracts/Types/Boolean.php index 3850761..9f8e394 100644 --- a/src/Contracts/Types/Boolean.php +++ b/src/Contracts/Types/Boolean.php @@ -35,7 +35,7 @@ class Boolean extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/bool(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^bool(\[([0-9]*)\])*/', $name) === 1); } /** diff --git a/src/Contracts/Types/Bytes.php b/src/Contracts/Types/Bytes.php index 55b13fc..29e7fad 100644 --- a/src/Contracts/Types/Bytes.php +++ b/src/Contracts/Types/Bytes.php @@ -36,7 +36,7 @@ class Bytes extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/bytes([0-9]{1,})?(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^bytes([0-9]{1,})?(\[([0-9]*)\])*/', $name) === 1); } /** diff --git a/src/Contracts/Types/DynamicBytes.php b/src/Contracts/Types/DynamicBytes.php index a0c8842..e662a52 100644 --- a/src/Contracts/Types/DynamicBytes.php +++ b/src/Contracts/Types/DynamicBytes.php @@ -36,7 +36,7 @@ class DynamicBytes extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/bytes(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^bytes(\[([0-9]*)\])*/', $name) === 1); } /** diff --git a/src/Contracts/Types/Integer.php b/src/Contracts/Types/Integer.php index 2db4716..8c12774 100644 --- a/src/Contracts/Types/Integer.php +++ b/src/Contracts/Types/Integer.php @@ -37,7 +37,7 @@ class Integer extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/int([0-9]{1,})?(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^int([0-9]{1,})?(\[([0-9]*)\])*/', $name) === 1); } /** diff --git a/src/Contracts/Types/Str.php b/src/Contracts/Types/Str.php index 344f070..e68f076 100644 --- a/src/Contracts/Types/Str.php +++ b/src/Contracts/Types/Str.php @@ -37,7 +37,7 @@ class Str extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/string(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^string(\[([0-9]*)\])*/', $name) === 1); } /** diff --git a/src/Contracts/Types/Uinteger.php b/src/Contracts/Types/Uinteger.php index d5f8c2a..c5bbfbb 100644 --- a/src/Contracts/Types/Uinteger.php +++ b/src/Contracts/Types/Uinteger.php @@ -37,7 +37,7 @@ class Uinteger extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/uint([0-9]{1,})?(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^uint([0-9]{1,})?(\[([0-9]*)\])*/', $name) === 1); } /** From ecafb1c5ec324eb4407d1267c785cac5ebf6fe9c Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Sun, 24 Jun 2018 18:30:45 +0800 Subject: [PATCH 3/6] Fix BytesTypeTest and DynamicBytesTypeTest --- test/unit/BytesTypeTest.php | 12 ++++++------ test/unit/DynamicBytesTypeTest.php | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/unit/BytesTypeTest.php b/test/unit/BytesTypeTest.php index 34a837d..c446cc5 100644 --- a/test/unit/BytesTypeTest.php +++ b/test/unit/BytesTypeTest.php @@ -16,22 +16,22 @@ class BytesTypeTest extends TestCase protected $testTypes = [ [ 'value' => 'bytes', - 'result' => true + 'result' => false ], [ 'value' => 'bytes[]', - 'result' => true + 'result' => false ], [ 'value' => 'bytes[4]', - 'result' => true + 'result' => false ], [ 'value' => 'bytes[][]', - 'result' => true + 'result' => false ], [ 'value' => 'bytes[3][]', - 'result' => true + 'result' => false ], [ 'value' => 'bytes[][6][]', - 'result' => true + 'result' => false ], [ 'value' => 'bytes32', 'result' => true diff --git a/test/unit/DynamicBytesTypeTest.php b/test/unit/DynamicBytesTypeTest.php index ecef1d1..821f73b 100644 --- a/test/unit/DynamicBytesTypeTest.php +++ b/test/unit/DynamicBytesTypeTest.php @@ -34,10 +34,10 @@ class DynamicBytesTypeTest extends TestCase 'result' => true ], [ 'value' => 'bytes32', - 'result' => true + 'result' => false ], [ 'value' => 'bytes8[4]', - 'result' => true + 'result' => false ], ]; From d5c21afec05eab232eb4168cadefc5cfeb2b7b2d Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Sun, 24 Jun 2018 21:16:12 +0800 Subject: [PATCH 4/6] Fix decode bytes * Return non zero bytes. Decode bytes1 data: 0x6300000000000000000000000000000000000000000000000000000000000000 Will return 0x63 --- src/Contracts/Types/Bytes.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Contracts/Types/Bytes.php b/src/Contracts/Types/Bytes.php index 29e7fad..542ba74 100644 --- a/src/Contracts/Types/Bytes.php +++ b/src/Contracts/Types/Bytes.php @@ -36,7 +36,7 @@ class Bytes extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/^bytes([0-9]{1,})?(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^bytes([0-9]{1,})(\[([0-9]*)\])*$/', $name) === 1); } /** @@ -90,6 +90,11 @@ class Bytes extends SolidityType implements IType if (empty($checkZero)) { return '0'; } + if (preg_match('/^bytes([0-9]*)/', $name, $match) === 1) { + $size = intval($match[1]); + $length = 2 * $size; + $value = mb_substr($value, 0, $length); + } return '0x' . $value; } } \ No newline at end of file From 07f730d8cef0fc0110cf530d71132195d51b8e96 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Sun, 24 Jun 2018 21:59:08 +0800 Subject: [PATCH 5/6] Fix decode dynamic bytes * Fix outputFormat function in dynamic bytes * Add test test for issue 85 #85 --- src/Contract.php | 2 + src/Contracts/Ethabi.php | 7 +- src/Contracts/Types/Address.php | 2 +- src/Contracts/Types/Boolean.php | 2 +- src/Contracts/Types/DynamicBytes.php | 7 +- src/Contracts/Types/Integer.php | 2 +- src/Contracts/Types/Str.php | 2 +- src/Contracts/Types/Uinteger.php | 2 +- test/unit/ContractTest.php | 284 +++++++++++++++++++++++++++ test/unit/EthabiTest.php | 4 +- 10 files changed, 305 insertions(+), 9 deletions(-) diff --git a/src/Contract.php b/src/Contract.php index b6c334a..6bdaf56 100644 --- a/src/Contract.php +++ b/src/Contract.php @@ -22,6 +22,7 @@ use Web3\Contracts\Ethabi; use Web3\Contracts\Types\Address; use Web3\Contracts\Types\Boolean; use Web3\Contracts\Types\Bytes; +use Web3\Contracts\Types\DynamicBytes; use Web3\Contracts\Types\Integer; use Web3\Contracts\Types\Str; use Web3\Contracts\Types\Uinteger; @@ -133,6 +134,7 @@ class Contract 'address' => new Address, 'bool' => new Boolean, 'bytes' => new Bytes, + 'dynamicBytes' => new DynamicBytes, 'int' => new Integer, 'string' => new Str, 'uint' => new Uinteger, diff --git a/src/Contracts/Ethabi.php b/src/Contracts/Ethabi.php index 12ee067..cf48ae0 100644 --- a/src/Contracts/Ethabi.php +++ b/src/Contracts/Ethabi.php @@ -280,7 +280,12 @@ class Ethabi $className = $this->types[$match[0]]; if (call_user_func([$this->types[$match[0]], 'isType'], $type) === false) { - throw new InvalidArgumentException('Unsupport solidity parameter type: ' . $type); + // check dynamic bytes + if ($match[0] === 'bytes') { + $className = $this->types['dynamicBytes']; + } else { + throw new InvalidArgumentException('Unsupport solidity parameter type: ' . $type); + } } $solidityTypes[$key] = $className; } diff --git a/src/Contracts/Types/Address.php b/src/Contracts/Types/Address.php index d366ad7..58de9c7 100644 --- a/src/Contracts/Types/Address.php +++ b/src/Contracts/Types/Address.php @@ -37,7 +37,7 @@ class Address extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/^address(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^address(\[([0-9]*)\])*$/', $name) === 1); } /** diff --git a/src/Contracts/Types/Boolean.php b/src/Contracts/Types/Boolean.php index 9f8e394..f997ac9 100644 --- a/src/Contracts/Types/Boolean.php +++ b/src/Contracts/Types/Boolean.php @@ -35,7 +35,7 @@ class Boolean extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/^bool(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^bool(\[([0-9]*)\])*$/', $name) === 1); } /** diff --git a/src/Contracts/Types/DynamicBytes.php b/src/Contracts/Types/DynamicBytes.php index e662a52..4446fa4 100644 --- a/src/Contracts/Types/DynamicBytes.php +++ b/src/Contracts/Types/DynamicBytes.php @@ -36,7 +36,7 @@ class DynamicBytes extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/^bytes(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^bytes(\[([0-9]*)\])*$/', $name) === 1); } /** @@ -89,6 +89,9 @@ class DynamicBytes extends SolidityType implements IType if (empty($checkZero)) { return '0'; } - return '0x' . $value; + $size = intval(Utils::toBn(mb_substr($value, 0, 64))->toString()); + $length = 2 * $size; + + return '0x' . mb_substr($value, 64, $length); } } \ No newline at end of file diff --git a/src/Contracts/Types/Integer.php b/src/Contracts/Types/Integer.php index 8c12774..4d6dae0 100644 --- a/src/Contracts/Types/Integer.php +++ b/src/Contracts/Types/Integer.php @@ -37,7 +37,7 @@ class Integer extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/^int([0-9]{1,})?(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^int([0-9]{1,})?(\[([0-9]*)\])*$/', $name) === 1); } /** diff --git a/src/Contracts/Types/Str.php b/src/Contracts/Types/Str.php index e68f076..51cf974 100644 --- a/src/Contracts/Types/Str.php +++ b/src/Contracts/Types/Str.php @@ -37,7 +37,7 @@ class Str extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/^string(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^string(\[([0-9]*)\])*$/', $name) === 1); } /** diff --git a/src/Contracts/Types/Uinteger.php b/src/Contracts/Types/Uinteger.php index c5bbfbb..c2099ed 100644 --- a/src/Contracts/Types/Uinteger.php +++ b/src/Contracts/Types/Uinteger.php @@ -37,7 +37,7 @@ class Uinteger extends SolidityType implements IType */ public function isType($name) { - return (preg_match('/^uint([0-9]{1,})?(\[([0-9]*)\])*/', $name) === 1); + return (preg_match('/^uint([0-9]{1,})?(\[([0-9]*)\])*$/', $name) === 1); } /** diff --git a/test/unit/ContractTest.php b/test/unit/ContractTest.php index 3fa0ea0..7e13fcb 100644 --- a/test/unit/ContractTest.php +++ b/test/unit/ContractTest.php @@ -10,6 +10,7 @@ use Web3\Contract; use Web3\Utils; use Web3\Contracts\Ethabi; use Web3\Formatters\IntegerFormatter; +use phpseclib\Math\BigInteger as BigNumber; class ContractTest extends TestCase { @@ -853,4 +854,287 @@ class ContractTest extends TestCase } }); } + + /** + * testIssue85 + * + * @return void + */ + public function testIssue85() + { + $bytecode = '0x608060405234801561001057600080fd5b50610a36806100206000396000f3006080604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630bcd3b33146100b45780631f9030371461014457806325f35c36146101775780632d1be94d146102735780638b84925b146102a2578063a15e05fd146102cd578063a5f807cc1461030f578063d07326681461039f578063ded516d21461043e578063f1d0876a146104ad578063f5c2e88a1461054c575b600080fd5b3480156100c057600080fd5b506100c96105dc565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101095780820151818401526020810190506100ee565b50505050905090810190601f1680156101365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015057600080fd5b5061015961061e565b60405180826000191660001916815260200191505060405180910390f35b34801561018357600080fd5b5061018c61064b565b604051808060200180602001838103835285818151815260200191508051906020019080838360005b838110156101d05780820151818401526020810190506101b5565b50505050905090810190601f1680156101fd5780820380516001836020036101000a031916815260200191505b50838103825284818151815260200191508051906020019080838360005b8381101561023657808201518184015260208101905061021b565b50505050905090810190601f1680156102635780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b34801561027f57600080fd5b506102886106cd565b604051808215151515815260200191505060405180910390f35b3480156102ae57600080fd5b506102b76106db565b6040518082815260200191505060405180910390f35b3480156102d957600080fd5b506102e26106e9565b60405180836000191660001916815260200182600019166000191681526020019250505060405180910390f35b34801561031b57600080fd5b50610324610741565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610364578082015181840152602081019050610349565b50505050905090810190601f1680156103915780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156103ab57600080fd5b506103b461076a565b60405180806020018360001916600019168152602001828103825284818151815260200191508051906020019080838360005b838110156104025780820151818401526020810190506103e7565b50505050905090810190601f16801561042f5780820380516001836020036101000a031916815260200191505b50935050505060405180910390f35b34801561044a57600080fd5b506104536107d9565b60405180827effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200191505060405180910390f35b3480156104b957600080fd5b506104c2610806565b60405180836000191660001916815260200180602001828103825283818151815260200191508051906020019080838360005b838110156105105780820151818401526020810190506104f5565b50505050905090810190601f16801561053d5780820380516001836020036101000a031916815260200191505b50935050505060405180910390f35b34801561055857600080fd5b50610561610875565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156105a1578082015181840152602081019050610586565b50505050905090810190601f1680156105ce5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6060806040805190810160405280600381526020017f616263000000000000000000000000000000000000000000000000000000000081525090508091505090565b6000807f616263000000000000000000000000000000000000000000000000000000000090508091505090565b6060806060806040805190810160405280600381526020017f616263000000000000000000000000000000000000000000000000000000000081525091506040805190810160405280600381526020017f78797a0000000000000000000000000000000000000000000000000000000000815250905081819350935050509091565b600080600190508091505090565b600080606390508091505090565b6000806000807f616263000000000000000000000000000000000000000000000000000000000091507f78797a0000000000000000000000000000000000000000000000000000000000905081819350935050509091565b6060806101606040519081016040528061012c81526020016108df61012c913990508091505090565b60606000606060006040805190810160405280600381526020017f616263000000000000000000000000000000000000000000000000000000000081525091507f78797a0000000000000000000000000000000000000000000000000000000000905081819350935050509091565b6000807f610000000000000000000000000000000000000000000000000000000000000090508091505090565b60006060600060607f78797a000000000000000000000000000000000000000000000000000000000091506040805190810160405280600381526020017f6162630000000000000000000000000000000000000000000000000000000000815250905081819350935050509091565b606080606060405190810160405280603c81526020017f616263616263616263636162636162636162636361626361626361626363616281526020017f6361626361626363616263616263616263636162636162636162636300000000815250905080915050905600616263616263616263636162636162636162636361626361626361626363616263616263616263636162636162636162636361626361626361626363616263616263616263636162636162636162636361626361626361626363616263616263616263636162636162636162636361626361626361626363616263616263616263636162636162636162636361626361626361626363616263616263616263636162636162636162636361626361626361626363616263616263616263636162636162636162636361626361626361626363616263616263616263636162636162636162636361626361626361626363616263616263616263636162636162636162636361626361626361626363616263616263616263636162636162636162636361626361626361626363a165627a7a7230582020ee9e6b05918d0df987776ee24808f4dd1c522806bf9fa8f4336c93f6b0ec050029'; + $abi = '[ + { + "constant": true, + "inputs": [], + "name": "getBytes", + "outputs": [ + { + "name": "", + "type": "bytes" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getBytes32", + "outputs": [ + { + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getDynamicData", + "outputs": [ + { + "name": "", + "type": "bytes" + }, + { + "name": "", + "type": "bytes" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getBoolean", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getInteger", + "outputs": [ + { + "name": "", + "type": "int256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getTwoBytes32", + "outputs": [ + { + "name": "", + "type": "bytes32" + }, + { + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getBytesVeryLong", + "outputs": [ + { + "name": "", + "type": "bytes" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getDynamicDataMixedOne", + "outputs": [ + { + "name": "", + "type": "bytes" + }, + { + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getBytes1", + "outputs": [ + { + "name": "", + "type": "bytes1" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getDynamicDataMixedTwo", + "outputs": [ + { + "name": "", + "type": "bytes32" + }, + { + "name": "", + "type": "bytes" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getBytesLong", + "outputs": [ + { + "name": "", + "type": "bytes" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + } + ]'; + $functions = [ + [ + 'name' => 'getBoolean', + 'test' => function ($value) { + return is_bool($value); + } + ], [ + 'name' => 'getInteger', + 'test' => function ($value) { + return ($value instanceof BigNumber); + } + ], [ + 'name' => 'getBytes1', + 'test' => function ($value) { + return Utils::isHex($value) && mb_strlen($value) === 4; + } + ], [ + 'name' => 'getBytes32', + 'test' => function ($value) { + return Utils::isHex($value) && mb_strlen($value) === 66; + } + ], [ + 'name' => 'getBytesLong', + 'test' => function ($value) { + return Utils::isHex($value); + } + ], [ + 'name' => 'getDynamicData', + 'test' => function ($value) { + return Utils::isHex($value); + } + ], [ + 'name' => 'getDynamicDataMixedOne', + 'test' => function ($value) { + return Utils::isHex($value); + } + ], [ + 'name' => 'getDynamicDataMixedTwo', + 'test' => function ($value) { + return Utils::isHex($value); + } + ], [ + 'name' => 'getTwoBytes32', + 'test' => function ($value) { + return Utils::isHex($value) && mb_strlen($value) === 66; + } + ] + ]; + $contractAddress = ""; + + if (!isset($this->accounts[0])) { + $account = '0x407d73d8a49eeb85d32cf465507dd71d507100c1'; + } else { + $account = $this->accounts[0]; + } + $contract = new Contract($this->web3->provider, $abi); + $contract->bytecode($bytecode)->new([ + 'from' => $account, + 'gas' => '0x200b20' + ], function ($err, $result) use ($contract, &$contractAddress) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + if ($result) { + echo "\nTransaction has made:) id: " . $result . "\n"; + } + $transactionId = $result; + $this->assertTrue((preg_match('/^0x[a-f0-9]{64}$/', $transactionId) === 1)); + + $contract->eth->getTransactionReceipt($transactionId, function ($err, $transaction) use (&$contractAddress) { + if ($err !== null) { + return $this->fail($err); + } + if ($transaction) { + $contractAddress = $transaction->contractAddress; + echo "\nTransaction has mind:) block number: " . $transaction->blockNumber . "\n"; + } + }); + }); + $contract->at($contractAddress); + + foreach ($functions as $function) { + $contract->call($function['name'], [], function ($err, $res) use ($function) { + if ($err !== null) { + echo 'Error when call ' . $function['name'] . '. Message: ' . $err->getMessage() . "\n"; + return; + } + foreach ($res as $r) { + if (!call_user_func($function['test'], $r)) { + var_dump($r); + } + $this->assertTrue(call_user_func($function['test'], $r)); + } + }); + } + } } \ No newline at end of file diff --git a/test/unit/EthabiTest.php b/test/unit/EthabiTest.php index 321350a..08260a9 100644 --- a/test/unit/EthabiTest.php +++ b/test/unit/EthabiTest.php @@ -9,6 +9,7 @@ use Web3\Contracts\Ethabi; use Web3\Contracts\Types\Address; use Web3\Contracts\Types\Boolean; use Web3\Contracts\Types\Bytes; +use Web3\Contracts\Types\DynamicBytes; use Web3\Contracts\Types\Integer; use Web3\Contracts\Types\Str; use Web3\Contracts\Types\Uinteger; @@ -179,9 +180,10 @@ class EthabiTest extends TestCase 'address' => new Address, 'bool' => new Boolean, 'bytes' => new Bytes, + 'dynamicBytes' => new DynamicBytes, 'int' => new Integer, 'string' => new Str, - 'uint' => new Uinteger, + 'uint' => new Uinteger ]); } From 234b1e695fee6abce0a50a316f48d85031c71ce9 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Sun, 24 Jun 2018 22:30:34 +0800 Subject: [PATCH 6/6] Fix failed test on travis * Change gas limt to 6000000 * Change ganache container compose file --- docker/ganache/Dockerfile | 2 +- scripts/test.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/ganache/Dockerfile b/docker/ganache/Dockerfile index fe4f1ca..17726d6 100644 --- a/docker/ganache/Dockerfile +++ b/docker/ganache/Dockerfile @@ -6,4 +6,4 @@ RUN npm install -g ganache-cli EXPOSE 8545 -CMD ganache-cli --hostname=0.0.0.0 \ No newline at end of file +CMD ganache-cli -g 0 -l 6000000 --hostname=0.0.0.0 \ No newline at end of file diff --git a/scripts/test.sh b/scripts/test.sh index 9eee9a1..de94ecd 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -ganache-cli -g 0 -l 0 > /dev/null & +ganache-cli -g 0 -l 6000000 > /dev/null & ganachecli_pid=$! echo "Start ganache-cli pid: $ganachecli_pid and sleep 3 seconds"