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

feat: allow test utils to use builds from outside the RPC repo root #543

Conversation

bajpai244
Copy link
Contributor

@bajpai244 bajpai244 commented Sep 8, 2023

Time spent on this PR:

Resolves: #542

Pull Request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build-related changes
  • Documentation content changes
  • Testing

What is the new behavior?

The current change will allow the RPC to consume builds outside from the project root of Kakarot RPC { as of now we need this to simplify CI flow for running ef-tests on kakarot main }, we still get all good DX features we used to have, the flow now is:

  • search for the path as absolute path.
  • if the above fails, then search for it relative to the project root.

A new environment variable FOUNDRY_OUTPUT_PATH has been added so that we can point to solidity builds outside from this repo, this will add no extra complexity as of now, the default value here will work out of the box with the current flow until a change is needed.

Does this introduce a breaking change?

  • Yes
  • No

@bajpai244 bajpai244 force-pushed the feat/remove-use-of-root_project_path-for-compiled-kakarot-path branch from 2279d16 to bc75858 Compare September 8, 2023 09:27
@bajpai244 bajpai244 force-pushed the feat/remove-use-of-root_project_path-for-compiled-kakarot-path branch from bc75858 to 4efddee Compare September 8, 2023 09:29
Copy link
Contributor

@greged93 greged93 left a comment

Choose a reason for hiding this comment

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

one remark

@@ -98,12 +98,29 @@ pub fn get_contract(filename: &str) -> CompactContractBytecode {
let dot_sol = format!("{filename}.sol");
let dot_json = format!("{filename}.json");

let foundry_default_out = load_config().out;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we keep the load config and use your method if there is not config? It makes more sense imo to use to config if you find one

Copy link
Contributor Author

@bajpai244 bajpai244 Sep 8, 2023

Choose a reason for hiding this comment

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

So, I think we should avoid this, because:

  • we would then need more logic, i.e checking whether FOUNDRY_OUTPUT_PATH exists or not, there are scenarious where someone might have forget to provide this variable, but RPC will still take the builds from local builds, this can create confusion, as they might not be suspecting that they have forgot to provide this variable. { TLDR; I think it will make it more automagical which we don't seem to need as of now, this is used in just one place, if complexity increases, might we can do this. }

Copy link
Member

@Eikix Eikix left a comment

Choose a reason for hiding this comment

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

It's not completely clear to me what we're doing in this PR
Is this because we'll run this repo in the Kakarot v0 context, so it's nonsensical to expect Kakarot to point to Kakarot-RPC that points as submodule Kakarot?

Could you add more comments to explain what relative and absolute mean in your context of this PR / CI Epic and maybe with more concrete context or examples.

That way when we read it back in a month we understand

@codecov
Copy link

codecov bot commented Sep 8, 2023

Codecov Report

Patch coverage: 83.33% and project coverage change: +49.29% 🎉

Comparison is base (71506a8) 23.17% compared to head (4efddee) 72.47%.
Report is 213 commits behind head on main.

❗ Current head 4efddee differs from pull request most recent head 510fe20. Consider uploading reports for the commit 510fe20 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #543       +/-   ##
===========================================
+ Coverage   23.17%   72.47%   +49.29%     
===========================================
  Files           9       44       +35     
  Lines        1247     4014     +2767     
===========================================
+ Hits          289     2909     +2620     
- Misses        958     1105      +147     
Files Changed Coverage Δ
crates/core/src/mock/serde.rs 0.00% <0.00%> (ø)
crates/core/src/models/transaction.rs 93.63% <ø> (ø)
crates/core/src/models/transaction_receipt.rs 97.02% <ø> (ø)
crates/core/src/test_utils/bin/dump-katana.rs 0.00% <ø> (ø)
crates/core/src/test_utils/deploy_helpers.rs 33.02% <ø> (ø)
crates/core/src/test_utils/execution_helpers.rs 100.00% <ø> (ø)
crates/core/src/test_utils/fixtures.rs 100.00% <ø> (ø)
crates/eth-rpc/src/api/alchemy_api.rs 100.00% <ø> (ø)
crates/eth-rpc/src/api/eth_api.rs 100.00% <ø> (ø)
crates/eth-rpc/src/api/net_api.rs 100.00% <ø> (ø)
... and 34 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bajpai244
Copy link
Contributor Author

@Eikix so, the scenarios is:

  • We have a CI job, where we build a recent PR of Kakarot

  • Now, we want to:

    • build this new version of kakarot { which will be outside of the Kakarot RPC repo }
    • create a katana dump on the RPC
    • run ef tests on this new dump

    Kakarot RPC as of now search for builds relative to its project path root, this makes it difficult to point it to use builds outside from the repo.

One option is to put builds inside Kakarot RPC, but when you do that, then you realize it is better to make this logic more generic on Kakarot RPC itself!

Does this helps in understanding the use case?

Concrete example

  • We build kakarot on CI { path let's say -> ~/kakarot/build }
  • We clone Kakarot RPC to make the dump { path let's say -> ~/kakarot-rpc }
  • We want to use { ~/kakarot/build on the ~/kakarot-rpc/ to create katana dump }

Since the RPC will look for this folder relative to its root, the solution the only solution that can work as of now is to move ~/kakarot/build to ~/kakarot-rpc, this should not be the behaviour.

Also, since as of now to load solidity contracts, we use the foundry.toml file, it makes pointing to some other directory for using contracts very difficult.
image

This PR is keeping all that used to work before this alongwith also adding the functionality of making this more generic.

@greged93
Copy link
Contributor

greged93 commented Sep 8, 2023

I think this might be overkill and cause more complexity in the already tangled up deploy helpers.

Could we maybe untangle the deploy helpers a bit and check if there isn't a cleaner way to do this? We can make a code smell issue to clean the config loading. I see for example a foundry_toml_dirs function which might be useful.

As discussed with @ClementWalter we might want to pause rolling out anything new a little and work on cleaning knots/smells. I think having ef-tests in Kakarot CI is important but this might be a little rushed. Just my opinion.

@bajpai244
Copy link
Contributor Author

@greged93 I agree with you here, but I was thinking might be we can for now proceed with this as ef-tests on Kakarot CI are important and this is doesn't change much in terms of DX we already have.

We can later fix this as a code smell issue, and once that is done we can make a small change to the CI file as well!

Lemme know what you think, if you still think we should do a different refactor first, then I am fine with that as well.

Copy link
Member

@Eikix Eikix left a comment

Choose a reason for hiding this comment

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

some comments about clarity of the two different cases

`./scripts/make_with_env.sh test`",
);

// We search firstly for existence for absolute path
Copy link
Member

Choose a reason for hiding this comment

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

this comment isn't so clear, absolute path for what, could we provide an example of path, and in which case it's used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, so by comments you mean comments on the code, lemme make this better!

`./scripts/make_with_env.sh test`",
);

// We search firstly for existence for absolute path
Copy link
Member

Choose a reason for hiding this comment

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

same remark as above

if compiled_kakarot_path_absolute.try_exists().unwrap() {
compiled_kakarot_path_absolute
} else {
// If the absolute path is not found, then we search for a path relative to the project root
Copy link
Member

Choose a reason for hiding this comment

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

same remark

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated, lemme know if this works.

if foundry_output_path_absolute.try_exists().unwrap() {
foundry_output_path_absolute
} else {
// If the absolute path is not found, then we search for a path relative to the project root
Copy link
Member

Choose a reason for hiding this comment

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

same remark

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated, lemme know if this works.

@greged93
Copy link
Contributor

@bajpai244 I agree that they are important but we didn't have them for 8 months, I would rather delayed them for 10 more days and integrate them nicely then increase the knots in the deploy helper.

@Eikix
Copy link
Member

Eikix commented Sep 11, 2023

Looking at the big picture, I'd ask for us to at least sit down for a second and look at the Kakarot cairo0 repo, and think how can we make the CI run smoothly:

  • run ef tests
  • run kakarot rpc tests

This requires a smooth dump management as you pointed out Harsh and maybe some refactors to be able to more freely handle build paths etc.

But i'd argue we need to think in terms of architecture first

@@ -24,6 +24,7 @@ PROXY_ACCOUNT_CLASS_HASH=0xba8f3f34eb92f56498fdf14ecac1f19d507dcc6859fa6d85eb854

## configurations for testing
COMPILED_KAKAROT_PATH=lib/kakarot/build
FOUNDRY_OUTPUT_PATH=./lib/kakarot/tests/integration/solidity_contracts/build
Copy link
Member

Choose a reason for hiding this comment

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

do we need ./ or not? see it's not put for COMPILED_KAKAROT_PATH ; when adding similar context into a file, make sure that you stay consistent

@@ -423,14 +443,31 @@ pub fn compute_kakarot_contracts_class_hash() -> Vec<(String, FieldElement)> {
.collect()
}

fn compiled_kakarot_path() -> PathBuf {
Copy link
Member

Choose a reason for hiding this comment

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

so this is kakarot build dir right? when the path is a directory, it's more explicit to use directory

Copy link
Member

Choose a reason for hiding this comment

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

in the beginning I thought it was the full path like kakarot/build/kakarot.json

let paths = fs::read_dir(&compiled_kakarot_path)
let compiled_kakarot_path = &compiled_kakarot_path();

let paths = fs::read_dir(compiled_kakarot_path)
Copy link
Member

Choose a reason for hiding this comment

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

so these paths are build artifacts?

@Eikix
Copy link
Member

Eikix commented Sep 15, 2023

Should this be closed?

@bajpai244
Copy link
Contributor Author

@Eikix this can be closed, with the new refactors we are doing this PR shouldn't be much needed anymore.

@Eikix Eikix closed this Sep 19, 2023
anukkrit149 pushed a commit to karnotxyz/kakarot-rpc that referenced this pull request Aug 9, 2024
<!--- Please provide a general summary of your changes in the title
above -->
Adds transfer of value when executing `CALLCODE`.

<!-- Give an estimate of the time you spent on this PR in terms of work
days. Did you spend 0.5 days on this PR or rather 2 days? -->


Time spent on this PR: 0.2 days

## Pull request type

<!-- Please try to limit your pull request to one type, submit multiple
pull requests if needed. -->

Please check the type of change your PR introduces:

- [ ] Bugfix
- [x] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?

<!-- Please describe the current behavior that you are modifying, or
link to a relevant issue. -->
Executing `CALLCODE` does not transfer any value to the target
`account`.

Resolves kkrt-labs#543 

## What is the new behavior?

<!-- Please describe the behavior or changes that are being added by
this PR. -->

- `CALLCODE` transfers `value` to `account`.
- Additional unit testing for `CALLCODE` opcode value transfer.
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.

dev: refactor derivation for compiled_kakarot_path and compiled_solidity_path
4 participants