Improved testing - added fixtures

This commit is contained in:
askeluv
2019-02-26 11:42:53 +08:00
parent 6eb923d22f
commit 9fbd809344
6 changed files with 65 additions and 51 deletions

View File

@@ -21,7 +21,7 @@ export interface EtherscanTransactionResponse {
gas: string;
gasPrice: string;
isError: string;
txreceiptStatus: string;
txreceipt_status: string;
input: string;
contractAddress: string;
cumulativeGasUsed: string;

View File

@@ -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);

View 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"
}

View 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 };

View File

@@ -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);
});

View File

@@ -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"
]
}