-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `PayoutApi` and the corresponding mock * Implement redeeming tokens * Add tests for `redeem_position` * Test `redeem_position` and dummy implement `Payout`
- Loading branch information
1 parent
dd58dc6
commit f57bf6b
Showing
11 changed files
with
434 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2024 Forecasting Technologies LTD. | ||
// | ||
// This file is part of Zeitgeist. | ||
// | ||
// Zeitgeist is free software: you can redistribute it and/or modify it | ||
// under the terms of the GNU General Public License as published by the | ||
// Free Software Foundation, either version 3 of the License, or (at | ||
// your option) any later version. | ||
// | ||
// Zeitgeist is distributed in the hope that it will be useful, but | ||
// WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
use alloc::vec::Vec; | ||
|
||
pub trait PayoutApi { | ||
type Balance; | ||
type MarketId; | ||
|
||
fn payout_vector(market_id: Self::MarketId) -> Option<Vec<Self::Balance>>; | ||
} |
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 |
---|---|---|
|
@@ -19,4 +19,5 @@ | |
|
||
pub(crate) mod consts; | ||
pub mod ext_builder; | ||
pub(crate) mod types; | ||
pub(crate) mod runtime; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod payout; | ||
|
||
pub use payout::MockPayout; |
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,47 @@ | ||
use alloc::vec; | ||
use core::cell::RefCell; | ||
use zeitgeist_primitives::{ | ||
traits::PayoutApi, | ||
types::{Balance, MarketId}, | ||
}; | ||
|
||
pub struct MockPayout; | ||
|
||
impl MockPayout { | ||
pub fn set_return_value(value: Option<Vec<Balance>>) { | ||
PAYOUT_VECTOR_RETURN_VALUE.with(|v| *v.borrow_mut() = Some(value)); | ||
} | ||
|
||
pub fn not_called() -> bool { | ||
PAYOUT_VECTOR_CALL_DATA.with(|values| values.borrow().is_empty()) | ||
} | ||
|
||
pub fn called_once_with(expected: MarketId) -> bool { | ||
if PAYOUT_VECTOR_CALL_DATA.with(|values| values.borrow().len()) != 1 { | ||
return false; | ||
} | ||
|
||
let actual = | ||
PAYOUT_VECTOR_CALL_DATA.with(|value| *value.borrow().first().expect("can't be empty")); | ||
|
||
actual == expected | ||
} | ||
} | ||
|
||
impl PayoutApi for MockPayout { | ||
type Balance = Balance; | ||
type MarketId = MarketId; | ||
|
||
fn payout_vector(market_id: Self::MarketId) -> Option<Vec<Self::Balance>> { | ||
PAYOUT_VECTOR_CALL_DATA.with(|values| values.borrow_mut().push(market_id)); | ||
|
||
PAYOUT_VECTOR_RETURN_VALUE | ||
.with(|value| value.borrow().clone()) | ||
.expect("MockPayout: No return value configured") | ||
} | ||
} | ||
|
||
thread_local! { | ||
pub static PAYOUT_VECTOR_CALL_DATA: RefCell<Vec<MarketId>> = const { RefCell::new(vec![]) }; | ||
pub static PAYOUT_VECTOR_RETURN_VALUE: RefCell<Option<Option<Vec<Balance>>>> = const { RefCell::new(None) }; | ||
} |
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
Oops, something went wrong.