Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions contracts/shade/src/components/invoice.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::components::{access_control, admin, merchant, pausable, signature_util};
use crate::components::{access_control, admin, merchant, signature_util};
use crate::errors::ContractError;
use crate::events;
use crate::types::{DataKey, Invoice, InvoiceFilter, InvoiceStatus, Role};
Expand All @@ -20,7 +20,6 @@ pub fn validate_invoice_creation(
token: &Address,
expires_at: Option<u64>,
) {
pausable::assert_not_paused(env);
if amount <= 0 {
panic_with_error!(env, ContractError::InvalidAmount);
}
Expand Down
12 changes: 6 additions & 6 deletions contracts/shade/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ pub mod test_account_factory;
pub mod test_admin_payment;
pub mod test_admin_transfer;
pub mod test_fees;
// pub mod test_invoice; // TODO: fix this
// pub mod test_invoice_partial_refund; // TODO: fix this
// pub mod test_invoice_signed; // TODO: fix this
// pub mod test_invoice_void; // TODO: fix this
pub mod test_invoice;
pub mod test_invoice_partial_refund;
pub mod test_invoice_signed;
pub mod test_invoice_void;
pub mod test_merchant;
pub mod test_merchant_activation;
pub mod test_merchant_key;
pub mod test_merchant_verification;
pub mod test_pausable;
pub mod test_payment;
// pub mod test_refund; // TODO: fix this
// pub mod test_signatures; // TODO: fix this
pub mod test_refund;
pub mod test_signatures;
pub mod test_subscription;
pub mod test_upgrade;
118 changes: 83 additions & 35 deletions contracts/shade/src/tests/test_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,15 @@ fn mark_invoice_paid(

#[test]
fn test_create_and_get_invoice_success() {
let (env, client, contract_id, _admin) = setup_test();
let (env, client, contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token = Address::generate(&env);
let token = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token);
let description = String::from_str(&env, "Test Invoice");
let amount: i128 = 1000;

Expand All @@ -109,13 +112,19 @@ fn test_create_and_get_invoice_success() {

#[test]
fn test_create_multiple_invoices() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token1 = Address::generate(&env);
let token2 = Address::generate(&env);
let token1 = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token1);
let token2 = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token2);

let id1 = client.create_invoice(
&merchant,
Expand Down Expand Up @@ -147,17 +156,20 @@ fn test_create_multiple_invoices() {
#[should_panic(expected = "HostError: Error(Contract, #8)")]
#[test]
fn test_get_invoice_not_found() {
let (_env, client, _contract_id, _admin) = setup_test();
let (_env, client, _contract_id, admin) = setup_test();
client.get_invoice(&999);
}

#[should_panic(expected = "HostError: Error(Contract, #1)")]
#[test]
fn test_create_invoice_unregistered_merchant() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let unregistered_merchant = Address::generate(&env);
let token = Address::generate(&env);
let token = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token);
let description = String::from_str(&env, "Test Invoice");
let amount: i128 = 1000;

Expand All @@ -167,12 +179,15 @@ fn test_create_invoice_unregistered_merchant() {
#[should_panic(expected = "HostError: Error(Contract, #7)")]
#[test]
fn test_create_invoice_invalid_amount() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token = Address::generate(&env);
let token = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token);
let description = String::from_str(&env, "Test Invoice");
let amount: i128 = 0;

Expand All @@ -181,11 +196,12 @@ fn test_create_invoice_invalid_amount() {

#[test]
fn test_refund_invoice_success_within_window() {
let (env, client, shade_contract_id, _admin) = setup_test();
let (env, client, shade_contract_id, admin) = setup_test();
let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token = create_test_token(&env);
client.add_accepted_token(&admin, &token);
let payer = Address::generate(&env);
let description = String::from_str(&env, "Refundable Invoice");
let amount = 1_000_i128;
Expand Down Expand Up @@ -225,11 +241,12 @@ fn test_refund_invoice_success_within_window() {
#[test]
#[should_panic(expected = "HostError: Error(Contract, #17)")]
fn test_refund_invoice_fails_after_refund_window() {
let (env, client, shade_contract_id, _admin) = setup_test();
let (env, client, shade_contract_id, admin) = setup_test();
let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token = create_test_token(&env);
client.add_accepted_token(&admin, &token);
let payer = Address::generate(&env);
let invoice_id = client.create_invoice(
&merchant,
Expand Down Expand Up @@ -262,12 +279,15 @@ fn test_refund_invoice_fails_after_refund_window() {

#[test]
fn test_void_invoice_success() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token = Address::generate(&env);
let token = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token);
let description = String::from_str(&env, "Test Invoice");
let invoice_id = client.create_invoice(&merchant, &description, &1000, &token, &None);

Expand All @@ -286,13 +306,14 @@ fn test_void_invoice_success() {
#[test]
#[should_panic(expected = "HostError: Error(Contract, #1)")]
fn test_refund_invoice_fails_for_non_owner() {
let (env, client, shade_contract_id, _admin) = setup_test();
let (env, client, shade_contract_id, admin) = setup_test();
let merchant = Address::generate(&env);
let other_merchant = Address::generate(&env);
client.register_merchant(&merchant);
client.register_merchant(&other_merchant);

let token = create_test_token(&env);
client.add_accepted_token(&admin, &token);
let payer = Address::generate(&env);
let invoice_id = client.create_invoice(
&merchant,
Expand Down Expand Up @@ -324,12 +345,15 @@ fn test_refund_invoice_fails_for_non_owner() {
#[test]
#[should_panic(expected = "HostError: Error(Contract, #1)")]
fn test_void_invoice_non_owner() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token = Address::generate(&env);
let token = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token);
let description = String::from_str(&env, "Test Invoice");
let invoice_id = client.create_invoice(&merchant, &description, &1000, &token, &None);

Expand Down Expand Up @@ -369,12 +393,15 @@ fn test_void_invoice_already_paid() {
#[test]
#[should_panic(expected = "HostError: Error(Contract, #16)")]
fn test_void_invoice_already_cancelled() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token = Address::generate(&env);
let token = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token);
let description = String::from_str(&env, "Test Invoice");
let invoice_id = client.create_invoice(&merchant, &description, &1000, &token, &None);

Expand Down Expand Up @@ -416,7 +443,7 @@ fn test_pay_cancelled_invoice() {
#[test]
#[should_panic(expected = "HostError: Error(Contract, #8)")]
fn test_void_non_existent_invoice() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);
Expand All @@ -429,12 +456,15 @@ fn test_void_non_existent_invoice() {

#[test]
fn test_amend_invoice_amount_success() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token = Address::generate(&env);
let token = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token);
let description = String::from_str(&env, "Original Invoice");
let invoice_id = client.create_invoice(&merchant, &description, &1000, &token, &None);

Expand All @@ -450,12 +480,15 @@ fn test_amend_invoice_amount_success() {

#[test]
fn test_amend_invoice_description_success() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token = Address::generate(&env);
let token = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token);
let description = String::from_str(&env, "Original Description");
let invoice_id = client.create_invoice(&merchant, &description, &1000, &token, &None);

Expand All @@ -477,12 +510,15 @@ fn test_amend_invoice_description_success() {

#[test]
fn test_amend_invoice_both_fields_success() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token = Address::generate(&env);
let token = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token);
let description = String::from_str(&env, "Original");
let invoice_id = client.create_invoice(&merchant, &description, &1000, &token, &None);

Expand Down Expand Up @@ -532,12 +568,15 @@ fn test_amend_invoice_paid_fails() {
#[test]
#[should_panic(expected = "HostError: Error(Contract, #16)")]
fn test_amend_invoice_cancelled_fails() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token = Address::generate(&env);
let token = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token);
let description = String::from_str(&env, "Test Invoice");
let invoice_id = client.create_invoice(&merchant, &description, &1000, &token, &None);

Expand All @@ -551,12 +590,15 @@ fn test_amend_invoice_cancelled_fails() {
#[test]
#[should_panic(expected = "HostError: Error(Contract, #1)")]
fn test_amend_invoice_non_owner_fails() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token = Address::generate(&env);
let token = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token);
let description = String::from_str(&env, "Test Invoice");
let invoice_id = client.create_invoice(&merchant, &description, &1000, &token, &None);

Expand All @@ -569,12 +611,15 @@ fn test_amend_invoice_non_owner_fails() {
#[test]
#[should_panic(expected = "HostError: Error(Contract, #7)")]
fn test_amend_invoice_invalid_amount_fails() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token = Address::generate(&env);
let token = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token);
let description = String::from_str(&env, "Test Invoice");
let invoice_id = client.create_invoice(&merchant, &description, &1000, &token, &None);

Expand All @@ -585,12 +630,15 @@ fn test_amend_invoice_invalid_amount_fails() {
#[test]
#[should_panic(expected = "HostError: Error(Contract, #7)")]
fn test_amend_invoice_negative_amount_fails() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);

let token = Address::generate(&env);
let token = env
.register_stellar_asset_contract_v2(Address::generate(&env))
.address();
client.add_accepted_token(&admin, &token);
let description = String::from_str(&env, "Test Invoice");
let invoice_id = client.create_invoice(&merchant, &description, &1000, &token, &None);

Expand All @@ -601,7 +649,7 @@ fn test_amend_invoice_negative_amount_fails() {
#[test]
#[should_panic(expected = "HostError: Error(Contract, #8)")]
fn test_amend_non_existent_invoice_fails() {
let (env, client, _contract_id, _admin) = setup_test();
let (env, client, _contract_id, admin) = setup_test();

let merchant = Address::generate(&env);
client.register_merchant(&merchant);
Expand Down
Loading