-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data decoder/master copy endpoint calls (#42)
* build: Add get master copies + decoded data Co-authored-by: Aaron Cook <[email protected]> * chore: Clean-up types * fix: Remove unnecessary test * fix: Broken tests + bump version * fix: Remove frontend types from response * build: Add e2e tests * fix: Remove lint Co-authored-by: Diogo Soares <[email protected]> Co-authored-by: Aaron Cook <[email protected]>
- Loading branch information
1 parent
c84f332
commit a9c2051
Showing
11 changed files
with
149 additions
and
471 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { getDecodedData } from '../src' | ||
import config from './config' | ||
|
||
describe('getDecodedData tests', () => { | ||
it('should post getDecodedData', async () => { | ||
const result = await getDecodedData( | ||
config.baseUrl, | ||
'4', | ||
'0x095ea7b3000000000000000000000000ae9844f89d98c150f5e61bfc676d68b4921559900000000000000000000000000000000000000000000000000001c6bf52634000', | ||
) | ||
|
||
expect(result).toStrictEqual({ | ||
method: 'approve', | ||
parameters: [ | ||
{ | ||
name: 'spender', | ||
type: 'address', | ||
value: '0xae9844F89D98c150F5e61bfC676D68b492155990', | ||
}, | ||
{ | ||
name: 'value', | ||
type: 'uint256', | ||
value: '500000000000000', | ||
}, | ||
], | ||
}) | ||
}) | ||
}) |
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,15 @@ | ||
import { getMasterCopies } from '../src' | ||
import config from './config' | ||
|
||
describe('get mastercopy tests', () => { | ||
it('should get master copy response', async () => { | ||
const masterCopies = await getMasterCopies(config.baseUrl, '4') | ||
|
||
expect(Array.isArray(masterCopies)).toBe(true) | ||
|
||
// version 1.1.1 should be present | ||
const lastVersionRinkeby = masterCopies.find((mastercopy) => mastercopy.version === '1.1.1') | ||
expect(lastVersionRinkeby).toBeDefined() | ||
expect(lastVersionRinkeby.address).toBe('0x34CfAC646f301356fAa8B21e94227e3583Fe3F5F') | ||
}) | ||
}) |
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,29 +1,18 @@ | ||
import { fetchData, insertParams, stringifyQuery } from './utils' | ||
import { paths } from './types/api' | ||
import { fetchData, stringifyQuery } from './utils' | ||
|
||
type Primitive = string | number | boolean | null | ||
|
||
interface Params { | ||
path?: { [key: string]: Primitive } | ||
query?: { [key: string]: Primitive } | ||
body?: unknown | ||
} | ||
|
||
export function callEndpoint<T extends keyof paths>( | ||
baseUrl: string, | ||
path: T, | ||
parameters?: paths[T]['get']['parameters'], | ||
rawUrl?: string, | ||
): Promise<paths[T]['get']['responses'][200]['schema']> { | ||
let url = rawUrl | ||
let body | ||
if (!url) { | ||
const params = parameters as Params | ||
const pathname = insertParams(path, params?.path) | ||
const search = stringifyQuery(params?.query) | ||
url = `${baseUrl}${pathname}${search}` | ||
body = params?.body | ||
export function callEndpoint<T>(url: string, params?: Params, rawUrl?: string): Promise<T> { | ||
if (rawUrl) { | ||
return fetchData(rawUrl) | ||
} | ||
|
||
return fetchData(url, body) | ||
const search = stringifyQuery(params?.query) | ||
const endpoint = `${url}${search}` | ||
return fetchData(endpoint, params?.body) | ||
} |
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.