Skip to content

Commit

Permalink
bump sdk to 0.7. Use test-helpers to cut down on boilerplate (FuelLab…
Browse files Browse the repository at this point in the history
  • Loading branch information
simonr0204 authored Mar 22, 2022
1 parent 385c457 commit aa36aea
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 129 deletions.
8 changes: 4 additions & 4 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
153 changes: 37 additions & 116 deletions tests/test_projects/registers/mod.rs
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down
25 changes: 16 additions & 9 deletions tests/test_projects/token_ops/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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() };
Expand All @@ -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() };
Expand Down

0 comments on commit aa36aea

Please sign in to comment.