Compare commits
1 Commits
master
...
update-val
Author | SHA1 | Date | |
---|---|---|---|
|
dcb0721077 |
49
.github/workflows/php.yml
vendored
49
.github/workflows/php.yml
vendored
@ -1,49 +0,0 @@
|
||||
name: PHP
|
||||
|
||||
on: ["push", "pull_request", "workflow_dispatch"]
|
||||
|
||||
jobs:
|
||||
build_and_test:
|
||||
name: Build and test web3.php with ${{ matrix.php-version }}
|
||||
strategy:
|
||||
matrix:
|
||||
php-version: ["7.3", "7.4", "8.0"]
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php-version }}
|
||||
|
||||
- name: PHP version
|
||||
run: |
|
||||
php --version
|
||||
|
||||
- name: Install nodejs and ganache-cli
|
||||
run: |
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y nodejs
|
||||
sudo npm install -g ganache-cli
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Validate composer.json and composer.lock
|
||||
run: composer validate
|
||||
|
||||
- name: Cache Composer packages
|
||||
id: composer-cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: vendor
|
||||
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-php-${{ matrix.php-version }}-
|
||||
|
||||
- name: Install dependencies
|
||||
if: steps.composer-cache.outputs.cache-hit != 'true'
|
||||
run: composer install --prefer-dist --no-progress --no-suggest
|
||||
|
||||
- name: Run test suite
|
||||
run: sudo scripts/test.sh
|
@ -5,8 +5,6 @@ language: php
|
||||
php:
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- 7.4
|
||||
|
||||
before_install:
|
||||
- nvm install 8
|
||||
@ -26,4 +24,4 @@ script:
|
||||
- scripts/test.sh
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash) -t 76a0abaf-bbc4-4829-b5b8-474f10a6b9e9
|
||||
- bash <(curl -s https://codecov.io/bash) -t 8436848f-9a99-4b49-be60-629d7ff9a62c
|
22
README.md
22
README.md
@ -1,10 +1,9 @@
|
||||
# web3.php
|
||||
|
||||
[](https://github.com/web3p/web3.php/actions/workflows/php.yml)
|
||||
[](https://travis-ci.org/web3p/web3.php)
|
||||
[](https://codecov.io/gh/web3p/web3.php)
|
||||
[](https://travis-ci.org/sc0Vu/web3.php)
|
||||
[](https://codecov.io/gh/sc0Vu/web3.php)
|
||||
[](https://gitter.im/web3-php/web3.php)
|
||||
[](https://github.com/web3p/web3.php/blob/master/LICENSE)
|
||||
[](https://github.com/sc0Vu/web3.php/blob/master/LICENSE)
|
||||
|
||||
|
||||
A php interface for interacting with the Ethereum blockchain and ecosystem.
|
||||
@ -18,13 +17,13 @@ Set minimum stability to dev
|
||||
|
||||
Then
|
||||
```
|
||||
composer require web3p/web3.php dev-master
|
||||
composer require sc0vu/web3.php dev-master
|
||||
```
|
||||
|
||||
Or you can add this line in composer.json
|
||||
|
||||
```
|
||||
"web3p/web3.php": "dev-master"
|
||||
"sc0vu/web3.php": "dev-master"
|
||||
```
|
||||
|
||||
|
||||
@ -217,7 +216,7 @@ If you are using docker as development machain, you can try [ethdock](https://gi
|
||||
|
||||
1. Clone the repo and install packages.
|
||||
```
|
||||
git clone https://github.com/web3p/web3.php.git && cd web3.php && composer install
|
||||
git clone https://github.com/sc0Vu/web3.php.git && cd web3.php && composer install
|
||||
```
|
||||
|
||||
2. Run test script.
|
||||
@ -229,7 +228,7 @@ vendor/bin/phpunit
|
||||
|
||||
1. Clone the repo and run docker container.
|
||||
```
|
||||
git clone https://github.com/web3p/web3.php.git
|
||||
git clone https://github.com/sc0Vu/web3.php.git
|
||||
```
|
||||
|
||||
2. Copy web3.php to web3.php/docker/app directory and start container.
|
||||
@ -284,12 +283,5 @@ mv /usr/local/etc/php/conf.d/extension-config-name to/directory
|
||||
|
||||
Todo.
|
||||
|
||||
# Contribution
|
||||
|
||||
Thank you to all the people who already contributed to web3.php!
|
||||
<a href="https://github.com/web3p/web3.php/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=web3p/web3.php" />
|
||||
</a>
|
||||
|
||||
# License
|
||||
MIT
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "web3p/web3.php",
|
||||
"name": "sc0vu/web3.php",
|
||||
"description": "Ethereum web3 interface.",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
@ -10,14 +10,14 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "^6.3|^7.0",
|
||||
"PHP": "^7.2|^8.0",
|
||||
"guzzlehttp/guzzle": "~6.0",
|
||||
"PHP": "^7.1",
|
||||
"kornrunner/keccak": "~1.0",
|
||||
"phpseclib/phpseclib": "~2.0.30",
|
||||
"phpseclib/phpseclib": "~2.0.11",
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~8.0|~9.0"
|
||||
"phpunit/phpunit": "~6.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@ -1,4 +1,4 @@
|
||||
FROM php:7.1-alpine
|
||||
FROM php:7.1.14-alpine
|
||||
|
||||
MAINTAINER Peter Lai <alk03073135@gmail.com>
|
||||
|
||||
@ -8,10 +8,6 @@ COPY composer-setup.php composer-setup.php
|
||||
RUN apk update && \
|
||||
apk add git
|
||||
|
||||
# Install gmp
|
||||
Run apk add gmp-dev && \
|
||||
docker-php-ext-install gmp
|
||||
|
||||
# Install nodejs
|
||||
# Run apk add --update nodejs nodejs-npm
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
FROM php:7.2-alpine
|
||||
FROM php:7.2.2-alpine
|
||||
|
||||
MAINTAINER Peter Lai <alk03073135@gmail.com>
|
||||
|
||||
@ -8,10 +8,6 @@ COPY composer-setup.php composer-setup.php
|
||||
RUN apk update && \
|
||||
apk add git
|
||||
|
||||
# Install gmp
|
||||
Run apk add gmp-dev && \
|
||||
docker-php-ext-install gmp
|
||||
|
||||
# Install nodejs
|
||||
# Run apk add --update nodejs nodejs-npm
|
||||
|
||||
|
@ -1,23 +0,0 @@
|
||||
FROM php:7.3-alpine
|
||||
|
||||
MAINTAINER Peter Lai <alk03073135@gmail.com>
|
||||
|
||||
COPY composer-setup.php composer-setup.php
|
||||
# COPY php.ini-production $PHP_INI_DIR/php.ini
|
||||
|
||||
RUN apk update && \
|
||||
apk add git
|
||||
|
||||
# Install gmp
|
||||
Run apk add gmp-dev && \
|
||||
docker-php-ext-install gmp
|
||||
|
||||
# Install nodejs
|
||||
# Run apk add --update nodejs nodejs-npm
|
||||
|
||||
# Install composer
|
||||
RUN php composer-setup.php && \
|
||||
php composer-setup.php --install-dir=/usr/bin --filename=composer && \
|
||||
php -r "unlink('composer-setup.php');"
|
||||
|
||||
WORKDIR /app
|
@ -1,23 +0,0 @@
|
||||
FROM php:7.4-alpine
|
||||
|
||||
MAINTAINER Peter Lai <alk03073135@gmail.com>
|
||||
|
||||
COPY composer-setup.php composer-setup.php
|
||||
# COPY php.ini-production $PHP_INI_DIR/php.ini
|
||||
|
||||
RUN apk update && \
|
||||
apk add git
|
||||
|
||||
# Install gmp
|
||||
Run apk add gmp-dev && \
|
||||
docker-php-ext-install gmp
|
||||
|
||||
# Install nodejs
|
||||
# Run apk add --update nodejs nodejs-npm
|
||||
|
||||
# Install composer
|
||||
RUN php composer-setup.php && \
|
||||
php composer-setup.php --install-dir=/usr/bin --filename=composer && \
|
||||
php -r "unlink('composer-setup.php');"
|
||||
|
||||
WORKDIR /app
|
@ -1,23 +0,0 @@
|
||||
FROM php:8.0-alpine
|
||||
|
||||
MAINTAINER Peter Lai <alk03073135@gmail.com>
|
||||
|
||||
COPY composer-setup.php composer-setup.php
|
||||
# COPY php.ini-production $PHP_INI_DIR/php.ini
|
||||
|
||||
RUN apk update && \
|
||||
apk add git
|
||||
|
||||
# Install gmp
|
||||
Run apk add gmp-dev && \
|
||||
docker-php-ext-install gmp
|
||||
|
||||
# Install nodejs
|
||||
# Run apk add --update nodejs nodejs-npm
|
||||
|
||||
# Install composer
|
||||
RUN php composer-setup.php && \
|
||||
php composer-setup.php --install-dir=/usr/bin --filename=composer && \
|
||||
php -r "unlink('composer-setup.php');"
|
||||
|
||||
WORKDIR /app
|
@ -7,7 +7,8 @@
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false">
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false">
|
||||
|
||||
<testsuite name="Web3.php unit test">
|
||||
<directory suffix="Test.php">./test/unit</directory>
|
||||
|
114
src/Contract.php
114
src/Contract.php
@ -28,10 +28,8 @@ use Web3\Contracts\Types\Str;
|
||||
use Web3\Contracts\Types\Uinteger;
|
||||
use Web3\Validators\AddressValidator;
|
||||
use Web3\Validators\HexValidator;
|
||||
use Web3\Validators\StringValidator;
|
||||
use Web3\Validators\TagValidator;
|
||||
use Web3\Validators\QuantityValidator;
|
||||
use Web3\Formatters\AddressFormatter;
|
||||
use Web3\Validators\StringValidator;
|
||||
|
||||
class Contract
|
||||
{
|
||||
@ -98,22 +96,14 @@ class Contract
|
||||
*/
|
||||
protected $ethabi;
|
||||
|
||||
/**
|
||||
* defaultBlock
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $defaultBlock;
|
||||
|
||||
/**
|
||||
* construct
|
||||
*
|
||||
* @param string|\Web3\Providers\Provider $provider
|
||||
* @param string|\stdClass|array $abi
|
||||
* @param mixed $defaultBlock
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($provider, $abi, $defaultBlock = 'latest')
|
||||
public function __construct($provider, $abi)
|
||||
{
|
||||
if (is_string($provider) && (filter_var($provider, FILTER_VALIDATE_URL) !== false)) {
|
||||
// check the uri schema
|
||||
@ -147,11 +137,6 @@ class Contract
|
||||
}
|
||||
}
|
||||
}
|
||||
if (TagValidator::validate($defaultBlock) || QuantityValidator::validate($defaultBlock)) {
|
||||
$this->defaultBlock = $defaultBlock;
|
||||
} else {
|
||||
$this->$defaultBlock = 'latest';
|
||||
}
|
||||
$this->abi = $abiArray;
|
||||
$this->eth = new Eth($this->provider);
|
||||
$this->ethabi = new Ethabi([
|
||||
@ -239,32 +224,6 @@ class Contract
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDefaultBlock
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultBlock()
|
||||
{
|
||||
return $this->defaultBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* setDefaultBlock
|
||||
*
|
||||
* @param mixed $defaultBlock
|
||||
* @return $this
|
||||
*/
|
||||
public function setDefaultBlock($defaultBlock)
|
||||
{
|
||||
if (TagValidator::validate($defaultBlock) || QuantityValidator::validate($defaultBlock)) {
|
||||
$this->defaultBlock = $defaultBlock;
|
||||
} else {
|
||||
$this->$defaultBlock = 'latest';
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* getFunctions
|
||||
*
|
||||
@ -604,17 +563,47 @@ class Contract
|
||||
throw new \InvalidArgumentException('The last param must be callback function.');
|
||||
}
|
||||
|
||||
// check the arguments
|
||||
// check the last one in arguments is transaction object
|
||||
$argsLen = count($arguments);
|
||||
$transaction = [];
|
||||
$defaultBlock = $this->defaultBlock;
|
||||
$hasTransaction = false;
|
||||
|
||||
if ($argsLen > 0) {
|
||||
$transaction = $arguments[$argsLen - 1];
|
||||
}
|
||||
if (
|
||||
isset($transaction["from"]) ||
|
||||
isset($transaction["to"]) ||
|
||||
isset($transaction["gas"]) ||
|
||||
isset($transaction["gasPrice"]) ||
|
||||
isset($transaction["value"]) ||
|
||||
isset($transaction["data"]) ||
|
||||
isset($transaction["nonce"])
|
||||
) {
|
||||
$hasTransaction = true;
|
||||
} else {
|
||||
$transaction = [];
|
||||
}
|
||||
|
||||
$params = [];
|
||||
$data = "";
|
||||
$functionName = "";
|
||||
foreach ($functions as $function) {
|
||||
if ($hasTransaction) {
|
||||
if ($argsLen - 1 !== count($function['inputs'])) {
|
||||
continue;
|
||||
} else {
|
||||
$paramsLen = $argsLen - 1;
|
||||
}
|
||||
} else {
|
||||
if ($argsLen !== count($function['inputs'])) {
|
||||
continue;
|
||||
} else {
|
||||
$paramsLen = $argsLen;
|
||||
}
|
||||
}
|
||||
try {
|
||||
$paramsLen = count($function['inputs']);
|
||||
$params = array_slice($arguments, 0, $paramsLen);
|
||||
$params = array_splice($arguments, 0, $paramsLen);
|
||||
$data = $this->ethabi->encodeParameters($function, $params);
|
||||
$functionName = Utils::jsonMethodToString($function);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
@ -625,40 +614,11 @@ class Contract
|
||||
if (empty($data) || empty($functionName)) {
|
||||
throw new InvalidArgumentException('Please make sure you have put all function params and callback.');
|
||||
}
|
||||
// remove arguments
|
||||
array_splice($arguments, 0, $paramsLen);
|
||||
$argsLen -= $paramsLen;
|
||||
|
||||
if ($argsLen > 1) {
|
||||
$defaultBlock = $arguments[$argsLen - 1];
|
||||
$transaction = $arguments[$argsLen - 2];
|
||||
} else if ($argsLen > 0) {
|
||||
if (is_array($arguments[$argsLen - 1])) {
|
||||
$transaction = $arguments[$argsLen - 1];
|
||||
} else {
|
||||
$defaultBlock = $arguments[$argsLen - 1];
|
||||
}
|
||||
}
|
||||
if (!TagValidator::validate($defaultBlock) && !QuantityValidator::validate($defaultBlock)) {
|
||||
$defaultBlock = $this->defaultBlock;
|
||||
}
|
||||
if (
|
||||
!is_array($transaction) &&
|
||||
!isset($transaction["from"]) &&
|
||||
!isset($transaction["to"]) &&
|
||||
!isset($transaction["gas"]) &&
|
||||
!isset($transaction["gasPrice"]) &&
|
||||
!isset($transaction["value"]) &&
|
||||
!isset($transaction["data"]) &&
|
||||
!isset($transaction["nonce"])
|
||||
) {
|
||||
$transaction = [];
|
||||
}
|
||||
$functionSignature = $this->ethabi->encodeFunctionSignature($functionName);
|
||||
$transaction['to'] = $this->toAddress;
|
||||
$transaction['data'] = $functionSignature . Utils::stripZero($data);
|
||||
|
||||
$this->eth->call($transaction, $defaultBlock, function ($err, $transaction) use ($callback, $function){
|
||||
$this->eth->call($transaction, function ($err, $transaction) use ($callback, $function){
|
||||
if ($err !== null) {
|
||||
return call_user_func($callback, $err, null);
|
||||
}
|
||||
|
@ -23,14 +23,18 @@ class NewBlockFilter extends EthMethod
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $validators = [];
|
||||
protected $validators = [
|
||||
QuantityValidator::class
|
||||
];
|
||||
|
||||
/**
|
||||
* inputFormatters
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $inputFormatters = [];
|
||||
protected $inputFormatters = [
|
||||
QuantityFormatter::class
|
||||
];
|
||||
|
||||
/**
|
||||
* outputFormatters
|
||||
|
@ -118,11 +118,13 @@ class EthMethod extends JSONRPC implements IMethod
|
||||
}
|
||||
}
|
||||
if ($isError) {
|
||||
throw new RuntimeException('Wrong type of ' . $this->method . ' method argument ' . $key . '.');
|
||||
$verifyMessage = call_user_func([$subRule, 'getVerifyMessage']);
|
||||
throw new RuntimeException('Wrong type of ' . $this->method . ' method argument ' . $key . ', message: ' . $verifyMessage . '.');
|
||||
}
|
||||
} else {
|
||||
if (call_user_func([$rule, 'validate'], $params[$key]) === false) {
|
||||
throw new RuntimeException('Wrong type of ' . $this->method . ' method argument ' . $key . '.');
|
||||
$verifyMessage = call_user_func([$rule, 'getVerifyMessage']);
|
||||
throw new RuntimeException('Wrong type of ' . $this->method . ' method argument ' . $key . ', message: ' . $verifyMessage . '.');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -212,31 +212,6 @@ class Utils
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* toChecksumAddress
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function toChecksumAddress($value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
throw new InvalidArgumentException('The value to toChecksumAddress function must be string.');
|
||||
}
|
||||
$value = self::stripZero(strtolower($value));
|
||||
$hash = self::stripZero(self::sha3($value));
|
||||
$ret = '0x';
|
||||
|
||||
for ($i = 0; $i < 40; $i++) {
|
||||
if (intval($hash[$i], 16) >= 8) {
|
||||
$ret .= strtoupper($value[$i]);
|
||||
} else {
|
||||
$ret .= $value[$i];
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* isHex
|
||||
*
|
||||
@ -529,7 +504,7 @@ class Utils
|
||||
$number = str_replace('-', '', $number, $count);
|
||||
$negative1 = new BigNumber(-1);
|
||||
}
|
||||
if (self::isZeroPrefixed($number) || preg_match('/^[0-9a-f]+$/i', $number) === 1) {
|
||||
if (self::isZeroPrefixed($number) || preg_match('/[a-f]+/', $number) === 1) {
|
||||
$number = self::stripZero($number);
|
||||
$bn = new BigNumber($number, 16);
|
||||
} elseif (empty($number)) {
|
||||
|
@ -12,8 +12,9 @@
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
use Web3\Validators\Validator;
|
||||
|
||||
class AddressValidator
|
||||
class AddressValidator extends Validator implements IValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
|
@ -12,8 +12,9 @@
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
use Web3\Validators\Validator;
|
||||
|
||||
class BlockHashValidator
|
||||
class BlockHashValidator extends Validator implements IValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
|
@ -12,8 +12,9 @@
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
use Web3\Validators\Validator;
|
||||
|
||||
class BooleanValidator
|
||||
class BooleanValidator extends Validator implements IValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
|
@ -12,11 +12,12 @@
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
use Web3\Validators\Validator;
|
||||
use Web3\Validators\QuantityValidator;
|
||||
use Web3\Validators\TagValidator;
|
||||
use Web3\Validators\HexValidator;
|
||||
|
||||
class CallValidator
|
||||
class CallValidator extends Validator implements IValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
@ -27,30 +28,39 @@ class CallValidator
|
||||
public static function validate($value)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
self::$verifyMessage = 'call must be array';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['from']) && AddressValidator::validate($value['from']) === false) {
|
||||
self::$verifyMessage = 'from is not valid';
|
||||
return false;
|
||||
}
|
||||
if (!isset($value['to'])) {
|
||||
self::$verifyMessage = 'to is required';
|
||||
return false;
|
||||
}
|
||||
if (AddressValidator::validate($value['to']) === false) {
|
||||
self::$verifyMessage = 'to is not valid';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['gas']) && QuantityValidator::validate($value['gas']) === false) {
|
||||
self::$verifyMessage = 'gas is not valid';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['gasPrice']) && QuantityValidator::validate($value['gasPrice']) === false) {
|
||||
self::$verifyMessage = 'gasPrice is not valid';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['value']) && QuantityValidator::validate($value['value']) === false) {
|
||||
self::$verifyMessage = 'value is not valid';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['data']) && HexValidator::validate($value['data']) === false) {
|
||||
self::$verifyMessage = 'data is not valid';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['nonce']) && QuantityValidator::validate($value['nonce']) === false) {
|
||||
self::$verifyMessage = 'nonce is not valid';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -12,12 +12,13 @@
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
use Web3\Validators\Validator;
|
||||
use Web3\Validators\QuantityValidator;
|
||||
use Web3\Validators\TagValidator;
|
||||
use Web3\Validators\HexValidator;
|
||||
use Web3\Validators\AddressValidator;
|
||||
|
||||
class FilterValidator
|
||||
class FilterValidator extends Validator implements IValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
@ -28,6 +29,7 @@ class FilterValidator
|
||||
public static function validate($value)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
self::$verifyMessage = 'filter must be array';
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
@ -35,6 +37,7 @@ class FilterValidator
|
||||
QuantityValidator::validate($value['fromBlock']) === false &&
|
||||
TagValidator::validate($value['fromBlock']) === false
|
||||
) {
|
||||
self::$verifyMessage = 'fromBlock is not valid';
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
@ -42,16 +45,19 @@ class FilterValidator
|
||||
QuantityValidator::validate($value['toBlock']) === false &&
|
||||
TagValidator::validate($value['toBlock']) === false
|
||||
) {
|
||||
self::$verifyMessage = 'toBlock is not valid';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['address'])) {
|
||||
if (is_array($value['address'])) {
|
||||
foreach ($value['address'] as $address) {
|
||||
if (AddressValidator::validate($address) === false) {
|
||||
self::$verifyMessage = 'address is not valid';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} elseif (AddressValidator::validate($value['address']) === false) {
|
||||
self::$verifyMessage = 'address is not valid';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -60,11 +66,13 @@ class FilterValidator
|
||||
if (is_array($topic)) {
|
||||
foreach ($topic as $v) {
|
||||
if (isset($v) && HexValidator::validate($v) === false) {
|
||||
self::$verifyMessage = 'topics are not valid';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (isset($topic) && HexValidator::validate($topic) === false) {
|
||||
self::$verifyMessage = 'topics are not valid';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,9 @@
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
use Web3\Validators\Validator;
|
||||
|
||||
class HexValidator
|
||||
class HexValidator extends Validator implements IValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
|
@ -12,8 +12,9 @@
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
use Web3\Validators\Validator;
|
||||
|
||||
class IdentityValidator
|
||||
class IdentityValidator extends Validator implements IValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
|
@ -12,8 +12,9 @@
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
use Web3\Validators\Validator;
|
||||
|
||||
class NonceValidator
|
||||
class NonceValidator extends Validator implements IValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
|
@ -12,11 +12,12 @@
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
use Web3\Validators\Validator;
|
||||
use Web3\Validators\QuantityValidator;
|
||||
use Web3\Validators\HexValidator;
|
||||
use Web3\Validators\IdentityValidator;
|
||||
|
||||
class PostValidator
|
||||
class PostValidator extends Validator implements IValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
@ -27,38 +28,49 @@ class PostValidator
|
||||
public static function validate($value)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
self::$verifyMessage = 'post must be array';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['from']) && IdentityValidator::validate($value['from']) === false) {
|
||||
self::$verifyMessage = 'from is not valid';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['to']) && IdentityValidator::validate($value['to']) === false) {
|
||||
self::$verifyMessage = 'to is not valid';
|
||||
return false;
|
||||
}
|
||||
if (!isset($value['topics']) || !is_array($value['topics'])) {
|
||||
self::$verifyMessage = 'topics are not valid';
|
||||
return false;
|
||||
}
|
||||
foreach ($value['topics'] as $topic) {
|
||||
if (IdentityValidator::validate($topic) === false) {
|
||||
self::$verifyMessage = 'topics are not valid';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!isset($value['payload'])) {
|
||||
self::$verifyMessage = 'payload is required';
|
||||
return false;
|
||||
}
|
||||
if (HexValidator::validate($value['payload']) === false) {
|
||||
self::$verifyMessage = 'payload is not valid';
|
||||
return false;
|
||||
}
|
||||
if (!isset($value['priority'])) {
|
||||
self::$verifyMessage = 'priority is required';
|
||||
return false;
|
||||
}
|
||||
if (QuantityValidator::validate($value['priority']) === false) {
|
||||
self::$verifyMessage = 'priority is not valid';
|
||||
return false;
|
||||
}
|
||||
if (!isset($value['ttl'])) {
|
||||
self::$verifyMessage = 'ttl is required';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['ttl']) && QuantityValidator::validate($value['ttl']) === false) {
|
||||
self::$verifyMessage = 'ttl is not valid';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -12,8 +12,9 @@
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
use Web3\Validators\Validator;
|
||||
|
||||
class QuantityValidator
|
||||
class QuantityValidator extends Validator implements IValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
|
@ -12,11 +12,12 @@
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
use Web3\Validators\Validator;
|
||||
use Web3\Validators\QuantityValidator;
|
||||
use Web3\Validators\HexValidator;
|
||||
use Web3\Validators\IdentityValidator;
|
||||
|
||||
class ShhFilterValidator
|
||||
class ShhFilterValidator extends Validator implements IValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
@ -27,18 +28,26 @@ class ShhFilterValidator
|
||||
public static function validate($value)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
self::$verifyMessage = 'filter of shh must be array';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['to']) && IdentityValidator::validate($value['to']) === false) {
|
||||
self::$verifyMessage = 'to is not valid';
|
||||
return false;
|
||||
}
|
||||
if (!isset($value['topics']) || !is_array($value['topics'])) {
|
||||
if (!isset($value['topics'])) {
|
||||
self::$verifyMessage = 'topics are required';
|
||||
return false;
|
||||
}
|
||||
if (!is_array($value['topics'])) {
|
||||
self::$verifyMessage = 'topics must be array';
|
||||
return false;
|
||||
}
|
||||
foreach ($value['topics'] as $topic) {
|
||||
if (is_array($topic)) {
|
||||
foreach ($topic as $subTopic) {
|
||||
if (HexValidator::validate($subTopic) === false) {
|
||||
self::$verifyMessage = 'topics are not valid';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -46,6 +55,7 @@ class ShhFilterValidator
|
||||
}
|
||||
if (HexValidator::validate($topic) === false) {
|
||||
if (!is_null($topic)) {
|
||||
self::$verifyMessage = 'topics are not valid';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,9 @@
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
use Web3\Validators\Validator;
|
||||
|
||||
class StringValidator
|
||||
class StringValidator extends Validator implements IValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
|
@ -12,9 +12,10 @@
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
use Web3\Validators\Validator;
|
||||
use Web3\Utils;
|
||||
|
||||
class TagValidator implements IValidator
|
||||
class TagValidator extends Validator implements IValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
|
@ -12,11 +12,12 @@
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
use Web3\Validators\Validator;
|
||||
use Web3\Validators\QuantityValidator;
|
||||
use Web3\Validators\TagValidator;
|
||||
use Web3\Validators\HexValidator;
|
||||
|
||||
class TransactionValidator
|
||||
class TransactionValidator extends Validator implements IValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
@ -29,36 +30,39 @@ class TransactionValidator
|
||||
public static function validate($value)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
self::$verifyMessage = 'transaction must be array';
|
||||
return false;
|
||||
}
|
||||
if (!isset($value['from'])) {
|
||||
self::$verifyMessage = 'from is required';
|
||||
return false;
|
||||
}
|
||||
if (AddressValidator::validate($value['from']) === false) {
|
||||
self::$verifyMessage = 'from must be address';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['to']) && AddressValidator::validate($value['to']) === false && $value['to'] !== '') {
|
||||
self::$verifyMessage = 'to must be address';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['gas']) && QuantityValidator::validate($value['gas']) === false) {
|
||||
self::$verifyMessage = 'gas is not valid';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['gasPrice']) && QuantityValidator::validate($value['gasPrice']) === false) {
|
||||
self::$verifyMessage = 'gasPrice is not valid';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['value']) && QuantityValidator::validate($value['value']) === false) {
|
||||
self::$verifyMessage = 'value is not valid';
|
||||
return false;
|
||||
}
|
||||
// if (!isset($value['data'])) {
|
||||
// return false;
|
||||
// }
|
||||
// if (HexValidator::validate($value['data']) === false) {
|
||||
// return false;
|
||||
// }
|
||||
if (isset($value['data']) && HexValidator::validate($value['data']) === false) {
|
||||
self::$verifyMessage = 'data is not valid';
|
||||
return false;
|
||||
}
|
||||
if (isset($value['nonce']) && QuantityValidator::validate($value['nonce']) === false) {
|
||||
self::$verifyMessage = 'nonce is not valid';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
68
src/Validators/Validator.php
Normal file
68
src/Validators/Validator.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of web3.php package.
|
||||
*
|
||||
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
|
||||
*
|
||||
* @author Peter Lai <alk03073135@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
|
||||
class Validator
|
||||
{
|
||||
/**
|
||||
* verifyMessage
|
||||
* verify result from calling validate function
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $verifyMessage;
|
||||
|
||||
/**
|
||||
* get
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
$method = 'get' . ucfirst($name);
|
||||
|
||||
if (method_exists($this, $method)) {
|
||||
return call_user_func_array([$this, $method], []);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* set
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
$method = 'set' . ucfirst($name);
|
||||
|
||||
if (method_exists($this, $method)) {
|
||||
return call_user_func_array([$this, $method], [$value]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* getVerifyMessage
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getVerifyMessage()
|
||||
{
|
||||
return self::$verifyMessage;
|
||||
}
|
||||
}
|
@ -37,8 +37,10 @@ class TestCase extends BaseTestCase
|
||||
|
||||
/**
|
||||
* setUp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
$web3 = new Web3($this->testHost);
|
||||
$this->web3 = $web3;
|
||||
@ -53,6 +55,8 @@ class TestCase extends BaseTestCase
|
||||
|
||||
/**
|
||||
* tearDown
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown(): void {}
|
||||
public function tearDown() {}
|
||||
}
|
@ -19,7 +19,7 @@ class AddressFormatterTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->formatter = new AddressFormatter;
|
||||
|
@ -47,7 +47,7 @@ class AddressTypeTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->solidityType = new Address;
|
||||
|
@ -19,7 +19,7 @@ class AddressValidatorTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validator = new AddressValidator;
|
||||
|
@ -20,7 +20,7 @@ class BigNumberFormatterTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->formatter = new BigNumberFormatter;
|
||||
|
@ -19,7 +19,7 @@ class BlockHashValidatorTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validator = new BlockHashValidator;
|
||||
|
@ -20,7 +20,7 @@ class BooleanFormatterTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->formatter = new BooleanFormatter;
|
||||
|
@ -47,7 +47,7 @@ class BooleanTypeTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->solidityType = new Boolean;
|
||||
|
@ -19,7 +19,7 @@ class BooleanValidatorTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validator = new BooleanValidator;
|
||||
|
@ -53,7 +53,7 @@ class BytesTypeTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->solidityType = new Bytes;
|
||||
|
@ -19,7 +19,7 @@ class CallValidatorTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validator = new CallValidator;
|
||||
|
@ -412,7 +412,7 @@ class ContractTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
@ -1134,7 +1134,7 @@ class ContractTest extends TestCase
|
||||
$contract->at($contractAddress);
|
||||
|
||||
foreach ($functions as $function) {
|
||||
$contract->call($function['name'], [], 'latest', function ($err, $res) use ($function) {
|
||||
$contract->call($function['name'], function ($err, $res) use ($function) {
|
||||
if ($err !== null) {
|
||||
echo 'Error when call ' . $function['name'] . '. Message: ' . $err->getMessage() . "\n";
|
||||
return;
|
||||
@ -1468,22 +1468,13 @@ class ContractTest extends TestCase
|
||||
// $this->assertEquals($contract->ethabi->encodeEventSignature($contract->events['Say']), $topics[0]);
|
||||
$this->assertEquals('0x' . IntegerFormatter::format($testNumber), $topics[1]);
|
||||
}
|
||||
$blockNumber = Utils::toBn($transaction->blockNumber);
|
||||
$contract->call('number', Utils::toHex($blockNumber, true), function ($err, $res) use ($testNumber) {
|
||||
$contract->call('number', function ($err, $res) use ($testNumber) {
|
||||
if ($err !== null) {
|
||||
echo 'Error when call ' . $function['name'] . '. Message: ' . $err->getMessage() . "\n";
|
||||
return;
|
||||
}
|
||||
$this->assertEquals((string) $testNumber, $res[0]->toString());
|
||||
});
|
||||
$blockNumber = $blockNumber->subtract(Utils::toBn(1));
|
||||
$contract->call('number', Utils::toHex($blockNumber, true), function ($err, $res) use ($testNumber) {
|
||||
if ($err !== null) {
|
||||
echo 'Error when call ' . $function['name'] . '. Message: ' . $err->getMessage() . "\n";
|
||||
return;
|
||||
}
|
||||
$this->assertEquals((string) $testNumber-1, $res[0]->toString());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -53,7 +53,7 @@ class DynamicBytesTypeTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->solidityType = new DynamicBytes;
|
||||
|
@ -21,7 +21,7 @@ class EthApiTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
@ -439,7 +439,7 @@ class EthApiTest extends TestCase
|
||||
if ($err !== null) {
|
||||
return $this->assertTrue($err !== null);
|
||||
}
|
||||
// weird behavior, see https://github.com/web3p/web3.php/issues/16
|
||||
// weired behavior, see https://github.com/sc0Vu/web3.php/issues/16
|
||||
$this->assertTrue($block !== null);
|
||||
});
|
||||
}
|
||||
@ -629,7 +629,7 @@ class EthApiTest extends TestCase
|
||||
{
|
||||
$eth = $this->eth;
|
||||
|
||||
$eth->newBlockFilter(function ($err, $filter) {
|
||||
$eth->newBlockFilter('0x01', function ($err, $filter) {
|
||||
if ($err !== null) {
|
||||
// infura banned us to new block filter
|
||||
return $this->assertTrue($err !== null);
|
||||
|
@ -20,7 +20,7 @@ class EthBatchTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -23,7 +23,7 @@ class EthTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -163,7 +163,7 @@ class EthabiTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
// Error: Using $this when not in object context
|
||||
@ -298,7 +298,7 @@ class EthabiTest extends TestCase
|
||||
|
||||
/**
|
||||
* testIssue71
|
||||
* test 33 bytes and 128 bytes string, see: https://github.com/web3p/web3.php/issues/71
|
||||
* test 33 bytes and 128 bytes string, see: https://github.com/sc0Vu/web3.php/issues/71
|
||||
* string generated from: https://www.lipsum.com/
|
||||
*
|
||||
* @return void
|
||||
|
@ -19,7 +19,7 @@ class FilterValidatorTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validator = new FilterValidator;
|
||||
|
@ -19,7 +19,7 @@ class HexFormatterTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->formatter = new HexFormatter;
|
||||
|
@ -19,7 +19,7 @@ class HexValidatorTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validator = new HexValidator;
|
||||
|
@ -19,7 +19,7 @@ class IdentityValidatorTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validator = new IdentityValidator;
|
||||
|
@ -19,7 +19,7 @@ class IntegerFormatterTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->formatter = new IntegerFormatter;
|
||||
|
@ -53,7 +53,7 @@ class IntegerTypeTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->solidityType = new Integer;
|
||||
|
@ -21,7 +21,7 @@ class NetApiTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -20,7 +20,7 @@ class NetBatchTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -23,7 +23,7 @@ class NetTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -19,7 +19,7 @@ class NonceValidatorTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validator = new NonceValidator;
|
||||
|
@ -19,7 +19,7 @@ class NumberFormatterTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->formatter = new NumberFormatter;
|
||||
|
@ -19,7 +19,7 @@ class OptionalQuantityFormatterTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->formatter = new OptionalQuantityFormatter;
|
||||
@ -55,8 +55,6 @@ class OptionalQuantityFormatterTest extends TestCase
|
||||
$this->assertEquals('latest', $formatter->format('latest'));
|
||||
$this->assertEquals('earliest', $formatter->format('earliest'));
|
||||
$this->assertEquals('pending', $formatter->format('pending'));
|
||||
|
||||
$this->expectExceptionMessage('toBn number must be valid hex string.');
|
||||
$formatter->format('hello');
|
||||
$this->assertEquals('0x0', $formatter->format('hello'));
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ class PersonalApiTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -19,7 +19,7 @@ class PersonalBatchTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -23,7 +23,7 @@ class PersonalTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -19,7 +19,7 @@ class PostFormatterTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->formatter = new PostFormatter;
|
||||
|
@ -19,7 +19,7 @@ class PostValidatorTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validator = new PostValidator;
|
||||
|
@ -19,7 +19,7 @@ class QuantityFormatterTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->formatter = new QuantityFormatter;
|
||||
|
@ -19,7 +19,7 @@ class QuantityValidatorTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validator = new QuantityValidator;
|
||||
|
@ -21,7 +21,7 @@ class ShhApiTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -19,7 +19,7 @@ class ShhBatchTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -19,7 +19,7 @@ class ShhFilterValidatorTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validator = new ShhFilterValidator;
|
||||
|
@ -23,7 +23,7 @@ class ShhTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@ -20,7 +20,7 @@ class SolidityTypeTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->type = new SolidityType();
|
||||
|
@ -47,7 +47,7 @@ class StrTypeTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->solidityType = new Str;
|
||||
|
@ -19,7 +19,7 @@ class StringFormatterTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->formatter = new StringFormatter;
|
||||
|
@ -19,7 +19,7 @@ class StringValidatorTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validator = new StringValidator;
|
||||
|
@ -19,7 +19,7 @@ class TagValidatorTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validator = new TagValidator;
|
||||
|
@ -19,7 +19,7 @@ class TransactionFormatterTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->formatter = new TransactionFormatter;
|
||||
|
@ -19,7 +19,7 @@ class TransactionValidatorTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->validator = new TransactionValidator;
|
||||
|
@ -53,7 +53,7 @@ class UintegerTypeTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->solidityType = new Uinteger;
|
||||
|
@ -55,7 +55,7 @@ class UtilsTest extends TestCase
|
||||
|
||||
/**
|
||||
* testIssue112Json
|
||||
* see: https://github.com/web3p/web3.php/issues/112
|
||||
* see: https://github.com/sc0Vu/web3.php/issues/112
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
@ -137,7 +137,7 @@ class UtilsTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
@ -291,33 +291,6 @@ class UtilsTest extends TestCase
|
||||
$isAddressChecksum = Utils::isAddressChecksum(new stdClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* testToChecksumAddress
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testToChecksumAddress()
|
||||
{
|
||||
$checksumAddressTest = [
|
||||
// All caps
|
||||
'0x52908400098527886E0F7030069857D2E4169EE7',
|
||||
'0x8617E340B3D01FA5F11F306F4090FD50E238070D',
|
||||
// All Lower
|
||||
'0xde709f2102306220921060314715629080e2fb77',
|
||||
'0x27b1fdb04752bbc536007a920d24acb045561c26',
|
||||
// Normal
|
||||
'0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed',
|
||||
'0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359',
|
||||
'0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB',
|
||||
'0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb'
|
||||
];
|
||||
|
||||
for ($i=0; $i<count($checksumAddressTest); $i++) {
|
||||
$checksumAddress = Utils::toChecksumAddress(strtolower($checksumAddressTest[$i]));
|
||||
$this->assertEquals($checksumAddressTest[$i], $checksumAddress);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* testStripZero
|
||||
*
|
||||
|
@ -29,7 +29,7 @@ class Web3ApiTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class Web3BatchTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class Web3Test extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user