Skip to content

Commit

Permalink
Feat: refactor to contain only logic
Browse files Browse the repository at this point in the history
  • Loading branch information
GideonBature committed Dec 25, 2024
1 parent f8acf93 commit cffcb9d
Showing 1 changed file with 0 additions and 64 deletions.
64 changes: 0 additions & 64 deletions src/utils/erc20_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,68 +43,4 @@ impl<P: Provider + Send + Sync> TokenAllowanceChecker<P> {

Ok(call_result[0])
}
}

#[cfg(test)]
mod tests {

use super::*;
use std::str::FromStr;

/* # NOTE #
* Please make sure to set the correct TEST_RPC_URL and TEST_TOKEN before running the tests
* Also make sure to set the correct `owner`` and `spender` before running the tests
*/

const TEST_RPC_URL: &str = "https://starknet-sepolia.public.blastapi.io";
const TEST_TOKEN: Felt = felt!("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7");

async fn setup() -> TokenAllowanceChecker<JsonRpcClient<HttpTransport>> {
let provider = JsonRpcClient::new(HttpTransport::new(Url::from_str(TEST_RPC_URL).unwrap()));
TokenAllowanceChecker::new(Arc::new(provider))
}

#[tokio::test]
async fn test_zero_allowance() {
let checker = setup().await;
let token = TEST_TOKEN;
let owner = felt!("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7");
let spender = Felt::ZERO;

let allowance = checker.get_allowance(token, owner, spender).await;
assert!(allowance.is_err());
}

#[tokio::test]
async fn test_invalid_token_address() {
let checker = setup().await;
let token = Felt::ZERO;
let owner = felt!("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7");
let spender = felt!("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7");

let allowance = checker.get_allowance(token, owner, spender).await;
assert!(allowance.is_err());
}

#[tokio::test]
async fn test_invalid_owner_address() {
let checker = setup().await;
let token = TEST_TOKEN;
let owner = Felt::ZERO;
let spender = felt!("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7");

let allowance = checker.get_allowance(token, owner, spender).await;
assert!(allowance.is_err());
}

#[tokio::test]
async fn test_invalid_spender_address() {
let checker = setup().await;
let token = TEST_TOKEN;
let owner = felt!("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7");
let spender = Felt::ZERO;

let allowance = checker.get_allowance(token, owner, spender).await;
assert!(allowance.is_err());
}
}

0 comments on commit cffcb9d

Please sign in to comment.