Skip to content

Commit

Permalink
feat: Updating all templates to rust v0.62.0 (#6067)
Browse files Browse the repository at this point in the history
## Description


## Checklist

- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [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
calldelegation authored May 29, 2024
1 parent 94b2713 commit 6db265a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion templates/sway-predicate-test-rs/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["{{authors}}"]
license = "Apache-2.0"

[dev-dependencies]
fuels = { version = "0.53", features = ["fuel-core-lib"] }
fuels = { version = "0.62", features = ["fuel-core-lib"] }
tokio = { version = "1.12", features = ["rt", "macros"] }

[[test]]
Expand Down
12 changes: 7 additions & 5 deletions templates/sway-predicate-test-rs/template/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ abigen!(Predicate(
abi = "out/debug/{{project-name}}-abi.json"
));

async fn get_predicate_instance() -> (WalletUnlocked, Predicate) {
async fn get_predicate_instance() -> (WalletUnlocked, Predicate, AssetId) {
let mut wallets = launch_custom_provider_and_get_wallets(
WalletsConfig::new(
Some(1), /* Single wallet */
Expand All @@ -23,11 +23,13 @@ async fn get_predicate_instance() -> (WalletUnlocked, Predicate) {

let provider = wallet.provider().clone().unwrap();

let base_asset_id = provider.base_asset_id().clone();

let bin_path = "./out/debug/{{project-name}}.bin";

let instance: Predicate = Predicate::load_from(bin_path).unwrap().with_provider(provider.clone());

(wallet, instance)
(wallet, instance, base_asset_id)
}

async fn check_balances(
Expand All @@ -52,19 +54,19 @@ async fn check_balances(

#[tokio::test]
async fn can_get_predicate_instance() {
let (wallet, instance) = get_predicate_instance().await;
let (wallet, instance, base_asset_id) = get_predicate_instance().await;
let predicate_root = instance.address();

// Check balances before funding predicate
check_balances(&wallet, &instance, Some(1_000_000_000u64), None).await;

// Fund predicate from wallet
let _ = wallet.transfer(predicate_root, 1234, BASE_ASSET_ID, TxPolicies::default()).await;
let _ = wallet.transfer(predicate_root, 1234, base_asset_id, TxPolicies::default()).await;

// Check balances after funding predicate
check_balances(&wallet, &instance, Some(999_998_766u64), Some(1234u64)).await;

let _ = instance.transfer(wallet.address(), 1234, BASE_ASSET_ID, TxPolicies::default()).await;
let _ = instance.transfer(wallet.address(), 1234, base_asset_id, TxPolicies::default()).await;

// Check balances after transferring funds out of predicate
check_balances(&wallet, &instance, Some(1_000_000_000u64), Some(0u64)).await;
Expand Down
2 changes: 1 addition & 1 deletion templates/sway-script-test-rs/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["{{authors}}"]
license = "Apache-2.0"

[dev-dependencies]
fuels = { version = "0.53", features = ["fuel-core-lib"] }
fuels = { version = "0.62", features = ["fuel-core-lib"] }
tokio = { version = "1.12", features = ["rt", "macros"] }

[[test]]
Expand Down
6 changes: 3 additions & 3 deletions templates/sway-script-test-rs/template/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ abigen!(Script(

async fn get_script_instance() -> MyScript<WalletUnlocked> {
// Launch a local network
let mut wallets = launch_custom_provider_and_get_wallets(
let wallets = launch_custom_provider_and_get_wallets(
WalletsConfig::new(
Some(1), /* Single wallet */
Some(1), /* Single coin (UTXO) */
Expand All @@ -18,7 +18,7 @@ async fn get_script_instance() -> MyScript<WalletUnlocked> {
None,
)
.await;
let wallet = wallets.pop().unwrap();
let wallet = wallets.unwrap().pop().unwrap();

let bin_path = "./out/debug/{{project-name}}.bin";

Expand All @@ -30,7 +30,7 @@ async fn get_script_instance() -> MyScript<WalletUnlocked> {
#[tokio::test]
async fn can_get_script_instance() {
const LUCKY_NUMBER: u64 = 777;
let configurables = MyScriptConfigurables::new().with_SECRET_NUMBER(LUCKY_NUMBER.clone());
let configurables = MyScriptConfigurables::default().with_SECRET_NUMBER(LUCKY_NUMBER.clone()).unwrap();

let instance = get_script_instance().await;

Expand Down
2 changes: 1 addition & 1 deletion templates/sway-test-rs/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["{{authors}}"]
license = "Apache-2.0"

[dev-dependencies]
fuels = { version = "0.54.0", features = ["fuel-core-lib"] }
fuels = { version = "0.62.0", features = ["fuel-core-lib"] }
tokio = { version = "1.12", features = ["rt", "macros"] }

[[test]]
Expand Down

0 comments on commit 6db265a

Please sign in to comment.