Skip to content

Commit

Permalink
fix: order hash manager
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Mar 22, 2023
1 parent abe92fd commit f29c236
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 55 deletions.
15 changes: 4 additions & 11 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,15 @@ module.exports = {
// globals: {},

// An array of directory names to be searched recursively up from the requiring module's location
moduleDirectories: ['<rootDir>', 'node_modules', 'src'],
moduleDirectories: ['node_modules', '<rootDir>/src'],

// An array of file extensions your modules use
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],

// A map from regular expressions to module names that allow to stub out resources with a single module
// moduleNameMapper: {
// '^~/(.*)$': '<rootDir>/src/$1',
// '^@injectivelabs/(.*)$': '<rootDir>/../$1/src'
// },
moduleNameMapper: {
...pathsToModuleNameMapper(packagePaths),
...pathsToModuleNameMapper(directoryPaths, { prefix: '<rootDir>/' }),
...pathsToModuleNameMapper(packagePaths, { prefix: '<rootDir>/' }),
...pathsToModuleNameMapper(directoryPaths),
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
Expand Down Expand Up @@ -178,10 +174,7 @@ module.exports = {
},

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
transformIgnorePatterns: [
'^.+\\.json$',
'node_modules/(?!(ethereum-cryptography|eth-crypto)/)',
],
transformIgnorePatterns: ['^.+\\.json$', 'node_modules/(?!(eth-crypto)/)'],

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,66 +1,57 @@
import { OrderType } from '@injectivelabs/chain-api/injective/exchange/v1beta1/exchange_pb'
import { Network } from 'packages/networks/dist'
import { Network } from '@injectivelabs/networks'
import { Address } from '../../../../accounts/Address'
import { OrderHashManager } from './OrderHashManager'

const address = Address.fromBech32('inj1cml96vmptgw99syqrrz8az79xer2pcgp0a885r')
const address = Address.fromBech32('inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r')
const orderHashManager = new OrderHashManager({
network: Network.TestnetK8s,
address: address.bech32Address,
subaccountIndex: 0,
})
const subaccountId = address.getSubaccountId()
const subaccountId = address.getSubaccountId(1)

const spotOrder = {
orderInfo: {
subaccountId: subaccountId,
price: '1.523',
quantity: '0.02',
subaccountId:
'0x2968698c6b9ed6d44b667a0b1f312a3b5d94ded7000000000000000000000000',
price: '1.524',
quantity: '0.01',
feeRecipient: address.bech32Address,
},
marketId:
'0x6afc76766d011522634481b5987c405ce34357c504537eb5feabb3d32d34d15b',
orderType: OrderType.BUY.toString(),
'0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe',
orderType: OrderType.BUY,
}

const derivativeOrder = {
orderInfo: {
subaccountId: subaccountId,
price: '1.523',
quantity: '0.02',
price: '10500',
quantity: '0.01',
feeRecipient: address.bech32Address,
},
margin: '1',
margin: '105',
marketId:
'0x6afc76766d011522634481b5987c405ce34357c504537eb5feabb3d32d34d15b',
orderType: OrderType.BUY.toString(),
orderType: OrderType.BUY,
}

describe('OrderHashManager', () => {
it.only('generates proper hash', async () => {
test('generates proper hash', async () => {
orderHashManager.setNonce(78)

const spotOrderHashes = await orderHashManager.getSpotOrderHashes([
spotOrder,
])
const derivativeOrderHashes =
await orderHashManager.getDerivativeOrderHashes([derivativeOrder])
const {
spotOrderHashes: spotOrderHashes2,
derivativeOrderHashes: derivativeOrderHashes2,
} = await orderHashManager.getOrderHashes({
spotOrders: [spotOrder],
derivativeOrders: [derivativeOrder],
})

expect(spotOrderHashes).toStrictEqual([
'0xd9094b276416bb16a8c681c04872dc6fe9c3fdd3e69efc53c292d682f21cf048',
'0xd9bf0dcb2b135aa27c46b52031029676894e41993cc076508ca826a38e887db4',
])
expect(derivativeOrderHashes).toStrictEqual([
'0x4e9260232fe5947c3afdeb6c28fc8ed72f29bd64e7cf9a33e5190c31de478791',
])
expect(spotOrderHashes2).toStrictEqual([
'0xd9094b276416bb16a8c681c04872dc6fe9c3fdd3e69efc53c292d682f21cf048',
])
expect(derivativeOrderHashes2).toStrictEqual([
'0x4e9260232fe5947c3afdeb6c28fc8ed72f29bd64e7cf9a33e5190c31de478791',
'0xb4f264cbf4df1aa27a1686d812f771d6d3b2ffdc3504eca8f7b16e99d8e7fb1a',
])
})
})
Loading

0 comments on commit f29c236

Please sign in to comment.