Coder Social home page Coder Social logo

0xspaceshard / starknet-devnet Goto Github PK

View Code? Open in Web Editor NEW
212.0 10.0 78.0 4.04 MB

A local testnet for Starknet

Home Page: https://0xspaceshard.github.io/starknet-devnet/

License: MIT License

Python 93.67% Shell 1.95% Dockerfile 0.10% JavaScript 0.88% Cairo 1.18% Solidity 1.86% CSS 0.37%
starknet blockchain

starknet-devnet's People

Contributors

amanusk avatar badurinantun avatar bartekryba avatar bigherc18 avatar ca11ab1e avatar cfal avatar cptartur avatar dribeiro-shardlabs avatar drknzz avatar fabijanc avatar fmoletta avatar gregoryguillou avatar hug0x0 avatar internnos avatar ivpavici avatar lucaslvy avatar mikiw avatar nathan-sl avatar omahs avatar pscott avatar ptisserand avatar redfox20 avatar remedcu avatar solpatium avatar tabaktoni avatar thenry14 avatar tomek0123456789 avatar tonypony220 avatar war-in avatar wraitii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

starknet-devnet's Issues

Performance enhancements while running tests

I'm trying to setup a hardhat cairo project (using the starknet plugin).
I initially used this devnet to run the test suite on. But I'm noticing it is extremely slow to run tests on, comparatively to the standard pytest tests that one can write in Nile

I'm trying to understand what the reason is for this difference in performance, and if it's something I could maybe help fixing?

RPC call starknet_chainId does not return DEVNET

Describe the bug
RPC calls to starknet_chainId does not return DEVNET but SN_GOERLI.

To Reproduce
Call starknet_chainId with json rpc. From what I see, the reason is that the value returned is DEFAULT_CHAIN_ID from starknet_devnet/general_config.py that is imported fromcairo-lang in src/starkware/starknet/definitions/general_config.py andTESTNET.

Expected behavior
I would expect the returned value is DEVNET or something else so that, from the chain we can know what we are using.

Devnet version

  • I am using Devnet version: 0.2.4
  • This happens with a dockerized Devnet (check the box if true).

Persisting the state fails

Hello team.
I am trying to use the new state dumping feature but it fails (macOS, pyenv, python 3.9.10, venv).

Apart from the fact that it would be nice to have the params for dumping and loading which don't error if the load path does not exists yet (so I can always copy and paste the same command and not having different results if it's the first or the nth time).
So having something like this always working

starknet-devnet \
  --dump-on transaction \
  --dump-path ~/.starknet_devnet \
  --load-path ~/.starknet_devnet

But there is a more pressing issue on my machine. If I start the devnet then I send the transaction, when I stop the devnet and the dump has to be written, it throws errors.

❯ starknet-devnet \                                
  --dump-on exit \    
  --dump-path ~/.starknet_devnet.pkl          
 * Running on http://localhost:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [28/Feb/2022 14:37:47] "POST /gateway/add_transaction HTTP/1.1" 200 -
^CDumping Devnet to: /Users/claudio/.starknet_devnet.pkl
Traceback (most recent call last):
  File "/Users/claudio/cairo_venv/bin/starknet-devnet", line 8, in <module>
    sys.exit(main())
  File "/Users/claudio/cairo_venv/lib/python3.9/site-packages/starknet_devnet/server.py", line 275, in main
    app.run(host=args.host, port=args.port)
  File "/Users/claudio/cairo_venv/lib/python3.9/site-packages/flask/app.py", line 920, in run
    run_simple(t.cast(str, host), port, self, **options)
  File "/Users/claudio/cairo_venv/lib/python3.9/site-packages/werkzeug/serving.py", line 1017, in run_simple
    inner()
  File "/Users/claudio/cairo_venv/lib/python3.9/site-packages/werkzeug/serving.py", line 970, in inner
    srv.serve_forever()
  File "/Users/claudio/cairo_venv/lib/python3.9/site-packages/werkzeug/serving.py", line 724, in serve_forever
    super().serve_forever(poll_interval=poll_interval)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/socketserver.py", line 232, in serve_forever
    ready = selector.select(poll_interval)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/selectors.py", line 416, in select
    fd_event_list = self._selector.poll(timeout)
  File "/Users/claudio/cairo_venv/lib/python3.9/site-packages/starknet_devnet/server.py", line 241, in dump_on_exit
    dumper.dump(dumper.dump_path)
  File "/Users/claudio/cairo_venv/lib/python3.9/site-packages/starknet_devnet/dump.py", line 34, in dump
    multiprocessing.Process(
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 47, in _launch
    reduction.dump(process_obj, fp)
  File "/Users/claudio/.pyenv/versions/3.9.10/lib/python3.9/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'CarriedState.empty_for_testing.<locals>.<lambda>'

If I start the devnet to dump at every transaction, then as soon as I send a transaction, I get a 500 error for the transaction, and I the dump fails.

Could it be some dependency missing? Or any mismatched python version?

Support StarkNet state `copy`?

StarkNet (from starkware.starknet.testing.starknet) has a copy method: https://github.com/starkware-libs/cairo-lang/blob/577d7a5ca085fc76fb1cb18e04d94991127e3724/src/starkware/starknet/testing/state.py#L51

The copy method is super useful for writing efficient tests, because you can deploy/initialize/etc a bunch of inter-related contracts, and then make multiple copies of that StarkNet state in order to run various tests on them in parallel.

I love that starknet-hardhat-plugin makes it easy to write tests against a local starknet-devnet instance — however I find myself missing the efficiency of the copy method.

Would you be open to supporting this functionality inside starknet-devnet? We could add a /gateway/copy endpoint which returns a new identifier which later could be optionally passed as a header or request arg to various gateway endpoints such as /gateway/add_transaction. (Of course, if this header/arg were omitted, the request would apply to the root starknet instance.)

Allow specifying how blocks are constructed

Block construction might add a lot to total execution time of calls and invokes. Yet, it might be that blocks aren't needed by developers that often. Therefore, an option like --no-block or --no-blocks could be added, which would do everything that Devnet does, but without block generation. Or more generally, something like --block could be provided to indicate how often blocks are generated, i.e. after how many transactions.

Mainnet forking

As I mentioned in the community call last week, it would be amazing to have mainnet forking. The use case it's to test how our dapp interacts with existing dapps deployed to the network. I know that now it's not possible to implement this, so this is more of a question to know what is needed to make this happen?

A list of pre-funded test accounts

Feature Request

To have a list of pre-populated accounts the same as ganache of Hardhat node does.

Bonus if we can have a single key, like HD-Path style, be the source of generating all of them.

Questions

Is this possible to do?
Is it wise to do?

Disclaimer

I am still getting used to these ZK rollup style ecosystems.
My perspective is a builder who needs to make tooling for Starknet and needs it to be roughly compatible / similar to other existing Python Ethereum tooling.

`invoke`/`call` fail finding the contract to call and return different parsed contract addresses

Hey,

When trying to invoke or call a function of my contract, I get errors when finding the contract referenced with --address:

starknet call --address 0x0180187d947f45e66a0b049422b9bc9673a11b7a8320daad28bdf247e7d28328 --abi contract_abi.json --function get_balance --gateway_url http://52.179.101.122:5000

returns

Got BadRequest
Traceback (most recent call last):
  File "/Users/sebastiendan/cairo_venv/lib/python3.9/site-packages/services/external_api/base_client.py", line 116, in _send_request
    raise BadRequest(status_code=response.status, text=text)
services.external_api.base_client.BadRequest: HTTP error ocurred. Status: 500. Text: {"code": "StarknetErrorCode.UNINITIALIZED_CONTRACT", "message": "Error at pc=0:13:\nGot an exception while executing a hint.\nCairo traceback (most recent call last):\nUnknown location (pc=0:467)\nUnknown location (pc=0:436)\n\nError in the called contract (0x180187d947f45e66a0b049422b9bc9673a11b7a8320daad28bdf247e7d28328):\nContract with address 0x180187d947f45e66a0b049422b9bc9673a11b7a8320daad28bdf247e7d28328 is not deployed."}
Error: BadRequest: HTTP error ocurred. Status: 500. Text: {"code": "StarknetErrorCode.UNINITIALIZED_CONTRACT", "message": "Error at pc=0:13:\nGot an exception while executing a hint.\nCairo traceback (most recent call last):\nUnknown location (pc=0:467)\nUnknown location (pc=0:436)\n\nError in the called contract (0x180187d947f45e66a0b049422b9bc9673a11b7a8320daad28bdf247e7d28328):\nContract with address 0x180187d947f45e66a0b049422b9bc9673a11b7a8320daad28bdf247e7d28328 is not deployed."}

=> The 0x180187d947f45e66a0b049422b9bc9673a11b7a8320daad28bdf247e7d28328 address displayed in the error message defers from the one referenced in the call (0x0180187d947f45e66a0b049422b9bc9673a11b7a8320daad28bdf247e7d28328).


starknet invoke --address 0x0180187d947f45e66a0b049422b9bc9673a11b7a8320daad28bdf247e7d28328 --abi contract_abi.json --function increase_balance --inputs 1234 --gateway_url http://52.179.101.122:5000
Invoke transaction was sent.
Contract address: 0x0180187d947f45e66a0b049422b9bc9673a11b7a8320daad28bdf247e7d28328
Transaction hash: 0x30261268712fc763f4b7bbefe24920853f98a20da32c340567a3b973e2ba4ee

leads to

starknet tx_status --hash 0x30261268712fc763f4b7bbefe24920853f98a20da32c340567a3b973e2ba4ee --feeder_gateway_url http://52.179.101.122:5000
{
    "tx_failure_reason": {
        "code": "TRANSACTION_FAILED",
        "error_message": "No contract at the provided address (0x039159e62d9936e67b2adb434aeab1201965bd7c3342e48a0cc6345d2a86ba87).",
        "tx_id": "0x030261268712fc763f4b7bbefe24920853f98a20da32c340567a3b973e2ba4ee"
    },
    "tx_status": "REJECTED"
}

This time the address displayed in the error message is 0x039159e62d9936e67b2adb434aeab1201965bd7c3342e48a0cc6345d2a86ba87.

Refactor DummyExecutionInfo

Ideally we would use TransactionExecutionInfo.load and give it a dict. Is it possible? We would benefit from the internal validation done by the loading.

Error when passing an empty array

When an empty array is provided as an argument to a contract function, an error is raised. E.g. in a test in hardhat-plugin:

const contract: StarknetContract = contractFactory.getContractAt(preservedAddress);
const arr = [];
const sum = await contract.call("sum_array", [arr.length, ...arr]);

yields

Error: BadRequest: HTTP error ocurred. Status: 400. Text: Too few function arguments provided: 1.

Version 0.1.8 throws error on start

Issue

MultiDict doesn't support generic types, which results in error:

> poetry run starknet-devnet
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/user/.pyenv/versions/3.7.12/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/user/work/starknet/starknet-devnet/starknet_devnet/server.py", line 124, in <module>
    def check_block_hash(request_args: MultiDict[str, str]):
TypeError: 'type' object is not subscriptable

The same thing happens when using starknet-devnet as a package.

Repro

git checkout v0.1.8
poetry run starknet-devnet

Possible fix

After replacing MultiDict[int, int] with MultiDict in starknet_devnet/server.py it seems to be working properly. I can create a PR if needed.

Crashes at launch (WERKZEUG_SERVER_FD)

Hello,

My instance crashes right at launch.

When I run starknet-devnet I get

Traceback (most recent call last):
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/bin/starknet-devnet", line 8, in <module>
    sys.exit(main())
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/lib/python3.8/site-packages/starknet_devnet/server.py", line 329, in main
    app.run(host=args.host, port=args.port)
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/lib/python3.8/site-packages/flask/app.py", line 920, in run
    run_simple(t.cast(str, host), port, self, **options)
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/lib/python3.8/site-packages/werkzeug/serving.py", line 1047, in run_simple
    fd = int(os.environ["WERKZEUG_SERVER_FD"])
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/os.py", line 675, in __getitem__
    raise KeyError(key) from None
KeyError: 'WERKZEUG_SERVER_FD'

Same with nile node

Traceback (most recent call last):
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/bin/starknet-devnet", line 8, in <module>
    sys.exit(main())
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/lib/python3.8/site-packages/starknet_devnet/server.py", line 329, in main
    app.run(host=args.host, port=args.port)
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/lib/python3.8/site-packages/flask/app.py", line 920, in run
    run_simple(t.cast(str, host), port, self, **options)
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/lib/python3.8/site-packages/werkzeug/serving.py", line 1047, in run_simple
    fd = int(os.environ["WERKZEUG_SERVER_FD"])
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/os.py", line 675, in __getitem__
    raise KeyError(key) from None
KeyError: 'WERKZEUG_SERVER_FD'
Traceback (most recent call last):
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/bin/nile", line 8, in <module>
    sys.exit(cli())
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/lib/python3.8/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/lib/python3.8/site-packages/nile/cli.py", line 190, in node
    node_command(host, port)
  File "/Users/alexandre/code/alexandrewolff/nile-cairo-examples/env/lib/python3.8/site-packages/nile/core/node.py", line 21, in node
    subprocess.check_call(["starknet-devnet", "--host", host, "--port", str(port)])
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['starknet-devnet', '--host', '127.0.0.1', '--port', '5000']' returned non-zero exit status 1.

I run on macOs 12.3.1 under apple m1 silicon cpu.

Any idea what causes that and how to fix ?

Sample HTTP request for successful setup

I'm trying to run a starknet devnet node to test caigo. However, I'm observing that it is difficult to determine if my devnet node is running correctly.

I'm able to confirm that it's running via docker ps and I observe 404s in logs when I try to make basic requests to my node

curl -X GET http://localhost:5000/get_block_number

But it would be helpful if there was a sample query in the README after this step to confirm the setup process was successful

Not receiving ACCEPTED_ON_L2 transaction on devnet

I am using the useStarknetTransactionManager() react hook and logging to console the transactions received.

When I point to devnet, I don't receive the transaction for the ACCEPTED_ON_L2. I am just receiving the TRANSACTION_RECEIVED transaction.
But, when I point to alpha I receive the ACCEPTED_ON_L2 transaction as expected.

Why on devnet don't I receive the other transaction events?

Max_fee missing from transaction

It seems like max_fee field is missing from transactions returned by feeder_gateway/getTransaction. E.g. see this random transaction from voyager. If you query it from feeder gateway directly you get a response containing a max_fee field (I believe this is different from actual_fee from transaction receipt.

This field is missing from transactions returned by devnet:

  1. Deploy any contract to devnet
  2. Make a invoke call to that contract
  3. GET devnet_address/feeder_gateway/get_transaction?transactionHash=hash_of_tx, field max_fee will be missing from the response.

Refactor JSON-RPC tests

The tests would ideally be reorganized into multiple files.
They could be grouped according to what they test (blocks, transactions, ...)

No transaction created for l1 -> l2 transactions

Summary

For l1 ->2 bridge transactions, the state changes are not yielding a new transaction/block.

General steps to reproduce

  1. Create contract on l1 with a function to send a message to l2 sendMessageToL2
  2. Create a contract on l2 with a @l1_handler to consume the message
  3. In the l2 contract update the state in some way

Build Docker image in parallel

Devnet docker image could be built in parallel with tests, then in the publish job it could just be pushed - right now the building needs to wait for tests to finish

Not sure if this can actually be done, i.e. if the built image will be preserved for other circleci steps/jobs

Got ClientConnectorCertificateError while trying to access https://alpha4.starknet.io/gateway/add_transaction

when i deploy using localhost it's ok, but failed in goerli, and how can i choose the devnet?
--network localhost
🚀 Deploying ERC721
⏳ ️Deployment of ERC721 successfully sent at 0x0632bcc92835bb37b71c82fee273c966d0863134e4f1e2c2184dc8cb4713a7a1
🧾 Transaction hash: 0x17275a2d05f67778c1f0434b6b1b21e7a5d893c6904a10e6da50e779e819954
📦 Registering 0x0632bcc92835bb37b71c82fee273c966d0863134e4f1e2c2184dc8cb4713a7a1 in 127.0.0.1.deployments.txt
(env) (base) MacBook-Pro:starknet qkaver$ nile deploy ERC721 6001127147006152263 21336 2689760648704244976701818254133193310968075258309729491871695171359883455256 --network goerli
🚀 Deploying ERC721
Got ClientConnectorCertificateError while trying to access https://alpha4.starknet.io/gateway/add_transaction.
Error: ClientConnectorCertificateError: Cannot connect to host alpha4.starknet.io:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')]

Deploy argent-x wallet contract

Hey there,
I'm trying to deploy an argent-x wallet contract and get this strange error:
TRANSACTION_FAILED: Illegal method selector: 215307247182100370520050591091822763712463273430149262739280891880522753123.
To be honest I dont know if this is an issue on devnet side or on argent-x (although it deploys fine in testnet/mainnet) or even starknetjs.
And might even be a known issue. I thing this issue is on argent-x github as well but had receive no attention. Do you have any information regarding this?

Return Value Strangenesses

I am noticing some odd behaviors with return values as of recently where the length of return arguments is included. Here are the scenarios I have tried:

@external
func get_array{
        syscall_ptr : felt*, pedersen_ptr : HashBuiltin*,
        range_check_ptr}() -> (arr_len: felt, arr: felt*):
    const ARRAY_SIZE = 3
    let (ptr) = alloc()
    assert [ptr] = 1
    assert [ptr + 1] = 2
    assert [ptr + 2] = 3
    let (current_count) = array_get_counter.read()
    array_get_counter.write(current_count + 1)
    return (ARRAY_SIZE, ptr)
end

@view
func view_array{
        syscall_ptr : felt*, pedersen_ptr : HashBuiltin*,
        range_check_ptr}() -> (arr_len: felt, arr: felt*):
    const ARRAY_SIZE = 3
    let (ptr) = alloc()
    assert [ptr] = 1
    assert [ptr + 1] = 2
    assert [ptr + 2] = 3
    return (ARRAY_SIZE, ptr)
end
method client result
@external normal [3, 1, 2, 3]
@external account [4, 3, 1, 2, 3]
@view normal [3, 1, 2, 3]

Improve how docker version is tested

Currently only a simple is_alive call is done. More delicate use cases could be handled in these tests, like dump and load.

Ideally, testing the docker and non-docker version should use the same code (avoid duplication).

Storage_diffs missing for state updates from 0 -> any non negative value

Invoke transactions sent to devnet that modify contract's storage from initial value of 0 to any non negative value, don't show up as storage_diffs in the result of get_state_update.

Steps to reproduce

(note hash values will be different than in my example outputs):

  1. Deploy any contract with storage to devnet, for example this balance contract
# Declare this file as a StarkNet contract.
%lang starknet

from starkware.cairo.common.cairo_builtins import HashBuiltin

# Define a storage variable.
@storage_var
func balance() -> (res : felt):
end

# Increases the balance by the given amount.
@external
func increase_balance{
    syscall_ptr : felt*,
    pedersen_ptr : HashBuiltin*,
    range_check_ptr,
}(amount : felt):
    let (res) = balance.read()
    balance.write(res + amount)
    return ()
end

# Returns the current balance.
@view
func get_balance{
    syscall_ptr : felt*,
    pedersen_ptr : HashBuiltin*,
    range_check_ptr,
}() -> (res : felt):
    let (res) = balance.read()
    return (res)
end
  1. Increase the balance
    starknet invoke --address <address> --abi balance_abi.json --function increase_balance --inputs 123 --gateway_url <gateway> --feeder_gateway_url <feeder_gateway>

  2. Get the state_diff of the latest block
    starknet get_state_update --block_number latest --gateway_url <gateway> --feeder_gateway_url <feeder_gateway>

Both deployed_contracts and storage_diffs will be empty, even though storage increased.

{
    "block_hash": "0x1e1523a33336e8f75e69433569672087986a426ff9aad39e05e469b213618c8",
    "new_root": "07c7a16fdf3cac95f94a04ebc2da7e7d8e10496bde6bf4d0143ef560e188ae6f",
    "old_root": "058751f6b6e66e778aec353f0d17720292f7ab70b764e720f11e0de8e93289db",
    "state_diff": {
        "deployed_contracts": [],
        "storage_diffs": {}
    }
}
  1. Increase the balance again
    starknet invoke --address <address> --abi balance_abi.json --function increase_balance --inputs 123 --gateway_url <gateway> --feeder_gateway_url <feeder_gateway>

  2. Get the state_diff of the latest block

Storage diffs will now show a value

{
    "block_hash": "0x97caa35c003b4150fb8877916402f503308b9490b51481428967b27897c777",
    "new_root": "011247fe7c8f8ed7b8b34a7e090cb5117dd94412dfafb214eec2120363a14104",
    "old_root": "07c7a16fdf3cac95f94a04ebc2da7e7d8e10496bde6bf4d0143ef560e188ae6f",
    "state_diff": {
        "deployed_contracts": [],
        "storage_diffs": {
            "0x02e3217d5a75f5830c7a89b189c2b0e0622eaf1d066bb2fc7fc2545507576657": [
                {
                    "key": "0x206f38f7e4f15e87567361213c28f235cccdaa1d7fd34c9db1dfe9489c6a091",
                    "value": "0xf6"
                }
            ]
        }
    }
}

In the case of my inputs its 0xf6 == 246 == 123 + 123, so devnet calculates storage correctly, but even though it increased in the first invoke transaction, it was missing from the state diff.

Support `/get_block` endpoint

Hey guys! I wanted to ask if /get_block endpoint is going to be supported/is planned for implementing anytime soon?
If not, what work could be done to implement this or help you with that?
I'm willing to contribute to the repo, any guidance would be much appreciated :)

Increase timeout

It would be beneficial to provide users with an option to increase the timeout.

Events no longer show up on Receipts as of 0.2.2

When I use 0.2.1, my Starknet receipts contain the expected events.
However, when upgrading to 0.2.2, the events field is always an empty list on receipts.

My method and event:

@event
func balance_increased(amount : felt):
end

# Increases the balance by the given amount.
@external
func increase_balance{
        syscall_ptr : felt*, pedersen_ptr : HashBuiltin*,
        range_check_ptr}(user : felt, amount : felt):
    let (initialized) = is_initialized.read()
    assert initialized = TRUE

    let (res) = balance.read(user=user)
    balance.write(user, res + amount)
    balance_increased.emit(amount)
    return ()
end

Some simple code:

self.starknet_client.wait_for_tx_sync(txn_hash)
receipt = self.starknet_client.get_transaction_receipt_sync(tx_hash=txn_hash)

Let me know if you need more reproduction steps, but it is pretty standard contract txn i think

Change default port

Hey guys,

great work! While integrating this with Argent X we notices port 5000 is often already in use and the devnet doesn't check that and starts anyways (but doesn't work)
After a quick google search it seems like port 5000 is often used by the system on MacOS

would it be possible to change the default port to something less used?

Cheers, Janek

pip install starknet-devnet

× Encountered error while trying to install package.
╰─> crypto-cpp-py

i've already brew install gmp
python3.8

Mint devnet eth??

Hello team.
ArgentX updated with mandatory fee. So while running my own app against devnet, I now need some eth to pay for transactions.

How can I mint some eth for my wallet?
Thanks!

Contracts.get_by_address inconsistent typing

Based on type hints get_by_address accepts address as a string. But in the body of the method it is passed to fixed_length_hex which expects int. Also in starknet wrapper's invoke, it is called like this

self.contracts.get_by_address(invoke_transaction.contract_address)

where contract_address is a int.

Suggested solutions

  • Perhaps type hint for this and related method parameters should be changed.
  • Start enforcing str as parameter, add necessary type conversions to starknet_wrapper

Feature request: Set block timestamp for testing purpose.

It would be really useful to be able to set block timestamp for testing purpose.
Currently it is really hard to test smart contracts that use get_block_timestamp because we don't have a way to mock the value in order to test different scenario.

Having this ability would help a lot. If you use protostar it is possible to mock block timestamp using warp cheat code.
But if you use nile it is not possible to do the same because they use starknet-devnet.

UI Explorer

Hello :)

Do you think developing an UI around starknet-devnet would be interesting for the project? This would make it easy to explore transactions and contracts deployed easily.

Asking since I could spend some time on that feature, I want to be sure that it would be relevant to this use case!

Setup Voyager local to point to devnet

Hello team,
I tried to run the voyager-local as described here https://voyager.online/local-version/ but it's lacking the info about how to point it to the currently running devnet on the same machine.

Maybe it's just me not being prepared enough on Docker, but can you help with the launch command for the docker voyager-local?

Thanks a lot!

In tests, pre-deploy 0 accounts by default

This would reduce test log content and performance time.
However, it would increase line count and we would have to modify the tests where we need the accounts (we could only the number of accounts that we actually need).

Issue with `increase_time` and `set_time` RPC endpoint

Describe the bug

When using the RPC endpoint, if the new timestamp is called, there is no change to the timestamp value

current_timestamp = # Code to get timestamp here
response = requests.post(url=f"{self.uri}/increase_time", json={"time": seconds_to_increase})
new_timestamp = # Code to get timestamp here again
new_timestamp - current_timestamp != seconds_to_increase

Not a great example, but this is embedded in a python class, using Ape. My example wouldn't make sense

Not reproducible on alpha-goerli

  • This issue is only present on Devnet and cannot be reproduced on alpha-goerli.

To Reproduce
Steps to reproduce the behavior:

  1. Start a local devnet testnet
  2. get timestamp
  3. set the timestamp with a post request to /increase_time or /set_time
  4. get timestamp again
  5. old and new timestamp will be equal

Expected behavior

You would expect the new timestamp to be greater than the old timestamp

Devnet version

  • I am using Devnet version: 0.2.4
  • This does not appear on the following Devnet version: Unknown

Machine specifications

  • OS: Ubuntu 20.04
  • CPU: AMD Ryzen 9 5950x 16-core processor x 32
  • Memory: 64GB DDR4

How to connect to devnet?

Hey,

README says

Interact with Devnet as you would with the official Starknet Alpha testnet.

But how am I supposed to connect to my local/remote devnet? No args from the following list from starknet --help seem to actually redirect command executions to my devnet:

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  --network NETWORK     The name of the StarkNet network.
  --network_id NETWORK_ID
                        A textual identifier of the network. Used for account management.
  --wallet WALLET       The name of the wallet, including the python module and wallet class.
  --no_wallet           Perform a direct contract call without an account contract.
  --account ACCOUNT     The name of the account. If not given, the default account (as defined by the wallet) is used.
  --account_dir ACCOUNT_DIR
                        The directory containing the account files (default: '~/.starknet_accounts').
  --flavor {Debug,Release,RelWithDebInfo}
                        Build flavor.
  --gateway_url GATEWAY_URL
                        The URL of a StarkNet gateway.
  --feeder_gateway_url FEEDER_GATEWAY_URL
                        The URL of a StarkNet feeder gateway.

Improve logging

Currently only the default meinheld server logging is done (and initial predeployed accounts logging).

  1. The server logging could be optional (to be handled with gunicorn).
  2. More informative logging could be done on each:
    • transaction (deploy, declare, invoke)
    • emitted event
    • time manipulation
    • minting
  3. Users could opt for more or less verbose logging (-v, --verbose)
  4. Log all predeployed contract information (e.g. fee token, UDC)

AttributeError: module 'collections' has no attribute 'Mapping'

(env) xxxxx@xxxxxMacBook-Pro testProject % starknet-devnet
Traceback (most recent call last):
File "/Users/xxxxx/devData/starkNet/testProject/env/bin/starknet-devnet", line 5, in
from starknet_devnet.server import main
File "/Users/xxxxx/devData/starkNet/testProject/env/lib/python3.10/site-packages/starknet_devnet/server.py", line 4, in
from starkware.starknet.services.api.gateway.transaction import Deploy, InvokeFunction, Transaction
File "/Users/xxxxx/devData/starkNet/testProject/env/lib/python3.10/site-packages/starkware/starknet/services/api/gateway/transaction.py", line 13, in
from services.everest.api.gateway.transaction import (
File "/Users/xxxxx/devData/starkNet/testProject/env/lib/python3.10/site-packages/services/everest/api/gateway/transaction.py", line 5, in
from starkware.starkware_utils.validated_dataclass import ValidatedMarshmallowDataclass
File "/Users/xxxxx/devData/starkNet/testProject/env/lib/python3.10/site-packages/starkware/starkware_utils/validated_dataclass.py", line 13, in
from starkware.starkware_utils.validated_fields import Field
File "/Users/xxxxx/devData/starkNet/testProject/env/lib/python3.10/site-packages/starkware/starkware_utils/validated_fields.py", line 12, in
from starkware.starkware_utils.marshmallow_dataclass_fields import (
File "/Users/xxxxx/devData/starkNet/testProject/env/lib/python3.10/site-packages/starkware/starkware_utils/marshmallow_dataclass_fields.py", line 6, in
from frozendict import frozendict
File "/Users/xxxxx/devData/starkNet/testProject/env/lib/python3.10/site-packages/frozendict/init.py", line 16, in
class frozendict(collections.Mapping):
AttributeError: module 'collections' has no attribute 'Mapping'

OS: MacOS 12.0.1
python: 3.10
starknet-devnet: 0.1.6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.