Skip to content

Commit

Permalink
Bump SDK to 0.34 (FuelLabs#3879)
Browse files Browse the repository at this point in the history
Bumps the rust SDK for the `sdk_harness` tests.

Co-authored-by: Toby Hutton <[email protected]>
Co-authored-by: Mohammad Fawaz <[email protected]>
Co-authored-by: João Matos <[email protected]>
  • Loading branch information
4 people authored Jan 25, 2023
1 parent 0419c19 commit b070579
Show file tree
Hide file tree
Showing 43 changed files with 298 additions and 257 deletions.
3 changes: 1 addition & 2 deletions test/src/sdk-harness/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ version = "0.0.0"
assert_matches = "1.5.0"
fuel-core = { version = "0.15", default-features = false }
fuel-gql-client = { version = "0.15", default-features = false }
fuel-types = "0.5"
fuel-vm = "0.22"
fuels = { version = "0.33", features = ["fuel-core-lib"] }
fuels = { version = "0.34", features = ["fuel-core-lib"] }
hex = "0.4.3"
rand = "0.8"
sha2 = "0.10"
Expand Down
18 changes: 10 additions & 8 deletions test/src/sdk-harness/test_projects/auth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use fuels::{prelude::*, tx::ContractId};

abigen!(
AuthContract,
"test_artifacts/auth_testing_contract/out/debug/auth_testing_contract-abi.json"
);
abigen!(
AuthCallerContract,
"test_artifacts/auth_caller_contract/out/debug/auth_caller_contract-abi.json"
Contract(
name = "AuthContract",
abi = "test_artifacts/auth_testing_contract/out/debug/auth_testing_contract-abi.json"
),
Contract(
name = "AuthCallerContract",
abi = "test_artifacts/auth_caller_contract/out/debug/auth_caller_contract-abi.json"
)
);

#[tokio::test]
Expand Down Expand Up @@ -37,12 +39,12 @@ async fn msg_sender_from_sdk() {

#[tokio::test]
async fn msg_sender_from_contract() {
let (_, auth_id, caller_instance, caller_id, _) = get_contracts().await;
let (auth_instance, auth_id, caller_instance, caller_id, _) = get_contracts().await;

let result = caller_instance
.methods()
.call_auth_contract(auth_id, caller_id)
.set_contracts(&[auth_id.into()])
.set_contracts(&[&auth_instance])
.call()
.await
.unwrap();
Expand Down
8 changes: 4 additions & 4 deletions test/src/sdk-harness/test_projects/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use fuels::prelude::*;
use tai64::Tai64;
use tokio::time::{sleep, Duration};

abigen!(
BlockTestContract,
"test_projects/block/out/debug/block-abi.json"
);
abigen!(Contract(
name = "BlockTestContract",
abi = "test_projects/block/out/debug/block-abi.json"
));

async fn get_block_instance() -> (BlockTestContract, ContractId) {
let wallet = launch_provider_and_get_wallet().await;
Expand Down
8 changes: 4 additions & 4 deletions test/src/sdk-harness/test_projects/call_frames/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use fuels::{prelude::*, tx::ContractId};

use sha2::{Digest, Sha256};

abigen!(
CallFramesTestContract,
"test_projects/call_frames/out/debug/call_frames-abi.json"
);
abigen!(Contract(
name = "CallFramesTestContract",
abi = "test_projects/call_frames/out/debug/call_frames-abi.json"
));

async fn get_call_frames_instance() -> (CallFramesTestContract, ContractId) {
let wallet = launch_provider_and_get_wallet().await;
Expand Down
42 changes: 22 additions & 20 deletions test/src/sdk-harness/test_projects/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ use fuel_vm::consts::VM_MAX_RAM;
use fuels::{prelude::*, tx::ContractId};

abigen!(
TestContextContract,
"test_projects/context/out/debug/context-abi.json",
);
abigen!(
TestContextCallerContract,
"test_artifacts/context_caller_contract/out/debug/context_caller_contract-abi.json",
);
abigen!(
FuelCoin,
"test_projects/token_ops/out/debug/token_ops-abi.json"
Contract(
name = "TestContextContract",
abi = "test_projects/context/out/debug/context-abi.json",
),
Contract(
name = "TestContextCallerContract",
abi = "test_artifacts/context_caller_contract/out/debug/context_caller_contract-abi.json",
),
Contract(
name = "FuelCoin",
abi = "test_projects/token_ops/out/debug/token_ops-abi.json"
)
);

async fn get_contracts() -> (
Expand Down Expand Up @@ -63,7 +65,7 @@ async fn can_get_this_balance() {
caller_instance
.methods()
.call_receive_coins(send_amount, context_id)
.set_contracts(&[context_id.into()])
.set_contracts(&[&context_instance])
.tx_params(TxParameters::new(None, Some(1_000_000), None))
.call()
.await
Expand Down Expand Up @@ -94,7 +96,7 @@ async fn can_get_balance_of_contract() {
let result = context_instance
.methods()
.get_balance_of_contract(caller_id.clone(), caller_id.clone())
.set_contracts(&[caller_id.into()])
.set_contracts(&[&caller_instance])
.call()
.await
.unwrap();
Expand All @@ -104,7 +106,7 @@ async fn can_get_balance_of_contract() {

#[tokio::test]
async fn can_get_msg_value() {
let (_, context_id, caller_instance, _) = get_contracts().await;
let (context_instance, context_id, caller_instance, _) = get_contracts().await;
let send_amount = 11;

caller_instance
Expand All @@ -117,7 +119,7 @@ async fn can_get_msg_value() {
let result = caller_instance
.methods()
.call_get_amount_with_coins(send_amount, context_id)
.set_contracts(&[context_id.into()])
.set_contracts(&[&context_instance])
.call()
.await
.unwrap();
Expand All @@ -127,7 +129,7 @@ async fn can_get_msg_value() {

#[tokio::test]
async fn can_get_msg_id() {
let (_, context_id, caller_instance, caller_id) = get_contracts().await;
let (context_instance, context_id, caller_instance, caller_id) = get_contracts().await;
let send_amount = 42;

caller_instance
Expand All @@ -140,7 +142,7 @@ async fn can_get_msg_id() {
let result = caller_instance
.methods()
.call_get_asset_id_with_coins(send_amount, context_id)
.set_contracts(&[context_id.into()])
.set_contracts(&[&context_instance])
.tx_params(TxParameters::new(None, Some(1_000_000), None))
.call()
.await
Expand All @@ -151,7 +153,7 @@ async fn can_get_msg_id() {

#[tokio::test]
async fn can_get_msg_gas() {
let (_, context_id, caller_instance, _) = get_contracts().await;
let (context_instance, context_id, caller_instance, _) = get_contracts().await;
let send_amount = 11;

caller_instance
Expand All @@ -164,7 +166,7 @@ async fn can_get_msg_gas() {
let result = caller_instance
.methods()
.call_get_gas_with_coins(send_amount, context_id)
.set_contracts(&[context_id.into()])
.set_contracts(&[&context_instance])
.tx_params(TxParameters::new(Some(0), Some(1_000_000), None))
.call()
.await
Expand All @@ -175,7 +177,7 @@ async fn can_get_msg_gas() {

#[tokio::test]
async fn can_get_global_gas() {
let (_, context_id, caller_instance, _) = get_contracts().await;
let (context_instance, context_id, caller_instance, _) = get_contracts().await;
let send_amount = 11;

caller_instance
Expand All @@ -189,7 +191,7 @@ async fn can_get_global_gas() {
let result = caller_instance
.methods()
.call_get_global_gas_with_coins(send_amount, context_id)
.set_contracts(&[context_id.into()])
.set_contracts(&[&context_instance])
.tx_params(TxParameters::new(None, Some(1_000_000), None))
.call()
.await
Expand Down
13 changes: 6 additions & 7 deletions test/src/sdk-harness/test_projects/contract_bytecode/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use fuels::prelude::*;
use fuels::tx::Contract as FuelsTxContract;
use fuels::{prelude::*, tx::Contract as FuelsTxContract, types::core::Bits256};

abigen!(
ContractBytecodeTest,
"test_projects/contract_bytecode/out/debug/contract_bytecode-abi.json"
);
abigen!(Contract(
name = "ContractBytecodeTest",
abi = "test_projects/contract_bytecode/out/debug/contract_bytecode-abi.json"
));

#[tokio::test]
async fn can_get_bytecode_root() {
Expand All @@ -15,7 +14,7 @@ async fn can_get_bytecode_root() {
let bytecode_root = contract_instance
.methods()
.get_contract_bytecode_root(ContractId::from(id.clone()))
.set_contracts(&[id.clone()])
.set_contracts(&[&contract_instance])
.call()
.await
.unwrap()
Expand Down
11 changes: 6 additions & 5 deletions test/src/sdk-harness/test_projects/ec_recover/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use fuel_types::Bytes64;
use fuel_vm::fuel_types::Bytes64;
use fuels::{
prelude::*,
signers::fuel_crypto::{Message, PublicKey, SecretKey, Signature},
tx::Bytes32,
types::core::Bits256,
};
use rand::{rngs::StdRng, Rng, SeedableRng};

abigen!(
EcRecoverContract,
"test_projects/ec_recover/out/debug/ec_recover-abi.json"
);
abigen!(Contract(
name = "EcRecoverContract",
abi = "test_projects/ec_recover/out/debug/ec_recover-abi.json"
));

async fn setup_env() -> Result<
(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use fuels::prelude::*;
use fuels::{prelude::*, types::core::B512};

abigen!(
Predicate(
name = "TestPredicate",
abi = "test_projects/ec_recover_and_match_predicate/out/debug/ec_recover_and_match_predicate-abi.json"
)
);

#[tokio::test]
async fn ec_recover_and_match_predicate_test() -> Result<(), Error> {
use fuels::contract::predicate::Predicate;
use fuels::signers::fuel_crypto::SecretKey;

let secret_key1: SecretKey =
Expand All @@ -23,7 +29,7 @@ async fn ec_recover_and_match_predicate_test() -> Result<(), Error> {
let mut wallet = WalletUnlocked::new_from_private_key(secret_key1, None);
let mut wallet2 = WalletUnlocked::new_from_private_key(secret_key2, None);
let mut wallet3 = WalletUnlocked::new_from_private_key(secret_key3, None);
let receiver = WalletUnlocked::new_random(None);
let mut receiver = WalletUnlocked::new_random(None);

let all_coins = [&wallet, &wallet2, &wallet3]
.iter()
Expand All @@ -43,11 +49,11 @@ async fn ec_recover_and_match_predicate_test() -> Result<(), Error> {
)
.await;

[&mut wallet, &mut wallet2, &mut wallet3]
[&mut wallet, &mut wallet2, &mut wallet3, &mut receiver]
.iter_mut()
.for_each(|wallet| wallet.set_provider(provider.clone()));

let predicate = Predicate::load_from(
let predicate = TestPredicate::load_from(
"test_projects/ec_recover_and_match_predicate/out/debug/ec_recover_and_match_predicate.bin",
)?;

Expand All @@ -71,23 +77,27 @@ async fn ec_recover_and_match_predicate_test() -> Result<(), Error> {
assert_eq!(predicate_balance, amount_to_predicate);

let data_to_sign = [0; 32];
let signature1 = wallet.sign_message(&data_to_sign).await?.to_vec();
let signature2 = wallet2.sign_message(&data_to_sign).await?.to_vec();
let signature3 = wallet3.sign_message(&data_to_sign).await?.to_vec();

let signatures = vec![signature1, signature2, signature3];

let predicate_data = signatures.into_iter().flatten().collect();
wallet
.spend_predicate(
predicate_address,
predicate_code,
amount_to_predicate,
asset_id,
receiver.address(),
Some(predicate_data),
TxParameters::default(),
)
let signature1: B512 = wallet
.sign_message(&data_to_sign)
.await?
.as_ref()
.try_into()?;
let signature2: B512 = wallet2
.sign_message(&data_to_sign)
.await?
.as_ref()
.try_into()?;
let signature3: B512 = wallet3
.sign_message(&data_to_sign)
.await?
.as_ref()
.try_into()?;

let signatures = [signature1, signature2, signature3];

predicate
.encode_data(signatures)
.spend(&receiver, amount_to_predicate, asset_id, None)
.await?;

let receiver_balance_after = provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ fn extract_public_key_and_match(signature: B512, expected_public_key: b256) -> u
0
}

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

// let signatures: [B512; 3] = input_predicate_data(0);
let public_keys = [
0xd58573593432a30a800f97ad32f877425c223a9e427ab557aab5d5bb89156db0,
0x14df7c7e4e662db31fe2763b1734a3d680e7b743516319a49baaa22b2032a857,
Expand Down
11 changes: 9 additions & 2 deletions test/src/sdk-harness/test_projects/evm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use fuels::{prelude::*, tx::ContractId};
use fuels::{
prelude::*,
tx::ContractId,
types::core::{Bits256, EvmAddress},
};

abigen!(EvmTestContract, "test_projects/evm/out/debug/evm-abi.json");
abigen!(Contract(
name = "EvmTestContract",
abi = "test_projects/evm/out/debug/evm-abi.json"
));

async fn get_evm_test_instance() -> (EvmTestContract, ContractId) {
let wallet = launch_provider_and_get_wallet().await;
Expand Down
11 changes: 6 additions & 5 deletions test/src/sdk-harness/test_projects/evm_ec_recover/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use fuel_types::Bytes64;
use fuel_vm::fuel_types::Bytes64;
use fuels::{
prelude::*,
signers::fuel_crypto::{Message, PublicKey, SecretKey, Signature},
tx::Bytes32,
types::core::{Bits256, EvmAddress},
};
use rand::{rngs::StdRng, Rng, SeedableRng};
use sha3::{Digest, Keccak256};

abigen!(
EvmEcRecoverContract,
"test_projects/evm_ec_recover/out/debug/evm_ec_recover-abi.json"
);
abigen!(Contract(
name = "EvmEcRecoverContract",
abi = "test_projects/evm_ec_recover/out/debug/evm_ec_recover-abi.json"
));

fn keccak_hash<B>(data: B) -> Bytes32
where
Expand Down
5 changes: 4 additions & 1 deletion test/src/sdk-harness/test_projects/exponentiation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use fuels::prelude::*;
use fuels::tx::ContractId;

abigen!(TestPowContract, "test_artifacts/pow/out/debug/pow-abi.json");
abigen!(Contract(
name = "TestPowContract",
abi = "test_artifacts/pow/out/debug/pow-abi.json"
));

#[tokio::test]
#[should_panic(expected = "ArithmeticOverflow")]
Expand Down
Loading

0 comments on commit b070579

Please sign in to comment.