-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
39 changed files
with
1,039 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@moralisweb3/api-utils': minor | ||
'@moralisweb3/core': minor | ||
'moralis': minor | ||
'@moralisweb3/streams': minor | ||
--- | ||
|
||
Intergrating stream API in code base, creating a new package @moralisweb3/streams |
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const MOCK_API_KEY = 'test-api-key'; | ||
export const EVM_API_ROOT = 'https://deep-index.moralis.io/api/v2'; | ||
export const SOL_API_ROOT = 'https://solana-gateway.moralis.io'; | ||
export const STREAM_API_ROOT = 'https://streams-api.aws-prod-streams-master-1.moralis.io'; |
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,19 @@ | ||
import { setupServer } from 'msw/node'; | ||
|
||
import { mockCreateStream } from './streamApi/createStream'; | ||
import { mockDeleteStream } from './streamApi/deleteStream'; | ||
import { mockGetStreams } from './streamApi/getStreams'; | ||
import { mockUpdateStream } from './streamApi/updateStream'; | ||
import { mockSetSettings } from './streamApi/setSettings'; | ||
import { mockGetSettings } from './streamApi/getSettings'; | ||
|
||
const handlers = [ | ||
mockCreateStream, | ||
mockGetStreams, | ||
mockUpdateStream, | ||
mockDeleteStream, | ||
mockSetSettings, | ||
mockGetSettings, | ||
]; | ||
|
||
export const mockServer = setupServer(...handlers); |
23 changes: 23 additions & 0 deletions
23
packages/integration/mockRequests/streamApi/createStream.ts
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,23 @@ | ||
import { rest } from 'msw'; | ||
import { STREAM_API_ROOT, MOCK_API_KEY } from '../config'; | ||
|
||
export const mockCreateStreamOutput: Record<string, string> = { | ||
address: '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7', | ||
chainId: '0x3', | ||
}; | ||
|
||
export const mockCreateStream = rest.put(`${STREAM_API_ROOT}/streams`, (req, res, ctx) => { | ||
const apiKey = req.headers.get('x-api-key'); | ||
|
||
if (apiKey !== MOCK_API_KEY) { | ||
return res(ctx.status(401)); | ||
} | ||
|
||
const value = mockCreateStreamOutput; | ||
|
||
if (!value) { | ||
return res(ctx.status(404)); | ||
} | ||
|
||
return res(ctx.status(200), ctx.json(value)); | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/integration/mockRequests/streamApi/deleteStream.ts
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,28 @@ | ||
import { rest } from 'msw'; | ||
import { STREAM_API_ROOT, MOCK_API_KEY } from '../config'; | ||
|
||
export const mockDeleteStreamOutput: Record<string, string> = { | ||
'3fa85f64-5717-4562-b3fc-2c963f66afa6': '0x3', | ||
}; | ||
|
||
export const mockDeleteStream = rest.delete(`${STREAM_API_ROOT}/streams/:id`, (req, res, ctx) => { | ||
const id = req.params.id as string; | ||
const apiKey = req.headers.get('x-api-key'); | ||
|
||
if (apiKey !== MOCK_API_KEY) { | ||
return res(ctx.status(401)); | ||
} | ||
|
||
const value = mockDeleteStreamOutput[id]; | ||
|
||
if (!value) { | ||
return res(ctx.status(404)); | ||
} | ||
|
||
return res( | ||
ctx.status(200), | ||
ctx.json({ | ||
chainId: value, | ||
}), | ||
); | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/integration/mockRequests/streamApi/getSettings.ts
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,23 @@ | ||
import { rest } from 'msw'; | ||
import { STREAM_API_ROOT, MOCK_API_KEY } from '../config'; | ||
|
||
export const mockGetSettingsOutput: Record<string, string> = { | ||
secretKey: 'top_secret', | ||
region: 'us-east-1', | ||
}; | ||
|
||
export const mockGetSettings = rest.get(`${STREAM_API_ROOT}/settings`, (req, res, ctx) => { | ||
const apiKey = req.headers.get('x-api-key'); | ||
|
||
if (apiKey !== MOCK_API_KEY) { | ||
return res(ctx.status(401)); | ||
} | ||
|
||
const value = mockGetSettingsOutput; | ||
|
||
if (!value) { | ||
return res(ctx.status(404)); | ||
} | ||
|
||
return res(ctx.status(200), ctx.json(value)); | ||
}); |
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,25 @@ | ||
import { rest } from 'msw'; | ||
import { STREAM_API_ROOT, MOCK_API_KEY } from '../config'; | ||
|
||
export const mockGetStreamsOutput = 20; | ||
|
||
export const mockGetStreams = rest.get(`${STREAM_API_ROOT}/streams`, (req, res, ctx) => { | ||
const apiKey = req.headers.get('x-api-key'); | ||
|
||
if (apiKey !== MOCK_API_KEY) { | ||
return res(ctx.status(401)); | ||
} | ||
|
||
const value = mockGetStreamsOutput; | ||
|
||
if (!value) { | ||
return res(ctx.status(404)); | ||
} | ||
|
||
return res( | ||
ctx.status(200), | ||
ctx.json({ | ||
total: value, | ||
}), | ||
); | ||
}); |
20 changes: 20 additions & 0 deletions
20
packages/integration/mockRequests/streamApi/setSettings.ts
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,20 @@ | ||
import { rest } from 'msw'; | ||
import { STREAM_API_ROOT, MOCK_API_KEY } from '../config'; | ||
|
||
export const mockSetSettingsOutput: Record<string, string> = {}; | ||
|
||
export const mockSetSettings = rest.post(`${STREAM_API_ROOT}/settings`, (req, res, ctx) => { | ||
const apiKey = req.headers.get('x-api-key'); | ||
|
||
if (apiKey !== MOCK_API_KEY) { | ||
return res(ctx.status(401)); | ||
} | ||
|
||
const value = mockSetSettingsOutput; | ||
|
||
if (!value) { | ||
return res(ctx.status(404)); | ||
} | ||
|
||
return res(ctx.status(200), ctx.json(value)); | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/integration/mockRequests/streamApi/updateStream.ts
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,28 @@ | ||
import { rest } from 'msw'; | ||
import { STREAM_API_ROOT, MOCK_API_KEY } from '../config'; | ||
|
||
export const mockUpdateStreamOutput: Record<string, string> = { | ||
'3fa85f64-5717-4562-b3fc-2c963f66afa6': '0x3', | ||
}; | ||
|
||
export const mockUpdateStream = rest.post(`${STREAM_API_ROOT}/streams/:id`, (req, res, ctx) => { | ||
const id = req.params.id as string; | ||
const apiKey = req.headers.get('x-api-key'); | ||
|
||
if (apiKey !== MOCK_API_KEY) { | ||
return res(ctx.status(401)); | ||
} | ||
|
||
const value = mockUpdateStreamOutput[id]; | ||
|
||
if (!value) { | ||
return res(ctx.status(404)); | ||
} | ||
|
||
return res( | ||
ctx.status(200), | ||
ctx.json({ | ||
chainId: value, | ||
}), | ||
); | ||
}); |
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,58 @@ | ||
import { MoralisStreams } from '@moralisweb3/streams'; | ||
import { cleanStreamsApi, setupStreamApi } from './setup'; | ||
|
||
describe('Create stream', () => { | ||
let StreamApi: MoralisStreams; | ||
|
||
beforeAll(() => { | ||
StreamApi = setupStreamApi(); | ||
}); | ||
|
||
afterAll(() => { | ||
cleanStreamsApi(); | ||
}); | ||
|
||
it('should create a stream ', async () => { | ||
const result = await StreamApi.add({ | ||
chainId: '0x3', | ||
address: '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7', | ||
tag: 'test', | ||
description: 'test', | ||
type: 'tx', | ||
webhookUrl: 'https://webhook.site/4f1b1b1b-1b1b-4f1b-1b1b-1b1b1b1b1b1b', | ||
}); | ||
|
||
expect(result).toBeDefined(); | ||
expect(result).toEqual(expect.objectContaining({})); | ||
expect(result.result.chainId).toEqual('0x3'); | ||
}); | ||
|
||
it('should not create stream', async () => { | ||
const failedResult = await StreamApi.add({ | ||
chainId: 'invalid_chain', | ||
address: '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7', | ||
tag: 'test', | ||
description: 'test', | ||
type: 'tx', | ||
webhookUrl: 'https://webhook.site/4f1b1b1b-1b1b-4f1b-1b1b-1b1b1b1b1b1b', | ||
}) | ||
.then() | ||
.catch((err: any) => { | ||
return err; | ||
}); | ||
|
||
expect(failedResult).toBeDefined(); | ||
expect( | ||
StreamApi.add({ | ||
chainId: 'invalid_chain', | ||
address: '0x992eCcC191D6F74E8Be187ed6B6AC196b08314f7', | ||
tag: 'test', | ||
description: 'test', | ||
type: 'tx', | ||
webhookUrl: 'https://webhook.site/4f1b1b1b-1b1b-4f1b-1b1b-1b1b1b1b1b1b', | ||
}), | ||
).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"[C0005] Invalid provided chain, value must be a positive number, or a hex-string starting with '0x'"`, | ||
); | ||
}); | ||
}); |
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,24 @@ | ||
import { MoralisStreams } from '@moralisweb3/streams'; | ||
import { cleanStreamsApi, setupStreamApi } from './setup'; | ||
|
||
describe('Delete stream', () => { | ||
let StreamApi: MoralisStreams; | ||
|
||
beforeAll(() => { | ||
StreamApi = setupStreamApi(); | ||
}); | ||
|
||
afterAll(() => { | ||
cleanStreamsApi(); | ||
}); | ||
|
||
it('should delete a stream ', async () => { | ||
const result = await StreamApi.delete({ | ||
id: '3fa85f64-5717-4562-b3fc-2c963f66afa6', | ||
}); | ||
|
||
expect(result).toBeDefined(); | ||
expect(result).toEqual(expect.objectContaining({})); | ||
expect(result.result.chainId).toEqual('0x3'); | ||
}); | ||
}); |
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 @@ | ||
import { MoralisStreams } from '@moralisweb3/streams'; | ||
import { cleanStreamsApi, setupStreamApi } from './setup'; | ||
|
||
describe('Get settings', () => { | ||
let StreamApi: MoralisStreams; | ||
|
||
beforeAll(() => { | ||
StreamApi = setupStreamApi(); | ||
}); | ||
|
||
afterAll(() => { | ||
cleanStreamsApi(); | ||
}); | ||
|
||
it('should get stream settings ', async () => { | ||
const result = await StreamApi.readSettings(); | ||
|
||
expect(result).toBeDefined(); | ||
expect(result).toEqual(expect.objectContaining({})); | ||
expect(result.result.region).toEqual('us-east-1'); | ||
}); | ||
}); |
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,24 @@ | ||
import { MoralisStreams } from '@moralisweb3/streams'; | ||
import { cleanStreamsApi, setupStreamApi } from './setup'; | ||
|
||
describe('Get stream', () => { | ||
let StreamApi: MoralisStreams; | ||
|
||
beforeAll(() => { | ||
StreamApi = setupStreamApi(); | ||
}); | ||
|
||
afterAll(() => { | ||
cleanStreamsApi(); | ||
}); | ||
|
||
it('should get all streams', async () => { | ||
const result = await StreamApi.getAll({ | ||
limit: 20, | ||
}); | ||
|
||
expect(result).toBeDefined(); | ||
expect(result.result).toBeDefined(); | ||
expect(result.pagination.total).toEqual(20); | ||
}); | ||
}); |
Oops, something went wrong.