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

[BCI-2714]: adds sncast scripts #396

Merged
merged 9 commits into from
Apr 4, 2024
Merged

Conversation

chris-de-leon-cll
Copy link
Contributor

@chris-de-leon-cll chris-de-leon-cll commented Mar 29, 2024

Adds sncast Scripts

Overview

Please see the ticket here for more details! tl;dr this PR adds support for using sncast to interact with the data feed example contracts on Starknet testnet OR a local container running starknet-devnet-rs.

Primary Changes

  • bumps starknet foundry from v0.18.0 to v0.21.0
  • bumps cairo to v2.6.3
  • modifies ./ops/scripts/devnet-hardhat.sh such that the container version can be configured (snfoundry v0.21.0 needs an rpc v0.7 endpoint, and the script defaults to using rpc v0.6)
  • adds the following data feed sncast scripts (all located in ./examples/contracts/aggregator_consumer/scripts/src/test-consumer:
    • deploy_test_consumer (deploys MockAggregator and AggregatorConsumer)
    • read_decimals
    • read_latest_round
    • set_latest_round
  • adds helper commands in the Makefile to simplify script setup and execution
  • updates the README.md file in ./examples/contracts/aggregator_consumer
    • adds details on how to run the sncast scripts on both testnet and a local starknet devnet container using the helper commands in the Makefile
      • describes what commands exist
      • explains how to use the commands
      • explains what each commands does
      • explains how to read the output of the commands
  • simplifies the consumer.cairo contract
    • removes read_decimals (not needed for new docs)
    • removes read_latest_round (not needed for new docs)
    • adds read_answer (needed for new docs)
    • adds set_answer (needed for new docs)
    • updates the test cases in test_consumer.cairo accordingly


devnet:
@printf "\nStarting a local starknet devnet docker container:\n\n" \
&& bash ../../../ops/scripts/devnet-hardhat-down.sh \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already call cleanup on startup:

bash "$(dirname -- "$0")/devnet-hardhat-down.sh"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I'll modify the script

Comment on lines 42 to 46
tc-deploy:
@cd ./scripts && sncast --account "$(ACCOUNT_NAME)" script run deploy_test_consumer

tc-set-latest-round:
@cd ./scripts && sncast --account "$(ACCOUNT_NAME)" script run set_latest_round
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can define account = "$ACCOUNT_NAME" in the toml config under the default profile, then we don't need to specify --account everywhere

Copy link
Contributor Author

@chris-de-leon-cll chris-de-leon-cll Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

  • In snfoundry.toml the account name is now configurable through an environment variable which is set automatically in the Makefile
  • The Makefile is now the only place where the account names for devnet and testnet are defined - it is not hardcoded in any other place

make create-account
```

- Once the account has been created, its info should be stored in an accounts file on your local machine (usually at `~/.starknet_accounts/starknet_open_zeppelin_accounts.json`). If you'd like to view the account information later on, you can use the following command:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's define accounts-file to be in the current directory and gitignore it. That way we're not leaving global artifacts on user's system

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(only for devnet though)

Copy link
Contributor Author

@chris-de-leon-cll chris-de-leon-cll Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

  • In snfoundry.toml, I made accounts-file configurable through an environment variable which is set automatically in the Makefile
  • The Makefile is now the only place where the accounts-file paths for devnet and testnet are defined - it is not hardcoded in any other place
  • For devnet, the accounts file is called accounts.json and it lives at the same level as snfoundry.toml. It is currently gitignored using a pre-existing rule in the .gitignore file in the repo's root directory
  • For testnet, the accounts file is unchanged (~/.starknet_accounts/starknet_open_zeppelin_accounts.json)

add-account:
@printf "\nAdding an account named \"$(ACCOUNT_NAME)\"...\n\n" \
&& sncast \
--url "http://127.0.0.1:5050/rpc" \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a devnet and a testnet profile in sncast, then removing --url flags and hardcoding the account name on devnet?

Copy link
Contributor Author

@chris-de-leon-cll chris-de-leon-cll Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

  • In snfoundry.toml, there is now a devnet profile and testnet profile each with their own RPC URLs
  • In the Makefile the commands now use the --profile flag
  • The Makefile sncast commands now require an argument NETWORK which is used to determine which profile a.k.a which network to run the script on

…new docs, refactors test cases for test_consumer, renames MAKEFILE commands, reorganizes folders, updates README
@cl-sonarqube-production
Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@archseer archseer merged commit c97baa6 into develop Apr 4, 2024
19 checks passed
@archseer archseer deleted the feat/BCI-2714-sncast-scripts branch April 4, 2024 04:47
chray-zhang pushed a commit that referenced this pull request Nov 25, 2024
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

Successfully merging this pull request may close these issues.

3 participants