Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mike/new/create address #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/resources/common/eth_helper.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
*** Settings ***
Library ../custom/internal_json.py
Library ../custom/internal_eth.py

*** Variables ***
${CONTRACT_PATH} ${CURDIR}../../../../../dao-contracts/build/contracts/
*** Keywords ***
Pull Data From Contract
[Arguments] ${p_contractName} ${p_lookUp}
${t_content}= Normalize Path ${CONTRACT_PATH}/${p_contractName}
${t_value}= Find Value On Json File ${t_content} /${p_lookUp}
[Return] ${t_value}

Pull Latest Contract Address
[Arguments] ${p_contractName} ${p_lookUp}
${t_networks}= Pull Data From Contract ${p_contractName} ${p_lookUp}
${t_contract_address}= Latest Network Address ${t_networks}
[Return] ${t_contract_address}

Create New Wallet File
[Arguments] ${p_user_type} ${p_environment}=LOCAL
${t_wallet_json}= Create New Wallet Via Web3 ${p_environment}
${t_path}= Normalize Path ${CURDIR}/../testdata/keystores/${p_environment}/${p_user_type}.json
${t_content}= Convert Json To String ${t_wallet_json}
Create File ${t_path} ${t_content}
[Return] ${t_wallet_json}

Get Wallet Address From Json
[Arguments] ${p_json_content}
${t_wallet_address}= Get Value From Json ${p_json_content} /address
${t_asd}= Remove String ${t_wallet_address} "
${t_setAddress}= Set Variable 0x${t_asd}
[Return] ${t_setAddress}
28 changes: 28 additions & 0 deletions src/resources/custom/internal_eth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from web3 import Web3, HTTPProvider, IPCProvider
import json

HTTP_PROVIDER_ADDRESS = 'http://localhost:8545'
PASSWORD = 'digixdao'

def load_erc20_token(address, abi):
web3 = Web3(HTTPProvider(HTTP_PROVIDER_ADDRESS))
CHECKSUM_CONTRACT = web3.toChecksumAddress(address)
ERC20_ABI = json.loads(abi)
erc20 = web3.eth.contract(address=CHECKSUM_CONTRACT, abi=ERC20_ABI)
return erc20

def create_new_wallet_via_web3(environment):
web3 = Web3(HTTPProvider(HTTP_PROVIDER_ADDRESS))
acct = web3.eth.account.create(PASSWORD)
json = web3.eth.account.encrypt(acct.privateKey,PASSWORD)
return json

def transfer_funds_to_account(erc20 , address_to, value):
web3 = Web3(HTTPProvider(HTTP_PROVIDER_ADDRESS))
_from = web3.eth.coinbase
_to = web3.toChecksumAddress(address_to)
# amount = int(value * int(1e9))
erc20.functions.transfer(_to, int(10e9)).transact({'from': _from})
trans = {'from':_from, 'to':_to, 'value': web3.toWei(value, 'ether')}
tx_hash= web3.eth.sendTransaction(trans)
return (_to,amount,tx_hash)
19 changes: 17 additions & 2 deletions src/resources/custom/internal_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ def load_json_from_file(file_name):
data = json.load(json_file)
return data

def get_value_from_json(json_object, json_path):
def get_value_from_json(json_object,lookup):
dump = json.dumps(json_object)
data = json.loads(dump)
return data[json_path]
value = jsonpointer.resolve_pointer(data,lookup)
return json.dumps(value)

def convert_json_to_string(json_object):
return json.dumps(json_object)
Expand All @@ -28,3 +29,17 @@ def find_value_on_json_url(url, lookup):
data = json.loads(dump)
value = jsonpointer.resolve_pointer(data,lookup)
return value

def find_value_on_json_file(file_dir,lookup):
file_content = open(file_dir)
data = file_content.read()
load = json.loads(data)
abi = jsonpointer.resolve_pointer(load,lookup)
abi_dump = json.dumps(abi)
return abi_dump

def latest_network_address(json_object):
content = json.loads(json_object)
values = [(stamp, value['address']) for stamp, value in content.items()]
address = max(values, key=lambda abc:abc[0])
return address[1]
26 changes: 26 additions & 0 deletions src/suite/integration/DaoNewWalletTest.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
*** Settings ***
Documentation This suite will test enabling new user to
... interact to DigixDao
Force Tags regression smoke
Default Tags DaoNewWalletTest
Suite Teardown Close All Browsers
Resource ../../resources/common/web_helper.robot
Resource ../../resources/common/eth_helper.robot
Resource ../../resources/keywords/governance_page.robot

*** Test Cases ***
Test
${t_abi}= Pull Data From Contract MockDgd.json abi
Log ${t_abi}
${t_contract_addres}= Pull Latest Contract Address MockDgd.json networks
Log ${t_contract_addres}
${t_json}= Create New Wallet File newWallet
Log ${t_json}
# ${t_wallet_json}= Create New Wallet local
# Log ${t_wallet_json}
# Create Json Wallet ${t_wallet_json}
# ${cADD}= Set Variable 0x36376d6e66f20a2f5377a91a5e6ce37b53dda0d8

${t_wallet_address}= Get Wallet Address From Json ${t_json}
${t_erc20}= Load ERC20 Token ${t_contract_addres} ${t_abi}
${trax}= Transfer Funds To Account ${t_erc20} ${t_wallet_address} 10