Skip to content

Commit

Permalink
Merge pull request #27 from open-frames/dj/transactions
Browse files Browse the repository at this point in the history
Type Fixes
  • Loading branch information
daria-github authored Apr 19, 2024
2 parents 86ac7bb + 31d9a84 commit 72b2089
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-buttons-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@open-frames/proxy": patch
---

type fixes
3 changes: 2 additions & 1 deletion packages/server/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ export async function postTransaction(url: string, body: unknown) {
throw new Error(`Request failed with status ${response.status}`);
}

const validatedTransactionResponse = parseAndValidateTransactionResponse(response.json());
const responseData: TransactionResponse = (await response.json()) as TransactionResponse;
const validatedTransactionResponse = parseAndValidateTransactionResponse(responseData);
if (!validatedTransactionResponse) {
throw new Error(`Invalid transaction response from ${url}`);
} else {
Expand Down
9 changes: 5 additions & 4 deletions packages/server/src/parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readFile } from 'node:fs/promises';
import { createServer, Server } from 'node:http';

import { TransactionResponse } from '@open-frames/proxy-types';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';

import { downloadAndExtract } from './handlers.js';
Expand Down Expand Up @@ -262,7 +263,7 @@ describe('parseAndValidateTransactionResponse', () => {
value: '1000',
data: '0x00',
},
};
} as TransactionResponse;
expect(parseAndValidateTransactionResponse(validInput)).toEqual(validInput);
});

Expand All @@ -276,7 +277,7 @@ describe('parseAndValidateTransactionResponse', () => {
value: '1000',
data: '0x00',
},
};
} as unknown as TransactionResponse;
expect(parseAndValidateTransactionResponse(validInput)).toEqual(validInput);
});

Expand All @@ -287,7 +288,7 @@ describe('parseAndValidateTransactionResponse', () => {
params: {
abi: 'invalid abi',
},
};
} as unknown as TransactionResponse;
expect(parseAndValidateTransactionResponse(invalidChainId)).toBeNull();
});
test('should return null when input method is eth_sendTransaction with invalid chainId', () => {
Expand All @@ -300,7 +301,7 @@ describe('parseAndValidateTransactionResponse', () => {
value: '1000',
data: '0x00',
},
};
} as TransactionResponse;
expect(parseAndValidateTransactionResponse(invalidChainId)).toBeNull();
});
});

0 comments on commit 72b2089

Please sign in to comment.