-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
302 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
smart-contracts/contracts/babylon-vault/schema/raw/response_to_lsts.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "Array_of_LstInfo", | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/LstInfo" | ||
}, | ||
"definitions": { | ||
"LstInfo": { | ||
"type": "object", | ||
"required": [ | ||
"denom", | ||
"interface" | ||
], | ||
"properties": { | ||
"denom": { | ||
"type": "string" | ||
}, | ||
"interface": { | ||
"type": "string" | ||
} | ||
}, | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
use cosmwasm_std::Addr; | ||
use cw_storage_plus::Map; | ||
use mars_owner::Owner; | ||
|
||
pub const OWNER: Owner = Owner::new("owner"); | ||
pub const LSTS: Map<String, Addr> = Map::new("lsts"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod instantiate; | ||
pub mod register; | ||
pub mod setup; |
96 changes: 96 additions & 0 deletions
96
smart-contracts/contracts/babylon-vault/src/tests/register.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
use cosmwasm_std::Addr; | ||
use cw_orch::contract::interface_traits::CallAs; | ||
use mars_owner::OwnerError; | ||
|
||
use crate::{ | ||
msg::{ExecuteMsgFns, LstInfo, QueryMsgFns}, | ||
tests::setup::{setup, OWNER}, | ||
VaultError, | ||
}; | ||
|
||
#[test] | ||
fn register_lst_fails_for_non_owner() { | ||
let env = setup(); | ||
let vault = env.vault; | ||
|
||
let lst_denom = "lst".to_string(); | ||
let interface = "interface".to_string(); | ||
let result = vault.register_lst(lst_denom, interface); | ||
assert!(result.is_err()); | ||
assert_eq!( | ||
result.unwrap_err().downcast::<VaultError>().unwrap(), | ||
VaultError::Owner(OwnerError::NotOwner {}) | ||
); | ||
} | ||
|
||
#[test] | ||
fn unregister_lst_fails_for_non_owner() { | ||
let env = setup(); | ||
let vault = env.vault; | ||
|
||
let lst_denom = "lst".to_string(); | ||
let result = vault.unregister_lst(lst_denom); | ||
assert!(result.is_err()); | ||
assert_eq!( | ||
result.unwrap_err().downcast::<VaultError>().unwrap(), | ||
VaultError::Owner(OwnerError::NotOwner {}) | ||
); | ||
} | ||
|
||
#[test] | ||
fn register_and_unregister_lst() { | ||
let env = setup(); | ||
let mut vault = env.vault; | ||
vault.set_sender(&Addr::unchecked(OWNER)); | ||
|
||
let lst_denom = "lst".to_string(); | ||
let interface = "interface".to_string(); | ||
assert!(vault | ||
.register_lst(lst_denom.clone(), interface.clone()) | ||
.is_ok()); | ||
|
||
let lsts = vault.lsts().unwrap(); | ||
assert_eq!(lsts.len(), 1); | ||
assert_eq!( | ||
lsts[0], | ||
LstInfo { | ||
denom: lst_denom.clone(), | ||
interface | ||
} | ||
); | ||
|
||
assert!(vault.unregister_lst(lst_denom).is_ok()); | ||
let lsts = vault.lsts().unwrap(); | ||
assert_eq!(lsts.len(), 0); | ||
} | ||
|
||
#[test] | ||
fn unregister_fails_if_denom_is_not_registered() { | ||
let env = setup(); | ||
let mut vault = env.vault; | ||
vault.set_sender(&Addr::unchecked(OWNER)); | ||
|
||
let lst_denom = "lst".to_string(); | ||
let interface = "interface".to_string(); | ||
assert!(vault | ||
.register_lst(lst_denom.clone(), interface.clone()) | ||
.is_ok()); | ||
|
||
let lsts = vault.lsts().unwrap(); | ||
assert_eq!(lsts.len(), 1); | ||
assert_eq!( | ||
lsts[0], | ||
LstInfo { | ||
denom: lst_denom.clone(), | ||
interface | ||
} | ||
); | ||
|
||
let lst_denom = "other_lst".to_string(); | ||
let err = vault.unregister_lst(lst_denom.clone()).unwrap_err(); | ||
|
||
assert_eq!( | ||
err.downcast::<VaultError>().unwrap(), | ||
VaultError::LstNotFound { denom: lst_denom } | ||
); | ||
} |
Oops, something went wrong.