Skip to content

Commit

Permalink
chore!: use release paths for sway projects (#1275)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
- `setup_program_test` now expects `release` paths to work

### Checklist
- [ ] I have linked to any relevant issues.
- [ ] I have updated the documentation.
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added necessary labels.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
  • Loading branch information
Br1ght0ne authored May 3, 2024
1 parent 0ddb7e8 commit e898aea
Show file tree
Hide file tree
Showing 24 changed files with 165 additions and 158 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
working-directory: packages/fuels

- name: Build Sway test projects
run: forc build --terse --error-on-warnings
run: forc build --release --terse --error-on-warnings
working-directory: packages/fuels

- uses: actions/upload-artifact@v2
Expand All @@ -82,7 +82,7 @@ jobs:
# TODO: To be removed once https://github.com/FuelLabs/fuels-rs/issues/881 is unblocked.
- name: Build Sway test projects w type paths
run: forc build --terse --error-on-warnings --json-abi-with-callpaths
run: forc build --release --terse --error-on-warnings --json-abi-with-callpaths
working-directory: packages/fuels

- uses: actions/upload-artifact@v2
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ See [the `fuels-rs` book](https://fuellabs.github.io/fuels-rs/latest/)
First, build the test projects using `forc`:

```shell
forc build --path packages/fuels
forc build --release --path packages/fuels
```

Then you can run the SDK tests with:
Expand Down Expand Up @@ -73,7 +73,7 @@ Before doing anything else, try all these commands:
```shell
cargo clean
rm Cargo.lock
forc build --path packages/fuels
forc build --release --path packages/fuels
cargo test
```

Expand Down
4 changes: 2 additions & 2 deletions ci_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

cargo fmt --all -- --check &&
forc fmt --check --path packages/fuels &&
forc build --terse --path packages/fuels &&
forc build --terse --json-abi-with-callpaths --path packages/fuels &&
forc build --release --terse --path packages/fuels &&
forc build --release --terse --json-abi-with-callpaths --path packages/fuels &&
cargo clippy --all-targets &&
cargo clippy --all-targets --all-features &&
cargo test --all-targets --all-features &&
Expand Down
2 changes: 1 addition & 1 deletion docs/src/abigen/the-json-abi-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl MyContract for Contract {
The JSON ABI file looks like this:

```json
$ cat out/debug/my-test-abi.json
$ cat out/release/my-test-abi.json
[
{
"type": "function",
Expand Down
4 changes: 2 additions & 2 deletions docs/src/deploying/the-fuelvm-binary-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ impl MyContract for Contract {
After `forc build`, will have a binary file that contains:

```terminal
$ cat out/debug/my-test.bin
$ cat out/release/my-test.bin
G4]�]D`I]C�As@
6]C�$@!QK%
```

This seems very unreadable! But, `forc` has a nice interpreter for this bytecode: `forc parse-bytecode`, which will interpret that binary data and output the equivalent FuelVM assembly:

```terminal
$ forc parse-bytecode out/debug/my-test.bin
$ forc parse-bytecode out/release/my-test.bin
half-word byte op raw notes
0 0 JI(4) 90 00 00 04 jump to byte 16
1 4 NOOP 47 00 00 00
Expand Down
2 changes: 1 addition & 1 deletion docs/src/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Another way to experience the SDK is to look at the source code. The `packages/f
> To build these tests, run the following command:
```shell
forc build --path packages/fuels
forc build --release --path packages/fuels
```

> `forc` can also be used to clean and format the test projects. Check the `help` output for more info.
Expand Down
3 changes: 1 addition & 2 deletions docs/src/testing/the-setup-program-test-macro.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ Abigen(
)
```

Description: Generates the program bindings under the name `name`. `project`
should point to root of the `forc` project.
Description: Generates the program bindings under the name `name`. `project` should point to root of the `forc` project. The project must be compiled in `release` mode (`--release` flag) for `Abigen` command to work.

Cardinality: 0 or N.

Expand Down
54 changes: 27 additions & 27 deletions examples/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod tests {
// This will load and deploy your contract binary to the chain so that its ID can
// be used to initialize the instance
let contract_id = Contract::load_from(
"../../packages/fuels/tests/contracts/contract_test/out/debug/contract_test.bin",
"../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin",
LoadConfiguration::default(),
)?
.deploy(&wallet, TxPolicies::default())
Expand Down Expand Up @@ -89,13 +89,13 @@ mod tests {

abigen!(Contract(
name = "MyContract",
abi = "packages/fuels/tests/contracts/contract_test/out/debug/contract_test-abi.json"
abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json"
));

let wallet = launch_provider_and_get_wallet().await?;

let contract_id = Contract::load_from(
"../../packages/fuels/tests/contracts/contract_test/out/debug/contract_test.bin",
"../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin",
LoadConfiguration::default(),
)?
.deploy(&wallet, TxPolicies::default())
Expand All @@ -113,7 +113,7 @@ mod tests {
.await?;
// ANCHOR_END: contract_call_cost_estimation

let expected_gas = 2662;
let expected_gas = 2206;

assert_eq!(transaction_cost.gas_used, expected_gas);

Expand All @@ -128,7 +128,7 @@ mod tests {
let wallet = launch_provider_and_get_wallet().await?;

let contract_id_1 = Contract::load_from(
"../../packages/fuels/tests/contracts/contract_test/out/debug/contract_test.bin",
"../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin",
LoadConfiguration::default(),
)?
.deploy(&wallet, TxPolicies::default())
Expand Down Expand Up @@ -158,7 +158,7 @@ mod tests {
.with_maturity(0);

let contract_id_2 = Contract::load_from(
"../../packages/fuels/tests/contracts/contract_test/out/debug/contract_test.bin",
"../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin",
configuration,
)?
.deploy(&wallet, tx_policies)
Expand All @@ -176,7 +176,7 @@ mod tests {
// ANCHOR: abigen_example
abigen!(Contract(
name = "MyContract",
abi = "packages/fuels/tests/contracts/contract_test/out/debug/contract_test-abi.json"
abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json"
));
// ANCHOR_END: abigen_example

Expand Down Expand Up @@ -221,14 +221,14 @@ mod tests {

abigen!(Contract(
name = "MyContract",
abi = "packages/fuels/tests/contracts/contract_test/out/debug/contract_test-abi.json"
abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json"
));

let wallets =
launch_custom_provider_and_get_wallets(WalletsConfig::default(), None, None).await?;

let contract_id_1 = Contract::load_from(
"../../packages/fuels/tests/contracts/contract_test/out/debug/contract_test.bin",
"../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin",
LoadConfiguration::default(),
)?
.deploy(&wallets[0], TxPolicies::default())
Expand All @@ -247,7 +247,7 @@ mod tests {
assert_eq!(42, response.value);

let contract_id_2 = Contract::load_from(
"../../packages/fuels/tests/contracts/contract_test/out/debug/contract_test.bin",
"../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin",
LoadConfiguration::default().with_salt([1; 32]),
)?
.deploy(&wallets[1], TxPolicies::default())
Expand All @@ -273,13 +273,13 @@ mod tests {
use fuels::prelude::*;
abigen!(Contract(
name = "MyContract",
abi = "packages/fuels/tests/contracts/contract_test/out/debug/contract_test-abi.json"
abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json"
));

let wallet = launch_provider_and_get_wallet().await?;

let contract_id = Contract::load_from(
"../../packages/fuels/tests/contracts/contract_test/out/debug/contract_test.bin",
"../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin",
LoadConfiguration::default(),
)?
.deploy(&wallet, TxPolicies::default())
Expand Down Expand Up @@ -342,13 +342,13 @@ mod tests {
use fuels::prelude::*;
abigen!(Contract(
name = "MyContract",
abi = "packages/fuels/tests/contracts/token_ops/out/debug/token_ops-abi.json"
abi = "packages/fuels/tests/contracts/token_ops/out/release/token_ops-abi.json"
));

let wallet = launch_provider_and_get_wallet().await?;

let contract_id = Contract::load_from(
"../../packages/fuels/tests/contracts/token_ops/out/debug/token_ops\
"../../packages/fuels/tests/contracts/token_ops/out/release/token_ops\
.bin",
LoadConfiguration::default(),
)?
Expand Down Expand Up @@ -382,20 +382,20 @@ mod tests {
use fuels::prelude::*;
abigen!(
Contract(name="MyContract",
abi="packages/fuels/tests/contracts/lib_contract_caller/out/debug/lib_contract_caller-abi.json"
abi="packages/fuels/tests/contracts/lib_contract_caller/out/release/lib_contract_caller-abi.json"
));

let wallet = launch_provider_and_get_wallet().await?;

let called_contract_id: ContractId = Contract::load_from(
"../../packages/fuels/tests/contracts/lib_contract/out/debug/lib_contract.bin",
"../../packages/fuels/tests/contracts/lib_contract/out/release/lib_contract.bin",
LoadConfiguration::default(),
)?
.deploy(&wallet, TxPolicies::default())
.await?
.into();

let bin_path = "../../packages/fuels/tests/contracts/lib_contract_caller/out/debug/lib_contract_caller.bin";
let bin_path = "../../packages/fuels/tests/contracts/lib_contract_caller/out/release/lib_contract_caller.bin";
let caller_contract_id = Contract::load_from(bin_path, LoadConfiguration::default())?
.deploy(&wallet, TxPolicies::default())
.await?;
Expand Down Expand Up @@ -455,7 +455,7 @@ mod tests {
abigen!(Contract(
name = "MyContract",
// Replace with your contract ABI.json path
abi = "packages/fuels/tests/contracts/contract_test/out/debug/contract_test-abi.json"
abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json"
));
let wallet_original = launch_provider_and_get_wallet().await?;

Expand Down Expand Up @@ -485,13 +485,13 @@ mod tests {
use fuels::prelude::*;
abigen!(Contract(
name = "MyContract",
abi = "packages/fuels/tests/contracts/contract_test/out/debug/contract_test-abi.json"
abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json"
));

let wallet = launch_provider_and_get_wallet().await?;

let contract_id = Contract::load_from(
"../../packages/fuels/tests/contracts/contract_test/out/debug/contract_test.bin",
"../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin",
LoadConfiguration::default(),
)?
.deploy(&wallet, TxPolicies::default())
Expand Down Expand Up @@ -523,13 +523,13 @@ mod tests {

abigen!(Contract(
name = "MyContract",
abi = "packages/fuels/tests/contracts/contract_test/out/debug/contract_test-abi.json"
abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json"
));

let wallet = launch_provider_and_get_wallet().await?;

let contract_id = Contract::load_from(
"../../packages/fuels/tests/contracts/contract_test/out/debug/contract_test.bin",
"../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin",
LoadConfiguration::default(),
)?
.deploy(&wallet, TxPolicies::default())
Expand Down Expand Up @@ -579,13 +579,13 @@ mod tests {

abigen!(Contract(
name = "MyContract",
abi = "packages/fuels/tests/contracts/contract_test/out/debug/contract_test-abi.json"
abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json"
));

let wallet = launch_provider_and_get_wallet().await?;

let contract_id = Contract::load_from(
"../../packages/fuels/tests/contracts/contract_test/out/debug/contract_test.bin",
"../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin",
LoadConfiguration::default(),
)?
.deploy(&wallet, TxPolicies::default())
Expand All @@ -610,7 +610,7 @@ mod tests {
.await?;
// ANCHOR_END: multi_call_cost_estimation

let expected_gas = 4152;
let expected_gas = 3378;

assert_eq!(transaction_cost.gas_used, expected_gas);

Expand All @@ -623,7 +623,7 @@ mod tests {
use fuels::prelude::*;
abigen!(Contract(
name = "MyContract",
abi = "packages/fuels/tests/contracts/contract_test/out/debug/contract_test-abi.json"
abi = "packages/fuels/tests/contracts/contract_test/out/release/contract_test-abi.json"
));

let config = WalletsConfig::new(Some(2), Some(1), Some(DEFAULT_COIN_AMOUNT));
Expand All @@ -632,7 +632,7 @@ mod tests {
let wallet_2 = wallets.pop().unwrap();

let contract_id = Contract::load_from(
"../../packages/fuels/tests/contracts/contract_test/out/debug/contract_test.bin",
"../../packages/fuels/tests/contracts/contract_test/out/release/contract_test.bin",
LoadConfiguration::default(),
)?
.deploy(&wallet_1, TxPolicies::default())
Expand Down
7 changes: 4 additions & 3 deletions examples/cookbook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ mod tests {
// ANCHOR: liquidity_abigen
abigen!(Contract(
name = "MyContract",
abi = "packages/fuels/tests/contracts/liquidity_pool/out/debug/liquidity_pool-abi.json"
abi =
"packages/fuels/tests/contracts/liquidity_pool/out/release/liquidity_pool-abi.json"
));
// ANCHOR_END: liquidity_abigen

Expand All @@ -52,7 +53,7 @@ mod tests {

// ANCHOR: liquidity_deploy
let contract_id = Contract::load_from(
"../../packages/fuels/tests/contracts/liquidity_pool/out/debug/liquidity_pool.bin",
"../../packages/fuels/tests/contracts/liquidity_pool/out/release/liquidity_pool.bin",
LoadConfiguration::default(),
)?
.deploy(wallet, TxPolicies::default())
Expand Down Expand Up @@ -225,7 +226,7 @@ mod tests {
let mut hot_wallet = WalletUnlocked::new_random(None);
let mut cold_wallet = WalletUnlocked::new_random(None);

let code_path = "../../packages/fuels/tests/predicates/swap/out/debug/swap.bin";
let code_path = "../../packages/fuels/tests/predicates/swap/out/release/swap.bin";
let mut predicate = Predicate::load_from(code_path)?;

let num_coins = 5;
Expand Down
4 changes: 2 additions & 2 deletions examples/debugging/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ mod tests {
fn decoded_debug_matches_rust_debug() -> Result<()> {
abigen!(Contract(
name = "MyContract",
abi = "packages/fuels/tests/types/contracts/generics/out/debug/generics-abi.json"
abi = "packages/fuels/tests/types/contracts/generics/out/release/generics-abi.json"
));

let json_abi_file =
"../../packages/fuels/tests/types/contracts/generics/out/debug/generics-abi.json";
"../../packages/fuels/tests/types/contracts/generics/out/release/generics-abi.json";
let abi_file_contents = std::fs::read_to_string(json_abi_file)?;

let parsed_abi: ProgramABI = serde_json::from_str(&abi_file_contents)?;
Expand Down
8 changes: 4 additions & 4 deletions examples/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ mod tests {
fn example_of_abigen_usage() {
// ANCHOR: multiple_abigen_program_types
abigen!(
Contract(name="ContractA", abi="packages/fuels/tests/bindings/sharing_types/contract_a/out/debug/contract_a-abi.json"),
Contract(name="ContractB", abi="packages/fuels/tests/bindings/sharing_types/contract_b/out/debug/contract_b-abi.json"),
Script(name="MyScript", abi="packages/fuels/tests/scripts/arguments/out/debug/arguments-abi.json"),
Predicate(name="MyPredicateEncoder", abi="packages/fuels/tests/predicates/basic_predicate/out/debug/basic_predicate-abi.json"),
Contract(name="ContractA", abi="packages/fuels/tests/bindings/sharing_types/contract_a/out/release/contract_a-abi.json"),
Contract(name="ContractB", abi="packages/fuels/tests/bindings/sharing_types/contract_b/out/release/contract_b-abi.json"),
Script(name="MyScript", abi="packages/fuels/tests/scripts/arguments/out/release/arguments-abi.json"),
Predicate(name="MyPredicateEncoder", abi="packages/fuels/tests/predicates/basic_predicate/out/release/basic_predicate-abi.json"),
);
// ANCHOR_END: multiple_abigen_program_types
}
Expand Down
Loading

0 comments on commit e898aea

Please sign in to comment.