Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 debug token initialize test #2

Merged
merged 1 commit into from Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions tests/actions/deploy_token_contract.rs
@@ -1,7 +1,7 @@
use dotenv::dotenv;
use fuels::prelude::*;

const RPC: &str = "http://node-beta-1.fuel.network/graphql";
const RPC: &str = "node-beta-2.fuel.network";

#[tokio::test]
async fn deploy_token_contract() {
Expand All @@ -21,7 +21,7 @@ async fn deploy_token_contract() {
let token_contract_id = Contract::deploy(
"out/debug/token_contract.bin",
&wallet,
TxParameters::default(),
TxParameters::new(Some(1), None, None),
StorageConfiguration::with_storage_path(Some(
"./out/debug/token_contract-storage_slots.json".to_string(),
)),
Expand All @@ -34,3 +34,5 @@ async fn deploy_token_contract() {

println!("✅ Contract deployed @ {token_contract_id}");
}

// ✅ Contract deployed @ fuel19nluhjt8zlj6zqkmr4w6ghqcjfydqzs8pnt94q3qj6uhx0fmqu0q70c9j2
61 changes: 61 additions & 0 deletions tests/actions/initialize.rs
@@ -0,0 +1,61 @@
use dotenv::dotenv;
use fuels::prelude::*;
use std::str::FromStr;

abigen!(UsdtContract, "out/debug/token_contract-abi.json");

const RPC: &str = "node-beta-2.fuel.network";
const USDT_ADDRESS: &str = "0x2cffcbc96717e5a102db1d5da45c189248d00a070cd65a822096b9733d3b071e";

async fn init() -> (WalletUnlocked, UsdtContract) {
let provider = match Provider::connect(RPC).await {
Ok(p) => p,
Err(error) => panic!("❌ Problem creating provider: {:#?}", error),
};

dotenv().ok();
let secret = match std::env::var("SECRET") {
Ok(s) => s,
Err(error) => panic!("❌ Cannot find .env file: {:#?}", error),
};

let wallet = WalletUnlocked::new_from_private_key(secret.parse().unwrap(), Some(provider));

let usdt_dapp_id = Bech32ContractId::from(ContractId::from_str(USDT_ADDRESS).unwrap());
let usdt_dapp_instance = UsdtContract::new(usdt_dapp_id, wallet.clone());

println!("👛 Account address @ {}", wallet.clone().address());
println!(
"🗞 USDT dapp address @ {}",
usdt_dapp_instance.get_contract_id()
);
return (wallet, usdt_dapp_instance);
}

#[tokio::test]
async fn initialize() {
let (wallet, instance) = init().await;
let decimals = instance.methods().decimals().call().await.unwrap().value;
let symbol = instance.methods().symbol().call().await.unwrap().value;

instance
.methods()
.initialize(parse_units(1000, decimals), Address::from(wallet.address()))
.tx_params(TxParameters::new(Some(1), Some(1000000), None))
.call()
.await
.unwrap();
let mint_amount = instance.methods().get_mint_amount().call().await.unwrap();
println!(
"Mint amount {} {symbol}",
format_units(mint_amount.value, decimals)
);
}

fn parse_units(num: u64, decimals: u8) -> u64 {
num * 10u64.pow(decimals as u32)
}

fn format_units(num: u64, decimals: u8) -> u64 {
num / 10u64.pow(decimals as u32)
}
2 changes: 2 additions & 0 deletions tests/actions/mod.rs
@@ -1,2 +1,4 @@
mod deploy_token_contract;
mod initialize;