This repository has been archived by the owner on Apr 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PI-139]: Add a single function for backup in clientjs
- Loading branch information
Showing
7 changed files
with
446 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Backup the Stark L1 registration payload for the currently logged in account | ||
* @type {(dvf: ReturnType<import('../lib/dvf/bindApi')>, | ||
* nonce: string, | ||
* signature: string) => string} | ||
*/ | ||
module.exports = async (dvf, tradingKey, nonce, signature) => { | ||
const url = '/v1/trading/storeStarkL1Registration' | ||
|
||
const { ethAddress } = await dvf.getUserConfig() | ||
|
||
const l1RegistrationSignature = await dvf.stark.signRegistration( | ||
tradingKey, | ||
ethAddress | ||
) | ||
|
||
const data = { | ||
l1RegistrationSignature | ||
} | ||
|
||
return dvf.postAuthenticated(url, nonce, signature, data) | ||
} |
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,47 @@ | ||
const nock = require('nock') | ||
const instance = require('./test/helpers/instance') | ||
const mockGetConf = require('./test/fixtures/getConf') | ||
|
||
describe('dvf.storeStarkL1Registration', () => { | ||
const tradingKey = process.env.PRIVATE_STARK_KEY | ||
const config = { | ||
wallet: { | ||
type: 'tradingKey', | ||
meta: { | ||
starkPrivateKey: tradingKey | ||
} | ||
} | ||
} | ||
/** | ||
* @param {(dvf: Awaited<ReturnType<typeof instance>) => Promise<unknown>} fn | ||
*/ | ||
const withInstance = (fn) => async () => fn(await instance(config)) | ||
|
||
beforeAll(async () => { | ||
mockGetConf() | ||
}) | ||
|
||
afterAll(() => { | ||
nock.restore() | ||
}) | ||
|
||
it('Generates and submits the registration payload', withInstance(async (dvf) => { | ||
mockGetConf() | ||
|
||
const expectedBody = { | ||
l1RegistrationSignature: '0x025e160f8936b367f1aa10f4602dd54a31831de28cfc4263cbfd6b2fd3e9328602421b80ed0520b9e4d20620339ecd34093f04cec933bdebddc31e3bfcd32e5504de195d61296b6ac602ab5db8d190b90cd1e767fe9d47d4c9d96ab62cf7ad41' | ||
} | ||
|
||
const payloadValidator = jest.fn(body => { | ||
expect(body).toMatchObject(expectedBody) | ||
return true | ||
}) | ||
|
||
nock(dvf.config.api) | ||
.post('/v1/trading/storeStarkL1Registration', payloadValidator) | ||
.reply(200) | ||
|
||
await dvf.storeStarkL1Registration(tradingKey) | ||
expect(payloadValidator).toBeCalled() | ||
})) | ||
}) |
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
Oops, something went wrong.