Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(api): updated the protocol params endpoint with the new api response #3720

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/wallet-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"@shopify/flash-list": "^1.4.1",
"@types/bip39": "^3.0.0",
"@types/pbkdf2": "^3.1.2",
"@yoroi/api": "^1.5.2",
"@yoroi/api": "1.5.3",
"@yoroi/claim": "1.0.0",
"@yoroi/common": "^1.5.4",
"@yoroi/exchange": "^2.1.1",
Expand Down Expand Up @@ -264,7 +264,7 @@
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.32.0",
"@yoroi/types": "1.5.8",
"@yoroi/types": "1.5.9",
"babel-eslint": "^10.1.0",
"babel-jest": "^29.2.1",
"babel-loader": "8.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,136 @@ export const protocolParamsPlaceholder: Chain.Cardano.ProtocolParams = freeze({
constant: '155381',
coefficient: '44',
},
minFeeReferenceScript: {
coinsPerByte: {
numerator: '15',
denominator: '1',
},
tierStepBytes: '25600',
multiplier: '1.2',
},
coinsPerUtxoByte: '4310',
poolDeposit: '500000000',
keyDeposit: '2000000',
epoch: 509,
epoch: 67,
maxBlockBodySize: '90112',
maxBlockHeaderSize: '1100',
maxTxSize: '16384',
maxReferenceScriptsSize: '204800',
stakePoolPledgeInfluence: {
numerator: '3',
denominator: '10',
},
monetaryExpansion: {
numerator: '3',
denominator: '1000',
},
treasuryExpansion: {
numerator: '1',
denominator: '5',
},
minPoolCost: '340000000',
maxExecutionUnits: {
perTransaction: {
memory: '14000000',
cpu: '10000000000',
},
perBlock: {
memory: '62000000',
cpu: '20000000000',
},
},
scriptExecutionPrices: {
memory: {
numerator: '577',
denominator: '10000',
},
cpu: {
numerator: '721',
denominator: '10000000',
},
},
maxCollateralInputs: '3',
collateralPercentage: '150',
maxValueSize: '5000',
version: {
major: '8',
minor: '0',
},
governanceActionDeposit: '100000000000',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty @lisicky !

delegateRepresentativeDeposit: '500000000',
constitutionalCommitteeMinSize: '7',
constitutionalCommitteeMaxTermLength: '146',
governanceActionLifetime: '6',
delegateRepresentativeMaxIdleTime: '20',
desiredNumberOfStakePools: '500',
stakePoolRetirementEpochBound: '18',
votingThresholds: {
stakePool: {
noConfidence: {
numerator: '51',
denominator: '100',
},
committeeNormal: {
numerator: '51',
denominator: '100',
},
committeeNoConfidence: {
numerator: '51',
denominator: '100',
},
hardFork: {
numerator: '51',
denominator: '100',
},
ppSecurity: {
numerator: '51',
denominator: '100',
},
},
delegateRep: {
noConfidence: {
numerator: '67',
denominator: '100',
},
committeeNormal: {
numerator: '67',
denominator: '100',
},
committeeNoConfidence: {
numerator: '3',
denominator: '5',
},
constitution: {
numerator: '3',
denominator: '5',
},
hardFork: {
numerator: '3',
denominator: '5',
},
ppNetwork: {
numerator: '67',
denominator: '100',
},
ppEconomic: {
numerator: '67',
denominator: '100',
},
ppTechnical: {
numerator: '67',
denominator: '100',
},
ppGovernance: {
numerator: '3',
denominator: '4',
},
treasury: {
numerator: '67',
denominator: '100',
},
},
},
})

export const networkConfigs: Readonly<Record<Chain.SupportedNetworks, Readonly<Network.Config>>> = freeze({
Expand Down
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yoroi/api",
"version": "1.5.2",
"version": "1.5.3",
"description": "The API package of Yoroi SDK",
"keywords": [
"yoroi",
Expand Down Expand Up @@ -148,7 +148,7 @@
"@types/jest": "^29.5.12",
"@types/react": "^18.2.55",
"@types/react-test-renderer": "^18.0.7",
"@yoroi/types": "1.5.8",
"@yoroi/types": "1.5.9",
"axios": "^1.5.0",
"axios-mock-adapter": "^1.21.5",
"commitlint": "^17.0.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/cardano/api/cardano-api-maker.mocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* istanbul ignore file */
import {Api} from '@yoroi/types'
import {paramsMockResponse} from './protocol-params.mocks'
import {protocolParamsMockResponse} from './protocol-params.mocks'
import {bestBlockMockResponse} from './best-block.mocks'

const loading = () => new Promise(() => {})
Expand All @@ -17,9 +17,9 @@ const delayedResponse = <T = never>({
})

const getProtocolParams = {
success: () => Promise.resolve(paramsMockResponse),
success: () => Promise.resolve(protocolParamsMockResponse),
delayed: (timeout?: number) =>
delayedResponse({data: paramsMockResponse, timeout}),
delayedResponse({data: protocolParamsMockResponse, timeout}),
empty: () => Promise.resolve({}),
loading,
error: {
Expand Down
137 changes: 133 additions & 4 deletions packages/api/src/cardano/api/protocol-params.mocks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,138 @@
import {Chain} from '@yoroi/types'

export const paramsMockResponse: Chain.Cardano.ProtocolParams = {
export const protocolParamsMockResponse: Chain.Cardano.ProtocolParams = {
linearFee: {
constant: '155381',
coefficient: '44',
},
minFeeReferenceScript: {
coinsPerByte: {
numerator: '15',
denominator: '1',
},
tierStepBytes: '25600',
multiplier: '1.2',
},
coinsPerUtxoByte: '4310',
keyDeposit: '2000000',
linearFee: {coefficient: '44', constant: '155381'},
poolDeposit: '500000000',
epoch: 509,
keyDeposit: '2000000',
epoch: 67,
maxBlockBodySize: '90112',
maxBlockHeaderSize: '1100',
maxTxSize: '16384',
maxReferenceScriptsSize: '204800',
stakePoolPledgeInfluence: {
numerator: '3',
denominator: '10',
},
monetaryExpansion: {
numerator: '3',
denominator: '1000',
},
treasuryExpansion: {
numerator: '1',
denominator: '5',
},
minPoolCost: '340000000',
maxExecutionUnits: {
perTransaction: {
memory: '14000000',
cpu: '10000000000',
},
perBlock: {
memory: '62000000',
cpu: '20000000000',
},
},
scriptExecutionPrices: {
memory: {
numerator: '577',
denominator: '10000',
},
cpu: {
numerator: '721',
denominator: '10000000',
},
},
maxCollateralInputs: '3',
collateralPercentage: '150',
maxValueSize: '5000',
version: {
major: '8',
minor: '0',
},
governanceActionDeposit: '100000000000',
delegateRepresentativeDeposit: '500000000',
constitutionalCommitteeMinSize: '7',
constitutionalCommitteeMaxTermLength: '146',
governanceActionLifetime: '6',
delegateRepresentativeMaxIdleTime: '20',
desiredNumberOfStakePools: '500',
stakePoolRetirementEpochBound: '18',
votingThresholds: {
stakePool: {
noConfidence: {
numerator: '51',
denominator: '100',
},
committeeNormal: {
numerator: '51',
denominator: '100',
},
committeeNoConfidence: {
numerator: '51',
denominator: '100',
},
hardFork: {
numerator: '51',
denominator: '100',
},
ppSecurity: {
numerator: '51',
denominator: '100',
},
},
delegateRep: {
noConfidence: {
numerator: '67',
denominator: '100',
},
committeeNormal: {
numerator: '67',
denominator: '100',
},
committeeNoConfidence: {
numerator: '3',
denominator: '5',
},
constitution: {
numerator: '3',
denominator: '5',
},
hardFork: {
numerator: '3',
denominator: '5',
},
ppNetwork: {
numerator: '67',
denominator: '100',
},
ppEconomic: {
numerator: '67',
denominator: '100',
},
ppTechnical: {
numerator: '67',
denominator: '100',
},
ppGovernance: {
numerator: '3',
denominator: '4',
},
treasury: {
numerator: '67',
denominator: '100',
},
},
},
}
22 changes: 13 additions & 9 deletions packages/api/src/cardano/api/protocol-params.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {getProtocolParams, isProtocolParamsResponse} from './protocol-params'
import {paramsMockResponse} from './protocol-params.mocks'
import {protocolParamsMockResponse} from './protocol-params.mocks'
import axios from 'axios'

jest.mock('axios')
Expand All @@ -8,13 +8,17 @@ const mockedAxios = axios as jest.MockedFunction<typeof axios>
describe('getProtocolParams', () => {
const baseUrl = 'https://localhost'
const mockFetch = jest.fn()
const customFetcher = jest.fn().mockResolvedValue(paramsMockResponse)
const customFetcher = jest.fn().mockResolvedValue(protocolParamsMockResponse)

beforeEach(() => {
jest.clearAllMocks()
})

it('returns parsed data when response is valid', async () => {
mockFetch.mockResolvedValue(paramsMockResponse)
mockFetch.mockResolvedValue(protocolParamsMockResponse)
const protocolParams = getProtocolParams(baseUrl, mockFetch)
const result = await protocolParams()
expect(result).toEqual(paramsMockResponse)
expect(result).toEqual(protocolParamsMockResponse)
})

it('throws an error if response is not valid', async () => {
Expand All @@ -39,16 +43,16 @@ describe('getProtocolParams', () => {
const protocolParams = getProtocolParams(baseUrl, customFetcher)
const result = await protocolParams()
expect(customFetcher).toHaveBeenCalled()
expect(result).toEqual(paramsMockResponse)
expect(result).toEqual(protocolParamsMockResponse)
})
it('uses fetcher and returns data on successful fetch', async () => {
mockedAxios.mockResolvedValue({data: paramsMockResponse})
mockedAxios.mockResolvedValue({data: protocolParamsMockResponse})

const protocolParams = getProtocolParams(baseUrl)
const result = await protocolParams()

expect(mockedAxios).toHaveBeenCalled()
expect(result).toEqual(paramsMockResponse)
expect(result).toEqual(protocolParamsMockResponse)
})

it('throws an error on network issues', async () => {
Expand All @@ -60,11 +64,11 @@ describe('getProtocolParams', () => {
})
describe('isProtocolParamsResponse', () => {
it('returns true for a valid protocol parameters response', () => {
expect(isProtocolParamsResponse(paramsMockResponse)).toBe(true)
expect(isProtocolParamsResponse(protocolParamsMockResponse)).toBe(true)
})

it('returns false for an invalid protocol parameters response', () => {
const invalidResponse = {...paramsMockResponse, epoch: 'invalid'}
const invalidResponse = {...protocolParamsMockResponse, epoch: 'invalid'}
expect(isProtocolParamsResponse(invalidResponse)).toBe(false)
})

Expand Down
Loading
Loading