Skip to content

Commit 786dc8f

Browse files
committed
Fix CI
1 parent f23e388 commit 786dc8f

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

contracts/assetsup/src/errors.rs

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,56 @@
1-
use soroban_sdk::contracterror;
1+
use soroban_sdk::{Env, contracterror, panic_with_error};
22

33
#[contracterror]
4-
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
5-
pub enum ContractError {
6-
AssetAlreadyExists = 1,
7-
AssetNotFound = 2,
8-
Unauthorized = 3,
4+
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
5+
#[repr(u32)]
6+
pub enum Error {
7+
AlreadyInitialized = 1,
8+
AdminNotFound = 2,
9+
// Asset exist
10+
AssetAlreadyExists = 3,
11+
//Asset not found
12+
AssetNotFound = 4,
13+
// Branch already exists
14+
BranchAlreadyExists = 5,
15+
// Branch not found
16+
BranchNotFound = 6,
17+
// Subscription already exist
18+
SubscriptionAlreadyExists = 7,
19+
// User not authorized
20+
Unauthorized = 8,
21+
// Payment is not valid
22+
InvalidPayment = 9,
923
}
24+
25+
pub fn handle_error(env: &Env, error: Error) -> ! {
26+
panic_with_error!(env, error);
27+
}
28+
29+
#[allow(dead_code)]
30+
pub fn dummy_function(_env: Env, asset_exists: bool) -> Result<(), Error> {
31+
if asset_exists {
32+
Err(Error::AssetAlreadyExists)
33+
} else {
34+
Ok(())
35+
}
36+
}
37+
38+
#[cfg(test)]
39+
mod tests {
40+
use super::*;
41+
use soroban_sdk::Env;
42+
43+
#[test]
44+
fn test_dummy_function_asset_exists() {
45+
let env = Env::default();
46+
let result = dummy_function(env.clone(), true);
47+
assert_eq!(result, Err(Error::AssetAlreadyExists));
48+
}
49+
50+
#[test]
51+
fn test_dummy_function_asset_not_exists() {
52+
let env = Env::default();
53+
let result = dummy_function(env.clone(), false);
54+
assert_eq!(result, Ok(()));
55+
}
56+
}

0 commit comments

Comments
 (0)