-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Eric Lau <ericglau@outlook.com>
- Loading branch information
Showing
20 changed files
with
888 additions
and
22 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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { infoOptions } from '../set-info'; | ||
import type { VestingOptions } from '../vesting'; | ||
import { generateAlternatives } from './alternatives'; | ||
|
||
const blueprint = { | ||
name: ['MyVesting'], | ||
startDate: ['2024-12-31T23:59'], | ||
duration: ['90 days', '1 year'], | ||
cliffDuration: ['0 seconds', '30 day'], | ||
schedule: ['linear', 'custom'] as const, | ||
info: infoOptions | ||
}; | ||
|
||
export function* generateVestingOptions(): Generator<Required<VestingOptions>> { | ||
yield* generateAlternatives(blueprint); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import test from 'ava'; | ||
import { OptionsError, vesting } from '.'; | ||
import { buildVesting, VestingOptions } from './vesting'; | ||
import { printContract } from './print'; | ||
|
||
const defaults: VestingOptions = { | ||
name: 'MyVesting', | ||
startDate: '', | ||
duration: '0 day', | ||
cliffDuration: '0 day', | ||
schedule: 'linear' | ||
}; | ||
|
||
const CUSTOM_NAME = 'CustomVesting'; | ||
const CUSTOM_DATE = '2024-12-31T23:59'; | ||
const CUSTOM_DURATION = '36 months'; | ||
const CUSTOM_CLIFF = '90 days'; | ||
|
||
// | ||
// Test helpers | ||
// | ||
|
||
function testVesting(title: string, opts: Partial<VestingOptions>) { | ||
test(title, t => { | ||
const c = buildVesting({ | ||
...defaults, | ||
...opts | ||
}); | ||
t.snapshot(printContract(c)); | ||
}); | ||
} | ||
|
||
function testAPIEquivalence(title: string, opts?: VestingOptions) { | ||
test(title, t => { | ||
t.is(vesting.print(opts), printContract(buildVesting({ | ||
...defaults, | ||
...opts | ||
}))); | ||
}); | ||
} | ||
|
||
// | ||
// Snapshot tests | ||
// | ||
|
||
testVesting('custom name', { | ||
name: CUSTOM_NAME, | ||
}); | ||
|
||
testVesting('custom start date', { | ||
startDate: CUSTOM_DATE | ||
}); | ||
|
||
testVesting('custom duration', { | ||
duration: CUSTOM_DURATION | ||
}); | ||
|
||
testVesting('custom cliff', { | ||
duration: CUSTOM_DURATION, | ||
cliffDuration: CUSTOM_CLIFF | ||
}); | ||
|
||
testVesting('custom schedule', { | ||
schedule: 'custom' | ||
}); | ||
|
||
testVesting('all custom settings', { | ||
startDate: CUSTOM_DATE, | ||
duration: CUSTOM_DURATION, | ||
cliffDuration: CUSTOM_CLIFF, | ||
schedule: 'custom' | ||
}); | ||
|
||
// | ||
// API tests | ||
// | ||
|
||
testAPIEquivalence('API custom name', { | ||
...defaults, | ||
name: CUSTOM_NAME | ||
}); | ||
|
||
testAPIEquivalence('API custom start date', { | ||
...defaults, | ||
startDate: CUSTOM_DATE | ||
}); | ||
|
||
testAPIEquivalence('API custom duration', { | ||
...defaults, | ||
duration: CUSTOM_DURATION | ||
}); | ||
|
||
testAPIEquivalence('API custom cliff', { | ||
...defaults, | ||
duration: CUSTOM_DURATION, | ||
cliffDuration: CUSTOM_CLIFF | ||
}); | ||
|
||
testAPIEquivalence('API custom schedule', { | ||
...defaults, | ||
schedule: 'custom' | ||
}); | ||
|
||
testAPIEquivalence('API all custom settings', { | ||
...defaults, | ||
startDate: CUSTOM_DATE, | ||
duration: CUSTOM_DURATION, | ||
cliffDuration: CUSTOM_CLIFF, | ||
schedule: 'custom' | ||
}); | ||
|
||
test('Vesting API isAccessControlRequired', async t => { | ||
t.is(vesting.isAccessControlRequired({}), true); | ||
}); | ||
|
||
test('cliff too high', async t => { | ||
const error = t.throws(() => buildVesting({ | ||
...defaults, | ||
duration: '20 days', | ||
cliffDuration: '21 days' | ||
})); | ||
t.is((error as OptionsError).messages.cliffDuration, 'Cliff duration must be less than or equal to the total duration'); | ||
}); |
Oops, something went wrong.