Skip to content

Commit

Permalink
Merge pull request #33 from AstarNetwork/feat/staking_test
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci authored May 31, 2024
2 parents 19a45f6 + 7205be7 commit 9792e7e
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 33 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
'plugin:import/typescript',
],
rules: {
'import/no-named-as-default': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'sort-imports-es6-autofix/sort-imports-es6': 'error',
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,13 @@ jobs:
strategy:
fail-fast: false
matrix:
tests: [xcm-transfer]
tests: [xcm-transfer, staking]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: setup node
uses: actions/setup-node@v4
with:
node-version: 18.x
- name: Setup yarn
run: npm install -g yarn
- name: setup node env
uses: actions/setup-node@v4
with:
node-version: 18.x
Expand Down
22 changes: 2 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,23 @@ env:
DB_PATH: ./db.sqlite

jobs:
# lint:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# with:
# submodules: recursive
# - name: Use Node.js
# uses: actions/setup-node@v3
# with:
# node-version: 18.x
# cache: 'yarn'
# - run: yarn --immutable
# - run: yarn lint
tests:
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
tests: [xcm-transfer]
tests: [xcm-transfer, staking]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: setup node
uses: actions/setup-node@v4
with:
node-version: 18.x
- name: Setup yarn
run: npm install -g yarn
- name: setup node env
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: 'yarn'
- run: yarn --immutable
- run: yarn lint
- run: yarn update-env
- run: yarn test tests/${{ matrix.tests }}
6 changes: 0 additions & 6 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ jobs:
with:
submodules: recursive
- name: setup node
uses: actions/setup-node@v4
with:
node-version: 18.x
- name: Setup yarn
run: npm install -g yarn
- name: setup node env
uses: actions/setup-node@v4
with:
node-version: 18.x
Expand Down
180 changes: 180 additions & 0 deletions tests/staking/tier-threshold.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
import { expect } from 'vitest'
import { given } from '../../helpers'

given('astar')('Number of slots adjusted based on price', async ({ networks: { astar } }) => {
const advanceNextEra = async () => {
const state = await astar.api.query.dappStaking.activeProtocolState<any>()
await astar.dev.newBlock({ count: 1, unsafeBlockHeight: state.nextEraStart.toNumber() })
}

// set price to $0.10
await astar.dev.setStorage({
priceAggregator: {
valuesCircularBuffer: {
head: 1,
buffer: [
100_000_000_000_000_000n, // $0.10
],
},
},
})

await advanceNextEra()

expect((await astar.api.query.dappStaking.tierConfig()).toHuman()).toMatchInlineSnapshot(`
{
"numberOfSlots": "150",
"rewardPortion": [
"25.00%",
"47.00%",
"25.00%",
"3.00%",
],
"slotsPerTier": [
"7",
"30",
"45",
"67",
],
"tierThresholds": [
{
"DynamicTvlAmount": {
"amount": "200,000,000,000,000,000,100,000,000",
"minimumAmount": "200,000,000,000,000,000,000,000,000",
},
},
{
"DynamicTvlAmount": {
"amount": "50,000,000,000,000,000,025,000,000",
"minimumAmount": "50,000,000,000,000,000,000,000,000",
},
},
{
"DynamicTvlAmount": {
"amount": "15,000,000,000,000,000,000,000,000",
"minimumAmount": "15,000,000,000,000,000,000,000,000",
},
},
{
"FixedTvlAmount": {
"amount": "1,500,000,000,000,000,000,000,000",
},
},
],
}
`)

// set price to $0.50
await astar.dev.setStorage({
priceAggregator: {
valuesCircularBuffer: {
head: 1,
buffer: [
500_000_000_000_000_000n, // $0.50
],
},
},
})

await advanceNextEra()

expect((await astar.api.query.dappStaking.tierConfig()).toHuman()).toMatchInlineSnapshot(`
{
"numberOfSlots": "550",
"rewardPortion": [
"25.00%",
"47.00%",
"25.00%",
"3.00%",
],
"slotsPerTier": [
"27",
"110",
"165",
"247",
],
"tierThresholds": [
{
"DynamicTvlAmount": {
"amount": "200,000,000,000,000,000,000,000,000",
"minimumAmount": "200,000,000,000,000,000,000,000,000",
},
},
{
"DynamicTvlAmount": {
"amount": "50,000,000,000,000,000,000,000,000",
"minimumAmount": "50,000,000,000,000,000,000,000,000",
},
},
{
"DynamicTvlAmount": {
"amount": "15,000,000,000,000,000,000,000,000",
"minimumAmount": "15,000,000,000,000,000,000,000,000",
},
},
{
"FixedTvlAmount": {
"amount": "1,500,000,000,000,000,000,000,000",
},
},
],
}
`)

// set price to $0.05
await astar.dev.setStorage({
priceAggregator: {
valuesCircularBuffer: {
head: 1,
buffer: [
50_000_000_000_000_000n, // $0.05
],
},
},
})

await advanceNextEra()

expect((await astar.api.query.dappStaking.tierConfig()).toHuman()).toMatchInlineSnapshot(`
{
"numberOfSlots": "100",
"rewardPortion": [
"25.00%",
"47.00%",
"25.00%",
"3.00%",
],
"slotsPerTier": [
"5",
"20",
"30",
"45",
],
"tierThresholds": [
{
"DynamicTvlAmount": {
"amount": "300,000,000,000,000,000,000,000,000",
"minimumAmount": "200,000,000,000,000,000,000,000,000",
},
},
{
"DynamicTvlAmount": {
"amount": "75,000,000,000,000,000,000,000,000",
"minimumAmount": "50,000,000,000,000,000,000,000,000",
},
},
{
"DynamicTvlAmount": {
"amount": "20,000,000,000,000,000,000,000,000",
"minimumAmount": "15,000,000,000,000,000,000,000,000",
},
},
{
"FixedTvlAmount": {
"amount": "1,500,000,000,000,000,000,000,000",
},
},
],
}
`)
})

0 comments on commit 9792e7e

Please sign in to comment.