#[cfg(test)]
mod tests {
use crate::integration::utils::CliTest;
#[test]
fn test_defi_pools() {
let cli = CliTest::new();
let output = cli.run_command(&["de-fi", "pools", "--platform", "flamingo"]);
assert!(output.status.code().unwrap_or(0) != 127, "Command not found");
}
#[test]
fn test_defi_swap_info() {
let cli = CliTest::new();
let output = cli.run_command(&[
"de-fi",
"swap-info",
"--token-from",
"NEO",
"--token-to",
"GAS",
"--amount",
"1",
]);
assert!(output.status.code().unwrap_or(0) != 127, "Command not found");
}
#[test]
fn test_defi_swap() {
let cli = CliTest::new();
let wallet_content = r#"{
"name": "TestWallet",
"version": "1.0",
"accounts": []
}"#;
let wallet_path = cli.create_temp_file(wallet_content);
cli.run_command(&["wallet", "open", "--path", wallet_path.to_str().unwrap()]);
let output = cli.run_command(&[
"de-fi",
"swap",
"--token-from",
"NEO",
"--token-to",
"GAS",
"--amount",
"1",
"--slippage",
"0.5",
]);
assert!(output.status.code().unwrap_or(0) != 127, "Command not found");
}
#[test]
fn test_defi_add_liquidity() {
let cli = CliTest::new();
let wallet_content = r#"{
"name": "TestWallet",
"version": "1.0",
"accounts": []
}"#;
let wallet_path = cli.create_temp_file(wallet_content);
cli.run_command(&["wallet", "open", "--path", wallet_path.to_str().unwrap()]);
let output = cli.run_command(&[
"de-fi",
"add-liquidity",
"--token-a",
"NEO",
"--token-b",
"GAS",
"--amount-a",
"1",
"--amount-b",
"1",
]);
assert!(output.status.code().unwrap_or(0) != 127, "Command not found");
}
#[test]
fn test_defi_remove_liquidity() {
let cli = CliTest::new();
let wallet_content = r#"{
"name": "TestWallet",
"version": "1.0",
"accounts": []
}"#;
let wallet_path = cli.create_temp_file(wallet_content);
cli.run_command(&["wallet", "open", "--path", wallet_path.to_str().unwrap()]);
let output = cli.run_command(&[
"de-fi",
"remove-liquidity",
"--token-a",
"NEO",
"--token-b",
"GAS",
"--percent",
"50",
]);
assert!(output.status.code().unwrap_or(0) != 127, "Command not found");
}
#[test]
fn test_defi_token_info() {
let cli = CliTest::new();
let output = cli.run_command(&["de-fi", "token", "NEO"]);
assert!(output.status.code().unwrap_or(127) != 127, "Command not found");
}
#[test]
fn test_defi_token_info_gas() {
let cli = CliTest::new();
let output = cli.run_command(&["de-fi", "token", "GAS"]);
assert!(output.status.code().unwrap_or(127) != 127, "Command not found");
}
#[test]
fn test_defi_balance_with_wallet() {
let cli = CliTest::new();
let wallet_path = cli.create_temp_file(
r#"{
"name": "test_wallet",
"version": "1.0",
"scrypt": {"n": 16384, "r": 8, "p": 8},
"accounts": [
{
"address": "NZKvXidwBhnV8rNXh2eXtpm5bH1rkofaDz",
"label": "test_account",
"isDefault": true,
"lock": false,
"key": "6PYXHjPaNvW8YknSXaKzL1Xoxw4RjmQwCryMGEZ2GaLhGH8AdazLJPBBXw",
"contract": {
"script": "DCECIgZYieFCd+WHwCJK/I8btx1lYRIzOz8I8ZB6Ll6G3IIRLUFAQQ==",
"parameters": [{"name": "signature", "type": "Signature"}]
}
}
]
}"#,
);
let output = cli.run_command(&[
"de-fi",
"balance",
"NEO",
"--wallet",
wallet_path.to_str().unwrap(),
"--password",
"test123",
]);
assert!(output.status.code().unwrap_or(127) != 127, "Command not found");
}
#[test]
fn test_defi_invoke_test() {
let cli = CliTest::new();
let wallet_path = cli.create_temp_file(
r#"{
"name": "test_wallet",
"version": "1.0",
"scrypt": {"n": 16384, "r": 8, "p": 8},
"accounts": [
{
"address": "NZKvXidwBhnV8rNXh2eXtpm5bH1rkofaDz",
"label": "test_account",
"isDefault": true,
"lock": false,
"key": "6PYXHjPaNvW8YknSXaKzL1Xoxw4RjmQwCryMGEZ2GaLhGH8AdazLJPBBXw",
"contract": {
"script": "DCECIgZYieFCd+WHwCJK/I8btx1lYRIzOz8I8ZB6Ll6G3IIRLUFAQQ==",
"parameters": [{"name": "signature", "type": "Signature"}]
}
}
]
}"#,
);
let output = cli.run_command(&[
"de-fi",
"invoke",
"NEO Token",
"symbol",
"--wallet",
wallet_path.to_str().unwrap(),
"--password",
"test123",
]);
assert!(output.status.code().unwrap_or(0) != 127, "Command not found");
}
#[test]
fn test_defi_balance() {
let cli = CliTest::new();
let wallet_path = cli.create_temp_file(
r#"{
"name": "test_wallet",
"version": "1.0",
"scrypt": {"n": 16384, "r": 8, "p": 8},
"accounts": [
{
"address": "NZKvXidwBhnV8rNXh2eXtpm5bH1rkofaDz",
"label": "test_account",
"isDefault": true,
"lock": false,
"key": "6PYXHjPaNvW8YknSXaKzL1Xoxw4RjmQwCryMGEZ2GaLhGH8AdazLJPBBXw",
"contract": {
"script": "DCECIgZYieFCd+WHwCJK/I8btx1lYRIzOz8I8ZB6Ll6G3IIRLUFAQQ==",
"parameters": [{"name": "signature", "type": "Signature"}]
}
}
]
}"#,
);
let output = cli.run_command(&[
"de-fi",
"balance",
"NEO Token",
"--address",
"NZKvXidwBhnV8rNXh2eXtpm5bH1rkofaDz",
"--wallet",
wallet_path.to_str().unwrap(),
"--password",
"test123",
]);
assert!(output.status.code().unwrap_or(0) != 127, "Command not found");
}
#[test]
fn test_defi_invalid_token() {
let cli = CliTest::new();
let output = cli.run_command(&["de-fi", "token", "INVALID"]);
assert!(output.status.code().unwrap_or(127) != 127, "Command not found");
}
}