mirror of
https://github.com/chaintool-py/eth-erc20.git
synced 2026-04-27 12:51:05 +02:00
Add previously missing files
This commit is contained in:
25
python/tests/conftest.py
Normal file
25
python/tests/conftest.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# standard imports
|
||||
import os
|
||||
|
||||
# external imports
|
||||
import pytest
|
||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def keystore():
|
||||
ks = DictKeystore()
|
||||
|
||||
pk = os.urandom(32)
|
||||
ks.import_raw_key(pk)
|
||||
return ks
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def signer(
|
||||
keystore,
|
||||
):
|
||||
|
||||
s = EIP155Signer(keystore)
|
||||
return s
|
||||
74
python/tests/test_erc20.py
Normal file
74
python/tests/test_erc20.py
Normal file
@@ -0,0 +1,74 @@
|
||||
# standard imports
|
||||
import logging
|
||||
import os
|
||||
|
||||
# external imports
|
||||
from hexathon import (
|
||||
strip_0x,
|
||||
add_0x,
|
||||
)
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
from chainlib.eth.tx import (
|
||||
unpack,
|
||||
TxFormat,
|
||||
)
|
||||
from chainlib.eth.pytest import *
|
||||
|
||||
# local imports
|
||||
from eth_erc20 import ERC20
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
contract_address = to_checksum_address('0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef')
|
||||
benefactor_address = to_checksum_address('0xefdeadbeefdeadbeefdeadbeefdeadbeefdeadbe')
|
||||
|
||||
|
||||
# TODO: use unittest instead
|
||||
def test_erc20_balance(
|
||||
default_chain_spec,
|
||||
):
|
||||
e = ERC20(default_chain_spec,)
|
||||
|
||||
holder_address = to_checksum_address('0xbeefdeadbeefdeadbeefdeadbeefdeadbeefdead')
|
||||
o = e.balance_of(contract_address, holder_address)
|
||||
assert len(o['params'][0]['data']) == 64 + 8 + 2
|
||||
assert o['params'][0]['data'][:10] == add_0x('70a08231')
|
||||
|
||||
|
||||
def test_erc20_decimals(
|
||||
default_chain_spec,
|
||||
):
|
||||
e = ERC20(default_chain_spec)
|
||||
|
||||
o = e.decimals(contract_address)
|
||||
assert o['params'][0]['data'] == add_0x('313ce567')
|
||||
|
||||
|
||||
def test_erc20_transfer(
|
||||
keystore,
|
||||
signer,
|
||||
default_chain_spec,
|
||||
):
|
||||
e = ERC20(default_chain_spec, signer=signer)
|
||||
|
||||
addresses = keystore.list()
|
||||
(tx_hash_hex, o) = e.transfer(contract_address, addresses[0], benefactor_address, 1024)
|
||||
|
||||
|
||||
def test_erc20_parse_transfer_request(
|
||||
keystore,
|
||||
signer,
|
||||
default_chain_spec,
|
||||
):
|
||||
|
||||
e = ERC20(default_chain_spec, signer=signer)
|
||||
|
||||
addresses = keystore.list()
|
||||
(tx_hash_hex, o) = e.transfer(contract_address, addresses[0], benefactor_address, 1024, tx_format=TxFormat.RLP_SIGNED)
|
||||
b = bytes.fromhex(strip_0x(o))
|
||||
|
||||
#chain_spec = ChainSpec('evm', 'foo', 1, 'bar')
|
||||
tx = unpack(b, default_chain_spec)
|
||||
r = ERC20.parse_transfer_request(tx['data'])
|
||||
assert r[0] == benefactor_address
|
||||
assert r[1] == 1024
|
||||
Reference in New Issue
Block a user