Compare commits

..

4 Commits

Author SHA1 Message Date
lash
5dfd3db2d3
Fix pysha break 2024-04-02 12:43:20 +01:00
lash
54759c3428
Update deps 2023-08-06 16:14:01 +01:00
lash
637080c464
Factor out token publish in giftable token unittest fixture 2023-07-27 07:36:33 +01:00
lash
2fb7143956
Add unittest for static token 2023-06-29 20:55:52 +01:00
14 changed files with 172 additions and 31 deletions

4
.gitignore vendored
View File

@ -5,4 +5,6 @@ build/
gmon.out
*.egg-info
.venv/
.idea
.idea
solidity/*.json
solidity/*.bin

View File

@ -1,3 +1,5 @@
* 0.7.5
- Factor out token publish method in unittest fixture
* 0.7.4
- Add missing unittest module to python package
* 0.7.3

View File

@ -100,16 +100,6 @@ def main():
decimals = int(strip_0x(r), 16)
logg.info('decimals {}'.format(decimals))
# name_o = g.name(token_address, sender_address=sender_address)
# r = conn.do(name_o)
# token_name = g.parse_name(r)
# logg.info('name {}'.format(token_name))
#
# symbol_o = g.symbol(token_address, sender_address=sender_address)
# r = conn.do(symbol_o)
# token_symbol = g.parse_symbol(r)
# logg.info('symbol {}'.format(token_symbol))
# get balance
balance_o = g.balance(token_address, settings.get('RECIPIENT'), sender_address=sender_address)
r = conn.do(balance_o)

View File

@ -12,7 +12,6 @@ from chainlib.eth.tx import (
from hexathon import strip_0x
# local imports
from giftable_erc20_token.unittest import TestGiftableToken
from eth_erc20 import ERC20
logging.basicConfig(level=logging.DEBUG)
@ -53,12 +52,13 @@ class TestInterface:
self.assertEqual(self.symbol, symbol)
def test_transfer(self):
def test_direct_transfer(self):
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
gas_oracle = OverrideGasOracle(limit=100000, conn=self.conn)
c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
(tx_hash, o) = c.transfer(self.address, self.accounts[0], self.accounts[1], 1000)
r = self.rpc.do(o)
self.rpc.do(o)
o = receipt(tx_hash)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
@ -85,7 +85,7 @@ class TestInterface:
gas_oracle = OverrideGasOracle(limit=100000, conn=self.conn)
c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
(tx_hash, o) = c.approve(self.address, self.accounts[0], self.accounts[1], 1000)
r = self.rpc.do(o)
self.rpc.do(o)
o = receipt(tx_hash)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)

View File

@ -22,19 +22,11 @@ class TestGiftableToken(EthTesterCase):
def setUp(self):
super(TestGiftableToken, self).setUp()
self.conn = RPCConnection.connect(self.chain_spec, 'default')
address = self.publish_giftable_token('Foo Token', 'FOO', 16, expire=self.expire)
self.address = to_checksum_address(address)
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
self.symbol = 'FOO'
self.name = 'Foo Token'
self.decimals = 16
(tx_hash, o) = c.constructor(self.accounts[0], self.name, self.symbol, self.decimals, expire=self.expire)
self.rpc.do(o)
o = receipt(tx_hash)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
self.address = to_checksum_address(r['contract_address'])
logg.debug('published on address {} with hash {}'.format(self.address, tx_hash))
self.initial_supply = 1 << 40
(tx_hash, o) = c.mint_to(self.address, self.accounts[0], self.accounts[0], self.initial_supply)
r = self.conn.do(o)
@ -43,6 +35,22 @@ class TestGiftableToken(EthTesterCase):
self.assertEqual(r['status'], 1)
def publish_giftable_token(self, name, symbol, decimals=16, expire=None):
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
c = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
self.symbol = name
self.name = symbol
self.decimals = decimals
(tx_hash, o) = c.constructor(self.accounts[0], self.name, self.symbol, self.decimals, expire=expire)
self.rpc.do(o)
o = receipt(tx_hash)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
address = r['contract_address']
logg.debug('published on address {} with hash {}'.format(address, tx_hash))
return address
class TestGiftableExpireToken(TestGiftableToken):
expire = int(time.time()) + 100000

View File

@ -1,4 +1,4 @@
confini~=0.6.1
chainlib-eth~=0.4.17
chainlib~=0.4.12
chainlib-eth~=0.6.0
chainlib~=0.5.0
potaahto~=0.1.1

View File

@ -1,6 +1,6 @@
[metadata]
name = eth-erc20
version = 0.7.4
version = 0.9.0
description = ERC20 interface and simple contract with deployment script that lets any address mint and gift itself tokens.
author = Louis Holbrook
author_email = dev@holbrook.no

View File

@ -0,0 +1 @@
from .factory import *

View File

@ -0,0 +1,3 @@
import os
data_dir = os.path.realpath(os.path.dirname(__file__))

View File

@ -0,0 +1,60 @@
# standard imports
import os
import logging
# external imports
from chainlib.eth.tx import (
TxFactory,
TxFormat,
)
from chainlib.hash import keccak256_string_to_hex
from chainlib.eth.contract import (
ABIContractEncoder,
ABIContractType,
)
# local imports
from static_token.data import data_dir
logg = logging.getLogger(__name__)
class StaticToken(TxFactory):
__abi = None
__bytecode = None
def constructor(self, sender_address, name, symbol, decimals, supply, tx_format=TxFormat.JSONRPC):
code = StaticToken.bytecode()
enc = ABIContractEncoder()
enc.string(name)
enc.string(symbol)
enc.uint256(decimals)
enc.uint256(supply)
code += enc.get()
tx = self.template(sender_address, None, use_nonce=True)
tx = self.set_code(tx, code)
return self.finalize(tx, tx_format)
@staticmethod
def gas(code=None):
return 2000000
@staticmethod
def abi():
if StaticToken.__abi == None:
f = open(os.path.join(data_dir, 'StaticToken.json'), 'r')
StaticToken.__abi = json.load(f)
f.close()
return StaticToken.__abi
@staticmethod
def bytecode():
if StaticToken.__bytecode == None:
f = open(os.path.join(data_dir, 'StaticToken.bin'))
StaticToken.__bytecode = f.read()
f.close()
return StaticToken.__bytecode

View File

@ -0,0 +1 @@
from .base import TestStaticToken

View File

@ -0,0 +1,36 @@
# standard imports
import logging
import time
# external imports
from chainlib.eth.unittest.ethtester import EthTesterCase
from chainlib.connection import RPCConnection
from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.tx import receipt
from chainlib.eth.address import to_checksum_address
# local imports
from static_token import StaticToken
from eth_erc20.unittest import TestInterface
logg = logging.getLogger(__name__)
class TestStaticToken(EthTesterCase, TestInterface):
def setUp(self):
super(TestStaticToken, self).setUp()
self.conn = RPCConnection.connect(self.chain_spec, 'default')
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
c = StaticToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
self.symbol = 'FOO'
self.name = 'Foo Token'
self.decimals = 16
self.initial_supply = 1 << 24
(tx_hash, o) = c.constructor(self.accounts[0], self.name, self.symbol, self.decimals, self.initial_supply)
self.rpc.do(o)
o = receipt(tx_hash)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
self.address = to_checksum_address(r['contract_address'])
logg.debug('published statictoken on address {} with hash {}'.format(self.address, tx_hash))

View File

@ -1,3 +1,3 @@
eth_tester==0.5.0b3
py-evm==0.3.0a20
eth_tester==0.10.0b4
py-evm==0.10.0b4
pytest==6.0.1

View File

@ -0,0 +1,38 @@
# standard imports
import os
import unittest
import json
import logging
import datetime
# external imports
from chainlib.eth.constant import ZERO_ADDRESS
from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.tx import receipt
from chainlib.eth.block import (
block_latest,
block_by_number,
)
# local imports
from static_token import StaticToken
from static_token.unittest import TestStaticToken
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
testdir = os.path.dirname(__file__)
class TestExpire(TestStaticToken):
def setUp(self):
super(TestExpire, self).setUp()
def test_static_interface(self):
pass
if __name__ == '__main__':
unittest.main()