Skip to content

Commit

Permalink
test: add small regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
emilbayes committed Oct 5, 2023
1 parent 6894660 commit 3c28dd1
Show file tree
Hide file tree
Showing 3 changed files with 320 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.8.0",
"description": "Protocol Buffer messages for Vega in Javascript",
"scripts": {
"test": "true"
"test": "brittle tests/**/*.js"
},
"repository": {
"type": "git",
Expand All @@ -21,6 +21,7 @@
},
"devDependencies": {
"@vegaprotocol/crypto": "^0.5.1",
"brittle": "^3.3.2",
"esbuild": "^0.17.8",
"got": "^12.4.1",
"protoc-plugin-js": "^0.5.1",
Expand Down
1 change: 0 additions & 1 deletion test.js

This file was deleted.

318 changes: 318 additions & 0 deletions tests/proposal-regression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,318 @@
const test = require('brittle')
const InputData = require('../vega/commands/v1/InputData.js')

test('encode then decode proposal submission', assert => {
const proposalSubmission = {
reference: 'BTC/USD-PERPS Incentive 2',
terms: {
closingTimestamp: '1695394443',
enactmentTimestamp: '1695394503',
newMarket: {
changes: {
instrument: {
name: 'BTC/USD Perpetual Incentive',
code: 'BTC/USD-PERP Inc',

perpetual: {
clampLowerBound: '0',
clampUpperBound: '0',
interestRate: '0',
marginFundingFactor: '0.1',
settlementAsset: '8a246b15bf185065d3f41a710f3eea0fbbe8754a8464501cf4a6d253d69c6423',
quoteName: 'USD-P',
dataSourceSpecForSettlementData: {
external: {
ethOracle: {
address: '0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43',
abi: '[{"inputs":[],"name":"latestAnswer","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"}]',
method: 'latestAnswer',
normalisers: [
{
name: 'btc.price',
expression: '$[0]'
}
],
requiredConfirmations: 3,
trigger: {
timeTrigger: {
every: 30
}
},
filters: [
{
key: {
name: 'btc.price',
type: 'TYPE_INTEGER',
numberDecimalPlaces: 8
},
conditions: [
{
operator: 'OPERATOR_GREATER_THAN_OR_EQUAL',
value: '0'
}
]
}
]
}
}
},
dataSourceSpecForSettlementSchedule: {
internal: {
timeTrigger: {
conditions: [
{
operator: 'OPERATOR_GREATER_THAN_OR_EQUAL',
value: '0'
}
],
triggers: [
{
every: 1800
}
]
}
}
},
dataSourceSpecBinding: {
settlementDataProperty: 'btc.price',
settlementScheduleProperty: 'vegaprotocol.builtin.timetrigger'
}
}

},
metadata: [
'base:BTC',
'quote:USD-P',
'class:fx/crypto',
'quarterly',
'sector:defi',
'enactment:2023-06-15T14:00:00Z',
'settlement:2023-09-30T08:00:00Z'
],
priceMonitoringParameters: {
triggers: [
{
horizon: '3600',
probability: '0.9999',
auctionExtension: '120'
},
{
horizon: '14400',
probability: '0.9999',
auctionExtension: '180'
},
{
horizon: '43200',
probability: '0.9999',
auctionExtension: '300'
}
]
},
liquidityMonitoringParameters: {
targetStakeParameters: {
timeWindow: '3600',
scalingFactor: 1
},
triggeringRatio: '0.7',
auctionExtension: '1'
},

liquiditySlaParameters: {
priceRange: '0.05',
commitmentMinTimeFraction: '0.95',
performanceHysteresisEpochs: 1,
slaCompetitionFactor: '0.95'
},

logNormal: {
riskAversionParameter: 0.000001,
tau: 0.0001140771161,
params: {
sigma: 1.5
}
},
decimalPlaces: '1',
positionDecimalPlaces: '4',
linearSlippageFactor: '0.001',
quadraticSlippageFactor: '0.0'
}
}
},
rationale: {
description: '## Summary\n\nThis proposal requests to list BTC PERPS Incentive as a market with USD-P as a settlement asset on the Vega Network as discussed in: https://community.vega.xyz/.\n\n## Rationale\n\n- BTC is the largest Crypto asset with the highest volume and Marketcap.\n- Given the price, 1 decimal places will be used for price due to the number of valid digits in asset price. \n- Position decimal places will be set to 4 considering the value per contract\n- USDT is chosen as settlement asset due to its stability.',
title: 'BTC USD PERPS Incentive'
}
}

const expected = {
nonce: 0n,
blockHeight: 0n,
command: {
proposalSubmission: {
reference: 'BTC/USD-PERPS Incentive 2',
terms: {
closingTimestamp: 1695394443n,
enactmentTimestamp: 1695394503n,
validationTimestamp: 0n,
change: {
newMarket: {
changes: {
instrument: {
name: 'BTC/USD Perpetual Incentive',
code: 'BTC/USD-PERP Inc',
product: {
perpetual: {
settlementAsset: '8a246b15bf185065d3f41a710f3eea0fbbe8754a8464501cf4a6d253d69c6423',
quoteName: 'USD-P',
marginFundingFactor: '0.1',
interestRate: '0',
clampLowerBound: '0',
clampUpperBound: '0',
dataSourceSpecForSettlementSchedule: {
sourceType: {
internal: {
sourceType: {
timeTrigger: {
conditions: [
{
operator: 'OPERATOR_GREATER_THAN_OR_EQUAL',
value: '0'
}
],
triggers: [{ initial: null, every: 1800n }]
}
}
}
}
},
dataSourceSpecForSettlementData: {
sourceType: {
external: {
sourceType: {
ethOracle: {
address: '0x1b44F3514812d835EB1BDB0acB33d3fA3351Ee43',
abi: '[{"inputs":[],"name":"latestAnswer","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"}]',
method: 'latestAnswer',
args: [],
trigger: {
trigger: {
timeTrigger: {
initial: null,
every: 30n,
until: null
}
}
},
requiredConfirmations: 3n,
filters: [
{
key: {
name: 'btc.price',
type: 'TYPE_INTEGER',
numberDecimalPlaces: 8n
},
conditions: [
{
operator: 'OPERATOR_GREATER_THAN_OR_EQUAL',
value: '0'
}
]
}
],
normalisers: [
{
name: 'btc.price',
expression: '$[0]'
}
]
}
}
}
}
},
dataSourceSpecBinding: {
settlementDataProperty: 'btc.price',
settlementScheduleProperty: 'vegaprotocol.builtin.timetrigger'
}
}
}
},
decimalPlaces: 1n,
metadata: [
'base:BTC',
'quote:USD-P',
'class:fx/crypto',
'quarterly',
'sector:defi',
'enactment:2023-06-15T14:00:00Z',
'settlement:2023-09-30T08:00:00Z'
],
priceMonitoringParameters: {
triggers: [
{
horizon: 3600n,
probability: '0.9999',
auctionExtension: 120n
},
{
horizon: 14400n,
probability: '0.9999',
auctionExtension: 180n
},
{
horizon: 43200n,
probability: '0.9999',
auctionExtension: 300n
}
]
},
liquidityMonitoringParameters: {
targetStakeParameters: { timeWindow: 3600n, scalingFactor: 1 },
triggeringRatio: '0.7',
auctionExtension: 1n
},
positionDecimalPlaces: 4n,
lpPriceRange: null,
linearSlippageFactor: '0.001',
quadraticSlippageFactor: '0.0',
successor: null,
liquiditySlaParameters: {
priceRange: '0.05',
commitmentMinTimeFraction: '0.95',
performanceHysteresisEpochs: 1n,
slaCompetitionFactor: '0.95'
},
riskParameters: {
logNormal: {
riskAversionParameter: 0.000001,
tau: 0.0001140771161,
params: { mu: 0, r: 0, sigma: 1.5 }
}
}
}
}
}
},
rationale: {
description: '## Summary\n' +
'\n' +
'This proposal requests to list BTC PERPS Incentive as a market with USD-P as a settlement asset on the Vega Network as discussed in: https://community.vega.xyz/.\n' +
'\n' +
'## Rationale\n' +
'\n' +
'- BTC is the largest Crypto asset with the highest volume and Marketcap.\n' +
'- Given the price, 1 decimal places will be used for price due to the number of valid digits in asset price. \n' +
'- Position decimal places will be set to 4 considering the value per contract\n' +
'- USDT is chosen as settlement asset due to its stability.',
title: 'BTC USD PERPS Incentive'
}
}
}
}

const actual = InputData.decode(InputData.encode({ proposalSubmission }))

assert.alike(actual, expected)

assert.end()
})

0 comments on commit 3c28dd1

Please sign in to comment.