Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ce33185
Add script test_faucet.py (166-faucet)
vakond Aug 27, 2021
18a4081
Add faucet service to docker-compose-test.yml (166-faucet)
vakond Aug 27, 2021
d7bbec5
No need for container for faucet (166-faucet)
vakond Aug 30, 2021
8d280f1
Merge branch 'develop' into 166-faucet
vakond Aug 31, 2021
c42e379
Merge branch 'develop' into 166-faucet
vakond Sep 6, 2021
4d7e0ec
Merge branch 'develop' into 166-faucet
vakond Sep 22, 2021
49c9144
Create test for faucet (166-faucet)
vakond Sep 22, 2021
0ef9665
Add port 3333 in container to use by faucet service (166-faucet)
vakond Sep 22, 2021
ee58f06
Start and stop the faucet service (166-faucet)
vakond Sep 22, 2021
09e9a4f
First successful request (166-faucet)
vakond Sep 23, 2021
4ccc279
Merge branch 'develop' into 166-faucet
vakond Sep 23, 2021
61072d9
Implement test_eth_token (166-faucet)
vakond Sep 23, 2021
a16238c
Developing test_erc20_tokens (166-faucet)
vakond Sep 23, 2021
170cd90
Merge branch 'develop' into 166-faucet
vakond Sep 23, 2021
059f655
Deploy 2 ERC20 tokens (166-faucet)
vakond Sep 23, 2021
8433595
Refactoring (166-faucet)
vakond Sep 23, 2021
43dd3b3
Complete test_erc20_tokens (166-faucet)
vakond Sep 23, 2021
10f4dc4
Refactoring (166-faucet)
vakond Sep 23, 2021
880ccc3
Comment out check temporarily (166-faucet)
vakond Sep 24, 2021
b11e947
Merge branch 'develop' into 166-faucet
vakond Sep 24, 2021
818dc68
Merge branch 'develop' into 166-faucet
vakond Sep 27, 2021
3a7d4cd
Use solc 0.7 (166-faucet)
vakond Sep 27, 2021
1412456
Developing (166-faucet)
vakond Sep 29, 2021
65a1228
Enable all tests (166-faucet)
vakond Sep 29, 2021
5da9bb8
Copy faucet to /spl/bin (166-faucet)
vakond Sep 29, 2021
db0e4d0
Refactoring (166-faucet)
vakond Sep 29, 2021
80be914
Refactoring (166-faucet)
vakond Sep 29, 2021
f25da2b
Merge branch 'develop' into 166-faucet
vakond Sep 29, 2021
2907cb8
Remove unneeded variable (166-faucet)
vakond Sep 30, 2021
8092e8c
Merge branch 'develop' into 166-faucet
vakond Sep 30, 2021
340325e
Remove unneeded ports (166-faucet)
vakond Sep 30, 2021
ffb3292
Merge branch 'develop' into 166-faucet
vakond Nov 3, 2021
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
Prev Previous commit
Next Next commit
Deploy 2 ERC20 tokens (166-faucet)
  • Loading branch information
vakond committed Sep 23, 2021
commit 059f655d01e92415583f868a6f36732512260b16
171 changes: 159 additions & 12 deletions proxy/test_neon_faucet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,174 @@
import subprocess
import requests
from web3 import Web3
from solcx import install_solc
install_solc(version='0.8.7')
from solcx import compile_source

EXTRA_GAS = int(os.environ.get("EXTRA_GAS", "100000"))
proxy_url = os.environ.get('PROXY_URL', 'http://localhost:9090/solana')
proxy = Web3(Web3.HTTPProvider(proxy_url))
admin = proxy.eth.account.create('issues/neonlabsorg/neon-evm/166/admin')
user = proxy.eth.account.create('issues/neonlabsorg/neon-evm/166/user')
proxy.eth.default_account = admin.address

ERC20_CONTRACT_SOURCE = '''
pragma solidity >=0.8.0;
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
contract SafeMath {
function safeAdd(uint a, uint b) public pure returns (uint c) {
c = a + b;
require(c >= a);
}
function safeSub(uint a, uint b) public pure returns (uint c) {
require(b <= a);
c = a - b;
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
// ----------------------------------------------------------------------------
abstract contract ERC20Interface {
function totalSupply() virtual public view returns (uint);
function balanceOf(address tokenOwner) virtual public view returns (uint balance);
function allowance(address tokenOwner, address spender) virtual public view returns (uint remaining);
function transfer(address to, uint tokens) virtual public returns (bool success);
function approve(address spender, uint tokens) virtual public returns (bool success);
function transferFrom(address from, address to, uint tokens) virtual public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
// ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals
// assisted token transfers
// ----------------------------------------------------------------------------
contract N47Token is ERC20Interface, SafeMath {
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
constructor() {
symbol = "TST";
name = "TestToken";
decimals = 18;
_totalSupply = 10000000000000000000000000000;
balances[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public override view returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public override view returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to receiver account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address receiver, uint tokens) public override returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[receiver] = safeAdd(balances[receiver], tokens);
emit Transfer(msg.sender, receiver, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for spender to transferFrom(...) tokens
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public override returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer tokens from sender account to receiver account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from sender account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address sender, address receiver, uint tokens) public override returns (bool success) {
balances[sender] = safeSub(balances[sender], tokens);
allowed[sender][msg.sender] = safeSub(allowed[sender][msg.sender], tokens);
balances[receiver] = safeAdd(balances[receiver], tokens);
emit Transfer(sender, receiver, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public override view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
}
'''

class Test_Neon_Faucet(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.compile_erc20_contract(cls)
token_a = cls.deploy_erc20_token(cls)
token_b = cls.deploy_erc20_token(cls)
cls.start_faucet(cls, token_a, token_b)
print('Sleeping 1 sec...')
time.sleep(1)

def compile_erc20_contract(self):
compiled_contract = compile_source(ERC20_CONTRACT_SOURCE)
contract_id, contract_interface = compiled_contract.popitem()
self.contract = contract_interface

def deploy_erc20_token(self):
erc20 = proxy.eth.contract(abi=self.contract['abi'], bytecode=self.contract['bin'])
nonce = proxy.eth.get_transaction_count(proxy.eth.default_account)
tx = {'nonce': nonce}
tx_constructor = erc20.constructor().buildTransaction(tx)
tx_deploy = proxy.eth.account.sign_transaction(tx_constructor, admin.key)
tx_deploy_hash = proxy.eth.send_raw_transaction(tx_deploy.rawTransaction)
print('tx_deploy_hash:', tx_deploy_hash.hex())
tx_deploy_receipt = proxy.eth.wait_for_transaction_receipt(tx_deploy_hash)
print('tx_deploy_receipt:', tx_deploy_receipt)
print('deploy status:', tx_deploy_receipt.status)
return tx_deploy_receipt.contractAddress

def start_faucet(self, token_a, token_b):
os.environ['FAUCET_RPC_PORT'] = '3333'
os.environ['FAUCET_RPC_ALLOWED_ORIGINS'] = 'http://localhost'
os.environ['FAUCET_WEB3_ENABLE'] = 'true'
os.environ['WEB3_RPC_URL'] = proxy_url
os.environ['WEB3_PRIVATE_KEY'] = '0x0000000000000000000000000000000000000000000000000000000000000Ace'
os.environ['NEON_ERC20_TOKENS'] = '0x00000000000000000000000000000000CafeBabe, 0x00000000000000000000000000000000DeadBeef'
os.environ['WEB3_PRIVATE_KEY'] = proxy.eth.default_account
os.environ['NEON_ERC20_TOKENS'] = token_a + ',' + token_b
os.environ['NEON_ERC20_MAX_AMOUNT'] = '1000'
os.environ['FAUCET_SOLANA_ENABLE'] = 'true'
os.environ['SOLANA_URL'] = 'http://solana:8899'
os.environ['EVM_LOADER'] = '53DfF883gyixYNXnM7s5xhdeyV8mVk9T4i2hGV9vG9io'
os.environ['SOLANA_URL'] = os.environ.get('SOLANA_URL', 'http://solana:8899')
os.environ['EVM_LOADER'] = os.environ.get('EVM_LOADER', '53DfF883gyixYNXnM7s5xhdeyV8mVk9T4i2hGV9vG9io')
os.environ['NEON_TOKEN_MINT'] = 'HPsV9Deocecw3GeZv1FkAPNCBRfuVyfw9MMwjwRe1xaU'
os.environ['NEON_TOKEN_MINT_DECIMALS'] = '9'
os.environ['NEON_OPERATOR_KEYFILE'] = '/root/.config/solana/id.json'
os.environ['NEON_ETH_MAX_AMOUNT'] = '10'
cls.faucet = subprocess.Popen(['faucet', 'run', '--workers', '1'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print('Sleeping 1 sec...')
time.sleep(1) # 1 second
self.faucet = subprocess.Popen(['faucet', 'run', '--workers', '1'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

@unittest.skip("a.i.")
def test_eth_token(self):
Expand All @@ -49,7 +193,7 @@ def test_eth_token(self):
print('balance_after:', balance_after)
self.assertEqual(balance_after - balance_before, 1000000000000000000)

# @unittest.skip("a.i.")
@unittest.skip("a.i.")
def test_erc20_tokens(self):
print()
address = '0x1111111111111111111111111111111111111111'
Expand All @@ -60,16 +204,19 @@ def test_erc20_tokens(self):
print('Response:', r.status_code)
assert(r.ok)

@classmethod
def tearDownClass(cls):
def stop_faucet(self):
url = 'http://localhost:{}/request_stop'.format(os.environ['FAUCET_RPC_PORT'])
data = '{"delay": 1000}' # 1 second
r = requests.post(url, data=data)
if not r.ok:
cls.faucet.terminate
with io.TextIOWrapper(cls.faucet.stdout, encoding="utf-8") as out:
self.faucet.terminate
with io.TextIOWrapper(self.faucet.stdout, encoding="utf-8") as out:
for line in out:
print(line.strip())

@classmethod
def tearDownClass(cls):
cls.stop_faucet(cls)

if __name__ == '__main__':
unittest.main()