Skip to content

Commit

Permalink
update integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
netbonus committed Jul 30, 2024
1 parent a67b013 commit be6db5c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 56 deletions.
9 changes: 0 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 45 additions & 47 deletions src/__test__/integration/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';
import connectResponse from './connect.json';
import getAddressesResponse from './getAddresses.json';
import signResponse from './sign.json';
Expand All @@ -22,80 +22,78 @@ import {
} from './4byte';

export const handlers = [
rest.post('https://signing.gridpl.us/test/connect', (req, res, ctx) => {
return res(ctx.json(connectResponse));
http.post('https://signing.gridpl.us/test/connect', () => {
return HttpResponse.json(connectResponse);
}),
rest.post('https://signing.gridpl.us/test/getAddresses', (req, res, ctx) => {
return res(ctx.json(getAddressesResponse));
http.post('https://signing.gridpl.us/test/getAddresses', () => {
return HttpResponse.json(getAddressesResponse);
}),
rest.post('https://signing.gridpl.us/test/sign', (req, res, ctx) => {
return res(ctx.json(signResponse));
http.post('https://signing.gridpl.us/test/sign', () => {
return HttpResponse.json(signResponse);
}),
rest.post(
'https://signing.gridpl.us/test/fetchActiveWallet',
(req, res, ctx) => {
return res(ctx.json(fetchActiveWalletResponse));
},
),
rest.post('https://signing.gridpl.us/test/addKvRecords', (req, res, ctx) => {
return res(ctx.json(addKvRecordsResponse));
http.post('https://signing.gridpl.us/test/fetchActiveWallet', () => {
return HttpResponse.json(fetchActiveWalletResponse);
}),
rest.post('https://signing.gridpl.us/test/getKvRecords', (req, res, ctx) => {
return res(ctx.json(getKvRecordsResponse));
http.post('https://signing.gridpl.us/test/addKvRecords', () => {
return HttpResponse.json(addKvRecordsResponse);
}),
rest.post(
'https://signing.gridpl.us/test/removeKvRecords',
(req, res, ctx) => {
return res(ctx.json(removeKvRecordsResponse));
},
),
rest.get('https://api.etherscan.io/api', (req, res, ctx) => {
const module = req.url.searchParams.get('module');
const action = req.url.searchParams.get('action');
const address = req.url.searchParams.get('address');
http.post('https://signing.gridpl.us/test/getKvRecords', () => {
return HttpResponse.json(getKvRecordsResponse);
}),
http.post('https://signing.gridpl.us/test/removeKvRecords', () => {
return HttpResponse.json(removeKvRecordsResponse);
}),
http.get('https://api.etherscan.io/api', ({ request }) => {
const url = new URL(request.url);
const module = url.searchParams.get('module');
const action = url.searchParams.get('action');
const address = url.searchParams.get('address');

if (module === 'contract' && action === 'getabi') {
if (address === '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48') {
return res(
ctx.json({ result: JSON.stringify(etherscanResponse0xa0b86991) }),
);
return HttpResponse.json({
result: JSON.stringify(etherscanResponse0xa0b86991),
});
}
if (address === '0x7a250d5630b4cf539739df2c5dacb4c659f2488d') {
return res(
ctx.json({ result: JSON.stringify(etherscanResponse0x7a250d56) }),
);
return HttpResponse.json({
result: JSON.stringify(etherscanResponse0x7a250d56),
});
}
if (address === '0xc36442b4a4522e871399cd717abdd847ab11fe88') {
return res(
ctx.json({ result: JSON.stringify(etherscanResponse0xc36442b6) }),
);
return HttpResponse.json({
result: JSON.stringify(etherscanResponse0xc36442b6),
});
}
if (address === '0x06412d7ebfbf66c25607e2ed24c1d207043be327') {
return res(
ctx.json({ result: JSON.stringify(etherscanResponse0x06412d7e) }),
);
return HttpResponse.json({
result: JSON.stringify(etherscanResponse0x06412d7e),
});
}
}
return new HttpResponse(null, { status: 404 });
}),
rest.get('https://www.4byte.directory/api/v1/signatures', (req, res, ctx) => {
const hexSignature = req.url.searchParams.get('hex_signature');
http.get('https://www.4byte.directory/api/v1/signatures', ({ request }) => {
const url = new URL(request.url);
const hexSignature = url.searchParams.get('hex_signature');
if (hexSignature === '0xa9059cbb') {
return res(ctx.json(fourbyteResponse0xa9059cbb));
return HttpResponse.json(fourbyteResponse0xa9059cbb);
}
if (hexSignature === '0x38ed1739') {
return res(ctx.json(fourbyteResponse0x38ed1739));
return HttpResponse.json(fourbyteResponse0x38ed1739);
}
if (hexSignature === '0xac9650d8') {
return res(ctx.json(fourbyteResponseac9650d8));
return HttpResponse.json(fourbyteResponseac9650d8);
}
if (hexSignature === '0x0c49ccbe') {
return res(ctx.json(fourbyteResponse0c49ccbe));
return HttpResponse.json(fourbyteResponse0c49ccbe);
}
if (hexSignature === '0xfc6f7865') {
return res(ctx.json(fourbyteResponsefc6f7865));
return HttpResponse.json(fourbyteResponsefc6f7865);
}
if (hexSignature === '0x6a761202') {
return res(ctx.json(fourbyteResponse0x6a761202));
return HttpResponse.json(fourbyteResponse0x6a761202);
}
return new HttpResponse(null, { status: 404 });
}),
];

0 comments on commit be6db5c

Please sign in to comment.