Giter Site home page Giter Site logo

Comments (5)

Karrq avatar Karrq commented on August 21, 2024

Thanks for the report!
Could you let us know exactly the error you are getting? Is is the last assertion that fails or is there some other error message?

from foundry-zksync.

0xBrian avatar 0xBrian commented on August 21, 2024

It's just the assertion that doesn't pass, no error message. I think test1 and test2 should either both pass, or both fail. Thanks.

from foundry-zksync.

Karrq avatar Karrq commented on August 21, 2024

Hey @0xBrian, I investigated the issue. Thanks for the reproducible example, it was really helpful!

I actually tried fetching the source and luckily the contract was verified on the explorer so I could take a look at how it worked, and noticed that the DIGEST is computed using a few items from the contract state, but also the msg.sender.

Unfortunately, the answer to your issue is rather bland: prank simply doesn't set the msg.sender for nested calls!
So, in test2, the msg.sender would end up being the address where Blah was deployed, and not MINER, as it would be in the test1.

I hope this helps!

from foundry-zksync.

0xBrian avatar 0xBrian commented on August 21, 2024

OK, thank you for investigating. We figured it was something like that. But does it work this way in normal Foundry, or is it something related to the changes required for ZKSync? To me it seems like this behavior would prevent anyone from writing realistic tests.

from foundry-zksync.

Karrq avatar Karrq commented on August 21, 2024

Yes, that's intended foundry behaviour, we can also see this in the test suite here.

What we do require for ZKSync is that any contract running inside zkVM isn't able to use cheatcodes (in this case Blah), but you can work around that by disabling zkVM before the call to the external contract, run your cheatcodes there, and re-enable zkVM afterwards.

For example:

vm.zkVm(false);
blah.doit(...);

and inside doit:

vm.zkVm(true); //here or after prank is fine either way
// the important part is that `doit` isn't run inside zkVM
vm.prank(MINER);
...

As far as realistic test, I'm not sure I understand what you mean. If instead of Blah you had another contract, on chain, which handled the calls to MINING_CONTRACT_ADDRESS somehow, shouldn't you be calling tha contract instead then? And if instead it was some other kind of program off chain, wouldn't that basically be Test1?

You can always create other functions in the Test1 contract to group functionality, and as long as it's not prefixed with test (or a few others like invariant) then it won't be executed as a standalone test.

I'll go ahead and close the issue since we clarified it's intended behaviour, but if you have any more questions you can just comment here on the issue and I'll still reply :)

from foundry-zksync.

Related Issues (20)

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.