Skip to content
Prev Previous commit
Next Next commit
Introduce ERC20 Interface (197-integration-test-for-erc20-wrapper-con…
…tract)
  • Loading branch information
vakond committed Sep 16, 2021
commit 4796c3a714e3b8156cfb8651fc99a39e07577619
49 changes: 33 additions & 16 deletions proxy/test_erc20_wrapper_contract.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
## File: test_erc20_wrapper_contract.py
## Integration test for the Neon ERC20 Wrapper contract.

import unittest
import os
import pprint
from web3 import Web3
from solcx import install_solc

# install_solc(version='latest')
install_solc(version='0.7.0')
install_solc(version='0.7.6')
from solcx import compile_source

EXTRA_GAS = int(os.environ.get("EXTRA_GAS", "0"))
Expand All @@ -21,10 +23,27 @@
# Convert Base58 to hex number:
TOKEN_MINT = bytes.fromhex('f396da383e57418540f8caa598584f49a3b50d256f75cb6d94d101681d6d9d21')

# Standard interface of ERC20 contract to generate ABI for wrapper
ERC20_INTERFACE_SOURCE = '''
pragma solidity >=0.7.0;

interface IERC20 {
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);

event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
'''

# Copy of contract: https://github.com/neonlabsorg/neon-evm/blob/develop/evm_loader/SPL_ERC20_Wrapper.sol
ERC20_WRAPPER_SOURCE = '''
pragma solidity >=0.5.12;

pragma solidity >=0.7.0;

interface IERC20 {
function decimals() external view returns (uint8);
Expand All @@ -38,13 +57,10 @@
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);


function approveSolana(bytes32 spender, uint64 value) external returns (bool);
event ApprovalSolana(address indexed owner, bytes32 indexed spender, uint64 value);
}



/*abstract*/ contract NeonERC20Wrapper /*is IERC20*/ {
address constant NeonERC20 = 0xff00000000000000000000000000000000000001;

Expand Down Expand Up @@ -75,7 +91,6 @@
}
'''


class Test_erc20_wrapper_contract(unittest.TestCase):
@classmethod
def setUpClass(cls):
Expand All @@ -85,19 +100,23 @@ def setUpClass(cls):
cls.deploy_erc20_wrapper_contract(cls)

def deploy_erc20_wrapper_contract(self):
compiled_sol = compile_source(ERC20_WRAPPER_SOURCE)
contract_id, contract_interface = compiled_sol.popitem()
compiled_interface = compile_source(ERC20_INTERFACE_SOURCE)
interface_id, interface = compiled_interface.popitem()

compiled_wrapper = compile_source(ERC20_WRAPPER_SOURCE)
wrapper_id, wrapper_interface = compiled_wrapper.popitem()

erc20 = proxy.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin'])
erc20 = proxy.eth.contract(abi=wrapper_interface['abi'], bytecode=wrapper_interface['bin'])
trx_constructor = erc20.constructor(NAME, SYMBOL, TOKEN_MINT).buildTransaction(
{'nonce': proxy.eth.get_transaction_count(proxy.eth.default_account)}
)
trx_deploy = proxy.eth.account.sign_transaction(trx_constructor, eth_account.key)
print('trx_deploy:', trx_deploy)
#print('trx_deploy:', trx_deploy)
trx_deploy_hash = proxy.eth.send_raw_transaction(trx_deploy.rawTransaction)
print('trx_deploy_hash:', trx_deploy_hash.hex())
#print('trx_deploy_hash:', trx_deploy_hash.hex())
trx_deploy_receipt = proxy.eth.wait_for_transaction_receipt(trx_deploy_hash)
print('trx_deploy_receipt:', trx_deploy_receipt)
#print('trx_deploy_receipt:', trx_deploy_receipt)
print('deploy status:', trx_deploy_receipt.status)

self.erc20_contract = proxy.eth.contract(
address=trx_deploy_receipt.contractAddress,
Expand All @@ -106,9 +125,7 @@ def deploy_erc20_wrapper_contract(self):

# @unittest.skip("a.i.")
def test_erc20_name(self):
print("\ntest_erc20_name")
name = self.erc20_contract.functions.name().call()
print('name:', name)
self.assertEqual(name, NAME)

@unittest.skip("a.i.")
Expand Down