-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
calculateDeadline -> applyOptionalDeadline
- Loading branch information
1 parent
6722fa7
commit 686e00a
Showing
4 changed files
with
25 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,30 @@ | ||
import { BigNumber } from '@ethersproject/bignumber' | ||
|
||
import { | ||
calculateDeadline, | ||
getDestinationDeadline, | ||
getOriginDeadline, | ||
} from './deadlines' | ||
import { applyOptionalDeadline, calculateDeadline } from './deadlines' | ||
|
||
describe('deadlines', () => { | ||
// Something good happened on this day | ||
Date.now = jest.fn(() => Date.parse('2021-08-29')) | ||
|
||
it('calculates correct deadlines', () => { | ||
const seconds = 1337 | ||
const deadline = calculateDeadline(seconds) | ||
const now = Math.floor(Date.now() / 1000) | ||
expect(deadline.toNumber()).toBe(now + seconds) | ||
}) | ||
|
||
describe('getOriginDeadline', () => { | ||
it('returns the deadline if it is defined', () => { | ||
const deadline = BigNumber.from(1337) | ||
expect(getOriginDeadline(deadline)).toBe(deadline) | ||
}) | ||
|
||
it('Uses 10 minutes if deadline is undefined', () => { | ||
const deadline = getOriginDeadline() | ||
describe('calculateDeadline', () => { | ||
it('calculates correct deadlines', () => { | ||
const seconds = 1337 | ||
const deadline = calculateDeadline(seconds) | ||
const now = Math.floor(Date.now() / 1000) | ||
expect(deadline.toNumber()).toBe(now + 10 * 60) | ||
expect(deadline.toNumber()).toBe(now + seconds) | ||
}) | ||
}) | ||
|
||
describe('getDestinationDeadline', () => { | ||
describe('applyOptionalDeadline', () => { | ||
it('returns the deadline if it is defined', () => { | ||
const deadline = BigNumber.from(1337) | ||
expect(getDestinationDeadline(deadline)).toBe(deadline) | ||
expect(applyOptionalDeadline(deadline, 1234)).toBe(deadline) | ||
}) | ||
|
||
it('Uses 1 week if deadline is undefined', () => { | ||
const deadline = getDestinationDeadline() | ||
it('applies the default period if the deadline is undefined', () => { | ||
const deadline = applyOptionalDeadline(undefined, 1234) | ||
const now = Math.floor(Date.now() / 1000) | ||
expect(deadline.toNumber()).toBe(now + 7 * 24 * 60 * 60) | ||
expect(deadline.toNumber()).toBe(now + 1234) | ||
}) | ||
}) | ||
}) |
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