Add token deployment

This commit is contained in:
nolash 2021-10-10 15:37:26 +02:00
parent 538b352cf7
commit c2999f466a
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
8 changed files with 121 additions and 8 deletions

View File

@ -1 +1 @@
include requirements.txt cic/data/* cic/schema/*
include *requirements.txt cic/data/* cic/schema/*

View File

@ -4,8 +4,12 @@ import copy
# external imports
from chainlib.chain import ChainSpec
from chainlib.eth.tx import TxFormat
from chainlib.eth.tx import (
TxFormat,
TxFactory,
)
from chainlib.eth.connection import RPCConnection
from chainlib.eth.contract import ABIContractEncoder
from eth_token_index import TokenUniqueSymbolIndex
from eth_address_declarator import Declarator
@ -24,7 +28,9 @@ class CICEth:
self.rpc = rpc
self.nonce_oracle = nonce_oracle
self.fee_oracle = fee_oracle
self.token_details = None
self.token_address = None
self.token_code = None
self.outputs = []
self.tx_format = TxFormat.RAW_ARGS
if self.rpc != None:
@ -33,10 +39,43 @@ class CICEth:
self.tx_format = TxFormat.RLP_SIGNED
def process_token(self):
raise NotImplementedError
def prepare_token(self, name, symbol, precision, code, extra={}, positions=None):
self.token_details = {
'name': name,
'symbol': symbol,
'precision': precision,
'code': code,
'extra': extra,
'positions': positions,
}
def process_token(self):
enc = ABIContractEncoder()
enc.string(self.token_details['name'])
enc.string(self.token_details['symbol'])
enc.uint256(self.token_details['precision'])
code = self.token_details['code'] + enc.get()
signer_address = self.resources['token']['key_address']
c = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=self.nonce_oracle, gas_oracle=self.fee_oracle)
tx = c.template(signer_address, None, use_nonce=True)
tx = c.set_code(tx, code)
o = c.finalize(tx, self.tx_format)
r = None
if self.rpc != None:
r = self.rpc.do(o[1])
elif self.signer != None:
r = o[1]
if r == None:
r = code
self.outputs.append(r)
return r
def process_token_index(self):
c = TokenUniqueSymbolIndex(self.chain_spec, signer=self.signer)
@ -79,7 +118,13 @@ class CICEth:
self.token_address = self.resources['token']['reference']
if self.token_address == None:
tasks.append('token')
tasks.append('token_index')
for k in self.resources.keys():
if k == 'token':
continue
if self.resources[k]['reference'] != None:
tasks.append(k)
for task in tasks:
getattr(self, 'process_̈́ ' + task)()

View File

@ -28,7 +28,7 @@ include_package_data = True
packages =
cic
cic.runnable
cic.ext
cic.ext.eth
[options.extras_require]
eth = chainlib-eth~=0.0.9rc

4
test_requirements.txt Normal file
View File

@ -0,0 +1,4 @@
erc20>=0.1.2a3,<0.2.0
eth_tester==0.5.0b3
py-evm==0.3.0a20
rlp==2.0.1

5
tests/base_cic.py Normal file
View File

@ -0,0 +1,5 @@
# standard imports
import os
test_base_dir = os.path.dirname(os.path.realpath(__file__))
test_data_dir = os.path.join(test_base_dir, 'testdata')

View File

@ -28,5 +28,6 @@ class TestCICEthOffline(TestCICEthBase):
self.assertEqual(len(v), 3)
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,56 @@
# standard imports
import os
import unittest
import logging
# external imports
from chainlib.eth.tx import (
TxFormat,
receipt,
)
# local imports
from cic.ext.eth import CICEth
# tests imports
from tests.eth.base_eth import TestCICEthBase
from tests.base_cic import test_data_dir
from giftable_erc20_token import GiftableToken
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
class TestCICEthToken(TestCICEthBase):
def setUp(self):
super(TestCICEthToken, self).setUp()
self.resources['token']['reference'] = None
self.adapter = CICEth(self.chain_spec, self.resources, self.proofs)
def test_token_nobackend(self):
self.adapter.prepare_token('FOoToken', 'FOO', 8, GiftableToken.bytecode())
v = self.adapter.process_token()
def test_token_sign(self):
self.adapter.signer = self.signer
self.adapter.tx_format = TxFormat.RLP_SIGNED
self.adapter.prepare_token('FOoToken', 'FOO', 8, GiftableToken.bytecode())
v = self.adapter.process_token()
def test_token_rpc(self):
self.adapter.signer = self.signer
self.adapter.rpc = self.rpc
self.adapter.tx_format = TxFormat.JSONRPC
self.adapter.prepare_token('FOoToken', 'FOO', 8, GiftableToken.bytecode())
v = self.adapter.process_token()
o = receipt(v)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
if __name__ == '__main__':
unittest.main()

View File

@ -9,10 +9,12 @@ from funga.eth.keystore.dict import DictKeystore
from funga.error import DecryptError
from hexathon import uniform as hex_uniform
# test imports
from tests.base_cic import test_base_dir
logging = logging.getLogger()
script_dir = os.path.dirname(os.path.realpath(__file__))
script_dir = test_base_dir
def pass_getter():
return 'test'