From aa36aea9362575c769781e7ab640d1d75dce13c8 Mon Sep 17 00:00:00 2001 From: Simon Roberts <46566889+simonr0204@users.noreply.github.com> Date: Tue, 22 Mar 2022 10:51:44 -0600 Subject: [PATCH] bump sdk to 0.7. Use test-helpers to cut down on boilerplate (#84) --- tests/Cargo.toml | 8 +- tests/test_projects/registers/mod.rs | 153 +++++++-------------------- tests/test_projects/token_ops/mod.rs | 25 +++-- 3 files changed, 57 insertions(+), 129 deletions(-) diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 4c72ed4a604..66ae00bd994 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -11,10 +11,10 @@ fuel-gql-client = { version = "0.4", default-features = false } fuel-tx = "0.6" fuel-types = "0.3" fuel-vm = "0.5" -fuels-abigen-macro = "0.6" -fuels-signers = { version = "0.6", features=["test-helpers"] } -fuels-contract = "0.6" -fuels-core = "0.6" +fuels-abigen-macro = "0.7" +fuels-signers = { version = "0.7", features=["test-helpers"] } +fuels-contract = "0.7" +fuels-core = "0.7" rand = "0.8" tokio = { version = "1.12", features = ["rt", "macros"] } diff --git a/tests/test_projects/registers/mod.rs b/tests/test_projects/registers/mod.rs index c32f31a8ef9..16d4a565d3d 100644 --- a/tests/test_projects/registers/mod.rs +++ b/tests/test_projects/registers/mod.rs @@ -1,222 +1,143 @@ -use fuel_core::service::Config; +use fuel_core::service::{Config, FuelService}; use fuel_tx::Salt; use fuel_vm::consts::VM_MAX_RAM; use fuels_abigen_macro::abigen; -use fuels_contract::contract::Contract; -use fuels_signers::provider::Provider; +use fuels_contract::{parameters::TxParameters, contract::Contract}; +use fuels_signers::util::test_helpers; + abigen!( - TestFuelCoinContract, + TestRegistersContract, "test_projects/registers/out/debug/registers-abi.json", ); -#[tokio::test] -async fn can_get_overflow() { + +// Compile contract, create node and deploy contract, returning TestRegistersContract contract instance +// TO DO : +// - Ability to return any type of Contract. +// - Return a result +async fn deploy_testRegisters_instance() -> TestRegistersContract { + let salt = Salt::from([0u8; 32]); let compiled = Contract::load_sway_contract("test_projects/registers/out/debug/registers.bin", salt) .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); + let server = FuelService::new_node(Config::local_node()).await.unwrap(); + let (provider, wallet) = test_helpers::setup_test_provider_and_wallet().await; + let id = Contract::deploy(&compiled, &provider, &wallet, TxParameters::default()).await.unwrap(); + + TestRegistersContract::new(id.to_string(), provider, wallet) +} - let result = instance.get_overflow().call().await.unwrap(); +#[tokio::test] +async fn can_get_overflow() { + let instance = deploy_testRegisters_instance().await; + let result = instance.get_overflow().call().await.unwrap(); assert_eq!(result.value, 0); } #[tokio::test] async fn can_get_program_counter() { - let salt = Salt::from([0u8; 32]); - let compiled = - Contract::load_sway_contract("test_projects/registers/out/debug/registers.bin", salt) - .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); + let instance = deploy_testRegisters_instance().await; let result = instance.get_program_counter().call().await.unwrap(); - assert!(is_within_range(result.value)); } #[tokio::test] async fn can_get_stack_start_ptr() { - let salt = Salt::from([0u8; 32]); - let compiled = - Contract::load_sway_contract("test_projects/registers/out/debug/registers.bin", salt) - .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); - + + let instance = deploy_testRegisters_instance().await; let result = instance.get_stack_start_ptr().call().await.unwrap(); - assert!(is_within_range(result.value)); } #[tokio::test] async fn can_get_stack_ptr() { - let salt = Salt::from([0u8; 32]); - let compiled = - Contract::load_sway_contract("test_projects/registers/out/debug/registers.bin", salt) - .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); - + + let instance = deploy_testRegisters_instance().await; let result = instance.get_stack_ptr().call().await.unwrap(); - assert!(is_within_range(result.value)); } #[tokio::test] async fn can_get_frame_ptr() { - let salt = Salt::from([0u8; 32]); - let compiled = - Contract::load_sway_contract("test_projects/registers/out/debug/registers.bin", salt) - .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); + let instance = deploy_testRegisters_instance().await; let result = instance.get_frame_ptr().call().await.unwrap(); - assert!(is_within_range(result.value)); } #[tokio::test] async fn can_get_heap_ptr() { - let salt = Salt::from([0u8; 32]); - let compiled = - Contract::load_sway_contract("test_projects/registers/out/debug/registers.bin", salt) - .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); + let instance = deploy_testRegisters_instance().await; let result = instance.get_heap_ptr().call().await.unwrap(); - assert!(is_within_range(result.value)); } #[tokio::test] async fn can_get_error() { - let salt = Salt::from([0u8; 32]); - let compiled = - Contract::load_sway_contract("test_projects/registers/out/debug/registers.bin", salt) - .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); + let instance = deploy_testRegisters_instance().await; let result = instance.get_error().call().await.unwrap(); - assert_eq!(result.value, 0); } #[tokio::test] async fn can_get_global_gas() { - let salt = Salt::from([0u8; 32]); - let compiled = - Contract::load_sway_contract("test_projects/registers/out/debug/registers.bin", salt) - .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); + let instance = deploy_testRegisters_instance().await; let result = instance.get_global_gas().call().await.unwrap(); - assert!(is_within_range(result.value)); } #[tokio::test] async fn can_get_context_gas() { - let salt = Salt::from([0u8; 32]); - let compiled = - Contract::load_sway_contract("test_projects/registers/out/debug/registers.bin", salt) - .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); + let instance = deploy_testRegisters_instance().await; let result = instance.get_context_gas().call().await.unwrap(); - assert!(is_within_range(result.value)); } #[tokio::test] async fn can_get_balance() { - let salt = Salt::from([0u8; 32]); - let compiled = - Contract::load_sway_contract("test_projects/registers/out/debug/registers.bin", salt) - .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); + let instance = deploy_testRegisters_instance().await; let result = instance.get_balance().call().await.unwrap(); - assert_eq!(result.value, 0); } #[tokio::test] async fn can_get_instrs_start() { - let salt = Salt::from([0u8; 32]); - let compiled = - Contract::load_sway_contract("test_projects/registers/out/debug/registers.bin", salt) - .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); + let instance = deploy_testRegisters_instance().await; let result = instance.get_instrs_start().call().await.unwrap(); - assert!(is_within_range(result.value)); } #[tokio::test] async fn can_get_return_value() { - let salt = Salt::from([0u8; 32]); - let compiled = - Contract::load_sway_contract("test_projects/registers/out/debug/registers.bin", salt) - .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); + let instance = deploy_testRegisters_instance().await; let result = instance.get_return_value().call().await.unwrap(); - assert_eq!(result.value, 0); } #[tokio::test] async fn can_get_return_length() { - let salt = Salt::from([0u8; 32]); - let compiled = - Contract::load_sway_contract("test_projects/registers/out/debug/registers.bin", salt) - .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); + let instance = deploy_testRegisters_instance().await; let result = instance.get_return_length().call().await.unwrap(); - assert_eq!(result.value, 0); } #[tokio::test] async fn can_get_flags() { - let salt = Salt::from([0u8; 32]); - let compiled = - Contract::load_sway_contract("test_projects/registers/out/debug/registers.bin", salt) - .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); + let instance = deploy_testRegisters_instance().await; let result = instance.get_flags().call().await.unwrap(); - assert_eq!(result.value, 0); } diff --git a/tests/test_projects/token_ops/mod.rs b/tests/test_projects/token_ops/mod.rs index e4cf92c2fdf..a11021ad355 100644 --- a/tests/test_projects/token_ops/mod.rs +++ b/tests/test_projects/token_ops/mod.rs @@ -1,8 +1,9 @@ -use fuel_core::service::Config; +use fuel_core::service::{Config, FuelService}; use fuel_tx::Salt; use fuels_abigen_macro::abigen; -use fuels_contract::contract::Contract; -use fuels_signers::provider::Provider; +use fuels_contract::{parameters::TxParameters, contract::Contract}; +use fuels_signers::util::test_helpers; + abigen!( TestFuelCoinContract, @@ -15,9 +16,12 @@ async fn mint() { let compiled = Contract::load_sway_contract("test_projects/token_ops/out/debug/token_ops.bin", salt) .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); + + let server = FuelService::new_node(Config::local_node()).await.unwrap(); + let (provider, wallet) = test_helpers::setup_test_provider_and_wallet().await; + let id = Contract::deploy(&compiled, &provider, &wallet, TxParameters::default()).await.unwrap(); + + let instance = TestFuelCoinContract::new(id.to_string(), provider, wallet); let target = testfuelcoincontract_mod::ContractId { value: id.into() }; let asset_id = testfuelcoincontract_mod::ContractId { value: id.into() }; @@ -41,9 +45,12 @@ async fn burn() { let compiled = Contract::load_sway_contract("test_projects/token_ops/out/debug/token_ops.bin", salt) .unwrap(); - let client = Provider::launch(Config::local_node()).await.unwrap(); - let id = Contract::deploy(&compiled, &client).await.unwrap(); - let instance = TestFuelCoinContract::new(id.to_string(), client); + + let server = FuelService::new_node(Config::local_node()).await.unwrap(); + let (provider, wallet) = test_helpers::setup_test_provider_and_wallet().await; + let id = Contract::deploy(&compiled, &provider, &wallet, TxParameters::default()).await.unwrap(); + + let instance = TestFuelCoinContract::new(id.to_string(), provider, wallet); let target = testfuelcoincontract_mod::ContractId { value: id.into() }; let asset_id = testfuelcoincontract_mod::ContractId { value: id.into() };