Skip to content

Commit

Permalink
ref(test): add init method to motsu tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNeshi committed Nov 26, 2024
1 parent cde0639 commit 729a646
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions contracts/src/finance/vesting_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,39 +520,44 @@ mod tests {
const TOKEN: Address = address!("A11CEacF9aa32246d767FCCD72e02d6bCbcC375d");
const DURATION: u64 = 4 * 365 * 86400; // 4 years

fn start() -> U64 {
U64::from(block::timestamp() + 3600) // 1 hour
fn start() -> u64 {
block::timestamp() + 3600 // 1 hour
}

fn init(
contract: &mut VestingWallet,
start: u64,
duration: u64,
) -> (U64, U64) {
let start = U64::from(start);
let duration = U64::from(duration);
contract._start.set(start);
contract._duration.set(duration);
(start, duration)
}

#[motsu::test]
fn reads_start(contract: VestingWallet) {
let start = start();
contract._start.set(start);
let (start, _) = init(contract, start(), 0);
assert_eq!(U256::from(start), contract.start());
}

#[motsu::test]
fn reads_duration(contract: VestingWallet) {
contract._duration.set(U64::from(DURATION));
assert_eq!(U256::from(DURATION), contract.duration());
let (_, duration) = init(contract, 0, DURATION);
assert_eq!(U256::from(duration), contract.duration());
}

#[motsu::test]
fn reads_end(contract: VestingWallet) {
let start = start();
let duration = U64::from(DURATION);
contract._start.set(start);
contract._duration.set(duration);
let (start, duration) = init(contract, start(), DURATION);
assert_eq!(U256::from(start + duration), contract.end());
}

#[motsu::test]
fn reads_max_end(contract: VestingWallet) {
let start = U64::MAX;
let duration = U64::MAX;
contract._start.set(start);
contract._duration.set(duration);
assert_eq!(U256::from(start) + U256::from(duration), contract.end());
init(contract, u64::MAX, u64::MAX);
assert_eq!(U256::from(U64::MAX) + U256::from(U64::MAX), contract.end());
}

#[motsu::test]
Expand All @@ -571,10 +576,7 @@ mod tests {

#[motsu::test]
fn gets_vesting_schedule(contract: VestingWallet) {
let start = start();
let duration = U64::from(DURATION);
contract._start.set(start);
contract._duration.set(duration);
let (start, duration) = init(contract, start(), DURATION);

let one = uint!(1_U256);
let two = uint!(2_U256);
Expand All @@ -596,9 +598,7 @@ mod tests {

#[motsu::test]
fn gets_vesting_schedule_zero_duration(contract: VestingWallet) {
let start = start();
contract._start.set(start);
contract._duration.set(U64::ZERO);
let (start, _) = init(contract, start(), 0);

let two = uint!(2_U256);

Expand Down

0 comments on commit 729a646

Please sign in to comment.