Compare commits
75 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
cede0cc410 | ||
|
1d2581e78e | ||
|
2eafffbbe5 | ||
|
cc7d01e7eb | ||
|
1d47285b8b | ||
|
7c46919e7d | ||
|
91f4d2c40b | ||
|
2ae840f538 | ||
|
217851c62d | ||
|
7eb8a46366 | ||
|
dabb7262b5 | ||
|
bd40f1946a | ||
|
fb94ea92c5 | ||
|
199cb1d175 | ||
|
1b093c8ad4 | ||
|
a96e8865a8 | ||
|
d1582e3a7c | ||
|
9ed1b0d2dd | ||
|
17472b55fd | ||
|
8ba41a37b7 | ||
|
c0c57219d7 | ||
|
d4f747606f | ||
|
292b579337 | ||
|
dc66eb1064 | ||
|
4e0548a3ea | ||
|
d69ce96a64 | ||
|
d0289506dc | ||
|
0659ec04dc | ||
|
0e303787ba | ||
|
fff321de37 | ||
|
5e284d0037 | ||
|
3943f00b38 | ||
|
8a34582d23 | ||
|
d67367a2f2 | ||
|
b6fc44d9e3 | ||
|
10b000d3e5 | ||
|
08a237df37 | ||
|
4779c7e710 | ||
|
13f6d3338d | ||
|
2b5295533f | ||
|
cd1bcf3a17 | ||
|
d35ecef5f7 | ||
|
b0615caf03 | ||
|
5e4e5e35fd | ||
|
fcb959dec7 | ||
|
b0b1841642 | ||
|
fbf2ba4f97 | ||
|
83188b171e | ||
|
c5fe156d97 | ||
|
734dbebb76 | ||
|
9dd5056790 | ||
|
53b5165062 | ||
|
08956500b0 | ||
|
0ef6000be3 | ||
|
51abbc2f5e | ||
|
d579535485 | ||
|
f3259100ec | ||
|
28627c5ecf | ||
|
46708ab7b1 | ||
|
60bbb2c17a | ||
|
77f20738aa | ||
|
fe5dc8ed63 | ||
|
0d415ce360 | ||
|
01a70408ac | ||
|
e7e04c542b | ||
|
29ceef6552 | ||
|
54e18048e3 | ||
|
70ac87df82 | ||
|
c81e4ee4e5 | ||
|
0f1b9183b0 | ||
|
908d841bce | ||
|
6d59d3d372 | ||
|
1a9784da30 | ||
|
e5729b757c | ||
|
16d341455d |
49
.github/workflows/php.yml
vendored
Normal file
49
.github/workflows/php.yml
vendored
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
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
2
.gitignore
vendored
@ -1,6 +1,8 @@
|
|||||||
composer.phar
|
composer.phar
|
||||||
/vendor/
|
/vendor/
|
||||||
.phpintel/
|
.phpintel/
|
||||||
|
/.idea/
|
||||||
|
|
||||||
|
|
||||||
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
|
# 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
|
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
|
||||||
|
@ -5,6 +5,8 @@ language: php
|
|||||||
php:
|
php:
|
||||||
- 7.1
|
- 7.1
|
||||||
- 7.2
|
- 7.2
|
||||||
|
- 7.3
|
||||||
|
- 7.4
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- nvm install 8
|
- nvm install 8
|
||||||
@ -24,4 +26,4 @@ script:
|
|||||||
- scripts/test.sh
|
- scripts/test.sh
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- bash <(curl -s https://codecov.io/bash) -t 8436848f-9a99-4b49-be60-629d7ff9a62c
|
- bash <(curl -s https://codecov.io/bash) -t 76a0abaf-bbc4-4829-b5b8-474f10a6b9e9
|
||||||
|
24
README.md
24
README.md
@ -1,9 +1,10 @@
|
|||||||
# web3.php
|
# web3.php
|
||||||
|
|
||||||
[](https://travis-ci.org/sc0Vu/web3.php)
|
[](https://github.com/web3p/web3.php/actions/workflows/php.yml)
|
||||||
[](https://codecov.io/gh/sc0Vu/web3.php)
|
[](https://travis-ci.org/web3p/web3.php)
|
||||||
|
[](https://codecov.io/gh/web3p/web3.php)
|
||||||
[](https://gitter.im/web3-php/web3.php)
|
[](https://gitter.im/web3-php/web3.php)
|
||||||
[](https://github.com/sc0Vu/web3.php/blob/master/LICENSE)
|
[](https://github.com/web3p/web3.php/blob/master/LICENSE)
|
||||||
|
|
||||||
|
|
||||||
A php interface for interacting with the Ethereum blockchain and ecosystem.
|
A php interface for interacting with the Ethereum blockchain and ecosystem.
|
||||||
@ -17,13 +18,13 @@ Set minimum stability to dev
|
|||||||
|
|
||||||
Then
|
Then
|
||||||
```
|
```
|
||||||
composer require sc0vu/web3.php dev-master
|
composer require web3p/web3.php dev-master
|
||||||
```
|
```
|
||||||
|
|
||||||
Or you can add this line in composer.json
|
Or you can add this line in composer.json
|
||||||
|
|
||||||
```
|
```
|
||||||
"sc0vu/web3.php": "dev-master"
|
"web3p/web3.php": "dev-master"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ $web3->clientVersion(function ($err, $version) {
|
|||||||
// do something
|
// do something
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isset($client)) {
|
if (isset($version)) {
|
||||||
echo 'Client version: ' . $version;
|
echo 'Client version: ' . $version;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -216,7 +217,7 @@ If you are using docker as development machain, you can try [ethdock](https://gi
|
|||||||
|
|
||||||
1. Clone the repo and install packages.
|
1. Clone the repo and install packages.
|
||||||
```
|
```
|
||||||
git clone https://github.com/sc0Vu/web3.php.git && cd web3.php && composer install
|
git clone https://github.com/web3p/web3.php.git && cd web3.php && composer install
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Run test script.
|
2. Run test script.
|
||||||
@ -228,7 +229,7 @@ vendor/bin/phpunit
|
|||||||
|
|
||||||
1. Clone the repo and run docker container.
|
1. Clone the repo and run docker container.
|
||||||
```
|
```
|
||||||
git clone https://github.com/sc0Vu/web3.php.git
|
git clone https://github.com/web3p/web3.php.git
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Copy web3.php to web3.php/docker/app directory and start container.
|
2. Copy web3.php to web3.php/docker/app directory and start container.
|
||||||
@ -283,5 +284,12 @@ mv /usr/local/etc/php/conf.d/extension-config-name to/directory
|
|||||||
|
|
||||||
Todo.
|
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
|
# License
|
||||||
MIT
|
MIT
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "sc0vu/web3.php",
|
"name": "web3p/web3.php",
|
||||||
"description": "Ethereum web3 interface.",
|
"description": "Ethereum web3 interface.",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -10,13 +10,14 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"guzzlehttp/guzzle": "~6.0",
|
"guzzlehttp/guzzle": "^6.3|^7.0",
|
||||||
"PHP": "^7.1",
|
"PHP": "^7.2|^8.0",
|
||||||
"kornrunner/keccak": "~1.0",
|
"kornrunner/keccak": "~1.0",
|
||||||
"phpseclib/phpseclib": "~2.0.11"
|
"phpseclib/phpseclib": "~2.0.30",
|
||||||
|
"ext-mbstring": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "~6.0"
|
"phpunit/phpunit": "~8.0|~9.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
@ -1,17 +1,23 @@
|
|||||||
FROM php:7.1.14-alpine
|
FROM php:7.1-alpine
|
||||||
|
|
||||||
MAINTAINER Peter Lai <alk03073135@gmail.com>
|
MAINTAINER Peter Lai <alk03073135@gmail.com>
|
||||||
|
|
||||||
ADD composer-setup.php composer-setup.php
|
COPY composer-setup.php composer-setup.php
|
||||||
|
# COPY php.ini-production $PHP_INI_DIR/php.ini
|
||||||
|
|
||||||
RUN apk update && \
|
RUN apk update && \
|
||||||
apk add git
|
apk add git
|
||||||
|
|
||||||
|
# Install gmp
|
||||||
|
Run apk add gmp-dev && \
|
||||||
|
docker-php-ext-install gmp
|
||||||
|
|
||||||
# Install nodejs
|
# Install nodejs
|
||||||
# Run apk add --update nodejs nodejs-npm
|
# Run apk add --update nodejs nodejs-npm
|
||||||
|
|
||||||
# Install composer
|
# Install composer
|
||||||
RUN php composer-setup.php && \
|
RUN php composer-setup.php && \
|
||||||
php composer-setup.php --install-dir=/usr/bin --filename=composer
|
php composer-setup.php --install-dir=/usr/bin --filename=composer && \
|
||||||
|
php -r "unlink('composer-setup.php');"
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
@ -1,17 +1,23 @@
|
|||||||
FROM php:7.2.2-alpine
|
FROM php:7.2-alpine
|
||||||
|
|
||||||
MAINTAINER Peter Lai <alk03073135@gmail.com>
|
MAINTAINER Peter Lai <alk03073135@gmail.com>
|
||||||
|
|
||||||
ADD composer-setup.php composer-setup.php
|
COPY composer-setup.php composer-setup.php
|
||||||
|
# COPY php.ini-production $PHP_INI_DIR/php.ini
|
||||||
|
|
||||||
RUN apk update && \
|
RUN apk update && \
|
||||||
apk add git
|
apk add git
|
||||||
|
|
||||||
|
# Install gmp
|
||||||
|
Run apk add gmp-dev && \
|
||||||
|
docker-php-ext-install gmp
|
||||||
|
|
||||||
# Install nodejs
|
# Install nodejs
|
||||||
# Run apk add --update nodejs nodejs-npm
|
# Run apk add --update nodejs nodejs-npm
|
||||||
|
|
||||||
# Install composer
|
# Install composer
|
||||||
RUN php composer-setup.php && \
|
RUN php composer-setup.php && \
|
||||||
php composer-setup.php --install-dir=/usr/bin --filename=composer
|
php composer-setup.php --install-dir=/usr/bin --filename=composer && \
|
||||||
|
php -r "unlink('composer-setup.php');"
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
23
docker/php/Dockerfile-73
Normal file
23
docker/php/Dockerfile-73
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
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
|
23
docker/php/Dockerfile-74
Normal file
23
docker/php/Dockerfile-74
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
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
|
23
docker/php/Dockerfile-80
Normal file
23
docker/php/Dockerfile-80
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
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
|
@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
$sig = file_get_contents('https://composer.github.io/installer.sig');
|
||||||
|
$sig = trim($sig);
|
||||||
|
|
||||||
copy('https://getcomposer.org/installer', 'composer-setup.php');
|
copy('https://getcomposer.org/installer', 'composer-setup.php');
|
||||||
|
|
||||||
if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;
|
if (hash_file('sha384', 'composer-setup.php') === $sig) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;
|
1923
docker/php/php.ini-development
Normal file
1923
docker/php/php.ini-development
Normal file
File diff suppressed because it is too large
Load Diff
1930
docker/php/php.ini-production
Normal file
1930
docker/php/php.ini-production
Normal file
File diff suppressed because it is too large
Load Diff
@ -38,3 +38,16 @@ $web3->eth->getBalance($newAccount, function ($err, $balance) {
|
|||||||
}
|
}
|
||||||
echo 'Balance: ' . $balance->toString() . PHP_EOL;
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
@ -7,8 +7,7 @@
|
|||||||
convertNoticesToExceptions="true"
|
convertNoticesToExceptions="true"
|
||||||
convertWarningsToExceptions="true"
|
convertWarningsToExceptions="true"
|
||||||
processIsolation="false"
|
processIsolation="false"
|
||||||
stopOnFailure="false"
|
stopOnFailure="false">
|
||||||
syntaxCheck="false">
|
|
||||||
|
|
||||||
<testsuite name="Web3.php unit test">
|
<testsuite name="Web3.php unit test">
|
||||||
<directory suffix="Test.php">./test/unit</directory>
|
<directory suffix="Test.php">./test/unit</directory>
|
||||||
|
356
src/Contract.php
356
src/Contract.php
@ -28,8 +28,10 @@ use Web3\Contracts\Types\Str;
|
|||||||
use Web3\Contracts\Types\Uinteger;
|
use Web3\Contracts\Types\Uinteger;
|
||||||
use Web3\Validators\AddressValidator;
|
use Web3\Validators\AddressValidator;
|
||||||
use Web3\Validators\HexValidator;
|
use Web3\Validators\HexValidator;
|
||||||
use Web3\Formatters\AddressFormatter;
|
|
||||||
use Web3\Validators\StringValidator;
|
use Web3\Validators\StringValidator;
|
||||||
|
use Web3\Validators\TagValidator;
|
||||||
|
use Web3\Validators\QuantityValidator;
|
||||||
|
use Web3\Formatters\AddressFormatter;
|
||||||
|
|
||||||
class Contract
|
class Contract
|
||||||
{
|
{
|
||||||
@ -96,14 +98,22 @@ class Contract
|
|||||||
*/
|
*/
|
||||||
protected $ethabi;
|
protected $ethabi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* defaultBlock
|
||||||
|
*
|
||||||
|
* @var mixed
|
||||||
|
*/
|
||||||
|
protected $defaultBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* construct
|
* construct
|
||||||
*
|
*
|
||||||
* @param string|\Web3\Providers\Provider $provider
|
* @param string|\Web3\Providers\Provider $provider
|
||||||
* @param string|\stdClass|array $abi
|
* @param string|\stdClass|array $abi
|
||||||
|
* @param mixed $defaultBlock
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($provider, $abi)
|
public function __construct($provider, $abi, $defaultBlock = 'latest')
|
||||||
{
|
{
|
||||||
if (is_string($provider) && (filter_var($provider, FILTER_VALIDATE_URL) !== false)) {
|
if (is_string($provider) && (filter_var($provider, FILTER_VALIDATE_URL) !== false)) {
|
||||||
// check the uri schema
|
// check the uri schema
|
||||||
@ -115,12 +125,21 @@ class Contract
|
|||||||
} else if ($provider instanceof Provider) {
|
} else if ($provider instanceof Provider) {
|
||||||
$this->provider = $provider;
|
$this->provider = $provider;
|
||||||
}
|
}
|
||||||
$abi = Utils::jsonToArray($abi, 5);
|
|
||||||
|
|
||||||
foreach ($abi as $item) {
|
$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) {
|
||||||
if (isset($item['type'])) {
|
if (isset($item['type'])) {
|
||||||
if ($item['type'] === 'function') {
|
if ($item['type'] === 'function') {
|
||||||
$this->functions[$item['name']] = $item;
|
$this->functions[] = $item;
|
||||||
} elseif ($item['type'] === 'constructor') {
|
} elseif ($item['type'] === 'constructor') {
|
||||||
$this->constructor = $item;
|
$this->constructor = $item;
|
||||||
} elseif ($item['type'] === 'event') {
|
} elseif ($item['type'] === 'event') {
|
||||||
@ -128,7 +147,12 @@ class Contract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->abi = $abi;
|
if (TagValidator::validate($defaultBlock) || QuantityValidator::validate($defaultBlock)) {
|
||||||
|
$this->defaultBlock = $defaultBlock;
|
||||||
|
} else {
|
||||||
|
$this->$defaultBlock = 'latest';
|
||||||
|
}
|
||||||
|
$this->abi = $abiArray;
|
||||||
$this->eth = new Eth($this->provider);
|
$this->eth = new Eth($this->provider);
|
||||||
$this->ethabi = new Ethabi([
|
$this->ethabi = new Ethabi([
|
||||||
'address' => new Address,
|
'address' => new Address,
|
||||||
@ -203,7 +227,7 @@ class Contract
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setProvider
|
* setProvider
|
||||||
*
|
*
|
||||||
* @param \Web3\Providers\Provider $provider
|
* @param \Web3\Providers\Provider $provider
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
@ -216,8 +240,34 @@ class Contract
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getFunctions
|
* 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
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
@ -227,7 +277,7 @@ class Contract
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* getEvents
|
* getEvents
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getEvents()
|
public function getEvents()
|
||||||
@ -245,7 +295,7 @@ class Contract
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* getConstructor
|
* getConstructor
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getConstructor()
|
public function getConstructor()
|
||||||
@ -255,7 +305,7 @@ class Contract
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* getAbi
|
* getAbi
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getAbi()
|
public function getAbi()
|
||||||
@ -359,12 +409,21 @@ class Contract
|
|||||||
if (StringValidator::validate($abi) === false) {
|
if (StringValidator::validate($abi) === false) {
|
||||||
throw new InvalidArgumentException('Please make sure abi is valid.');
|
throw new InvalidArgumentException('Please make sure abi is valid.');
|
||||||
}
|
}
|
||||||
$abi = Utils::jsonToArray($abi, 5);
|
$abiArray = [];
|
||||||
|
if (is_string($abi)) {
|
||||||
|
$abiArray = json_decode($abi, true);
|
||||||
|
|
||||||
foreach ($abi as $item) {
|
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) {
|
||||||
if (isset($item['type'])) {
|
if (isset($item['type'])) {
|
||||||
if ($item['type'] === 'function') {
|
if ($item['type'] === 'function') {
|
||||||
$this->functions[$item['name']] = $item;
|
$this->functions[] = $item;
|
||||||
} elseif ($item['type'] === 'constructor') {
|
} elseif ($item['type'] === 'constructor') {
|
||||||
$this->constructor = $item;
|
$this->constructor = $item;
|
||||||
} elseif ($item['type'] === 'event') {
|
} elseif ($item['type'] === 'event') {
|
||||||
@ -372,7 +431,7 @@ class Contract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->abi = $abi;
|
$this->abi = $abiArray;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -391,7 +450,8 @@ class Contract
|
|||||||
$arguments = func_get_args();
|
$arguments = func_get_args();
|
||||||
$callback = array_pop($arguments);
|
$callback = array_pop($arguments);
|
||||||
|
|
||||||
if (count($arguments) < count($constructor['inputs'])) {
|
$input_count = isset($constructor['inputs']) ? count($constructor['inputs']) : 0;
|
||||||
|
if (count($arguments) < $input_count) {
|
||||||
throw new InvalidArgumentException('Please make sure you have put all constructor params and callback.');
|
throw new InvalidArgumentException('Please make sure you have put all constructor params and callback.');
|
||||||
}
|
}
|
||||||
if (is_callable($callback) !== true) {
|
if (is_callable($callback) !== true) {
|
||||||
@ -400,7 +460,7 @@ class Contract
|
|||||||
if (!isset($this->bytecode)) {
|
if (!isset($this->bytecode)) {
|
||||||
throw new \InvalidArgumentException('Please call bytecode($bytecode) before new().');
|
throw new \InvalidArgumentException('Please call bytecode($bytecode) before new().');
|
||||||
}
|
}
|
||||||
$params = array_splice($arguments, 0, count($constructor['inputs']));
|
$params = array_splice($arguments, 0, $input_count);
|
||||||
$data = $this->ethabi->encodeParameters($constructor, $params);
|
$data = $this->ethabi->encodeParameters($constructor, $params);
|
||||||
$transaction = [];
|
$transaction = [];
|
||||||
|
|
||||||
@ -432,26 +492,75 @@ class Contract
|
|||||||
$method = array_splice($arguments, 0, 1)[0];
|
$method = array_splice($arguments, 0, 1)[0];
|
||||||
$callback = array_pop($arguments);
|
$callback = array_pop($arguments);
|
||||||
|
|
||||||
if (!is_string($method) || !isset($this->functions[$method])) {
|
if (!is_string($method)) {
|
||||||
throw new InvalidArgumentException('Please make sure the method exists.');
|
throw new InvalidArgumentException('Please make sure the method is string.');
|
||||||
}
|
}
|
||||||
$function = $this->functions[$method];
|
|
||||||
|
|
||||||
if (count($arguments) < count($function['inputs'])) {
|
$functions = [];
|
||||||
throw new InvalidArgumentException('Please make sure you have put all function params and callback.');
|
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 (is_callable($callback) !== true) {
|
if (is_callable($callback) !== true) {
|
||||||
throw new \InvalidArgumentException('The last param must be callback function.');
|
throw new \InvalidArgumentException('The last param must be callback function.');
|
||||||
}
|
}
|
||||||
$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) {
|
// check the last one in arguments is transaction object
|
||||||
$transaction = $arguments[0];
|
$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.');
|
||||||
|
}
|
||||||
|
$functionSignature = $this->ethabi->encodeFunctionSignature($functionName);
|
||||||
$transaction['to'] = $this->toAddress;
|
$transaction['to'] = $this->toAddress;
|
||||||
$transaction['data'] = $functionSignature . Utils::stripZero($data);
|
$transaction['data'] = $functionSignature . Utils::stripZero($data);
|
||||||
|
|
||||||
@ -467,7 +576,7 @@ class Contract
|
|||||||
/**
|
/**
|
||||||
* call
|
* call
|
||||||
* Call function method.
|
* Call function method.
|
||||||
*
|
*
|
||||||
* @param mixed
|
* @param mixed
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@ -478,30 +587,78 @@ class Contract
|
|||||||
$method = array_splice($arguments, 0, 1)[0];
|
$method = array_splice($arguments, 0, 1)[0];
|
||||||
$callback = array_pop($arguments);
|
$callback = array_pop($arguments);
|
||||||
|
|
||||||
if (!is_string($method) || !isset($this->functions[$method])) {
|
if (!is_string($method)) {
|
||||||
throw new InvalidArgumentException('Please make sure the method exists.');
|
throw new InvalidArgumentException('Please make sure the method is string.');
|
||||||
}
|
}
|
||||||
$function = $this->functions[$method];
|
|
||||||
|
|
||||||
if (count($arguments) < count($function['inputs'])) {
|
$functions = [];
|
||||||
throw new InvalidArgumentException('Please make sure you have put all function params and callback.');
|
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 (is_callable($callback) !== true) {
|
if (is_callable($callback) !== true) {
|
||||||
throw new \InvalidArgumentException('The last param must be callback function.');
|
throw new \InvalidArgumentException('The last param must be callback function.');
|
||||||
}
|
}
|
||||||
$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) {
|
// check the arguments
|
||||||
$transaction = $arguments[0];
|
$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 = [];
|
||||||
|
}
|
||||||
|
$functionSignature = $this->ethabi->encodeFunctionSignature($functionName);
|
||||||
$transaction['to'] = $this->toAddress;
|
$transaction['to'] = $this->toAddress;
|
||||||
$transaction['data'] = $functionSignature . Utils::stripZero($data);
|
$transaction['data'] = $functionSignature . Utils::stripZero($data);
|
||||||
|
|
||||||
$this->eth->call($transaction, function ($err, $transaction) use ($callback, $function){
|
$this->eth->call($transaction, $defaultBlock, function ($err, $transaction) use ($callback, $function){
|
||||||
if ($err !== null) {
|
if ($err !== null) {
|
||||||
return call_user_func($callback, $err, null);
|
return call_user_func($callback, $err, null);
|
||||||
}
|
}
|
||||||
@ -544,36 +701,84 @@ class Contract
|
|||||||
if (count($arguments) > 0) {
|
if (count($arguments) > 0) {
|
||||||
$transaction = $arguments[0];
|
$transaction = $arguments[0];
|
||||||
}
|
}
|
||||||
$transaction['to'] = '';
|
|
||||||
$transaction['data'] = '0x' . $this->bytecode . Utils::stripZero($data);
|
$transaction['data'] = '0x' . $this->bytecode . Utils::stripZero($data);
|
||||||
} else {
|
} else {
|
||||||
$method = array_splice($arguments, 0, 1)[0];
|
$method = array_splice($arguments, 0, 1)[0];
|
||||||
|
|
||||||
if (!is_string($method) && !isset($this->functions[$method])) {
|
if (!is_string($method)) {
|
||||||
throw new InvalidArgumentException('Please make sure the method is existed.');
|
throw new InvalidArgumentException('Please make sure the method is string.');
|
||||||
}
|
}
|
||||||
$function = $this->functions[$method];
|
|
||||||
|
$functions = [];
|
||||||
if (count($arguments) < count($function['inputs'])) {
|
foreach ($this->functions as $function) {
|
||||||
throw new InvalidArgumentException('Please make sure you have put all function params and callback.');
|
if ($function["name"] === $method) {
|
||||||
|
$functions[] = $function;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (count($functions) < 1) {
|
||||||
|
throw new InvalidArgumentException('Please make sure the method exists.');
|
||||||
}
|
}
|
||||||
if (is_callable($callback) !== true) {
|
if (is_callable($callback) !== true) {
|
||||||
throw new \InvalidArgumentException('The last param must be callback function.');
|
throw new \InvalidArgumentException('The last param must be callback function.');
|
||||||
}
|
}
|
||||||
$params = array_splice($arguments, 0, count($function['inputs']));
|
|
||||||
$data = $this->ethabi->encodeParameters($function, $params);
|
// check the last one in arguments is transaction object
|
||||||
$functionName = Utils::jsonMethodToString($function);
|
$argsLen = count($arguments);
|
||||||
$functionSignature = $this->ethabi->encodeFunctionSignature($functionName);
|
|
||||||
$transaction = [];
|
$transaction = [];
|
||||||
|
$hasTransaction = false;
|
||||||
|
|
||||||
if (count($arguments) > 0) {
|
if ($argsLen > 0) {
|
||||||
$transaction = $arguments[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.');
|
||||||
|
}
|
||||||
|
$functionSignature = $this->ethabi->encodeFunctionSignature($functionName);
|
||||||
$transaction['to'] = $this->toAddress;
|
$transaction['to'] = $this->toAddress;
|
||||||
$transaction['data'] = $functionSignature . Utils::stripZero($data);
|
$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) {
|
if ($err !== null) {
|
||||||
return call_user_func($callback, $err, null);
|
return call_user_func($callback, $err, null);
|
||||||
}
|
}
|
||||||
@ -614,17 +819,38 @@ class Contract
|
|||||||
} else {
|
} else {
|
||||||
$method = array_splice($arguments, 0, 1)[0];
|
$method = array_splice($arguments, 0, 1)[0];
|
||||||
|
|
||||||
if (!is_string($method) && !isset($this->functions[$method])) {
|
if (!is_string($method)) {
|
||||||
throw new InvalidArgumentException('Please make sure the method is existed.');
|
throw new InvalidArgumentException('Please make sure the method is string.');
|
||||||
}
|
}
|
||||||
$function = $this->functions[$method];
|
|
||||||
|
$functions = [];
|
||||||
if (count($arguments) < count($function['inputs'])) {
|
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)) {
|
||||||
throw new InvalidArgumentException('Please make sure you have put all function params and callback.');
|
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);
|
$functionSignature = $this->ethabi->encodeFunctionSignature($functionName);
|
||||||
$functionData = Utils::stripZero($functionSignature) . Utils::stripZero($data);
|
$functionData = Utils::stripZero($functionSignature) . Utils::stripZero($data);
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,7 @@ class Ethabi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* encodeEventSignature
|
* encodeEventSignature
|
||||||
|
* TODO: Fix same event name with different params
|
||||||
*
|
*
|
||||||
* @param string|stdClass|array $functionName
|
* @param string|stdClass|array $functionName
|
||||||
* @return string
|
* @return string
|
||||||
@ -155,21 +156,6 @@ class Ethabi
|
|||||||
}
|
}
|
||||||
$typesLength = count($types);
|
$typesLength = count($types);
|
||||||
$solidityTypes = $this->getSolidityTypes($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, '');
|
$encodes = array_fill(0, $typesLength, '');
|
||||||
|
|
||||||
foreach ($solidityTypes as $key => $type) {
|
foreach ($solidityTypes as $key => $type) {
|
||||||
|
@ -63,9 +63,10 @@ class Bytes extends SolidityType implements IType
|
|||||||
}
|
}
|
||||||
$value = Utils::stripZero($value);
|
$value = Utils::stripZero($value);
|
||||||
|
|
||||||
// if (mb_strlen($value) % 2 !== 0) {
|
if (mb_strlen($value) % 2 !== 0) {
|
||||||
// throw new InvalidArgumentException('The value to inputFormat has invalid length. Value: ' . $value);
|
$value = "0" . $value;
|
||||||
// }
|
// throw new InvalidArgumentException('The value to inputFormat has invalid length. Value: ' . $value);
|
||||||
|
}
|
||||||
|
|
||||||
if (mb_strlen($value) > 64) {
|
if (mb_strlen($value) > 64) {
|
||||||
throw new InvalidArgumentException('The value to inputFormat is too long.');
|
throw new InvalidArgumentException('The value to inputFormat is too long.');
|
||||||
|
@ -63,12 +63,17 @@ class DynamicBytes extends SolidityType implements IType
|
|||||||
}
|
}
|
||||||
$value = Utils::stripZero($value);
|
$value = Utils::stripZero($value);
|
||||||
|
|
||||||
// if (mb_strlen($value) % 2 !== 0) {
|
if (mb_strlen($value) % 2 !== 0) {
|
||||||
// throw new InvalidArgumentException('The value to inputFormat has invalid length.');
|
$value = "0" . $value;
|
||||||
// }
|
// throw new InvalidArgumentException('The value to inputFormat has invalid length.');
|
||||||
$bn = Utils::toBn(mb_strlen($value) / 2);
|
}
|
||||||
|
$bn = Utils::toBn(floor(mb_strlen($value) / 2));
|
||||||
$bnHex = $bn->toHex(true);
|
$bnHex = $bn->toHex(true);
|
||||||
$padded = mb_substr($bnHex, 0, 1);
|
$padded = mb_substr($bnHex, 0, 1);
|
||||||
|
|
||||||
|
if ($padded !== '0' && $padded !== 'f') {
|
||||||
|
$padded = '0';
|
||||||
|
}
|
||||||
$l = floor((mb_strlen($value) + 63) / 64);
|
$l = floor((mb_strlen($value) + 63) / 64);
|
||||||
$padding = (($l * 64 - mb_strlen($value) + 1) >= 0) ? $l * 64 - mb_strlen($value) : 0;
|
$padding = (($l * 64 - mb_strlen($value) + 1) >= 0) ? $l * 64 - mb_strlen($value) : 0;
|
||||||
|
|
||||||
@ -89,7 +94,7 @@ class DynamicBytes extends SolidityType implements IType
|
|||||||
if (empty($checkZero)) {
|
if (empty($checkZero)) {
|
||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
$size = intval(Utils::toBn(mb_substr($value, 0, 64))->toString());
|
$size = intval(Utils::toBn('0x' . mb_substr($value, 0, 64))->toString());
|
||||||
$length = 2 * $size;
|
$length = 2 * $size;
|
||||||
|
|
||||||
return '0x' . mb_substr($value, 64, $length);
|
return '0x' . mb_substr($value, 64, $length);
|
||||||
|
@ -38,7 +38,7 @@ class Eth
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $allowedMethods = [
|
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_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'
|
'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'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,18 +23,14 @@ class NewBlockFilter extends EthMethod
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $validators = [
|
protected $validators = [];
|
||||||
QuantityValidator::class
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inputFormatters
|
* inputFormatters
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $inputFormatters = [
|
protected $inputFormatters = [];
|
||||||
QuantityFormatter::class
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* outputFormatters
|
* outputFormatters
|
||||||
@ -61,4 +57,4 @@ class NewBlockFilter extends EthMethod
|
|||||||
// {
|
// {
|
||||||
// parent::__construct($method, $arguments);
|
// parent::__construct($method, $arguments);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
@ -9,26 +9,31 @@
|
|||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Web3\Methods\Eth;
|
namespace Web3\Methods\Personal;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use Web3\Methods\EthMethod;
|
use Web3\Methods\EthMethod;
|
||||||
|
use Web3\Validators\AddressValidator;
|
||||||
|
use Web3\Formatters\AddressFormatter;
|
||||||
|
|
||||||
class GetCompilers extends EthMethod
|
class LockAccount extends EthMethod
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* validators
|
* validators
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $validators = [];
|
protected $validators = [
|
||||||
|
AddressValidator::class
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inputFormatters
|
* inputFormatters
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $inputFormatters = [];
|
protected $inputFormatters = [
|
||||||
|
AddressFormatter::class
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* outputFormatters
|
* outputFormatters
|
||||||
@ -55,4 +60,5 @@ class GetCompilers extends EthMethod
|
|||||||
// {
|
// {
|
||||||
// parent::__construct($method, $arguments);
|
// parent::__construct($method, $arguments);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
@ -38,7 +38,7 @@ class Personal
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $allowedMethods = [
|
private $allowedMethods = [
|
||||||
'personal_listAccounts', 'personal_newAccount', 'personal_unlockAccount', 'personal_sendTransaction'
|
'personal_listAccounts', 'personal_newAccount', 'personal_unlockAccount', 'personal_lockAccount', 'personal_sendTransaction'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -177,4 +177,4 @@ class Personal
|
|||||||
|
|
||||||
$this->provider->batch($status);
|
$this->provider->batch($status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This file is part of web3.php package.
|
* This file is part of web3.php package.
|
||||||
*
|
*
|
||||||
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
|
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
|
||||||
*
|
*
|
||||||
* @author Peter Lai <alk03073135@gmail.com>
|
* @author Peter Lai <alk03073135@gmail.com>
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
@ -12,6 +12,7 @@
|
|||||||
namespace Web3\RequestManagers;
|
namespace Web3\RequestManagers;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
use Psr\Http\Message\StreamInterface;
|
||||||
use RuntimeException as RPCException;
|
use RuntimeException as RPCException;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
@ -23,14 +24,14 @@ class HttpRequestManager extends RequestManager implements IRequestManager
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* client
|
* client
|
||||||
*
|
*
|
||||||
* @var \GuzzleHttp
|
* @var \GuzzleHttp
|
||||||
*/
|
*/
|
||||||
protected $client;
|
protected $client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* construct
|
* construct
|
||||||
*
|
*
|
||||||
* @param string $host
|
* @param string $host
|
||||||
* @param int $timeout
|
* @param int $timeout
|
||||||
* @return void
|
* @return void
|
||||||
@ -43,7 +44,7 @@ class HttpRequestManager extends RequestManager implements IRequestManager
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* sendPayload
|
* sendPayload
|
||||||
*
|
*
|
||||||
* @param string $payload
|
* @param string $payload
|
||||||
* @param callable $callback
|
* @param callable $callback
|
||||||
* @return void
|
* @return void
|
||||||
@ -53,22 +54,7 @@ class HttpRequestManager extends RequestManager implements IRequestManager
|
|||||||
if (!is_string($payload)) {
|
if (!is_string($payload)) {
|
||||||
throw new \InvalidArgumentException('Payload must be string.');
|
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 {
|
try {
|
||||||
$res = $this->client->post($this->host, [
|
$res = $this->client->post($this->host, [
|
||||||
'headers' => [
|
'headers' => [
|
||||||
@ -78,7 +64,12 @@ class HttpRequestManager extends RequestManager implements IRequestManager
|
|||||||
'timeout' => $this->timeout,
|
'timeout' => $this->timeout,
|
||||||
'connect_timeout' => $this->timeout
|
'connect_timeout' => $this->timeout
|
||||||
]);
|
]);
|
||||||
$json = json_decode($res->getBody());
|
/**
|
||||||
|
* @var StreamInterface $stream ;
|
||||||
|
*/
|
||||||
|
$stream = $res->getBody();
|
||||||
|
$json = json_decode($stream);
|
||||||
|
$stream->close();
|
||||||
|
|
||||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
if (JSON_ERROR_NONE !== json_last_error()) {
|
||||||
call_user_func($callback, new InvalidArgumentException('json_decode error: ' . json_last_error_msg()), null);
|
call_user_func($callback, new InvalidArgumentException('json_decode error: ' . json_last_error_msg()), null);
|
||||||
@ -89,7 +80,7 @@ class HttpRequestManager extends RequestManager implements IRequestManager
|
|||||||
$errors = [];
|
$errors = [];
|
||||||
|
|
||||||
foreach ($json as $result) {
|
foreach ($json as $result) {
|
||||||
if (isset($result->result)) {
|
if (property_exists($result,'result')) {
|
||||||
$results[] = $result->result;
|
$results[] = $result->result;
|
||||||
} else {
|
} else {
|
||||||
if (isset($json->error)) {
|
if (isset($json->error)) {
|
||||||
@ -105,7 +96,7 @@ class HttpRequestManager extends RequestManager implements IRequestManager
|
|||||||
} else {
|
} else {
|
||||||
call_user_func($callback, null, $results);
|
call_user_func($callback, null, $results);
|
||||||
}
|
}
|
||||||
} elseif (isset($json->result)) {
|
} elseif (property_exists($json,'result')) {
|
||||||
call_user_func($callback, null, $json->result);
|
call_user_func($callback, null, $json->result);
|
||||||
} else {
|
} else {
|
||||||
if (isset($json->error)) {
|
if (isset($json->error)) {
|
||||||
|
@ -189,7 +189,7 @@ class Utils
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* isAddressChecksum
|
* isAddressChecksum
|
||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -212,6 +212,31 @@ class Utils
|
|||||||
return true;
|
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
|
* isHex
|
||||||
*
|
*
|
||||||
@ -266,12 +291,15 @@ class Utils
|
|||||||
* $wei = Utils::toWei('1', 'kwei');
|
* $wei = Utils::toWei('1', 'kwei');
|
||||||
* $wei->toString(); // 1000
|
* $wei->toString(); // 1000
|
||||||
*
|
*
|
||||||
* @param BigNumber|string|int $number
|
* @param BigNumber|string $number
|
||||||
* @param string $unit
|
* @param string $unit
|
||||||
* @return \phpseclib\Math\BigInteger
|
* @return \phpseclib\Math\BigInteger
|
||||||
*/
|
*/
|
||||||
public static function toWei($number, $unit)
|
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);
|
$bn = self::toBn($number);
|
||||||
|
|
||||||
if (!is_string($unit)) {
|
if (!is_string($unit)) {
|
||||||
@ -419,52 +447,34 @@ class Utils
|
|||||||
/**
|
/**
|
||||||
* jsonToArray
|
* jsonToArray
|
||||||
*
|
*
|
||||||
* @param stdClass|array|string $json
|
* @param stdClass|array $json
|
||||||
* @param int $depth
|
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function jsonToArray($json, $depth=1)
|
public static function jsonToArray($json)
|
||||||
{
|
{
|
||||||
if (!is_int($depth) || $depth <= 0) {
|
|
||||||
throw new InvalidArgumentException('jsonToArray depth must be int and depth must bigger than 0.');
|
|
||||||
}
|
|
||||||
if ($json instanceof stdClass) {
|
if ($json instanceof stdClass) {
|
||||||
$json = (array) $json;
|
$json = (array) $json;
|
||||||
$typeName = [];
|
$typeName = [];
|
||||||
|
|
||||||
if ($depth > 1) {
|
foreach ($json as $key => $param) {
|
||||||
foreach ($json as $key => $param) {
|
if (is_array($param)) {
|
||||||
if (is_array($param)) {
|
foreach ($param as $subKey => $subParam) {
|
||||||
foreach ($param as $subKey => $subParam) {
|
$json[$key][$subKey] = self::jsonToArray($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)) {
|
} elseif (is_array($json)) {
|
||||||
if ($depth > 1) {
|
foreach ($json as $key => $param) {
|
||||||
foreach ($json as $key => $param) {
|
if (is_array($param)) {
|
||||||
if (is_array($param)) {
|
foreach ($param as $subKey => $subParam) {
|
||||||
foreach ($param as $subKey => $subParam) {
|
$json[$key][$subKey] = self::jsonToArray($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;
|
return $json;
|
||||||
}
|
}
|
||||||
@ -519,7 +529,7 @@ class Utils
|
|||||||
$number = str_replace('-', '', $number, $count);
|
$number = str_replace('-', '', $number, $count);
|
||||||
$negative1 = new BigNumber(-1);
|
$negative1 = new BigNumber(-1);
|
||||||
}
|
}
|
||||||
if (self::isZeroPrefixed($number) || preg_match('/[a-f]+/', $number) === 1) {
|
if (self::isZeroPrefixed($number) || preg_match('/^[0-9a-f]+$/i', $number) === 1) {
|
||||||
$number = self::stripZero($number);
|
$number = self::stripZero($number);
|
||||||
$bn = new BigNumber($number, 16);
|
$bn = new BigNumber($number, 16);
|
||||||
} elseif (empty($number)) {
|
} elseif (empty($number)) {
|
||||||
|
@ -37,10 +37,8 @@ class TestCase extends BaseTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setUp
|
* setUp
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$web3 = new Web3($this->testHost);
|
$web3 = new Web3($this->testHost);
|
||||||
$this->web3 = $web3;
|
$this->web3 = $web3;
|
||||||
@ -55,8 +53,6 @@ class TestCase extends BaseTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* tearDown
|
* tearDown
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function tearDown() {}
|
public function tearDown(): void {}
|
||||||
}
|
}
|
||||||
|
15
test/contracts/issue125.sol
Normal file
15
test/contracts/issue125.sol
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
26
test/contracts/issue134.sol
Normal file
26
test/contracts/issue134.sol
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -19,7 +19,7 @@ class AddressFormatterTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->formatter = new AddressFormatter;
|
$this->formatter = new AddressFormatter;
|
||||||
|
@ -47,7 +47,7 @@ class AddressTypeTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->solidityType = new Address;
|
$this->solidityType = new Address;
|
||||||
|
@ -19,7 +19,7 @@ class AddressValidatorTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->validator = new AddressValidator;
|
$this->validator = new AddressValidator;
|
||||||
|
@ -20,7 +20,7 @@ class BigNumberFormatterTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->formatter = new BigNumberFormatter;
|
$this->formatter = new BigNumberFormatter;
|
||||||
|
@ -19,7 +19,7 @@ class BlockHashValidatorTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->validator = new BlockHashValidator;
|
$this->validator = new BlockHashValidator;
|
||||||
|
@ -20,7 +20,7 @@ class BooleanFormatterTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->formatter = new BooleanFormatter;
|
$this->formatter = new BooleanFormatter;
|
||||||
|
@ -47,7 +47,7 @@ class BooleanTypeTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->solidityType = new Boolean;
|
$this->solidityType = new Boolean;
|
||||||
|
@ -19,7 +19,7 @@ class BooleanValidatorTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->validator = new BooleanValidator;
|
$this->validator = new BooleanValidator;
|
||||||
|
@ -53,7 +53,7 @@ class BytesTypeTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->solidityType = new Bytes;
|
$this->solidityType = new Bytes;
|
||||||
|
@ -19,7 +19,7 @@ class CallValidatorTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->validator = new CallValidator;
|
$this->validator = new CallValidator;
|
||||||
|
@ -412,7 +412,7 @@ class ContractTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
@ -491,7 +491,7 @@ class ContractTest extends TestCase
|
|||||||
}
|
}
|
||||||
if ($transaction) {
|
if ($transaction) {
|
||||||
$this->contractAddress = $transaction->contractAddress;
|
$this->contractAddress = $transaction->contractAddress;
|
||||||
echo "\nTransaction has mind:) block number: " . $transaction->blockNumber . "\n";
|
echo "\nTransaction has mined:) block number: " . $transaction->blockNumber . "\n";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -535,7 +535,7 @@ class ContractTest extends TestCase
|
|||||||
}
|
}
|
||||||
if ($transaction) {
|
if ($transaction) {
|
||||||
$this->contractAddress = $transaction->contractAddress;
|
$this->contractAddress = $transaction->contractAddress;
|
||||||
echo "\nTransaction has mind:) block number: " . $transaction->blockNumber . "\n";
|
echo "\nTransaction has mined:) block number: " . $transaction->blockNumber . "\n";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -562,7 +562,7 @@ class ContractTest extends TestCase
|
|||||||
}
|
}
|
||||||
if ($transaction) {
|
if ($transaction) {
|
||||||
$topics = $transaction->logs[0]->topics;
|
$topics = $transaction->logs[0]->topics;
|
||||||
echo "\nTransaction has mind:) block number: " . $transaction->blockNumber . "\n";
|
echo "\nTransaction has mined:) block number: " . $transaction->blockNumber . "\n";
|
||||||
|
|
||||||
// validate topics
|
// validate topics
|
||||||
$this->assertEquals($contract->ethabi->encodeEventSignature($this->contract->events['Transfer']), $topics[0]);
|
$this->assertEquals($contract->ethabi->encodeEventSignature($this->contract->events['Transfer']), $topics[0]);
|
||||||
@ -611,7 +611,7 @@ class ContractTest extends TestCase
|
|||||||
}
|
}
|
||||||
if ($transaction) {
|
if ($transaction) {
|
||||||
$this->contractAddress = $transaction->contractAddress;
|
$this->contractAddress = $transaction->contractAddress;
|
||||||
echo "\nTransaction has mind:) block number: " . $transaction->blockNumber . "\n";
|
echo "\nTransaction has mined:) block number: " . $transaction->blockNumber . "\n";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -631,6 +631,17 @@ class ContractTest extends TestCase
|
|||||||
$this->assertTrue($result !== null);
|
$this->assertTrue($result !== null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// test issue 143
|
||||||
|
$contract->at($this->contractAddress)->call('balanceOf', $fromAccount, function ($err, $result) use ($contract) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
if (isset($result)) {
|
||||||
|
// $bn = Utils::toBn($result);
|
||||||
|
// $this->assertEquals($bn->toString(), '10000', 'Balance should be 10000.');
|
||||||
|
$this->assertTrue($result !== null);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -671,7 +682,7 @@ class ContractTest extends TestCase
|
|||||||
}
|
}
|
||||||
if ($transaction) {
|
if ($transaction) {
|
||||||
$this->contractAddress = $transaction->contractAddress;
|
$this->contractAddress = $transaction->contractAddress;
|
||||||
echo "\nTransaction has mind:) block number: " . $transaction->blockNumber . "\n";
|
echo "\nTransaction has mined:) block number: " . $transaction->blockNumber . "\n";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -744,7 +755,7 @@ class ContractTest extends TestCase
|
|||||||
}
|
}
|
||||||
if ($transaction) {
|
if ($transaction) {
|
||||||
$this->contractAddress = $transaction->contractAddress;
|
$this->contractAddress = $transaction->contractAddress;
|
||||||
echo "\nTransaction has mind:) block number: " . $transaction->blockNumber . "\n";
|
echo "\nTransaction has mined:) block number: " . $transaction->blockNumber . "\n";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -802,7 +813,7 @@ class ContractTest extends TestCase
|
|||||||
}
|
}
|
||||||
if ($transaction) {
|
if ($transaction) {
|
||||||
$this->contractAddress = $transaction->contractAddress;
|
$this->contractAddress = $transaction->contractAddress;
|
||||||
echo "\nTransaction has mind:) block number: " . $transaction->blockNumber . "\n";
|
echo "\nTransaction has mined:) block number: " . $transaction->blockNumber . "\n";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -831,7 +842,7 @@ class ContractTest extends TestCase
|
|||||||
}
|
}
|
||||||
if ($transaction) {
|
if ($transaction) {
|
||||||
$topics = $transaction->logs[0]->topics;
|
$topics = $transaction->logs[0]->topics;
|
||||||
echo "\nTransaction has mind:) block number: " . $transaction->blockNumber . "\n";
|
echo "\nTransaction has mined:) block number: " . $transaction->blockNumber . "\n";
|
||||||
|
|
||||||
// validate topics
|
// validate topics
|
||||||
$this->assertEquals($contract->ethabi->encodeEventSignature($this->contract->events['AddUser']), $topics[0]);
|
$this->assertEquals($contract->ethabi->encodeEventSignature($this->contract->events['AddUser']), $topics[0]);
|
||||||
@ -1116,14 +1127,14 @@ class ContractTest extends TestCase
|
|||||||
}
|
}
|
||||||
if ($transaction) {
|
if ($transaction) {
|
||||||
$contractAddress = $transaction->contractAddress;
|
$contractAddress = $transaction->contractAddress;
|
||||||
echo "\nTransaction has mind:) block number: " . $transaction->blockNumber . "\n";
|
echo "\nTransaction has mined:) block number: " . $transaction->blockNumber . "\n";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$contract->at($contractAddress);
|
$contract->at($contractAddress);
|
||||||
|
|
||||||
foreach ($functions as $function) {
|
foreach ($functions as $function) {
|
||||||
$contract->call($function['name'], [], function ($err, $res) use ($function) {
|
$contract->call($function['name'], [], 'latest', function ($err, $res) use ($function) {
|
||||||
if ($err !== null) {
|
if ($err !== null) {
|
||||||
echo 'Error when call ' . $function['name'] . '. Message: ' . $err->getMessage() . "\n";
|
echo 'Error when call ' . $function['name'] . '. Message: ' . $err->getMessage() . "\n";
|
||||||
return;
|
return;
|
||||||
@ -1137,4 +1148,370 @@ class ContractTest extends TestCase
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testIssue125
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testIssue125()
|
||||||
|
{
|
||||||
|
$bytecode = '0x608060405234801561001057600080fd5b506103bb806100206000396000f3fe608060405260043610610046576000357c01000000000000000000000000000000000000000000000000000000009004806373d4a13a1461004b578063ab62f0e1146100db575b600080fd5b34801561005757600080fd5b506100606101a3565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100a0578082015181840152602081019050610085565b50505050905090810190601f1680156100cd5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156100e757600080fd5b506101a1600480360360208110156100fe57600080fd5b810190808035906020019064010000000081111561011b57600080fd5b82018360208201111561012d57600080fd5b8035906020019184600183028401116401000000008311171561014f57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610241565b005b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102395780601f1061020e57610100808354040283529160200191610239565b820191906000526020600020905b81548152906001019060200180831161021c57829003601f168201915b505050505081565b80600090805190602001906102579291906102ea565b50806040518082805190602001908083835b60208310151561028e5780518252602082019150602081019050602083039250610269565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405180910390207fae08ae866f3211e692b7cdd30e8b6ec658a153397150437cb873f95239953a5460405160405180910390a250565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061032b57805160ff1916838001178555610359565b82800160010185558215610359579182015b8281111561035857825182559160200191906001019061033d565b5b509050610366919061036a565b5090565b61038c91905b80821115610388576000816000905550600101610370565b5090565b9056fea165627a7a72305820bb836a29a397513a3f2e2199520262ef5978d3a3d7e3d3532da41064d39177e30029';
|
||||||
|
$abi = '[
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"name": "_data",
|
||||||
|
"type": "bytes"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "setData",
|
||||||
|
"outputs": [],
|
||||||
|
"payable": false,
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"anonymous": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"indexed": true,
|
||||||
|
"name": "_data",
|
||||||
|
"type": "bytes"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "SetData",
|
||||||
|
"type": "event"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"constant": true,
|
||||||
|
"inputs": [],
|
||||||
|
"name": "data",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"type": "bytes"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"payable": false,
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
}
|
||||||
|
]';
|
||||||
|
$contractAddress = "";
|
||||||
|
|
||||||
|
if (!isset($this->accounts[0])) {
|
||||||
|
$account = '0x407d73d8a49eeb85d32cf465507dd71d507100c1';
|
||||||
|
} else {
|
||||||
|
$account = $this->accounts[0];
|
||||||
|
}
|
||||||
|
$contract = new Contract($this->web3->provider, $abi);
|
||||||
|
$contract->bytecode($bytecode)->new([
|
||||||
|
'from' => $account,
|
||||||
|
'gas' => '0x200b20'
|
||||||
|
], function ($err, $result) use ($contract, &$contractAddress) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
if ($result) {
|
||||||
|
echo "\nTransaction has made:) id: " . $result . "\n";
|
||||||
|
}
|
||||||
|
$transactionId = $result;
|
||||||
|
$this->assertTrue((preg_match('/^0x[a-f0-9]{64}$/', $transactionId) === 1));
|
||||||
|
|
||||||
|
$contract->eth->getTransactionReceipt($transactionId, function ($err, $transaction) use (&$contractAddress) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err);
|
||||||
|
}
|
||||||
|
if ($transaction) {
|
||||||
|
$contractAddress = $transaction->contractAddress;
|
||||||
|
echo "\nTransaction has mined:) block number: " . $transaction->blockNumber . "\n";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$contract->at($contractAddress);
|
||||||
|
|
||||||
|
$contract->call('data', function ($err, $res) {
|
||||||
|
if ($err !== null) {
|
||||||
|
echo 'Error when call ' . $function['name'] . '. Message: ' . $err->getMessage() . "\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->assertEquals('0', $res[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
$contract->send('setData', '0x44aec9b900000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000021000000000000000000000000000000000000000000000000000000000000000b', [
|
||||||
|
'from' => $account,
|
||||||
|
'gas' => '0x200b20'
|
||||||
|
], function ($err, $result) use ($contract) {
|
||||||
|
if ($err !== null) {
|
||||||
|
var_dump('Error' . $err->getMessage());
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
if ($result) {
|
||||||
|
echo "\nTransaction has made:) id: " . $result . "\n";
|
||||||
|
}
|
||||||
|
$transactionId = $result;
|
||||||
|
$this->assertTrue((preg_match('/^0x[a-f0-9]{64}$/', $transactionId) === 1));
|
||||||
|
|
||||||
|
$contract->eth->getTransactionReceipt($transactionId, function ($err, $transaction) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err);
|
||||||
|
}
|
||||||
|
$this->assertTrue($transaction !== null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$contract->call('data', function ($err, $res) {
|
||||||
|
if ($err !== null) {
|
||||||
|
echo 'Error when call ' . $function['name'] . '. Message: ' . $err->getMessage() . "\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->assertEquals('0x44aec9b900000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000021000000000000000000000000000000000000000000000000000000000000000b', $res[0]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testIssue134
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testIssue134()
|
||||||
|
{
|
||||||
|
$bytecode = '0x608060405234801561001057600080fd5b50610487806100206000396000f3fe60806040526004361061005c576000357c01000000000000000000000000000000000000000000000000000000009004806373d4a13a146100615780638381f58a146100f15780639a73c4091461011c578063c3fad957146101ee575b600080fd5b34801561006d57600080fd5b50610076610229565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b657808201518184015260208101905061009b565b50505050905090810190601f1680156100e35780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156100fd57600080fd5b506101066102c7565b6040518082815260200191505060405180910390f35b34801561012857600080fd5b506101ec6004803603604081101561013f57600080fd5b81019080803590602001909291908035906020019064010000000081111561016657600080fd5b82018360208201111561017857600080fd5b8035906020019184600183028401116401000000008311171561019a57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506102cd565b005b3480156101fa57600080fd5b506102276004803603602081101561021157600080fd5b810190808035906020019092919050505061037f565b005b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102bf5780601f10610294576101008083540402835291602001916102bf565b820191906000526020600020905b8154815290600101906020018083116102a257829003601f168201915b505050505081565b60015481565b80600090805190602001906102e39291906103b6565b5081600181905550806040518082805190602001908083835b60208310151561032157805182526020820191506020810190506020830392506102fc565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040518091039020827f95d23dc1ab7ea37e46bd697006b873f80ffecb4cb4ae085c7cc60a977ba7f2f560405160405180910390a35050565b80600181905550807f9d9c58c068c2bc9cb27d4e5c437f624ccbf4910ba8893ffd03ee311830becab160405160405180910390a250565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106103f757805160ff1916838001178555610425565b82800160010185558215610425579182015b82811115610424578251825591602001919060010190610409565b5b5090506104329190610436565b5090565b61045891905b8082111561045457600081600090555060010161043c565b5090565b9056fea165627a7a72305820830ee43c52ac89b1fbc68647e1893aea17aa8ca132532723176508a6bc4586c90029';
|
||||||
|
$abi = '[
|
||||||
|
{
|
||||||
|
"constant": true,
|
||||||
|
"inputs": [],
|
||||||
|
"name": "data",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"type": "bytes"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"payable": false,
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"constant": true,
|
||||||
|
"inputs": [],
|
||||||
|
"name": "number",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"payable": false,
|
||||||
|
"stateMutability": "view",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"name": "_number",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "_data",
|
||||||
|
"type": "bytes"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "say",
|
||||||
|
"outputs": [],
|
||||||
|
"payable": false,
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"name": "_number",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "say",
|
||||||
|
"outputs": [],
|
||||||
|
"payable": false,
|
||||||
|
"stateMutability": "nonpayable",
|
||||||
|
"type": "function"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"anonymous": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"indexed": true,
|
||||||
|
"name": "_number",
|
||||||
|
"type": "uint256"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "Say",
|
||||||
|
"type": "event"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"anonymous": false,
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"indexed": true,
|
||||||
|
"name": "_number",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"indexed": true,
|
||||||
|
"name": "_data",
|
||||||
|
"type": "bytes"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"name": "Say",
|
||||||
|
"type": "event"
|
||||||
|
}
|
||||||
|
]';
|
||||||
|
$testNumber = 16;
|
||||||
|
$testData = "0x01234";
|
||||||
|
$contractAddress = "";
|
||||||
|
$contract = new Contract($this->web3->provider, $abi);
|
||||||
|
|
||||||
|
if (!isset($this->accounts[0])) {
|
||||||
|
$account = '0x407d73d8a49eeb85d32cf465507dd71d507100c1';
|
||||||
|
} else {
|
||||||
|
$account = $this->accounts[0];
|
||||||
|
}
|
||||||
|
$contract = new Contract($this->web3->provider, $abi);
|
||||||
|
$contract->bytecode($bytecode)->new([
|
||||||
|
'from' => $account,
|
||||||
|
'gas' => '0x200b20'
|
||||||
|
], function ($err, $result) use ($contract, &$contractAddress) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
if ($result) {
|
||||||
|
echo "\nTransaction has made:) id: " . $result . "\n";
|
||||||
|
}
|
||||||
|
$transactionId = $result;
|
||||||
|
$this->assertTrue((preg_match('/^0x[a-f0-9]{64}$/', $transactionId) === 1));
|
||||||
|
|
||||||
|
$contract->eth->getTransactionReceipt($transactionId, function ($err, $transaction) use (&$contractAddress) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err);
|
||||||
|
}
|
||||||
|
if ($transaction) {
|
||||||
|
$contractAddress = $transaction->contractAddress;
|
||||||
|
echo "\nTransaction has mined:) block number: " . $transaction->blockNumber . "\n";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$contract->at($contractAddress);
|
||||||
|
|
||||||
|
// test for send transaction and get data
|
||||||
|
$contract->send('say', $testNumber, $testData, [
|
||||||
|
'from' => $account,
|
||||||
|
'gas' => '0x200b20'
|
||||||
|
], function ($err, $result) use ($contract, $testNumber, $testData) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
if ($result) {
|
||||||
|
echo "\nTransaction has made:) id: " . $result . "\n";
|
||||||
|
}
|
||||||
|
$transactionId = $result;
|
||||||
|
$this->assertTrue((preg_match('/^0x[a-f0-9]{64}$/', $transactionId) === 1));
|
||||||
|
|
||||||
|
$contract->eth->getTransactionReceipt($transactionId, function ($err, $transaction) use ($testNumber, $testData, $contract) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err);
|
||||||
|
}
|
||||||
|
if ($transaction) {
|
||||||
|
$topics = $transaction->logs[0]->topics;
|
||||||
|
echo "\nTransaction has mined:) block number: " . $transaction->blockNumber . "\n";
|
||||||
|
|
||||||
|
// validate topics
|
||||||
|
$this->assertEquals($contract->ethabi->encodeEventSignature($contract->events['Say']), $topics[0]);
|
||||||
|
$this->assertEquals('0x' . IntegerFormatter::format($testNumber), $topics[1], $topics[2]);
|
||||||
|
}
|
||||||
|
$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());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$testNumber++;
|
||||||
|
|
||||||
|
$contract->send('say', $testNumber, [
|
||||||
|
'from' => $account,
|
||||||
|
'gas' => '0x200b20'
|
||||||
|
], function ($err, $result) use ($contract, $testNumber) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
if ($result) {
|
||||||
|
echo "\nTransaction has made:) id: " . $result . "\n";
|
||||||
|
}
|
||||||
|
$transactionId = $result;
|
||||||
|
$this->assertTrue((preg_match('/^0x[a-f0-9]{64}$/', $transactionId) === 1));
|
||||||
|
|
||||||
|
$contract->eth->getTransactionReceipt($transactionId, function ($err, $transaction) use ($testNumber, $contract) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err);
|
||||||
|
}
|
||||||
|
if ($transaction) {
|
||||||
|
$topics = $transaction->logs[0]->topics;
|
||||||
|
echo "\nTransaction has mined:) block number: " . $transaction->blockNumber . "\n";
|
||||||
|
|
||||||
|
// validate topics
|
||||||
|
// $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) {
|
||||||
|
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());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// test for estimate gas
|
||||||
|
$contract->estimateGas("say", $testNumber, $testData, [
|
||||||
|
'from' => $account,
|
||||||
|
'gas' => '0x200b20'
|
||||||
|
], function ($err, $result) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
if (isset($result)) {
|
||||||
|
echo "\nEstimate gas: " . $result->toString() . "\n";
|
||||||
|
$this->assertTrue($result !== null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$contract->estimateGas("say", $testNumber, [
|
||||||
|
'from' => $account,
|
||||||
|
'gas' => '0x200b20'
|
||||||
|
], function ($err, $result) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail($err->getMessage());
|
||||||
|
}
|
||||||
|
if (isset($result)) {
|
||||||
|
echo "\nEstimate gas: " . $result->toString() . "\n";
|
||||||
|
$this->assertTrue($result !== null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
@ -53,7 +53,7 @@ class DynamicBytesTypeTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->solidityType = new DynamicBytes;
|
$this->solidityType = new DynamicBytes;
|
||||||
|
@ -21,7 +21,7 @@ class EthApiTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
@ -439,7 +439,7 @@ class EthApiTest extends TestCase
|
|||||||
if ($err !== null) {
|
if ($err !== null) {
|
||||||
return $this->assertTrue($err !== null);
|
return $this->assertTrue($err !== null);
|
||||||
}
|
}
|
||||||
// weired behavior, see https://github.com/sc0Vu/web3.php/issues/16
|
// weird behavior, see https://github.com/web3p/web3.php/issues/16
|
||||||
$this->assertTrue($block !== null);
|
$this->assertTrue($block !== null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -457,7 +457,7 @@ class EthApiTest extends TestCase
|
|||||||
if ($err !== null) {
|
if ($err !== null) {
|
||||||
return $this->assertTrue($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) {
|
if ($err !== null) {
|
||||||
return $this->assertTrue($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) {
|
if ($err !== null) {
|
||||||
return $this->assertTrue($err !== null);
|
return $this->assertTrue($err !== null);
|
||||||
}
|
}
|
||||||
$this->assertTrue($transaction !== null);
|
$this->assertTrue($transaction == null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,24 +546,6 @@ 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
|
* testCompileSolidity
|
||||||
*
|
*
|
||||||
@ -647,7 +629,7 @@ class EthApiTest extends TestCase
|
|||||||
{
|
{
|
||||||
$eth = $this->eth;
|
$eth = $this->eth;
|
||||||
|
|
||||||
$eth->newBlockFilter('0x01', function ($err, $filter) {
|
$eth->newBlockFilter(function ($err, $filter) {
|
||||||
if ($err !== null) {
|
if ($err !== null) {
|
||||||
// infura banned us to new block filter
|
// infura banned us to new block filter
|
||||||
return $this->assertTrue($err !== null);
|
return $this->assertTrue($err !== null);
|
||||||
|
@ -20,7 +20,7 @@ class EthBatchTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class EthTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ class EthabiTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
// Error: Using $this when not in object context
|
// Error: Using $this when not in object context
|
||||||
@ -298,7 +298,7 @@ class EthabiTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* testIssue71
|
* testIssue71
|
||||||
* test 33 bytes and 128 bytes string, see: https://github.com/sc0Vu/web3.php/issues/71
|
* test 33 bytes and 128 bytes string, see: https://github.com/web3p/web3.php/issues/71
|
||||||
* string generated from: https://www.lipsum.com/
|
* string generated from: https://www.lipsum.com/
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
@ -19,7 +19,7 @@ class FilterValidatorTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->validator = new FilterValidator;
|
$this->validator = new FilterValidator;
|
||||||
|
@ -19,7 +19,7 @@ class HexFormatterTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->formatter = new HexFormatter;
|
$this->formatter = new HexFormatter;
|
||||||
|
@ -19,7 +19,7 @@ class HexValidatorTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->validator = new HexValidator;
|
$this->validator = new HexValidator;
|
||||||
|
@ -19,7 +19,7 @@ class IdentityValidatorTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->validator = new IdentityValidator;
|
$this->validator = new IdentityValidator;
|
||||||
|
@ -19,7 +19,7 @@ class IntegerFormatterTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->formatter = new IntegerFormatter;
|
$this->formatter = new IntegerFormatter;
|
||||||
|
@ -53,7 +53,7 @@ class IntegerTypeTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->solidityType = new Integer;
|
$this->solidityType = new Integer;
|
||||||
|
@ -21,7 +21,7 @@ class NetApiTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ class NetBatchTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class NetTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class NonceValidatorTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->validator = new NonceValidator;
|
$this->validator = new NonceValidator;
|
||||||
|
@ -19,7 +19,7 @@ class NumberFormatterTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->formatter = new NumberFormatter;
|
$this->formatter = new NumberFormatter;
|
||||||
|
@ -19,7 +19,7 @@ class OptionalQuantityFormatterTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->formatter = new OptionalQuantityFormatter;
|
$this->formatter = new OptionalQuantityFormatter;
|
||||||
@ -55,6 +55,8 @@ class OptionalQuantityFormatterTest extends TestCase
|
|||||||
$this->assertEquals('latest', $formatter->format('latest'));
|
$this->assertEquals('latest', $formatter->format('latest'));
|
||||||
$this->assertEquals('earliest', $formatter->format('earliest'));
|
$this->assertEquals('earliest', $formatter->format('earliest'));
|
||||||
$this->assertEquals('pending', $formatter->format('pending'));
|
$this->assertEquals('pending', $formatter->format('pending'));
|
||||||
$this->assertEquals('0x0', $formatter->format('hello'));
|
|
||||||
|
$this->expectExceptionMessage('toBn number must be valid hex string.');
|
||||||
|
$formatter->format('hello');
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,7 +27,7 @@ class PersonalApiTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
@ -121,6 +121,39 @@ 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
|
* testSendTransaction
|
||||||
*
|
*
|
||||||
|
@ -19,7 +19,7 @@ class PersonalBatchTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class PersonalTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class PostFormatterTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->formatter = new PostFormatter;
|
$this->formatter = new PostFormatter;
|
||||||
|
@ -19,7 +19,7 @@ class PostValidatorTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->validator = new PostValidator;
|
$this->validator = new PostValidator;
|
||||||
|
@ -19,7 +19,7 @@ class QuantityFormatterTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->formatter = new QuantityFormatter;
|
$this->formatter = new QuantityFormatter;
|
||||||
|
@ -19,7 +19,7 @@ class QuantityValidatorTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->validator = new QuantityValidator;
|
$this->validator = new QuantityValidator;
|
||||||
|
@ -21,7 +21,7 @@ class ShhApiTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class ShhBatchTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class ShhFilterValidatorTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->validator = new ShhFilterValidator;
|
$this->validator = new ShhFilterValidator;
|
||||||
|
@ -23,7 +23,7 @@ class ShhTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ class SolidityTypeTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->type = new SolidityType();
|
$this->type = new SolidityType();
|
||||||
|
@ -47,7 +47,7 @@ class StrTypeTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->solidityType = new Str;
|
$this->solidityType = new Str;
|
||||||
|
@ -19,7 +19,7 @@ class StringFormatterTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->formatter = new StringFormatter;
|
$this->formatter = new StringFormatter;
|
||||||
|
@ -19,7 +19,7 @@ class StringValidatorTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->validator = new StringValidator;
|
$this->validator = new StringValidator;
|
||||||
|
@ -19,7 +19,7 @@ class TagValidatorTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->validator = new TagValidator;
|
$this->validator = new TagValidator;
|
||||||
|
@ -19,7 +19,7 @@ class TransactionFormatterTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->formatter = new TransactionFormatter;
|
$this->formatter = new TransactionFormatter;
|
||||||
|
@ -19,7 +19,7 @@ class TransactionValidatorTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->validator = new TransactionValidator;
|
$this->validator = new TransactionValidator;
|
||||||
|
@ -53,7 +53,7 @@ class UintegerTypeTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->solidityType = new Uinteger;
|
$this->solidityType = new Uinteger;
|
||||||
|
@ -7,6 +7,7 @@ use stdClass;
|
|||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
use phpseclib\Math\BigInteger as BigNumber;
|
use phpseclib\Math\BigInteger as BigNumber;
|
||||||
use Web3\Utils;
|
use Web3\Utils;
|
||||||
|
use Web3\Contract;
|
||||||
|
|
||||||
class UtilsTest extends TestCase
|
class UtilsTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -52,12 +53,91 @@ 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
|
* setUp
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
@ -169,7 +249,7 @@ class UtilsTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* testIsAddressChecksum
|
* testIsAddressChecksum
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testIsAddressChecksum()
|
public function testIsAddressChecksum()
|
||||||
@ -211,9 +291,36 @@ class UtilsTest extends TestCase
|
|||||||
$isAddressChecksum = Utils::isAddressChecksum(new stdClass);
|
$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
|
* testStripZero
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testStripZero()
|
public function testStripZero()
|
||||||
@ -252,82 +359,58 @@ class UtilsTest extends TestCase
|
|||||||
public function testToWei()
|
public function testToWei()
|
||||||
{
|
{
|
||||||
$bn = Utils::toWei('0x1', 'wei');
|
$bn = Utils::toWei('0x1', 'wei');
|
||||||
$this->assertEquals($bn->toString(), '1');
|
$this->assertEquals('1', $bn->toString());
|
||||||
|
|
||||||
$bn = Utils::toWei('18', 'wei');
|
$bn = Utils::toWei('18', 'wei');
|
||||||
$this->assertEquals($bn->toString(), '18');
|
$this->assertEquals('18', $bn->toString());
|
||||||
|
|
||||||
$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');
|
$bn = Utils::toWei('1', 'ether');
|
||||||
$this->assertEquals($bn->toString(), '1000000000000000000');
|
$this->assertEquals('1000000000000000000', $bn->toString());
|
||||||
|
|
||||||
$bn = Utils::toWei('0x5218', 'wei');
|
$bn = Utils::toWei('0x5218', 'wei');
|
||||||
$this->assertEquals($bn->toString(), '21016');
|
$this->assertEquals('21016', $bn->toString());
|
||||||
|
|
||||||
|
$bn = Utils::toWei('0.000012', 'ether');
|
||||||
|
$this->assertEquals('12000000000000', $bn->toString());
|
||||||
|
|
||||||
$bn = Utils::toWei('0.1', 'ether');
|
$bn = Utils::toWei('0.1', 'ether');
|
||||||
$this->assertEquals($bn->toString(), '100000000000000000');
|
$this->assertEquals('100000000000000000', $bn->toString());
|
||||||
|
|
||||||
$bn = Utils::toWei('1.69', 'ether');
|
$bn = Utils::toWei('1.69', 'ether');
|
||||||
$this->assertEquals($bn->toString(), '1690000000000000000');
|
$this->assertEquals('1690000000000000000', $bn->toString());
|
||||||
|
|
||||||
$bn = Utils::toWei('0.01', 'ether');
|
$bn = Utils::toWei('0.01', 'ether');
|
||||||
$this->assertEquals($bn->toString(), '10000000000000000');
|
$this->assertEquals('10000000000000000', $bn->toString());
|
||||||
|
|
||||||
$bn = Utils::toWei('0.002', 'ether');
|
$bn = Utils::toWei('0.002', 'ether');
|
||||||
$this->assertEquals($bn->toString(), '2000000000000000');
|
$this->assertEquals('2000000000000000', $bn->toString());
|
||||||
|
|
||||||
$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(0.01, 'ether');
|
|
||||||
$this->assertEquals($bn->toString(), '10000000000000000');
|
|
||||||
|
|
||||||
$bn = Utils::toWei(0.002, 'ether');
|
|
||||||
$this->assertEquals($bn->toString(), '2000000000000000');
|
|
||||||
|
|
||||||
$bn = Utils::toWei('-0.1', 'ether');
|
$bn = Utils::toWei('-0.1', 'ether');
|
||||||
$this->assertEquals($bn->toString(), '-100000000000000000');
|
$this->assertEquals('-100000000000000000', $bn->toString());
|
||||||
|
|
||||||
$bn = Utils::toWei('-1.69', 'ether');
|
$bn = Utils::toWei('-1.69', 'ether');
|
||||||
$this->assertEquals($bn->toString(), '-1690000000000000000');
|
$this->assertEquals('-1690000000000000000', $bn->toString());
|
||||||
|
|
||||||
$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');
|
$bn = Utils::toWei('', 'ether');
|
||||||
$this->assertEquals($bn->toString(), '0');
|
$this->assertEquals('0', $bn->toString());
|
||||||
|
|
||||||
$bn = Utils::toWei(-1.697, 'kwei');
|
|
||||||
$this->assertEquals($bn->toString(), '-1697');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$bn = Utils::toWei('0x5218', new stdClass);
|
$bn = Utils::toWei('0x5218', new stdClass);
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
$this->assertTrue($e !== null);
|
$this->assertEquals('toWei unit must be string.', $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$bn = Utils::toWei('0x5218', 'test');
|
$bn = Utils::toWei('0x5218', 'test');
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
$this->assertTrue($e !== null);
|
$this->assertEquals('toWei doesn\'t support test unit.', $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// out of limit
|
// out of limit
|
||||||
$bn = Utils::toWei(-1.6977, 'kwei');
|
$bn = Utils::toWei(-1.6977, 'kwei');
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
$this->assertTrue($e !== null);
|
$this->assertEquals('toWei number must be string or bignumber.', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,16 +431,6 @@ class UtilsTest extends TestCase
|
|||||||
$this->assertEquals($bnq->toString(), '0');
|
$this->assertEquals($bnq->toString(), '0');
|
||||||
$this->assertEquals($bnr->toString(), '18');
|
$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');
|
list($bnq, $bnr) = Utils::toEther('1', 'kether');
|
||||||
|
|
||||||
$this->assertEquals($bnq->toString(), '1000');
|
$this->assertEquals($bnq->toString(), '1000');
|
||||||
@ -452,39 +525,16 @@ class UtilsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testJsonToArray()
|
public function testJsonToArray()
|
||||||
{
|
{
|
||||||
$json = json_decode($this->testJsonMethodString);
|
$decodedJson = json_decode($this->testJsonMethodString);
|
||||||
$jsonArrayDepth1 = Utils::jsonToArray($json);
|
$jsonArray = Utils::jsonToArray($decodedJson);
|
||||||
|
|
||||||
$this->assertEquals($jsonArrayDepth1, (array) $json);
|
|
||||||
|
|
||||||
$jsonAssoc = json_decode($this->testJsonMethodString, true);
|
$jsonAssoc = json_decode($this->testJsonMethodString, true);
|
||||||
$jsonArrayDepth2 = Utils::jsonToArray($json, 2);
|
$jsonArray2 = Utils::jsonToArray($jsonAssoc);
|
||||||
|
$this->assertEquals($jsonAssoc, $jsonArray);
|
||||||
|
$this->assertEquals($jsonAssoc, $jsonArray2);
|
||||||
|
|
||||||
$this->assertEquals($jsonArrayDepth2, $jsonAssoc);
|
$jsonAssoc = json_decode($this->testIssue112Json, true);
|
||||||
|
$jsonArray = Utils::jsonToArray($jsonAssoc);
|
||||||
$jsonArrayDepth2 = Utils::jsonToArray($jsonArrayDepth1, 2);
|
$this->assertEquals($jsonAssoc, $jsonArray);
|
||||||
$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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,7 +29,7 @@ class Web3ApiTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class Web3BatchTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ class Web3Test extends TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user