Add transferfrom filter
This commit is contained in:
parent
bf8ddd0a5c
commit
5345803dc7
@ -34,12 +34,12 @@ def parse_transfer(tx):
|
||||
def parse_transferfrom(tx):
|
||||
if not tx.payload:
|
||||
return (None, None)
|
||||
r = ERC20.parse_transfer_request(tx.payload)
|
||||
r = ERC20.parse_transfer_from_request(tx.payload)
|
||||
transfer_data = {}
|
||||
transfer_data['from'] = r[0]
|
||||
transfer_data['to'] = r[1]
|
||||
transfer_data['value'] = r[2]
|
||||
transfer_data['token_address'] = tx['to']
|
||||
transfer_data['token_address'] = tx.inputs[0]
|
||||
return ('transferfrom', transfer_data)
|
||||
|
||||
|
||||
|
@ -16,6 +16,7 @@ from chainlib.eth.erc20 import ERC20
|
||||
# local imports
|
||||
from cic_eth.runnable.daemons.filters.callback import (
|
||||
parse_transfer,
|
||||
parse_transferfrom,
|
||||
)
|
||||
|
||||
logg = logging.getLogger()
|
||||
@ -56,3 +57,50 @@ def test_transfer_tx(
|
||||
(transfer_type, transfer_data) = parse_transfer(tx)
|
||||
|
||||
assert transfer_type == 'transfer'
|
||||
|
||||
|
||||
|
||||
def test_transfer_from_tx(
|
||||
default_chain_spec,
|
||||
init_database,
|
||||
eth_rpc,
|
||||
eth_signer,
|
||||
foo_token,
|
||||
agent_roles,
|
||||
token_roles,
|
||||
celery_session_worker,
|
||||
):
|
||||
|
||||
rpc = RPCConnection.connect(default_chain_spec, 'default')
|
||||
nonce_oracle = RPCNonceOracle(token_roles['FOO_TOKEN_OWNER'], rpc)
|
||||
gas_oracle = OverrideGasOracle(conn=rpc, limit=200000)
|
||||
|
||||
txf = ERC20(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||
|
||||
(tx_hash_hex, o) = txf.approve(foo_token, token_roles['FOO_TOKEN_OWNER'], agent_roles['ALICE'], 1024)
|
||||
r = rpc.do(o)
|
||||
o = receipt(tx_hash_hex)
|
||||
r = rpc.do(o)
|
||||
assert r['status'] == 1
|
||||
|
||||
nonce_oracle = RPCNonceOracle(agent_roles['ALICE'], rpc)
|
||||
txf = ERC20(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||
(tx_hash_hex, o) = txf.transfer_from(foo_token, agent_roles['ALICE'], token_roles['FOO_TOKEN_OWNER'], agent_roles['BOB'], 1024)
|
||||
r = rpc.do(o)
|
||||
|
||||
o = transaction(tx_hash_hex)
|
||||
r = rpc.do(o)
|
||||
logg.debug(r)
|
||||
tx_src = snake_and_camel(r)
|
||||
tx = Tx(tx_src)
|
||||
|
||||
o = receipt(tx_hash_hex)
|
||||
r = rpc.do(o)
|
||||
assert r['status'] == 1
|
||||
|
||||
rcpt = snake_and_camel(r)
|
||||
tx.apply_receipt(rcpt)
|
||||
|
||||
(transfer_type, transfer_data) = parse_transferfrom(tx)
|
||||
|
||||
assert transfer_type == 'transferfrom'
|
||||
|
Loading…
Reference in New Issue
Block a user