Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev-2.3' into dev-2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshihitoAso committed Mar 12, 2024
2 parents 542511b + d272064 commit 2808c12
Show file tree
Hide file tree
Showing 17 changed files with 2,000 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: format isort black test

install:
pip install -r tests/requirements.txt
cd tests && poetry install --no-root --sync

format: isort black

Expand All @@ -12,4 +12,4 @@ black:
black .

test:
pytest tests/ ${ARG}
cd tests && poetry run pytest -vv . ${ARG}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SPDX-License-Identifier: Apache-2.0
"""

import logging
import os
import sys
Expand Down
1 change: 1 addition & 0 deletions ibet-network/general/monitoring/monitor_block_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SPDX-License-Identifier: Apache-2.0
"""

import logging
import os
import sys
Expand Down
1 change: 1 addition & 0 deletions local-network/general/monitoring/monitor_block_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SPDX-License-Identifier: Apache-2.0
"""

import logging
import os
import sys
Expand Down
1 change: 1 addition & 0 deletions test-network/general/monitoring/monitor_block_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SPDX-License-Identifier: Apache-2.0
"""

import logging
import os
import sys
Expand Down
1 change: 1 addition & 0 deletions tests/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.python-version
38 changes: 24 additions & 14 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:20.04
FROM ubuntu:22.04

# make application directory
RUN mkdir -p /app/ibet-Network/
Expand Down Expand Up @@ -30,7 +30,8 @@ RUN apt-get update -q \
language-pack-ja \
git \
curl \
libyaml-cpp-dev
libyaml-cpp-dev \
liblzma-dev

# remove unnessesory package files
RUN apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
Expand All @@ -48,23 +49,32 @@ RUN echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~apl/.bash_profile \
# install python
USER apl
RUN . ~/.bash_profile \
&& pyenv install 3.8.7 \
&& pyenv global 3.8.7 \
&& pip install --upgrade pip
&& pyenv install 3.11.2 \
&& pyenv global 3.11.2 \
&& pip install --upgrade pip setuptools

# install poetry
RUN . ~/.bash_profile \
&& python -m pip install poetry==1.7.1
RUN . ~/.bash_profile \
&& poetry config virtualenvs.create false

# install python packages
USER root
COPY . /app/ibet-Network/tests
RUN chown -R apl:apl /app/ibet-Network/tests \
&& find /app/ibet-Network/tests/ -type d -name __pycache__ | xargs rm -fr \
&& chmod 755 /app/ibet-Network/tests

# install python packages
USER apl
COPY tests/requirements.txt /app/requirements.txt
RUN . ~/.bash_profile \
&& pip install -r /app/requirements.txt \
&& rm -f /app/requirements.txt
&& cd /app/ibet-Network/tests \
&& poetry install --no-root \
&& rm -f /app/ibet-Network/tests/pyproject.toml \
&& rm -f /app/ibet-Network/tests/poetry.lock

# app deploy
USER root
RUN mkdir -p /app/ibet-Network/tests/
COPY --chown=apl:apl tests/ /app/ibet-Network/tests/
RUN find /app/ibet-Network/ -type d -name __pycache__ | xargs rm -fr \
&& chmod -R 755 /app/ibet-Network/
ENV PYTHONPATH /app/ibet-Network/tests

USER apl
CMD tail -f /dev/null
1 change: 1 addition & 0 deletions tests/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SPDX-License-Identifier: Apache-2.0
"""

import json
import os
import sys
Expand Down
3 changes: 2 additions & 1 deletion tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
SPDX-License-Identifier: Apache-2.0
"""

import os

# Used common
ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"
CONTRACT_PATH = "tests/contracts"
CONTRACT_PATH = f"{os.path.dirname(__file__)}/contracts"
CONTRACT_NAME = "E2ETest"
ACCOUNT_NAME = "test_user"
ACCOUNT_PASSWORD = "password"
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SPDX-License-Identifier: Apache-2.0
"""

import logging
import os
import sys
Expand Down
1 change: 1 addition & 0 deletions tests/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SPDX-License-Identifier: Apache-2.0
"""

import os
import sys

Expand Down
89 changes: 87 additions & 2 deletions tests/e2e_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
SPDX-License-Identifier: Apache-2.0
"""

import pytest
from eth_utils import to_checksum_address
from eth_utils import keccak, to_checksum_address
from web3 import Web3
from web3.datastructures import AttributeDict
from web3.exceptions import ContractLogicError
from web3.exceptions import ContractLogicError, TimeExhausted
from web3.middleware import geth_poa_middleware

from tests.config import (
Expand Down Expand Up @@ -508,3 +509,87 @@ def test_error_4(self):
args = []
with pytest.raises(ContractLogicError):
_ = _function(*args).call()

# <Error_5>
# Occur ERROR
# Nonce too low
def test_error_5(self, contract):
args = [
False,
"0x0123456789ABCDeF0123456789aBcdEF01234568",
"test text2",
4,
8,
b"456789abcdefghijklmnopqrstuvwxyz",
]
tx = contract.functions.setItem2(*args, 0).build_transaction(
transaction={
"chainId": CHAIN_ID,
"from": TestAccount.address,
"gas": TX_GAS_LIMIT,
"gasPrice": 0,
}
)

# Get nonce
nonce = web3.eth.get_transaction_count(TestAccount.address)
tx["nonce"] = nonce
signed_tx = web3.eth.account.sign_transaction(
transaction_dict=tx, private_key=TestAccount.private_key
)

# Send Transaction (1): success
tx_hash = web3.eth.send_raw_transaction(signed_tx.rawTransaction.hex())
txn_receipt = web3.eth.wait_for_transaction_receipt(
transaction_hash=tx_hash, timeout=10
)
calculated_tx_hash = keccak(signed_tx.rawTransaction)
assert tx_hash == calculated_tx_hash
assert tx_hash == txn_receipt["transactionHash"]

# Send Transaction (2): nonce too low
with pytest.raises(
ValueError, match="{'code': -32000, 'message': 'nonce too low'}"
):
_ = web3.eth.send_raw_transaction(signed_tx.rawTransaction.hex())

# <Error_6>
# Occur ERROR
# Already known
def test_error_6(self, contract):
args = [
False,
"0x0123456789ABCDeF0123456789aBcdEF01234568",
"test text2",
4,
8,
b"456789abcdefghijklmnopqrstuvwxyz",
]
tx = contract.functions.setItem2(*args, 0).build_transaction(
transaction={
"chainId": CHAIN_ID,
"from": TestAccount.address,
"gas": TX_GAS_LIMIT,
"gasPrice": 0,
}
)

# Get nonce
nonce = web3.eth.get_transaction_count(TestAccount.address)
tx["nonce"] = nonce + 1
signed_tx = web3.eth.account.sign_transaction(
transaction_dict=tx, private_key=TestAccount.private_key
)

# Send Transaction (1): sent but not executed
tx_hash = web3.eth.send_raw_transaction(signed_tx.rawTransaction.hex())
with pytest.raises(TimeExhausted):
_ = web3.eth.wait_for_transaction_receipt(
transaction_hash=tx_hash, timeout=10
)

# Send Transaction (2): already known
with pytest.raises(
ValueError, match="{'code': -32000, 'message': 'already known'}"
):
_ = web3.eth.send_raw_transaction(signed_tx.rawTransaction.hex())
8 changes: 4 additions & 4 deletions tests/e2e_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This document describes how to run network end-to-end non-degrade tests.

- Need to set up a `local-network` beforehand (see [instructions](https://github.com/BoostryJP/ibet-Network/tree/develop/local-network)).
- E2E tests are run using pytest. Therefore, Python runtime environment is required.
- 3.9 or greater.
- 3.11 or greater.

## Setting environment variables

Expand All @@ -20,7 +20,7 @@ This document describes how to run network end-to-end non-degrade tests.
### Install python packages

```shell
$ pip install -r tests/requirements.txt
$ make install
```

### Compile the test contract
Expand All @@ -30,7 +30,7 @@ The contract code to be tested is `tests/contracts/E2ETest.sol`.
Compile the contract code.

````shell
$ python tests/compile.py
$ poetry run python tests/compile.py
````

After successful completion, `E2ETest.json` will be created in tests/contracts.
Expand All @@ -48,5 +48,5 @@ $ export DEPLOYED_CONTRACT_ADDRESS=0x79448CB02a0F8cff71005963075187aAD9a050f3
### Running the e2e tests

```shell
$ pytest tests/
$ poetry run pytest tests/
```
Loading

0 comments on commit 2808c12

Please sign in to comment.