Compare commits

..

No commits in common. "master" and "v0.1" have entirely different histories.
master ... v0.1

88 changed files with 404 additions and 5548 deletions

View File

@ -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

2
.gitignore vendored
View File

@ -1,8 +1,6 @@
composer.phar
/vendor/
.phpintel/
/.idea/
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file

View File

@ -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

View File

@ -1,10 +1,9 @@
# web3.php
[![PHP](https://github.com/web3p/web3.php/actions/workflows/php.yml/badge.svg)](https://github.com/web3p/web3.php/actions/workflows/php.yml)
[![Build Status](https://travis-ci.org/web3p/web3.php.svg?branch=master)](https://travis-ci.org/web3p/web3.php)
[![codecov](https://codecov.io/gh/web3p/web3.php/branch/master/graph/badge.svg)](https://codecov.io/gh/web3p/web3.php)
[![Build Status](https://travis-ci.org/sc0Vu/web3.php.svg?branch=master)](https://travis-ci.org/sc0Vu/web3.php)
[![codecov](https://codecov.io/gh/sc0Vu/web3.php/branch/master/graph/badge.svg)](https://codecov.io/gh/sc0Vu/web3.php)
[![Join the chat at https://gitter.im/web3-php/web3.php](https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg)](https://gitter.im/web3-php/web3.php)
[![Licensed under the MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/web3p/web3.php/blob/master/LICENSE)
[![Licensed under the MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](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"
```
@ -56,7 +55,7 @@ $web3->clientVersion(function ($err, $version) {
// do something
return;
}
if (isset($version)) {
if (isset($client)) {
echo 'Client version: ' . $version;
}
});
@ -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,12 +228,12 @@ 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.
```
cp files docker/app && docker-compose up -d php ganache
cp files docker/app && docker-compose up -d php
```
3. Enter php container and install packages.
@ -242,54 +241,14 @@ cp files docker/app && docker-compose up -d php ganache
docker-compose exec php ash
```
4. Change testHost in `TestCase.php`
```
/**
* testHost
*
* @var string
*/
protected $testHost = 'http://ganache:8545';
```
5. Run test script
4. Run test script
```
vendor/bin/phpunit
```
###### Install packages
Enter container first
```
docker-compose exec php ash
```
1. gmp
```
apk add gmp-dev
docker-php-ext-install gmp
```
2. bcmath
```
docker-php-ext-install bcmath
```
###### Remove extension
Move the extension config from `/usr/local/etc/php/conf.d/`
```
mv /usr/local/etc/php/conf.d/extension-config-name to/directory
```
# API
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

View File

@ -1,5 +1,5 @@
{
"name": "web3p/web3.php",
"name": "sc0vu/web3.php",
"description": "Ethereum web3 interface.",
"type": "library",
"license": "MIT",
@ -9,15 +9,15 @@
"email": "alk03073135@gmail.com"
}
],
"minimum-stability": "dev",
"require": {
"guzzlehttp/guzzle": "^6.3|^7.0",
"PHP": "^7.2|^8.0",
"kornrunner/keccak": "~1.0",
"phpseclib/phpseclib": "~2.0.30",
"ext-mbstring": "*"
"guzzlehttp/guzzle": "~6.0",
"PHP": "^7.1",
"kornrunner/keccak": "dev-master",
"phpseclib/phpseclib": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "~8.0|~9.0"
"phpunit/phpunit": "~6.0"
},
"autoload": {
"psr-4": {

View File

@ -9,10 +9,3 @@ services:
volumes:
- ./app:/app
tty: true
ganache:
build:
context: ./ganache
dockerfile: Dockerfile
ports:
- "8545"

View File

@ -1,9 +0,0 @@
FROM node:9.11.1-alpine
MAINTAINER Peter Lai <alk03073135@gmail.com>
RUN npm install -g ganache-cli
EXPOSE 8545
CMD ganache-cli -g 0 -l 6000000 --hostname=0.0.0.0

View File

@ -1,23 +1,17 @@
FROM php:7.1-alpine
FROM php:7.1.14-alpine
MAINTAINER Peter Lai <alk03073135@gmail.com>
COPY composer-setup.php composer-setup.php
# COPY php.ini-production $PHP_INI_DIR/php.ini
ADD 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
# Install composer
RUN php composer-setup.php && \
php composer-setup.php --install-dir=/usr/bin --filename=composer && \
php -r "unlink('composer-setup.php');"
php composer-setup.php --install-dir=/usr/bin --filename=composer
WORKDIR /app

View File

@ -1,23 +1,17 @@
FROM php:7.2-alpine
FROM php:7.2.2-alpine
MAINTAINER Peter Lai <alk03073135@gmail.com>
COPY composer-setup.php composer-setup.php
# COPY php.ini-production $PHP_INI_DIR/php.ini
ADD 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
# Install composer
RUN php composer-setup.php && \
php composer-setup.php --install-dir=/usr/bin --filename=composer && \
php -r "unlink('composer-setup.php');"
php composer-setup.php --install-dir=/usr/bin --filename=composer
WORKDIR /app

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,8 +1,5 @@
<?php
$sig = file_get_contents('https://composer.github.io/installer.sig');
$sig = trim($sig);
copy('https://getcomposer.org/installer', 'composer-setup.php');
if (hash_file('sha384', 'composer-setup.php') === $sig) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;
if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -38,16 +38,3 @@ $web3->eth->getBalance($newAccount, function ($err, $balance) {
}
echo 'Balance: ' . $balance->toString() . PHP_EOL;
});
// remember to lock account after transaction
$personal->lockAccount($newAccount, function ($err, $locked) {
if ($err !== null) {
echo 'Error: ' . $err->getMessage();
return;
}
if ($locked) {
echo 'New account is locked!' . PHP_EOL;
} else {
echo 'New account isn\'t locked' . PHP_EOL;
}
});

View File

@ -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>

View File

@ -1,15 +1,12 @@
#!/usr/bin/env bash
ganache-cli -g 0 -l 6000000 > /dev/null &
ganache-cli -g 0 -l 0 > /dev/null &
ganachecli_pid=$!
echo "Start ganache-cli pid: $ganachecli_pid and sleep 3 seconds"
sleep 3
vendor/bin/phpunit --coverage-clover=coverage.xml
ret=$?
kill -9 $ganachecli_pid
echo "Kill ganache-cli"
exit $ret
echo "Kill ganache-cli"

View File

@ -22,16 +22,13 @@ 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;
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 +95,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
@ -125,21 +114,12 @@ class Contract
} else if ($provider instanceof Provider) {
$this->provider = $provider;
}
$abi = Utils::jsonToArray($abi, 5);
$abiArray = [];
if (is_string($abi)) {
$abiArray = json_decode($abi, true);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new InvalidArgumentException('abi decode error: ' . json_last_error_msg());
}
} else {
$abiArray = Utils::jsonToArray($abi);
}
foreach ($abiArray as $item) {
foreach ($abi as $item) {
if (isset($item['type'])) {
if ($item['type'] === 'function') {
$this->functions[] = $item;
$this->functions[$item['name']] = $item;
} elseif ($item['type'] === 'constructor') {
$this->constructor = $item;
} elseif ($item['type'] === 'event') {
@ -147,18 +127,12 @@ class Contract
}
}
}
if (TagValidator::validate($defaultBlock) || QuantityValidator::validate($defaultBlock)) {
$this->defaultBlock = $defaultBlock;
} else {
$this->$defaultBlock = 'latest';
}
$this->abi = $abiArray;
$this->abi = $abi;
$this->eth = new Eth($this->provider);
$this->ethabi = new Ethabi([
'address' => new Address,
'bool' => new Boolean,
'bytes' => new Bytes,
'dynamicBytes' => new DynamicBytes,
'int' => new Integer,
'string' => new Str,
'uint' => new Uinteger,
@ -227,7 +201,7 @@ class Contract
/**
* setProvider
*
*
* @param \Web3\Providers\Provider $provider
* @return $this
*/
@ -239,35 +213,9 @@ 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
*
*
* @return array
*/
public function getFunctions()
@ -277,7 +225,7 @@ class Contract
/**
* getEvents
*
*
* @return array
*/
public function getEvents()
@ -285,17 +233,9 @@ class Contract
return $this->events;
}
/**
* @return string
*/
public function getToAddress()
{
return $this->toAddress;
}
/**
* getConstructor
*
*
* @return array
*/
public function getConstructor()
@ -305,7 +245,7 @@ class Contract
/**
* getAbi
*
*
* @return array
*/
public function getAbi()
@ -409,21 +349,12 @@ class Contract
if (StringValidator::validate($abi) === false) {
throw new InvalidArgumentException('Please make sure abi is valid.');
}
$abiArray = [];
if (is_string($abi)) {
$abiArray = json_decode($abi, true);
$abi = Utils::jsonToArray($abi, 5);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new InvalidArgumentException('abi decode error: ' . json_last_error_msg());
}
} else {
$abiArray = Utils::jsonToArray($abi);
}
foreach ($abiArray as $item) {
foreach ($abi as $item) {
if (isset($item['type'])) {
if ($item['type'] === 'function') {
$this->functions[] = $item;
$this->functions[$item['name']] = $item;
} elseif ($item['type'] === 'constructor') {
$this->constructor = $item;
} elseif ($item['type'] === 'event') {
@ -431,7 +362,7 @@ class Contract
}
}
}
$this->abi = $abiArray;
$this->abi = $abi;
return $this;
}
@ -450,8 +381,7 @@ class Contract
$arguments = func_get_args();
$callback = array_pop($arguments);
$input_count = isset($constructor['inputs']) ? count($constructor['inputs']) : 0;
if (count($arguments) < $input_count) {
if (count($arguments) < count($constructor['inputs'])) {
throw new InvalidArgumentException('Please make sure you have put all constructor params and callback.');
}
if (is_callable($callback) !== true) {
@ -460,13 +390,14 @@ class Contract
if (!isset($this->bytecode)) {
throw new \InvalidArgumentException('Please call bytecode($bytecode) before new().');
}
$params = array_splice($arguments, 0, $input_count);
$params = array_splice($arguments, 0, count($constructor['inputs']));
$data = $this->ethabi->encodeParameters($constructor, $params);
$transaction = [];
if (count($arguments) > 0) {
$transaction = $arguments[0];
}
$transaction['to'] = '';
$transaction['data'] = '0x' . $this->bytecode . Utils::stripZero($data);
$this->eth->sendTransaction($transaction, function ($err, $transaction) use ($callback){
@ -492,75 +423,26 @@ class Contract
$method = array_splice($arguments, 0, 1)[0];
$callback = array_pop($arguments);
if (!is_string($method)) {
throw new InvalidArgumentException('Please make sure the method is string.');
if (!is_string($method) && !isset($this->functions[$method])) {
throw new InvalidArgumentException('Please make sure the method is existed.');
}
$function = $this->functions[$method];
$functions = [];
foreach ($this->functions as $function) {
if ($function["name"] === $method) {
$functions[] = $function;
}
};
if (count($functions) < 1) {
throw new InvalidArgumentException('Please make sure the method exists.');
if (count($arguments) < count($function['inputs'])) {
throw new InvalidArgumentException('Please make sure you have put all function params and callback.');
}
if (is_callable($callback) !== true) {
throw new \InvalidArgumentException('The last param must be callback function.');
}
// check the last one in arguments is transaction object
$argsLen = count($arguments);
$transaction = [];
$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 {
$params = array_splice($arguments, 0, $paramsLen);
$data = $this->ethabi->encodeParameters($function, $params);
$functionName = Utils::jsonMethodToString($function);
} catch (InvalidArgumentException $e) {
continue;
}
break;
}
if (empty($data) || empty($functionName)) {
throw new InvalidArgumentException('Please make sure you have put all function params and callback.');
}
$params = array_splice($arguments, 0, count($function['inputs']));
$data = $this->ethabi->encodeParameters($function, $params);
$functionName = Utils::jsonMethodToString($function);
$functionSignature = $this->ethabi->encodeFunctionSignature($functionName);
$transaction = [];
if (count($arguments) > 0) {
$transaction = $arguments[0];
}
$transaction['to'] = $this->toAddress;
$transaction['data'] = $functionSignature . Utils::stripZero($data);
@ -576,7 +458,7 @@ class Contract
/**
* call
* Call function method.
*
*
* @param mixed
* @return void
*/
@ -587,78 +469,30 @@ class Contract
$method = array_splice($arguments, 0, 1)[0];
$callback = array_pop($arguments);
if (!is_string($method)) {
throw new InvalidArgumentException('Please make sure the method is string.');
if (!is_string($method) && !isset($this->functions[$method])) {
throw new InvalidArgumentException('Please make sure the method is existed.');
}
$function = $this->functions[$method];
$functions = [];
foreach ($this->functions as $function) {
if ($function["name"] === $method) {
$functions[] = $function;
}
};
if (count($functions) < 1) {
throw new InvalidArgumentException('Please make sure the method exists.');
if (count($arguments) < count($function['inputs'])) {
throw new InvalidArgumentException('Please make sure you have put all function params and callback.');
}
if (is_callable($callback) !== true) {
throw new \InvalidArgumentException('The last param must be callback function.');
}
// check the arguments
$argsLen = count($arguments);
$transaction = [];
$defaultBlock = $this->defaultBlock;
$params = [];
$data = "";
$functionName = "";
foreach ($functions as $function) {
try {
$paramsLen = count($function['inputs']);
$params = array_slice($arguments, 0, $paramsLen);
$data = $this->ethabi->encodeParameters($function, $params);
$functionName = Utils::jsonMethodToString($function);
} catch (InvalidArgumentException $e) {
continue;
}
break;
}
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 = [];
}
$params = array_splice($arguments, 0, count($function['inputs']));
$data = $this->ethabi->encodeParameters($function, $params);
$functionName = Utils::jsonMethodToString($function);
$functionSignature = $this->ethabi->encodeFunctionSignature($functionName);
$transaction = [];
if (count($arguments) > 0) {
$transaction = $arguments[0];
}
$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);
}
@ -701,84 +535,36 @@ class Contract
if (count($arguments) > 0) {
$transaction = $arguments[0];
}
$transaction['to'] = '';
$transaction['data'] = '0x' . $this->bytecode . Utils::stripZero($data);
} else {
$method = array_splice($arguments, 0, 1)[0];
if (!is_string($method)) {
throw new InvalidArgumentException('Please make sure the method is string.');
if (!is_string($method) && !isset($this->functions[$method])) {
throw new InvalidArgumentException('Please make sure the method is existed.');
}
$functions = [];
foreach ($this->functions as $function) {
if ($function["name"] === $method) {
$functions[] = $function;
}
};
if (count($functions) < 1) {
throw new InvalidArgumentException('Please make sure the method exists.');
$function = $this->functions[$method];
if (count($arguments) < count($function['inputs'])) {
throw new InvalidArgumentException('Please make sure you have put all function params and callback.');
}
if (is_callable($callback) !== true) {
throw new \InvalidArgumentException('The last param must be callback function.');
}
// check the last one in arguments is transaction object
$argsLen = count($arguments);
$transaction = [];
$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 {
$params = array_splice($arguments, 0, $paramsLen);
$data = $this->ethabi->encodeParameters($function, $params);
$functionName = Utils::jsonMethodToString($function);
} catch (InvalidArgumentException $e) {
continue;
}
break;
}
if (empty($data) || empty($functionName)) {
throw new InvalidArgumentException('Please make sure you have put all function params and callback.');
}
$params = array_splice($arguments, 0, count($function['inputs']));
$data = $this->ethabi->encodeParameters($function, $params);
$functionName = Utils::jsonMethodToString($function);
$functionSignature = $this->ethabi->encodeFunctionSignature($functionName);
$transaction = [];
if (count($arguments) > 0) {
$transaction = $arguments[0];
}
$transaction['to'] = $this->toAddress;
$transaction['data'] = $functionSignature . Utils::stripZero($data);
}
$this->eth->estimateGas($transaction, function ($err, $gas) use ($callback) {
$this->eth->estimateGas($transaction, function ($err, $gas) use ($callback){
if ($err !== null) {
return call_user_func($callback, $err, null);
}
@ -819,42 +605,21 @@ class Contract
} else {
$method = array_splice($arguments, 0, 1)[0];
if (!is_string($method)) {
throw new InvalidArgumentException('Please make sure the method is string.');
if (!is_string($method) && !isset($this->functions[$method])) {
throw new InvalidArgumentException('Please make sure the method is existed.');
}
$functions = [];
foreach ($this->functions as $function) {
if ($function["name"] === $method) {
$functions[] = $function;
}
};
if (count($functions) < 1) {
throw new InvalidArgumentException('Please make sure the method exists.');
}
$params = $arguments;
$data = "";
$functionName = "";
foreach ($functions as $function) {
if (count($arguments) !== count($function['inputs'])) {
continue;
}
try {
$data = $this->ethabi->encodeParameters($function, $params);
$functionName = Utils::jsonMethodToString($function);
} catch (InvalidArgumentException $e) {
continue;
}
break;
}
if (empty($data) || empty($functionName)) {
$function = $this->functions[$method];
if (count($arguments) < count($function['inputs'])) {
throw new InvalidArgumentException('Please make sure you have put all function params and callback.');
}
$params = array_splice($arguments, 0, count($function['inputs']));
$data = $this->ethabi->encodeParameters($function, $params);
$functionName = Utils::jsonMethodToString($function);
$functionSignature = $this->ethabi->encodeFunctionSignature($functionName);
$functionData = Utils::stripZero($functionSignature) . Utils::stripZero($data);
}
return $functionData;
}
}
}
}

View File

@ -100,7 +100,6 @@ class Ethabi
/**
* encodeEventSignature
* TODO: Fix same event name with different params
*
* @param string|stdClass|array $functionName
* @return string
@ -156,6 +155,21 @@ class Ethabi
}
$typesLength = count($types);
$solidityTypes = $this->getSolidityTypes($types);
foreach ($types as $key => $type) {
$match = [];
if (preg_match('/^([a-zA-Z]+)/', $type, $match) === 1) {
if (isset($this->types[$match[0]])) {
$className = $this->types[$match[0]];
if (call_user_func([$this->types[$match[0]], 'isType'], $type) === false) {
throw new InvalidArgumentException('Unsupport solidity parameter type: ' . $type);
}
$solidityTypes[$key] = $className;
}
}
}
$encodes = array_fill(0, $typesLength, '');
foreach ($solidityTypes as $key => $type) {
@ -235,7 +249,7 @@ class Ethabi
$param = mb_strtolower(Utils::stripZero($param));
for ($i=0; $i<$typesLength; $i++) {
if (isset($outputTypes['outputs'][$i]['name']) && empty($outputTypes['outputs'][$i]['name']) === false) {
if (isset($outputTypes['outputs'][$i]['name'])) {
$result[$outputTypes['outputs'][$i]['name']] = $solidityTypes[$i]->decode($param, $offsets[$i], $types[$i]);
} else {
$result[$i] = $solidityTypes[$i]->decode($param, $offsets[$i], $types[$i]);
@ -266,12 +280,7 @@ class Ethabi
$className = $this->types[$match[0]];
if (call_user_func([$this->types[$match[0]], 'isType'], $type) === false) {
// check dynamic bytes
if ($match[0] === 'bytes') {
$className = $this->types['dynamicBytes'];
} else {
throw new InvalidArgumentException('Unsupport solidity parameter type: ' . $type);
}
throw new InvalidArgumentException('Unsupport solidity parameter type: ' . $type);
}
$solidityTypes[$key] = $className;
}

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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);
}
/**
@ -63,10 +63,9 @@ class Bytes extends SolidityType implements IType
}
$value = Utils::stripZero($value);
if (mb_strlen($value) % 2 !== 0) {
$value = "0" . $value;
// throw new InvalidArgumentException('The value to inputFormat has invalid length. Value: ' . $value);
}
// if (mb_strlen($value) % 2 !== 0) {
// throw new InvalidArgumentException('The value to inputFormat has invalid length. Value: ' . $value);
// }
if (mb_strlen($value) > 64) {
throw new InvalidArgumentException('The value to inputFormat is too long.');
@ -91,11 +90,6 @@ 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;
}
}

View File

@ -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);
}
/**
@ -63,17 +63,12 @@ class DynamicBytes extends SolidityType implements IType
}
$value = Utils::stripZero($value);
if (mb_strlen($value) % 2 !== 0) {
$value = "0" . $value;
// throw new InvalidArgumentException('The value to inputFormat has invalid length.');
}
$bn = Utils::toBn(floor(mb_strlen($value) / 2));
// if (mb_strlen($value) % 2 !== 0) {
// throw new InvalidArgumentException('The value to inputFormat has invalid length.');
// }
$bn = Utils::toBn(mb_strlen($value) / 2);
$bnHex = $bn->toHex(true);
$padded = mb_substr($bnHex, 0, 1);
if ($padded !== '0' && $padded !== 'f') {
$padded = '0';
}
$l = floor((mb_strlen($value) + 63) / 64);
$padding = (($l * 64 - mb_strlen($value) + 1) >= 0) ? $l * 64 - mb_strlen($value) : 0;
@ -94,9 +89,6 @@ class DynamicBytes extends SolidityType implements IType
if (empty($checkZero)) {
return '0';
}
$size = intval(Utils::toBn('0x' . mb_substr($value, 0, 64))->toString());
$length = 2 * $size;
return '0x' . mb_substr($value, 64, $length);
return '0x' . $value;
}
}

View File

@ -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);
}
/**

View File

@ -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);
}
/**
@ -77,7 +77,7 @@ class Str extends SolidityType implements IType
public function outputFormat($value, $name)
{
$strLen = mb_substr($value, 0, 64);
$strValue = mb_substr($value, 64);
$strValue = mb_substr($value, 64, 64);
$match = [];
if (preg_match('/^[0]+([a-f0-9]+)$/', $strLen, $match) === 1) {
@ -87,4 +87,4 @@ class Str extends SolidityType implements IType
return Utils::hexToBin($strValue);
}
}
}

View File

@ -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);
}
/**

View File

@ -38,7 +38,7 @@ class Eth
* @var array
*/
private $allowedMethods = [
'eth_protocolVersion', 'eth_syncing', 'eth_coinbase', 'eth_mining', 'eth_hashrate', 'eth_gasPrice', 'eth_accounts', 'eth_blockNumber', 'eth_getBalance', 'eth_getStorageAt', 'eth_getTransactionCount', 'eth_getBlockTransactionCountByHash', 'eth_getBlockTransactionCountByNumber', 'eth_getUncleCountByBlockHash', 'eth_getUncleCountByBlockNumber', 'eth_getUncleByBlockHashAndIndex', 'eth_getUncleByBlockNumberAndIndex', 'eth_getCode', 'eth_sign', 'eth_sendTransaction', 'eth_sendRawTransaction', 'eth_call', 'eth_estimateGas', 'eth_getBlockByHash', 'eth_getBlockByNumber', 'eth_getTransactionByHash', 'eth_getTransactionByBlockHashAndIndex', 'eth_getTransactionByBlockNumberAndIndex', 'eth_getTransactionReceipt', 'eth_compileSolidity', 'eth_compileLLL', 'eth_compileSerpent', 'eth_getWork', 'eth_newFilter', 'eth_newBlockFilter', 'eth_newPendingTransactionFilter', 'eth_uninstallFilter', 'eth_getFilterChanges', 'eth_getFilterLogs', 'eth_getLogs', 'eth_submitWork', 'eth_submitHashrate'
'eth_protocolVersion', 'eth_syncing', 'eth_coinbase', 'eth_mining', 'eth_hashrate', 'eth_gasPrice', 'eth_accounts', 'eth_blockNumber', 'eth_getBalance', 'eth_getStorageAt', 'eth_getTransactionCount', 'eth_getBlockTransactionCountByHash', 'eth_getBlockTransactionCountByNumber', 'eth_getUncleCountByBlockHash', 'eth_getUncleCountByBlockNumber', 'eth_getUncleByBlockHashAndIndex', 'eth_getUncleByBlockNumberAndIndex', 'eth_getCode', 'eth_sign', 'eth_sendTransaction', 'eth_sendRawTransaction', 'eth_call', 'eth_estimateGas', 'eth_getBlockByHash', 'eth_getBlockByNumber', 'eth_getTransactionByHash', 'eth_getTransactionByBlockHashAndIndex', 'eth_getTransactionByBlockNumberAndIndex', 'eth_getTransactionReceipt', 'eth_getCompilers', 'eth_compileSolidity', 'eth_compileLLL', 'eth_compileSerpent', 'eth_getWork', 'eth_newFilter', 'eth_newBlockFilter', 'eth_newPendingTransactionFilter', 'eth_uninstallFilter', 'eth_getFilterChanges', 'eth_getFilterLogs', 'eth_getLogs', 'eth_submitWork', 'eth_submitHashrate'
];
/**

View File

@ -9,31 +9,26 @@
* @license MIT
*/
namespace Web3\Methods\Personal;
namespace Web3\Methods\Eth;
use InvalidArgumentException;
use Web3\Methods\EthMethod;
use Web3\Validators\AddressValidator;
use Web3\Formatters\AddressFormatter;
class LockAccount extends EthMethod
class GetCompilers extends EthMethod
{
/**
* validators
*
* @var array
*/
protected $validators = [
AddressValidator::class
];
protected $validators = [];
/**
* inputFormatters
*
* @var array
*/
protected $inputFormatters = [
AddressFormatter::class
];
protected $inputFormatters = [];
/**
* outputFormatters
@ -60,5 +55,4 @@ class LockAccount extends EthMethod
// {
// parent::__construct($method, $arguments);
// }
}
}

View File

@ -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
@ -57,4 +61,4 @@ class NewBlockFilter extends EthMethod
// {
// parent::__construct($method, $arguments);
// }
}
}

View File

@ -38,7 +38,7 @@ class Personal
* @var array
*/
private $allowedMethods = [
'personal_listAccounts', 'personal_newAccount', 'personal_unlockAccount', 'personal_lockAccount', 'personal_sendTransaction'
'personal_listAccounts', 'personal_newAccount', 'personal_unlockAccount', 'personal_sendTransaction'
];
/**
@ -177,4 +177,4 @@ class Personal
$this->provider->batch($status);
}
}
}

View File

@ -2,9 +2,9 @@
/**
* This file is part of web3.php package.
*
*
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
*
*
* @author Peter Lai <alk03073135@gmail.com>
* @license MIT
*/
@ -12,7 +12,6 @@
namespace Web3\RequestManagers;
use InvalidArgumentException;
use Psr\Http\Message\StreamInterface;
use RuntimeException as RPCException;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\RequestException;
@ -24,14 +23,14 @@ class HttpRequestManager extends RequestManager implements IRequestManager
{
/**
* client
*
*
* @var \GuzzleHttp
*/
protected $client;
/**
* construct
*
*
* @param string $host
* @param int $timeout
* @return void
@ -44,7 +43,7 @@ class HttpRequestManager extends RequestManager implements IRequestManager
/**
* sendPayload
*
*
* @param string $payload
* @param callable $callback
* @return void
@ -54,7 +53,22 @@ class HttpRequestManager extends RequestManager implements IRequestManager
if (!is_string($payload)) {
throw new \InvalidArgumentException('Payload must be string.');
}
// $promise = $this->client->postAsync($this->host, [
// 'headers' => [
// 'content-type' => 'application/json'
// ],
// 'body' => $payload
// ]);
// $promise->then(
// function (ResponseInterface $res) use ($callback) {
// var_dump($res->body());
// call_user_func($callback, null, $res);
// },
// function (RequestException $err) use ($callback) {
// var_dump($err->getMessage());
// call_user_func($callback, $err, null);
// }
// );
try {
$res = $this->client->post($this->host, [
'headers' => [
@ -64,12 +78,7 @@ class HttpRequestManager extends RequestManager implements IRequestManager
'timeout' => $this->timeout,
'connect_timeout' => $this->timeout
]);
/**
* @var StreamInterface $stream ;
*/
$stream = $res->getBody();
$json = json_decode($stream);
$stream->close();
$json = json_decode($res->getBody());
if (JSON_ERROR_NONE !== json_last_error()) {
call_user_func($callback, new InvalidArgumentException('json_decode error: ' . json_last_error_msg()), null);
@ -80,7 +89,7 @@ class HttpRequestManager extends RequestManager implements IRequestManager
$errors = [];
foreach ($json as $result) {
if (property_exists($result,'result')) {
if (isset($result->result)) {
$results[] = $result->result;
} else {
if (isset($json->error)) {
@ -96,7 +105,7 @@ class HttpRequestManager extends RequestManager implements IRequestManager
} else {
call_user_func($callback, null, $results);
}
} elseif (property_exists($json,'result')) {
} elseif (isset($json->result)) {
call_user_func($callback, null, $json->result);
} else {
if (isset($json->error)) {

View File

@ -189,7 +189,7 @@ class Utils
/**
* isAddressChecksum
*
*
* @param string $value
* @return bool
*/
@ -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
*
@ -291,15 +266,12 @@ class Utils
* $wei = Utils::toWei('1', 'kwei');
* $wei->toString(); // 1000
*
* @param BigNumber|string $number
* @param BigNumber|string|int $number
* @param string $unit
* @return \phpseclib\Math\BigInteger
*/
public static function toWei($number, $unit)
{
if (!is_string($number) && !($number instanceof BigNumber)) {
throw new InvalidArgumentException('toWei number must be string or bignumber.');
}
$bn = self::toBn($number);
if (!is_string($unit)) {
@ -312,33 +284,15 @@ class Utils
if (is_array($bn)) {
// fraction number
list($whole, $fraction, $fractionLength, $negative1) = $bn;
list($whole, $fraction, $negative1) = $bn;
$fractionLength = strlen($fraction->toString());
if ($fractionLength > strlen(self::UNITS[$unit])) {
throw new InvalidArgumentException('toWei fraction part is out of limit.');
}
$whole = $whole->multiply($bnt);
// There is no pow function in phpseclib 2.0, only can see in dev-master
// Maybe implement own biginteger in the future
// See 2.0 BigInteger: https://github.com/phpseclib/phpseclib/blob/2.0/phpseclib/Math/BigInteger.php
// See dev-master BigInteger: https://github.com/phpseclib/phpseclib/blob/master/phpseclib/Math/BigInteger.php#L700
// $base = (new BigNumber(10))->pow(new BigNumber($fractionLength));
// So we switch phpseclib special global param, change in the future
switch (MATH_BIGINTEGER_MODE) {
case $whole::MODE_GMP:
static $two;
$powerBase = gmp_pow(gmp_init(10), (int) $fractionLength);
break;
case $whole::MODE_BCMATH:
$powerBase = bcpow('10', (string) $fractionLength, 0);
break;
default:
$powerBase = pow(10, (int) $fractionLength);
break;
}
$base = new BigNumber($powerBase);
$base = (new BigNumber(10))->pow(new BigNumber($fractionLength));
$fraction = $fraction->multiply($bnt)->divide($base)[0];
if ($negative1 !== false) {
@ -447,34 +401,52 @@ class Utils
/**
* jsonToArray
*
* @param stdClass|array $json
* @param stdClass|array|string $json
* @param int $depth
* @return array
*/
public static function jsonToArray($json)
public static function jsonToArray($json, $depth=1)
{
if (!is_int($depth) || $depth <= 0) {
throw new InvalidArgumentException('jsonToArray depth must be int and depth must bigger than 0.');
}
if ($json instanceof stdClass) {
$json = (array) $json;
$typeName = [];
foreach ($json as $key => $param) {
if (is_array($param)) {
foreach ($param as $subKey => $subParam) {
$json[$key][$subKey] = self::jsonToArray($subParam);
if ($depth > 1) {
foreach ($json as $key => $param) {
if (is_array($param)) {
foreach ($param as $subKey => $subParam) {
$json[$key][$subKey] = self::jsonToArray($subParam, $depth-1);
}
} elseif ($param instanceof stdClass) {
$json[$key] = self::jsonToArray($param, $depth-1);
}
} elseif ($param instanceof stdClass) {
$json[$key] = self::jsonToArray($param);
}
}
return $json;
} elseif (is_array($json)) {
foreach ($json as $key => $param) {
if (is_array($param)) {
foreach ($param as $subKey => $subParam) {
$json[$key][$subKey] = self::jsonToArray($subParam);
if ($depth > 1) {
foreach ($json as $key => $param) {
if (is_array($param)) {
foreach ($param as $subKey => $subParam) {
$json[$key][$subKey] = self::jsonToArray($subParam, $depth-1);
}
} elseif ($param instanceof stdClass) {
$json[$key] = self::jsonToArray($param, $depth-1);
}
} elseif ($param instanceof stdClass) {
$json[$key] = self::jsonToArray($param);
}
}
} elseif (is_string($json)) {
$json = json_decode($json, true);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new InvalidArgumentException('json_decode error: ' . json_last_error_msg());
}
return $json;
} else {
throw new InvalidArgumentException('The json param to jsonToArray must be array or stdClass or string.');
}
return $json;
}
@ -512,7 +484,6 @@ class Utils
return [
new BigNumber($whole),
new BigNumber($fraction),
strlen($comps[1]),
isset($negative1) ? $negative1 : false
];
} else {
@ -529,7 +500,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)) {

View File

@ -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() {}
}

View File

@ -1,15 +0,0 @@
pragma solidity ^0.5.1;
contract FIX125 {
bytes public data;
event SetData(
bytes indexed _data
);
function setData(bytes memory _data) public {
data = _data;
emit SetData(_data);
}
}

View File

@ -1,26 +0,0 @@
pragma solidity ^0.5.1;
contract FIX134 {
bytes public data;
uint256 public number;
event Say(
uint256 indexed _number
);
event Say(
uint256 indexed _number,
bytes indexed _data
);
function say(uint256 _number) public {
number = _number;
emit Say(_number);
}
function say(uint256 _number, bytes memory _data) public {
data = _data;
number = _number;
emit Say(_number, _data);
}
}

View File

@ -19,7 +19,7 @@ class AddressFormatterTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->formatter = new AddressFormatter;

View File

@ -47,7 +47,7 @@ class AddressTypeTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->solidityType = new Address;

View File

@ -19,7 +19,7 @@ class AddressValidatorTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->validator = new AddressValidator;

View File

@ -20,7 +20,7 @@ class BigNumberFormatterTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->formatter = new BigNumberFormatter;

View File

@ -19,7 +19,7 @@ class BlockHashValidatorTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->validator = new BlockHashValidator;

View File

@ -20,7 +20,7 @@ class BooleanFormatterTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->formatter = new BooleanFormatter;

View File

@ -47,7 +47,7 @@ class BooleanTypeTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->solidityType = new Boolean;

View File

@ -19,7 +19,7 @@ class BooleanValidatorTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->validator = new BooleanValidator;

View File

@ -16,22 +16,22 @@ class BytesTypeTest extends TestCase
protected $testTypes = [
[
'value' => 'bytes',
'result' => false
'result' => true
], [
'value' => 'bytes[]',
'result' => false
'result' => true
], [
'value' => 'bytes[4]',
'result' => false
'result' => true
], [
'value' => 'bytes[][]',
'result' => false
'result' => true
], [
'value' => 'bytes[3][]',
'result' => false
'result' => true
], [
'value' => 'bytes[][6][]',
'result' => false
'result' => true
], [
'value' => 'bytes32',
'result' => true
@ -53,7 +53,7 @@ class BytesTypeTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->solidityType = new Bytes;

View File

@ -19,7 +19,7 @@ class CallValidatorTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->validator = new CallValidator;

File diff suppressed because one or more lines are too long

View File

@ -34,10 +34,10 @@ class DynamicBytesTypeTest extends TestCase
'result' => true
], [
'value' => 'bytes32',
'result' => false
'result' => true
], [
'value' => 'bytes8[4]',
'result' => false
'result' => true
],
];
@ -53,7 +53,7 @@ class DynamicBytesTypeTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->solidityType = new DynamicBytes;

View File

@ -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);
});
}
@ -457,7 +457,7 @@ class EthApiTest extends TestCase
if ($err !== null) {
return $this->assertTrue($err !== null);
}
$this->assertTrue($transaction == null);
$this->assertTrue($transaction !== null);
});
}
@ -474,7 +474,7 @@ class EthApiTest extends TestCase
if ($err !== null) {
return $this->assertTrue($err !== null);
}
$this->assertTrue($transaction == null);
$this->assertTrue($transaction !== null);
});
}
@ -508,7 +508,7 @@ class EthApiTest extends TestCase
if ($err !== null) {
return $this->assertTrue($err !== null);
}
$this->assertTrue($transaction == null);
$this->assertTrue($transaction !== null);
});
}
@ -546,6 +546,24 @@ class EthApiTest extends TestCase
});
}
/**
* testGetCompilers
*
* @return void
*/
public function testGetCompilers()
{
$eth = $this->eth;
$eth->getCompilers(function ($err, $compilers) {
if ($err !== null) {
return $this->assertTrue($err !== null);
}
$this->assertTrue(is_array($compilers));
$this->assertEquals($compilers[0], 'solidity');
});
}
/**
* testCompileSolidity
*
@ -629,7 +647,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);

View File

@ -20,7 +20,7 @@ class EthBatchTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();

View File

@ -23,7 +23,7 @@ class EthTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();

View File

@ -9,7 +9,6 @@ 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;
@ -163,7 +162,7 @@ class EthabiTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
// Error: Using $this when not in object context
@ -180,10 +179,9 @@ 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,
]);
}
@ -295,23 +293,4 @@ class EthabiTest extends TestCase
}
}
}
/**
* testIssue71
* test 33 bytes and 128 bytes string, see: https://github.com/web3p/web3.php/issues/71
* string generated from: https://www.lipsum.com/
*
* @return void
*/
public function testIssue71()
{
$abi = $this->abi;
$specialString = 'Lorem ipsum dolor sit amet metus.';
$encodedString = $abi->encodeParameter('string', $specialString);
$this->assertEquals($specialString, $abi->decodeParameter('string', $encodedString));
$specialString = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce pulvinar quam felis, suscipit posuere neque aliquam in cras amet.';
$encodedString = $abi->encodeParameter('string', $specialString);
$this->assertEquals($specialString, $abi->decodeParameter('string', $encodedString));
}
}

View File

@ -19,7 +19,7 @@ class FilterValidatorTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->validator = new FilterValidator;

View File

@ -19,7 +19,7 @@ class HexFormatterTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->formatter = new HexFormatter;

View File

@ -19,7 +19,7 @@ class HexValidatorTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->validator = new HexValidator;

View File

@ -17,7 +17,7 @@ class HttpProviderTest extends TestCase
*/
public function testSend()
{
$requestManager = new HttpRequestManager($this->testHost);
$requestManager = new HttpRequestManager('http://localhost:8545');
$provider = new HttpProvider($requestManager);
$method = new ClientVersion('web3_clientVersion', []);
@ -36,7 +36,7 @@ class HttpProviderTest extends TestCase
*/
public function testBatch()
{
$requestManager = new HttpRequestManager($this->testHost);
$requestManager = new HttpRequestManager('http://localhost:8545');
$provider = new HttpProvider($requestManager);
$method = new ClientVersion('web3_clientVersion', []);
$callback = function ($err, $data) {

View File

@ -19,7 +19,7 @@ class IdentityValidatorTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->validator = new IdentityValidator;

View File

@ -19,7 +19,7 @@ class IntegerFormatterTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->formatter = new IntegerFormatter;
@ -45,11 +45,5 @@ class IntegerFormatterTest extends TestCase
$hex = $formatter->format('1', 20);
$this->assertEquals($hex, implode('', array_fill(0, 19, '0')) . '1');
$hex = $formatter->format(48);
$this->assertEquals($hex, implode('', array_fill(0, 62, '0')) . '30');
$hex = $formatter->format('48');
$this->assertEquals($hex, implode('', array_fill(0, 62, '0')) . '30');
}
}

View File

@ -53,7 +53,7 @@ class IntegerTypeTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->solidityType = new Integer;

View File

@ -21,7 +21,7 @@ class NetApiTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();

View File

@ -20,7 +20,7 @@ class NetBatchTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();

View File

@ -23,7 +23,7 @@ class NetTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();

View File

@ -19,7 +19,7 @@ class NonceValidatorTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->validator = new NonceValidator;

View File

@ -19,7 +19,7 @@ class NumberFormatterTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->formatter = new NumberFormatter;

View File

@ -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'));
}
}

View File

@ -27,7 +27,7 @@ class PersonalApiTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
@ -63,7 +63,7 @@ class PersonalApiTest extends TestCase
$personal->newAccount('123456', function ($err, $account) {
if ($err !== null) {
return $this->fail($err->getMessage());
return $this->fail($e->getMessage());
}
$this->assertTrue(is_string($account));
});
@ -81,7 +81,7 @@ class PersonalApiTest extends TestCase
// create account
$personal->newAccount('123456', function ($err, $account) {
if ($err !== null) {
return $this->fail($err->getMessage());
return $this->fail($e->getMessage());
}
$this->newAccount = $account;
$this->assertTrue(is_string($account));
@ -107,7 +107,7 @@ class PersonalApiTest extends TestCase
// create account
$personal->newAccount('123456', function ($err, $account) {
if ($err !== null) {
return $this->fail($err->getMessage());
return $this->fail($e->getMessage());
}
$this->newAccount = $account;
$this->assertTrue(is_string($account));
@ -121,39 +121,6 @@ class PersonalApiTest extends TestCase
});
}
/**
* testLockAccount
*
* @return void
*/
public function testLockAccount()
{
$personal = $this->personal;
// create account
$personal->newAccount('123456', function ($err, $account) {
if ($err !== null) {
return $this->fail($err->getMessage());
}
$this->newAccount = $account;
$this->assertTrue(is_string($account));
});
$personal->unlockAccount($this->newAccount, '123456', function ($err, $unlocked) {
if ($err !== null) {
return $this->fail($err->getMessage());
}
$this->assertTrue($unlocked);
});
$personal->lockAccount($this->newAccount, function ($err, $locked) {
if ($err !== null) {
return $this->fail($err->getMessage());
}
$this->assertTrue($locked);
});
}
/**
* testSendTransaction
*
@ -166,7 +133,7 @@ class PersonalApiTest extends TestCase
// create account
$personal->newAccount('123456', function ($err, $account) {
if ($err !== null) {
return $this->fail($err->getMessage());
return $this->fail($e->getMessage());
}
$this->newAccount = $account;
$this->assertTrue(is_string($account));

View File

@ -19,7 +19,7 @@ class PersonalBatchTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();

View File

@ -23,7 +23,7 @@ class PersonalTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();

View File

@ -19,7 +19,7 @@ class PostFormatterTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->formatter = new PostFormatter;

View File

@ -19,7 +19,7 @@ class PostValidatorTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->validator = new PostValidator;

View File

@ -19,7 +19,7 @@ class QuantityFormatterTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->formatter = new QuantityFormatter;

View File

@ -19,7 +19,7 @@ class QuantityValidatorTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->validator = new QuantityValidator;

View File

@ -21,7 +21,7 @@ class ShhApiTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();

View File

@ -19,7 +19,7 @@ class ShhBatchTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();

View File

@ -19,7 +19,7 @@ class ShhFilterValidatorTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->validator = new ShhFilterValidator;

View File

@ -23,7 +23,7 @@ class ShhTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();

View File

@ -20,7 +20,7 @@ class SolidityTypeTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->type = new SolidityType();

View File

@ -47,7 +47,7 @@ class StrTypeTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->solidityType = new Str;

View File

@ -19,7 +19,7 @@ class StringFormatterTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->formatter = new StringFormatter;

View File

@ -19,7 +19,7 @@ class StringValidatorTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->validator = new StringValidator;

View File

@ -19,7 +19,7 @@ class TagValidatorTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->validator = new TagValidator;

View File

@ -19,7 +19,7 @@ class TransactionFormatterTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->formatter = new TransactionFormatter;

View File

@ -19,7 +19,7 @@ class TransactionValidatorTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->validator = new TransactionValidator;

View File

@ -53,7 +53,7 @@ class UintegerTypeTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
$this->solidityType = new Uinteger;

View File

@ -7,7 +7,6 @@ use stdClass;
use Test\TestCase;
use phpseclib\Math\BigInteger as BigNumber;
use Web3\Utils;
use Web3\Contract;
class UtilsTest extends TestCase
{
@ -53,91 +52,12 @@ class UtilsTest extends TestCase
}
}';
/**
* testIssue112Json
* see: https://github.com/web3p/web3.php/issues/112
*
* @var string
*/
protected $testIssue112Json = '[
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "tokenOwner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "balance",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "to",
"type": "address"
},
{
"name": "tokens",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]';
/**
* setUp
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
}
@ -167,16 +87,6 @@ class UtilsTest extends TestCase
$this->assertEquals('0x', Utils::toHex(0, true));
$this->assertEquals('0x', Utils::toHex(new BigNumber(0), true));
$this->assertEquals('0x30', Utils::toHex(48, true));
$this->assertEquals('0x30', Utils::toHex('48', true));
$this->assertEquals('30', Utils::toHex(48));
$this->assertEquals('30', Utils::toHex('48'));
$this->assertEquals('0x30', Utils::toHex(new BigNumber(48), true));
$this->assertEquals('0x30', Utils::toHex(new BigNumber('48'), true));
$this->assertEquals('30', Utils::toHex(new BigNumber(48)));
$this->assertEquals('30', Utils::toHex(new BigNumber('48')));
$this->expectException(InvalidArgumentException::class);
$hex = Utils::toHex(new stdClass);
}
@ -249,7 +159,7 @@ class UtilsTest extends TestCase
/**
* testIsAddressChecksum
*
*
* @return void
*/
public function testIsAddressChecksum()
@ -291,36 +201,9 @@ 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
*
*
* @return void
*/
public function testStripZero()
@ -359,58 +242,70 @@ class UtilsTest extends TestCase
public function testToWei()
{
$bn = Utils::toWei('0x1', 'wei');
$this->assertEquals('1', $bn->toString());
$this->assertEquals($bn->toString(), '1');
$bn = Utils::toWei('18', 'wei');
$this->assertEquals('18', $bn->toString());
$this->assertEquals($bn->toString(), '18');
$bn = Utils::toWei(1, 'wei');
$this->assertEquals($bn->toString(), '1');
$bn = Utils::toWei(0x11, 'wei');
$this->assertEquals($bn->toString(), '17');
$bn = Utils::toWei('1', 'ether');
$this->assertEquals('1000000000000000000', $bn->toString());
$this->assertEquals($bn->toString(), '1000000000000000000');
$bn = Utils::toWei('0x5218', 'wei');
$this->assertEquals('21016', $bn->toString());
$bn = Utils::toWei('0.000012', 'ether');
$this->assertEquals('12000000000000', $bn->toString());
$this->assertEquals($bn->toString(), '21016');
$bn = Utils::toWei('0.1', 'ether');
$this->assertEquals('100000000000000000', $bn->toString());
$this->assertEquals($bn->toString(), '100000000000000000');
$bn = Utils::toWei('1.69', 'ether');
$this->assertEquals('1690000000000000000', $bn->toString());
$this->assertEquals($bn->toString(), '1690000000000000000');
$bn = Utils::toWei('0.01', 'ether');
$this->assertEquals('10000000000000000', $bn->toString());
$bn = Utils::toWei(0.1, 'ether');
$this->assertEquals($bn->toString(), '100000000000000000');
$bn = Utils::toWei('0.002', 'ether');
$this->assertEquals('2000000000000000', $bn->toString());
$bn = Utils::toWei(1.69, 'ether');
$this->assertEquals($bn->toString(), '1690000000000000000');
$bn = Utils::toWei('-0.1', 'ether');
$this->assertEquals('-100000000000000000', $bn->toString());
$this->assertEquals($bn->toString(), '-100000000000000000');
$bn = Utils::toWei('-1.69', 'ether');
$this->assertEquals('-1690000000000000000', $bn->toString());
$this->assertEquals($bn->toString(), '-1690000000000000000');
$bn = Utils::toWei(-0.1, 'ether');
$this->assertEquals($bn->toString(), '-100000000000000000');
$bn = Utils::toWei(-1.69, 'ether');
$this->assertEquals($bn->toString(), '-1690000000000000000');
$bn = Utils::toWei('', 'ether');
$this->assertEquals('0', $bn->toString());
$this->assertEquals($bn->toString(), '0');
$bn = Utils::toWei(-1.697, 'kwei');
$this->assertEquals($bn->toString(), '-1697');
try {
$bn = Utils::toWei('0x5218', new stdClass);
} catch (InvalidArgumentException $e) {
$this->assertEquals('toWei unit must be string.', $e->getMessage());
$this->assertTrue($e !== null);
}
try {
$bn = Utils::toWei('0x5218', 'test');
} catch (InvalidArgumentException $e) {
$this->assertEquals('toWei doesn\'t support test unit.', $e->getMessage());
$this->assertTrue($e !== null);
}
try {
// out of limit
$bn = Utils::toWei(-1.6977, 'kwei');
} catch (InvalidArgumentException $e) {
$this->assertEquals('toWei number must be string or bignumber.', $e->getMessage());
$this->assertTrue($e !== null);
}
}
@ -431,6 +326,16 @@ class UtilsTest extends TestCase
$this->assertEquals($bnq->toString(), '0');
$this->assertEquals($bnr->toString(), '18');
list($bnq, $bnr) = Utils::toEther(1, 'wei');
$this->assertEquals($bnq->toString(), '0');
$this->assertEquals($bnr->toString(), '1');
list($bnq, $bnr) = Utils::toEther(0x11, 'wei');
$this->assertEquals($bnq->toString(), '0');
$this->assertEquals($bnr->toString(), '17');
list($bnq, $bnr) = Utils::toEther('1', 'kether');
$this->assertEquals($bnq->toString(), '1000');
@ -525,16 +430,39 @@ class UtilsTest extends TestCase
*/
public function testJsonToArray()
{
$decodedJson = json_decode($this->testJsonMethodString);
$jsonArray = Utils::jsonToArray($decodedJson);
$jsonAssoc = json_decode($this->testJsonMethodString, true);
$jsonArray2 = Utils::jsonToArray($jsonAssoc);
$this->assertEquals($jsonAssoc, $jsonArray);
$this->assertEquals($jsonAssoc, $jsonArray2);
$json = json_decode($this->testJsonMethodString);
$jsonArrayDepth1 = Utils::jsonToArray($json);
$jsonAssoc = json_decode($this->testIssue112Json, true);
$jsonArray = Utils::jsonToArray($jsonAssoc);
$this->assertEquals($jsonAssoc, $jsonArray);
$this->assertEquals($jsonArrayDepth1, (array) $json);
$jsonAssoc = json_decode($this->testJsonMethodString, true);
$jsonArrayDepth2 = Utils::jsonToArray($json, 2);
$this->assertEquals($jsonArrayDepth2, $jsonAssoc);
$jsonArrayDepth2 = Utils::jsonToArray($jsonArrayDepth1, 2);
$this->assertEquals($jsonArrayDepth2, $jsonAssoc);
$jsonArray = Utils::jsonToArray($this->testJsonMethodString);
$this->assertEquals($jsonArray, $jsonAssoc);
try {
$jsonArray = Utils::jsonToArray($json, 0);
} catch (InvalidArgumentException $e) {
$this->assertTrue($e !== null);
}
try {
$jsonArray = Utils::jsonToArray(mb_substr($this->testJsonMethodString, 0, 50), 1);
} catch (InvalidArgumentException $e) {
$this->assertTrue($e !== null);
}
try {
$jsonArray = Utils::jsonToArray(0, 1);
} catch (InvalidArgumentException $e) {
$this->assertTrue($e !== null);
}
}
/**
@ -603,45 +531,39 @@ class UtilsTest extends TestCase
$this->assertEquals($bn->toString(), '-1');
$bn = Utils::toBn('-0.1');
$this->assertEquals(count($bn), 4);
$this->assertEquals(count($bn), 3);
$this->assertEquals($bn[0]->toString(), '0');
$this->assertEquals($bn[1]->toString(), '1');
$this->assertEquals($bn[2], 1);
$this->assertEquals($bn[3]->toString(), '-1');
$this->assertEquals($bn[2]->toString(), '-1');
$bn = Utils::toBn(-0.1);
$this->assertEquals(count($bn), 4);
$this->assertEquals(count($bn), 3);
$this->assertEquals($bn[0]->toString(), '0');
$this->assertEquals($bn[1]->toString(), '1');
$this->assertEquals($bn[2], 1);
$this->assertEquals($bn[3]->toString(), '-1');
$this->assertEquals($bn[2]->toString(), '-1');
$bn = Utils::toBn('0.1');
$this->assertEquals(count($bn), 4);
$this->assertEquals(count($bn), 3);
$this->assertEquals($bn[0]->toString(), '0');
$this->assertEquals($bn[1]->toString(), '1');
$this->assertEquals($bn[2], 1);
$this->assertEquals($bn[3], false);
$this->assertEquals($bn[2], false);
$bn = Utils::toBn('-1.69');
$this->assertEquals(count($bn), 4);
$this->assertEquals(count($bn), 3);
$this->assertEquals($bn[0]->toString(), '1');
$this->assertEquals($bn[1]->toString(), '69');
$this->assertEquals($bn[2], 2);
$this->assertEquals($bn[3]->toString(), '-1');
$this->assertEquals($bn[2]->toString(), '-1');
$bn = Utils::toBn(-1.69);
$this->assertEquals($bn[0]->toString(), '1');
$this->assertEquals($bn[1]->toString(), '69');
$this->assertEquals($bn[2], 2);
$this->assertEquals($bn[3]->toString(), '-1');
$this->assertEquals($bn[2]->toString(), '-1');
$bn = Utils::toBn('1.69');
$this->assertEquals(count($bn), 4);
$this->assertEquals(count($bn), 3);
$this->assertEquals($bn[0]->toString(), '1');
$this->assertEquals($bn[1]->toString(), '69');
$this->assertEquals($bn[2], 2);
$this->assertEquals($bn[3], false);
$this->assertEquals($bn[2], false);
$bn = Utils::toBn(new BigNumber(1));
$this->assertEquals($bn->toString(), '1');

View File

@ -29,7 +29,7 @@ class Web3ApiTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
}

View File

@ -28,7 +28,7 @@ class Web3BatchTest extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
}

View File

@ -37,7 +37,7 @@ class Web3Test extends TestCase
*
* @return void
*/
public function setUp(): void
public function setUp()
{
parent::setUp();
}