Add custom ordering token deploy test

This commit is contained in:
nolash 2021-10-10 19:59:52 +02:00
parent 6a5b0388ec
commit fee303cf85
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 79 additions and 2 deletions

View File

@ -107,7 +107,7 @@ class CICEth:
typ = self.token_details['extra_types'][i]
else:
typ = self.__detect_arg_type(x)
arg_types.append(typ)
args_types.append(typ)
positions = self.token_details['positions']
if positions == None:

View File

@ -8,6 +8,13 @@ from chainlib.eth.tx import (
TxFormat,
receipt,
)
from chainlib.eth.contract import (
abi_decode_single,
ABIContractEncoder,
ABIContractType,
)
from chainlib.jsonrpc import JSONRPCRequest
from hexathon import add_0x
# local imports
from cic.ext.eth import CICEth
@ -16,6 +23,7 @@ from cic.ext.eth import CICEth
from tests.eth.base_eth import TestCICEthBase
from tests.base_cic import test_data_dir
from giftable_erc20_token import GiftableToken
from eth_erc20 import ERC20
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
@ -27,10 +35,13 @@ class TestCICEthToken(TestCICEthBase):
super(TestCICEthToken, self).setUp()
self.resources['token']['reference'] = None
self.adapter = CICEth(self.chain_spec, self.resources, self.proofs)
self.token_name = 'FOotoken'
self.token_symbol = 'FOO'
self.token_precision = 8
def test_token_nobackend(self):
self.adapter.prepare_token('FOoToken', 'FOO', 8, GiftableToken.bytecode())
self.adapter.prepare_token(self.token_name, self.token_symbol, self.token_precision, GiftableToken.bytecode())
v = self.adapter.process_token()
@ -51,6 +62,57 @@ class TestCICEthToken(TestCICEthBase):
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
def test_token_weirdorder(self):
weird_contract_bytecode_path = os.path.join(test_data_dir, 'contracts', 'WeirdPosToken.bin')
f = open(weird_contract_bytecode_path, 'r')
weird_bytecode = f.read()
f.close()
try:
self.adapter.prepare_token(self.token_name, self.token_symbol, self.token_precision, weird_bytecode, extra=['0xdeadbeef'], extra_types=['bytes32'])
except ValueError:
v = self.adapter.process_token()
self.adapter.prepare_token(self.token_name, self.token_symbol, self.token_precision, weird_bytecode, extra=['0xdeadbeef'], extra_types=['bytes32'], positions=[1, 2, 3, 0])
self.adapter.signer = self.signer
self.adapter.rpc = self.rpc
self.adapter.tx_format = TxFormat.JSONRPC
v = self.adapter.process_token()
logg.debug('v {}'.format(v))
o = receipt(v)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
contract_address = r['contract_address']
c = ERC20(self.chain_spec)
o = c.name(contract_address, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(c.parse_name(r), self.token_name)
o = c.symbol(contract_address, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(c.parse_symbol(r), self.token_symbol)
o = c.decimals(contract_address, sender_address=self.accounts[0])
r = self.rpc.do(o)
self.assertEqual(c.parse_decimals(r), self.token_precision)
j = JSONRPCRequest()
o = j.template()
o['method'] = 'eth_call'
enc = ABIContractEncoder()
enc.method('foo')
data = add_0x(enc.get())
tx = c.template(self.accounts[0], contract_address)
tx = c.set_code(tx, data)
o['params'].append(c.normalize(tx))
o['params'].append('latest')
o = j.finalize(o)
r = self.rpc.do(o)
v = abi_decode_single(ABIContractType.BYTES32, r)
self.assertEqual(v[-8:], 'deadbeef')
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1 @@
60806040523480156200001157600080fd5b5060405162000837380380620008378339818101604052810190620000379190620001e0565b80600090805190602001906200004f92919062000084565b5083600190805190602001906200006892919062000084565b508260ff1660028190555081600381905550505050506200045f565b82805462000092906200033c565b90600052602060002090601f016020900481019282620000b6576000855562000102565b82601f10620000d157805160ff191683800117855562000102565b8280016001018555821562000102579182015b8281111562000101578251825591602001919060010190620000e4565b5b50905062000111919062000115565b5090565b5b808211156200013057600081600090555060010162000116565b5090565b60006200014b6200014584620002b9565b62000290565b9050828152602081018484840111156200016a57620001696200040b565b5b6200017784828562000306565b509392505050565b60008151905062000190816200042b565b92915050565b600082601f830112620001ae57620001ad62000406565b5b8151620001c084826020860162000134565b91505092915050565b600081519050620001da8162000445565b92915050565b60008060008060808587031215620001fd57620001fc62000415565b5b600085015167ffffffffffffffff8111156200021e576200021d62000410565b5b6200022c8782880162000196565b94505060206200023f87828801620001c9565b935050604062000252878288016200017f565b925050606085015167ffffffffffffffff81111562000276576200027562000410565b5b620002848782880162000196565b91505092959194509250565b60006200029c620002af565b9050620002aa828262000372565b919050565b6000604051905090565b600067ffffffffffffffff821115620002d757620002d6620003d7565b5b620002e2826200041a565b9050602081019050919050565b6000819050919050565b600060ff82169050919050565b60005b838110156200032657808201518184015260208101905062000309565b8381111562000336576000848401525b50505050565b600060028204905060018216806200035557607f821691505b602082108114156200036c576200036b620003a8565b5b50919050565b6200037d826200041a565b810181811067ffffffffffffffff821117156200039f576200039e620003d7565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b6200043681620002ef565b81146200044257600080fd5b50565b6200045081620002f9565b81146200045c57600080fd5b50565b6103c8806200046f6000396000f3fe608060405234801561001057600080fd5b5060043610610069576000357c01000000000000000000000000000000000000000000000000000000009004806306fdde031461006e578063313ce5671461008c57806395d89b41146100aa578063c2985578146100c8575b600080fd5b6100766100e6565b6040516100839190610280565b60405180910390f35b610094610174565b6040516100a191906102a2565b60405180910390f35b6100b261017a565b6040516100bf9190610280565b60405180910390f35b6100d0610208565b6040516100dd9190610265565b60405180910390f35b600080546100f390610320565b80601f016020809104026020016040519081016040528092919081815260200182805461011f90610320565b801561016c5780601f106101415761010080835404028352916020019161016c565b820191906000526020600020905b81548152906001019060200180831161014f57829003601f168201915b505050505081565b60025481565b6001805461018790610320565b80601f01602080910402602001604051908101604052809291908181526020018280546101b390610320565b80156102005780601f106101d557610100808354040283529160200191610200565b820191906000526020600020905b8154815290600101906020018083116101e357829003601f168201915b505050505081565b60035481565b610217816102d9565b82525050565b6000610228826102bd565b61023281856102c8565b93506102428185602086016102ed565b61024b81610381565b840191505092915050565b61025f816102e3565b82525050565b600060208201905061027a600083018461020e565b92915050565b6000602082019050818103600083015261029a818461021d565b905092915050565b60006020820190506102b76000830184610256565b92915050565b600081519050919050565b600082825260208201905092915050565b6000819050919050565b6000819050919050565b60005b8381101561030b5780820151818401526020810190506102f0565b8381111561031a576000848401525b50505050565b6000600282049050600182168061033857607f821691505b6020821081141561034c5761034b610352565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000601f19601f830116905091905056fea2646970667358221220720dff6bb55eef097a1a16adca5deb82e325d0d31a2355c833ca15973748681964736f6c63430008070033

View File

@ -0,0 +1,14 @@
contract WeirdPosToken {
string public name;
string public symbol;
uint256 public decimals;
bytes32 public foo;
constructor(string memory _symbol, uint8 _decimals, bytes32 _foo, string memory _name) {
name = _name;
symbol = _symbol;
decimals = uint256(_decimals);
foo = _foo;
}
}