Skip to content

Commit

Permalink
fix: Re-enable tests blocked by stdlib's gtf integration (#557)
Browse files Browse the repository at this point in the history
Co-authored-by: Mohammad Fawaz <[email protected]>
  • Loading branch information
digorithm and mohammadfawaz authored Sep 1, 2022
1 parent ae73b81 commit d43b295
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:
RUSTFLAGS: "-D warnings"
FUEL_CORE_VERSION: 0.10.1
RUST_VERSION: 1.61.0
FORC_VERSION: 0.20.2
FORC_VERSION: 0.22.1

jobs:
setup-test-projects:
Expand Down
42 changes: 20 additions & 22 deletions examples/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod tests {
abigen!(
MyContract,
// This path is relative to the workspace (repository) root
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-abi.json"
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-flat-abi.json"
);

// This helper will launch a local node and provide a test wallet linked to it
Expand Down Expand Up @@ -79,7 +79,7 @@ mod tests {

abigen!(
MyContract,
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-abi.json"
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-flat-abi.json"
);

let wallet = launch_provider_and_get_wallet().await;
Expand All @@ -102,7 +102,7 @@ mod tests {
.await?;
// ANCHOR_END: contract_call_cost_estimation

assert_eq!(transaction_cost.gas_used, 631);
assert_eq!(transaction_cost.gas_used, 592);

Ok(())
}
Expand All @@ -116,7 +116,7 @@ mod tests {
// ANCHOR: abigen_example
abigen!(
MyContract,
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-abi.json"
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-flat-abi.json"
);
// ANCHOR_END: abigen_example

Expand Down Expand Up @@ -158,7 +158,7 @@ mod tests {

abigen!(
MyContract,
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-abi.json"
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-flat-abi.json"
);

let wallets = launch_custom_provider_and_get_wallets(WalletsConfig::default(), None).await;
Expand Down Expand Up @@ -212,7 +212,7 @@ mod tests {
use fuels::prelude::*;
abigen!(
MyContract,
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-abi.json"
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-flat-abi.json"
);

let wallet = launch_provider_and_get_wallet().await;
Expand Down Expand Up @@ -290,8 +290,7 @@ mod tests {
use fuels::prelude::*;
abigen!(
MyContract,
"packages/fuels/tests/test_projects/token_ops/out/debug/token_ops-abi\
.json"
"packages/fuels/tests/test_projects/token_ops/out/debug/token_ops-flat-abi.json"
);

let wallet = launch_provider_and_get_wallet().await;
Expand All @@ -312,15 +311,14 @@ mod tests {
// ANCHOR_END: simulate
let response = contract_instance.mint_coins(1_000_000).call().await?;
// ANCHOR: variable_outputs
// TODO: Enable test
// let address = wallet.address();
let address = wallet.address();

// withdraw some tokens to wallet
// let response = contract_instance
// .transfer_coins_to_output(1_000_000, contract_id.into(), address.into())
// .append_variable_outputs(1)
// .call()
// .await?;
let response = contract_instance
.transfer_coins_to_output(1_000_000, contract_id.into(), address.into())
.append_variable_outputs(1)
.call()
.await?;
// ANCHOR_END: variable_outputs
Ok(())
}
Expand All @@ -332,7 +330,7 @@ mod tests {
use fuels::tx::Receipt;
abigen!(
TestContract,
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-abi.json"
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-flat-abi.json"
);
let wallet = launch_provider_and_get_wallet().await;
let contract_id = Contract::deploy(
Expand Down Expand Up @@ -377,7 +375,7 @@ mod tests {
// Replace with your contract ABI.json path
abigen!(
MyContract,
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-abi.json"
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-flat-abi.json"
);
let wallet = launch_provider_and_get_wallet().await;
// Your contract ID as a String.
Expand All @@ -396,7 +394,7 @@ mod tests {
use fuels::prelude::*;
abigen!(
MyContract,
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-abi.json"
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-flat-abi.json"
);

let wallet = launch_provider_and_get_wallet().await;
Expand Down Expand Up @@ -436,7 +434,7 @@ mod tests {

abigen!(
MyContract,
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-abi.json"
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-flat-abi.json"
);

let wallet = launch_provider_and_get_wallet().await;
Expand Down Expand Up @@ -486,7 +484,7 @@ mod tests {

abigen!(
MyContract,
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-abi.json"
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-flat-abi.json"
);

let wallet = launch_provider_and_get_wallet().await;
Expand Down Expand Up @@ -518,7 +516,7 @@ mod tests {
.await?;
// ANCHOR_END: multi_call_cost_estimation

assert_eq!(transaction_cost.gas_used, 1051);
assert_eq!(transaction_cost.gas_used, 1012);

Ok(())
}
Expand All @@ -529,7 +527,7 @@ mod tests {
use fuels::prelude::*;
abigen!(
MyContract,
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-abi.json"
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-flat-abi.json"
);

let config = WalletsConfig::new(Some(2), Some(1), Some(DEFAULT_COIN_AMOUNT));
Expand Down
48 changes: 24 additions & 24 deletions examples/cookbook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod tests {
// ANCHOR: liquidity_abigen
abigen!(
MyContract,
"packages/fuels/tests/test_projects/liquidity_pool/out/debug/liquidity_pool-abi.json"
"packages/fuels/tests/test_projects/liquidity_pool/out/debug/liquidity_pool-flat-abi.json"
);
// ANCHOR_END: liquidity_abigen

Expand Down Expand Up @@ -43,35 +43,35 @@ mod tests {
)
.await?;

let _contract_instance =
let contract_instance =
MyContractBuilder::new(contract_id.to_string(), wallet.clone()).build();
// ANCHOR_END: liquidity_deploy
//TODO: Enable test

// ANCHOR: liquidity_deposit
// let deposit_amount = 1_000_000;
// let call_params = CallParameters::new(Some(deposit_amount), Some(base_asset_id), None);
// contract_instance
// .deposit(wallet.address().into())
// .call_params(call_params)
// .append_variable_outputs(1)
// .call()
// .await?;
let deposit_amount = 1_000_000;
let call_params = CallParameters::new(Some(deposit_amount), Some(base_asset_id), None);
contract_instance
.deposit(wallet.address().into())
.call_params(call_params)
.append_variable_outputs(1)
.call()
.await?;
// ANCHOR_END: liquidity_deposit

// ANCHOR: liquidity_withdraw
// let lp_asset_id = AssetId::from(*contract_id.hash());
// let lp_token_balance = wallet.get_asset_balance(&lp_asset_id).await?;

// let call_params = CallParameters::new(Some(lp_token_balance), Some(lp_asset_id), None);
// contract_instance
// .withdraw(wallet.address().into())
// .call_params(call_params)
// .append_variable_outputs(1)
// .call()
// .await?;

// let base_balance = wallet.get_asset_balance(&base_asset_id).await?;
// assert_eq!(base_balance, deposit_amount);
let lp_asset_id = AssetId::from(*contract_id.hash());
let lp_token_balance = wallet.get_asset_balance(&lp_asset_id).await?;

let call_params = CallParameters::new(Some(lp_token_balance), Some(lp_asset_id), None);
contract_instance
.withdraw(wallet.address().into())
.call_params(call_params)
.append_variable_outputs(1)
.call()
.await?;

let base_balance = wallet.get_asset_balance(&base_asset_id).await?;
assert_eq!(base_balance, deposit_amount);
// ANCHOR_END: liquidity_withdraw

Ok(())
Expand Down
71 changes: 36 additions & 35 deletions packages/fuels/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1522,15 +1522,14 @@ async fn test_amount_and_asset_forwarding() -> Result<(), Error> {
assert_eq!(call_response.unwrap().amount().unwrap(), 1_000_000);
assert_eq!(call_response.unwrap().asset_id().unwrap(), &BASE_ASSET_ID);

// TODO: Enable test
//let address = wallet.address();
let address = wallet.address();

// withdraw some tokens to wallet
// instance
// .transfer_coins_to_output(1_000_000, (&id).into(), address.into())
// .append_variable_outputs(1)
// .call()
// .await?;
instance
.transfer_coins_to_output(1_000_000, (&id).into(), address.into())
.append_variable_outputs(1)
.call()
.await?;

let asset_id = AssetId::from(*id.hash());
let call_params = CallParameters::new(Some(0), Some(asset_id), None);
Expand Down Expand Up @@ -1725,33 +1724,35 @@ async fn test_arrays_with_custom_types() -> Result<(), Error> {
assert_eq!(states[1], response.value[1]);
Ok(())
}
// TODO: Enable test
// #[tokio::test]
// async fn test_auth_msg_sender_from_sdk() -> Result<(), Error> {
// abigen!(
// AuthContract,
// "packages/fuels/tests/test_projects/auth_testing_contract/out/debug/auth_testing_contract-flat-abi.json"
// );

// let id = Contract::deploy(
// "tests/test_projects/auth_testing_contract/out/debug/auth_testing_contract.bin",
// &wallet,
// TxParameters::default(),
// StorageConfiguration::default(),
// )
// .await?;
#[tokio::test]
async fn test_auth_msg_sender_from_sdk() -> Result<(), Error> {
abigen!(
AuthContract,
"packages/fuels/tests/test_projects/auth_testing_contract/out/debug/auth_testing_contract-flat-abi.json"
);

let wallet = launch_provider_and_get_wallet().await;

let id = Contract::deploy(
"tests/test_projects/auth_testing_contract/out/debug/auth_testing_contract.bin",
&wallet,
TxParameters::default(),
StorageConfiguration::default(),
)
.await?;

// let auth_instance = AuthContractBuilder::new(id.to_string(), wallet.clone()).build();
let auth_instance = AuthContractBuilder::new(id.to_string(), wallet.clone()).build();

// // Contract returns true if `msg_sender()` matches `wallet.address()`.
// let response = auth_instance
// .check_msg_sender(wallet.address().into())
// .call()
// .await?;
// Contract returns true if `msg_sender()` matches `wallet.address()`.
let response = auth_instance
.check_msg_sender(wallet.address().into())
.call()
.await?;

// assert!(response.value);
// Ok(())
// }
assert!(response.value);
Ok(())
}

#[tokio::test]
async fn workflow_enum_inside_struct() -> Result<(), Error> {
Expand Down Expand Up @@ -3332,7 +3333,7 @@ async fn test_connect_wallet() -> anyhow::Result<()> {
async fn contract_call_fee_estimation() -> Result<(), Error> {
abigen!(
MyContract,
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-abi.json"
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-flat-abi.json"
);

let wallet = launch_provider_and_get_wallet().await;
Expand All @@ -3352,9 +3353,9 @@ async fn contract_call_fee_estimation() -> Result<(), Error> {
let tolerance = 0.2;

let expected_min_gas_price = 0; // This is the default min_gas_price from the ConsensusParameters
let expected_gas_used = 757;
let expected_gas_used = 710;
let expected_metered_bytes_size = 720;
let expected_total_fee = 364;
let expected_total_fee = 359;

let estimated_transaction_cost = contract_instance
.initialize_counter(42) // Build the ABI call
Expand All @@ -3381,7 +3382,7 @@ async fn contract_call_fee_estimation() -> Result<(), Error> {
async fn contract_call_has_same_estimated_and_used_gas() -> Result<(), Error> {
abigen!(
MyContract,
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-abi.json"
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-flat-abi.json"
);

let wallet = launch_provider_and_get_wallet().await;
Expand Down Expand Up @@ -3418,7 +3419,7 @@ async fn contract_call_has_same_estimated_and_used_gas() -> Result<(), Error> {
async fn mutl_call_has_same_estimated_and_used_gas() -> Result<(), Error> {
abigen!(
MyContract,
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-abi.json"
"packages/fuels/tests/test_projects/contract_test/out/debug/contract_test-flat-abi.json"
);

let wallet = launch_provider_and_get_wallet().await;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
predicate;

use std::tx::get_predicate_data;
use std::inputs::input_predicate_data;

fn main() -> bool {
let received: b256 = get_predicate_data();
let received: b256 = input_predicate_data(0);
let expected: b256 = 0xef86afa9696cf0dc6385e2c407a6e159a1103cefb7e2ae0636fb33d3cb2a9e4a;

received == expected
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
predicate;

use std::{
tx::get_predicate_data,
inputs::input_predicate_data,
ecr::ec_recover_address,
constants::ZERO_B256,
b512::B512,
Expand All @@ -18,7 +18,7 @@ fn extract_pulic_key_and_match(signature: B512, expected_public_key: b256) -> u6
}

fn main() -> bool {
let signatures: [B512;3] = get_predicate_data();
let signatures: [B512;3] = input_predicate_data(0);

let public_keys = [
0xd58573593432a30a800f97ad32f877425c223a9e427ab557aab5d5bb89156db0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
predicate;

use std::tx::get_predicate_data;

use std::inputs::input_predicate_data;

struct Validation {
has_account: bool,
total_complete: u64
}

fn main() -> bool {
let received: Validation = get_predicate_data();
let received: Validation = input_predicate_data(0);
let expected_has_account: bool = true;
let expected_total_complete: u64 = 100;

Expand Down
Loading

0 comments on commit d43b295

Please sign in to comment.