-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: inject contract id into the namespace for tests automatically (#…
…3729) closes #3673. ## About this PR This PR adds `CONTRACT_ID` injection while building contracts with `forc build --test`. `CONTRACT_ID` is the id of the contract without the tests added. To find out that id, we first compile the contract without tests enabled. The rough outline of stuff happening here: 1. We iterate over `BuildPlan` members to find out contracts and collect their contract id into an injection map. In this step only the contracts are built. To determine contract id we need to compile the contract without tests. Since we also need the bytecode of the contract without tests, we are collecting them as we come across them while iterating over members. 2. With the injection map build and execute all the tests, so basically after first step we are just doing the old `forc-test` behaviour. So basically I added a pre-processing step for contract id collection for those members that require it (contracts). This enables the following test structure: ```rust let caller = abi(MyContract, CONTRACT_ID); let result = caller.test_function {}(); assert(result == true) ```
- Loading branch information
1 parent
5f415ab
commit b8aa28b
Showing
7 changed files
with
149 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.