Skip to content

Commit

Permalink
Create contract_tests.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Dec 8, 2024
1 parent 9b0bf8d commit 6d79372
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/smart_contract/contract_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#[cfg(test)]
mod tests {
use super::*;
use ink_env::test;

#[ink::test]
fn test_transfer() {
let mut contract = MyContract::new();
let accounts = test::default_accounts();
let initial_balance = 100;

// Set initial balances
contract.balances.insert(accounts.alice, initial_balance);
contract.balances.insert(accounts.bob, 0);

// Transfer funds
assert_eq!(contract.transfer(accounts.bob, 50), Ok(()));
assert_eq!(contract.balance_of(accounts.alice), 50);
assert_eq!(contract.balance_of(accounts.bob), 50);
}

#[ink::test]
fn test_insufficient_balance() {
let mut contract = MyContract::new();
let accounts = test::default_accounts();
contract.balances.insert(accounts.alice, 10);
contract.balances.insert(accounts.bob, 0);

// Attempt to transfer more than available balance
assert_eq!(contract.transfer(accounts.bob, 20), Err("Insufficient balance"));
}
}

0 comments on commit 6d79372

Please sign in to comment.