Improved testing - added fixtures
This commit is contained in:
@@ -21,7 +21,7 @@ export interface EtherscanTransactionResponse {
|
||||
gas: string;
|
||||
gasPrice: string;
|
||||
isError: string;
|
||||
txreceiptStatus: string;
|
||||
txreceipt_status: string;
|
||||
input: string;
|
||||
contractAddress: string;
|
||||
cumulativeGasUsed: string;
|
||||
|
||||
@@ -31,7 +31,7 @@ export function _parseEtherscanTransaction(rawTx: EtherscanTransactionResponse):
|
||||
parsedTx.gas = new BigNumber(rawTx.gas);
|
||||
parsedTx.gasPrice = new BigNumber(rawTx.gasPrice);
|
||||
parsedTx.isError = rawTx.isError === '0' ? false : true;
|
||||
parsedTx.txreceiptStatus = rawTx.txreceiptStatus;
|
||||
parsedTx.txreceiptStatus = rawTx.txreceipt_status;
|
||||
parsedTx.input = rawTx.input;
|
||||
parsedTx.contractAddress = rawTx.contractAddress;
|
||||
parsedTx.cumulativeGasUsed = new BigNumber(rawTx.cumulativeGasUsed);
|
||||
|
||||
26
packages/pipeline/test/fixtures/etherscan/api_v1_accounts_transactions.json
vendored
Normal file
26
packages/pipeline/test/fixtures/etherscan/api_v1_accounts_transactions.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"message": "OK",
|
||||
"result": [
|
||||
{
|
||||
"blockHash": "0xee634af4cebd034ed9e5e3dc873a2b0ecc60fe11bef27f7b92542388869f21ee",
|
||||
"blockNumber": "6271590",
|
||||
"confirmations": "996941",
|
||||
"contractAddress": "0x4f833a24e1f95d70f028921e27040ca56e09ab0b",
|
||||
"cumulativeGasUsed": "6068925",
|
||||
"from": "0x2d7dc2ef7c6f6a2cbc3dba4db97b2ddb40e20713",
|
||||
"gas": "7000000",
|
||||
"gasPrice": "20000000000",
|
||||
"gasUsed": "6005925",
|
||||
"hash": "0x4a03044699c2fbd256e21632a6d8fbfc27655ea711157fa8b2b917f0eb954cea",
|
||||
"input": "0x60806040",
|
||||
"isError": "0",
|
||||
"nonce": "2",
|
||||
"timeStamp": "1536083185",
|
||||
"to": "",
|
||||
"transactionIndex": "3",
|
||||
"txreceipt_status": "1",
|
||||
"value": "0"
|
||||
}
|
||||
],
|
||||
"status": "1"
|
||||
}
|
||||
30
packages/pipeline/test/fixtures/etherscan/api_v1_accounts_transactions.ts
vendored
Normal file
30
packages/pipeline/test/fixtures/etherscan/api_v1_accounts_transactions.ts
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { BigNumber } from '@0x/utils';
|
||||
|
||||
import { EtherscanTransaction } from '../../../src/entities';
|
||||
|
||||
// To re-create the JSON file from the API (e.g. if the API output schema changes), run the below command:
|
||||
// curl "https://api.etherscan.io/api?module=account&action=txlist&address=0x4f833a24e1f95d70f028921e27040ca56e09ab0b&startblock=0&endblock=99999999&page=1&offset=1&sort=asc&apikey=YourApiKeyToken" | python -m json.tool > api_v1_accounts_transactions.json
|
||||
|
||||
const ParsedEtherscanTransactions: EtherscanTransaction[] = [
|
||||
{
|
||||
blockNumber: new BigNumber('6271590'),
|
||||
timeStamp: new BigNumber('1536083185'),
|
||||
hash: '0x4a03044699c2fbd256e21632a6d8fbfc27655ea711157fa8b2b917f0eb954cea',
|
||||
nonce: 2,
|
||||
blockHash: '0xee634af4cebd034ed9e5e3dc873a2b0ecc60fe11bef27f7b92542388869f21ee',
|
||||
transactionIndex: 3,
|
||||
from: '0x2d7dc2ef7c6f6a2cbc3dba4db97b2ddb40e20713',
|
||||
to: '',
|
||||
value: new BigNumber('0'),
|
||||
gas: new BigNumber('7000000'),
|
||||
gasPrice: new BigNumber('20000000000'),
|
||||
isError: false,
|
||||
txreceiptStatus: '1',
|
||||
input: '0x60806040', // shortened
|
||||
contractAddress: '0x4f833a24e1f95d70f028921e27040ca56e09ab0b',
|
||||
cumulativeGasUsed: new BigNumber('6068925'),
|
||||
gasUsed: new BigNumber('6005925'),
|
||||
confirmations: new BigNumber('996941'),
|
||||
}
|
||||
];
|
||||
export { ParsedEtherscanTransactions };
|
||||
@@ -7,6 +7,9 @@ import { EtherscanTransaction } from '../../../src/entities';
|
||||
import { parseEtherscanTransactions } from '../../../src/parsers/etherscan';
|
||||
import { chaiSetup } from '../../utils/chai_setup';
|
||||
|
||||
import * as etherscanResponse from '../../fixtures/etherscan/api_v1_accounts_transactions.json';
|
||||
import { ParsedEtherscanTransactions } from '../../fixtures/etherscan/api_v1_accounts_transactions';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
@@ -14,54 +17,8 @@ const expect = chai.expect;
|
||||
describe('etherscan_transactions', () => {
|
||||
describe('parseEtherscanTransactions', () => {
|
||||
it('converts etherscanTransactions to EtherscanTransaction entities', () => {
|
||||
const result: EtherscanTransactionResponse[] = [
|
||||
{
|
||||
blockNumber: '6271590',
|
||||
timeStamp: '1536083185',
|
||||
hash: '0x4a03044699c2fbd256e21632a6d8fbfc27655ea711157fa8b2b917f0eb954cea',
|
||||
nonce: '2',
|
||||
blockHash: '0xee634af4cebd034ed9e5e3dc873a2b0ecc60fe11bef27f7b92542388869f21ee',
|
||||
transactionIndex: '3',
|
||||
from: '0x2d7dc2ef7c6f6a2cbc3dba4db97b2ddb40e20713',
|
||||
to: '',
|
||||
value: '0',
|
||||
gas: '7000000',
|
||||
gasPrice: '20000000000',
|
||||
isError: '0',
|
||||
txreceiptStatus: '1',
|
||||
input: '0x60806040', // shortened
|
||||
contractAddress: '0x4f833a24e1f95d70f028921e27040ca56e09ab0b',
|
||||
cumulativeGasUsed: '6068925',
|
||||
gasUsed: '6005925',
|
||||
confirmations: '976529',
|
||||
},
|
||||
];
|
||||
const response: EtherscanResponse = {
|
||||
status: '1',
|
||||
message: 'OK',
|
||||
result,
|
||||
};
|
||||
const _expected: EtherscanTransaction = {
|
||||
blockNumber: new BigNumber('6271590'),
|
||||
timeStamp: new BigNumber('1536083185'),
|
||||
hash: '0x4a03044699c2fbd256e21632a6d8fbfc27655ea711157fa8b2b917f0eb954cea',
|
||||
nonce: 2,
|
||||
blockHash: '0xee634af4cebd034ed9e5e3dc873a2b0ecc60fe11bef27f7b92542388869f21ee',
|
||||
transactionIndex: 3,
|
||||
from: '0x2d7dc2ef7c6f6a2cbc3dba4db97b2ddb40e20713',
|
||||
to: '',
|
||||
value: new BigNumber('0'),
|
||||
gas: new BigNumber('7000000'),
|
||||
gasPrice: new BigNumber('20000000000'),
|
||||
isError: false,
|
||||
txreceiptStatus: '1',
|
||||
input: '0x60806040', // shortened
|
||||
contractAddress: '0x4f833a24e1f95d70f028921e27040ca56e09ab0b',
|
||||
cumulativeGasUsed: new BigNumber('6068925'),
|
||||
gasUsed: new BigNumber('6005925'),
|
||||
confirmations: new BigNumber('976529'),
|
||||
};
|
||||
const expected = [_expected];
|
||||
const response: EtherscanResponse = etherscanResponse;
|
||||
const expected = ParsedEtherscanTransactions;
|
||||
const actual = parseEtherscanTransactions(response.result);
|
||||
expect(actual).deep.equal(expected);
|
||||
});
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"./test/fixtures/copper/api_v1_custom_field_definitions.json",
|
||||
"./test/fixtures/copper/api_v1_list_activities.json",
|
||||
"./test/fixtures/copper/api_v1_list_leads.json",
|
||||
"./test/fixtures/copper/api_v1_list_opportunities.json"
|
||||
"./test/fixtures/copper/api_v1_list_opportunities.json",
|
||||
"./test/fixtures/etherscan/api_v1_accounts_transactions.json"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user