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

Set state error #109

Open
EtienneWallet opened this issue Feb 13, 2025 · 0 comments
Open

Set state error #109

EtienneWallet opened this issue Feb 13, 2025 · 0 comments

Comments

@EtienneWallet
Copy link

Context

My goal is to copy a smart-contract from mainnet to the chain-simulator

On a fresh chain-simulator full stack start, here is how I proceed:

from multiversx_sdk import Address, ProxyNetworkProvider

mainnet_proxy = ProxyNetworkProvider("https://gateway.multiversx.com")
cs_proxy = ProxyNetworkProvider("http://127.0.0.1:8085")


sc_address = Address.from_bech32("erd1qqqqqqqqqqqqqpgqq66xk9gfr4esuhem3jru86wg5hvp33a62jps2fy57p")
mainnet_account = mainnet_proxy.get_account(sc_address)
raw_account_data = mainnet_account.raw["account"]
raw_account_data

This gives the following data

{'address': 'erd1qqqqqqqqqqqqqpgqq66xk9gfr4esuhem3jru86wg5hvp33a62jps2fy57p',
 'nonce': 510,
 'balance': '0',
 'username': '',
 'code': '<REMOVED_FOR_TEXT_SIZE>',
 'codeHash': 'aM9kuvQt0HmqDi0QsEoC7Oe+V9bJvwyguWeRHaO5aEY=',
 'rootHash': 'Gj7vx7aJm+QbizMO4I466bA1/LpMbL5aVjGtllo/+vk=',
 'codeMetadata': 'BQQ=',
 'developerReward': '86069065022407600000',
 'ownerAddress': 'erd1ss6u80ruas2phpmr82r42xnkd6rxy40g9jl69frppl4qez9w2jpsqj8x97'}

I can check that this smart-contract is empty on the chain-simulator

cs_proxy.get_account(sc_address).raw
{'account': {'address': 'erd1qqqqqqqqqqqqqpgqq66xk9gfr4esuhem3jru86wg5hvp33a62jps2fy57p', 'nonce': 0, 'balance': '0', 'username': '', 'code': '', 'codeHash': None, 'rootHash': None, 'codeMetadata': None, 'developerReward': '0', 'ownerAddress': ''}

Now, I try to set the state of the mainnet contract to the chain-simulator

url = "simulator/set-state"
cs_proxy.do_post_generic(url, [raw_account_data])

This call doesn't produce any error

However, If I try to get the account again, I have the following error

cs_proxy.get_account(sc_address)
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
File ~/Documents/Programmation/company/project/.venv/lib/python3.11/site-packages/multiversx_sdk/network_providers/proxy_network_provider.py:361, in ProxyNetworkProvider._do_get(self, url)
    360 response = requests.get(url, **self.config.requests_options)
--> 361 response.raise_for_status()
    362 parsed = response.json()

File ~/Documents/Programmation/company/project/.venv/lib/python3.11/site-packages/requests/models.py:1024, in Response.raise_for_status(self)
   1023 if http_error_msg:
-> 1024     raise HTTPError(http_error_msg, response=self)

HTTPError: 500 Server Error: Internal Server Error for url: http://127.0.0.1:8085/address/erd1qqqqqqqqqqqqqpgqq66xk9gfr4esuhem3jru86wg5hvp33a62jps2fy57p

During handling of the above exception, another exception occurred:

GenericError                              Traceback (most recent call last)
Cell In[5], line 1
----> 1 cs_proxy.get_account(sc_address)

File ~/Documents/Programmation/company/project/.venv/lib/python3.11/site-packages/multiversx_sdk/network_providers/proxy_network_provider.py:121, in ProxyNetworkProvider.get_account(self, address)
    118 get_guardian_data_thread = Thread(target=self._get_guardian_data, args=(address, data))
    119 get_guardian_data_thread.start()
--> 121 response = self.do_get_generic(f"address/{address.to_bech32()}")
    122 account = account_from_proxy_response(response.to_dictionary())
    124 get_guardian_data_thread.join(timeout=2)

File ~/Documents/Programmation/company/project/.venv/lib/python3.11/site-packages/multiversx_sdk/network_providers/proxy_network_provider.py:344, in ProxyNetworkProvider.do_get_generic(self, url, url_parameters)
    341     params = urllib.parse.urlencode(url_parameters)
    342     url = f"{url}?{params}"
--> 344 response = self._do_get(url)
    345 return response

File ~/Documents/Programmation/company/project/.venv/lib/python3.11/site-packages/multiversx_sdk/network_providers/proxy_network_provider.py:366, in ProxyNetworkProvider._do_get(self, url)
    364 except requests.HTTPError as err:
    365     error_data = self._extract_error_from_response(err.response)
--> 366     raise GenericError(url, error_data)
    367 except requests.ConnectionError as err:
    368     raise GenericError(url, err)

GenericError: Url = [http://127.0.0.1:8085/address/erd1qqqqqqqqqqqqqpgqq66xk9gfr4esuhem3jru86wg5hvp33a62jps2fy57p], error = {'data': None, 'error': 'cannot get account: sending request error, could not get requested account: trie was not found for hash, rootHash = 1a3eefc7b6899be41b8b330ee08e3ae9b035fcba4c6cbe5a5631ad965a3ffaf9, err = getNodeFromDB error: key not found for key 1a3eefc7b6899be41b8b330ee08e3ae9b035fcba4c6cbe5a5631ad965a3ffaf9', 'code': 'internal_issue'}

Expected behavior

I would like to be able to copy paste a smart-contract from a given network to the chain-simulator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant