Skip to content

Commit

Permalink
ref
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbazan7 committed Jan 3, 2022
1 parent 905e93c commit 9ea5a36
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 45 deletions.
14 changes: 7 additions & 7 deletions packages/bitcore-node/src/modules/ethereum/models/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ export class EthTransactionModel extends BaseTransaction<IEthTransaction> {
const { web3 } = await ETH.getWeb3(network);

// handle incoming ERC20 transactions
if (tx.abiType?.type === 'ERC20' && ['transfer', 'transferFrom'].includes(tx.abiType.name)) {
const _to = tx.abiType.params.find(f => f.name === '_to')?.value;
const _from = tx.abiType.params.find(f => f.name === '_from')?.value;
if (tx.abiType && tx.abiType.type === 'ERC20' && ['transfer', 'transferFrom'].includes(tx.abiType.name)) {
const _to = tx.abiType.params.find(f => f.name === '_to');
const _from = tx.abiType.params.find(f => f.name === '_from');

if (_to) {
tos.push(web3.utils.toChecksumAddress(_to));
if (_to && _to.value) {
tos.push(web3.utils.toChecksumAddress(_to.value));
}
if (_from) {
froms.push(web3.utils.toChecksumAddress(_from));
if (_from && _from.value) {
froms.push(web3.utils.toChecksumAddress(_from.value));
}
}

Expand Down
38 changes: 0 additions & 38 deletions packages/bitcore-node/test/integration/ethereum/csp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { StreamWalletTransactionsParams } from '../../../src/types/namespaces/Ch
import { intAfterHelper, intBeforeHelper } from '../../helpers/integration';
import { EthTransactions } from '../../data/ETH/transactionsETH';
import { EthBlocks } from '../../data/ETH/blocksETH';
import { unprocessedEthBlocks } from '../../data/ETH/unprocessedBlocksETH';

describe('Ethereum API', function() {
const chain = 'ETH';
Expand Down Expand Up @@ -396,43 +395,6 @@ describe('Ethereum API', function() {
});
});
});

describe('#batchImport', () => {
const chain = 'ETH';
const network = 'testnet';

const wallet = new ObjectId();
const address = '0x3Ec3dA6E14BE9518A9a6e92DdCC6ACfF2CEFf4ef';

before(async () => {
await WalletAddressStorage.collection.insertOne({
chain,
network,
wallet,
address,
processed: true
});
});

afterEach(async () => {
await EthTransactionStorage.collection.deleteMany({});
});

it('should update eth transactions with related wallet id correctly (incoming)', async () => {
const block = unprocessedEthBlocks[0] as any; // block containing an eth transfer to 0x3Ec3dA6E14BE9518A9a6e92DdCC6ACfF2CEFf4ef
await EthTransactionStorage.batchImport({...block});
const walletTxs = await EthTransactionStorage.collection.find({ chain, network, wallets: wallet }).toArray();
expect(walletTxs.length).eq(1);
});

it('should update erc20 transactions with related wallet id correctly (incoming)', async () => {
const block = unprocessedEthBlocks[1] as any; // block containing an ERC20 transfer to 0x3Ec3dA6E14BE9518A9a6e92DdCC6ACfF2CEFf4ef
await EthTransactionStorage.batchImport({...block});
const walletTxs = await EthTransactionStorage.collection.find({ chain, network, wallets: wallet }).toArray();
expect(walletTxs.length).eq(1);
});
});

});

const streamWalletTransactionsTest = async (chain: string, network: string, includeInvalidTxs: boolean = false) => {
Expand Down
37 changes: 37 additions & 0 deletions packages/bitcore-node/test/integration/models/transaction.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { ObjectId } from 'bson';
import { expect } from 'chai';
import * as crypto from 'crypto';
import { CoinStorage, ICoin } from '../../../src/models/coin';
import { IBtcTransaction, SpendOp, TransactionStorage } from '../../../src/models/transaction';
import { SpentHeightIndicators } from '../../../src/types/Coin';
import { resetDatabase } from '../../helpers';
import { intAfterHelper, intBeforeHelper } from '../../helpers/integration';
import { unprocessedEthBlocks } from '../../data/ETH/unprocessedBlocksETH';
import { WalletAddressStorage } from '../../../src/models/walletAddress';
import { EthTransactionStorage } from '../../../src/modules/ethereum/models/transaction';

async function makeMempoolTxChain(chain: string, network: string, startingTxid: string, chainLength = 1) {
let txid = startingTxid;
Expand Down Expand Up @@ -199,4 +203,37 @@ describe('Transaction Model', function() {
expect(goodTxs[0].txid).to.eq(blockTx.txid);
expect(goodTxs[0].blockHeight).to.eq(blockTx.blockHeight);
});

describe('#batchImport', () => {
const chain = 'ETH';
const network = 'testnet';

const wallet = new ObjectId();
const address = '0x3Ec3dA6E14BE9518A9a6e92DdCC6ACfF2CEFf4ef';

beforeEach(async () => {
await WalletAddressStorage.collection.insertOne({
chain,
network,
wallet,
address,
processed: true
});
});

it('should update eth transactions with related wallet id correctly (incoming)', async () => {
const block = unprocessedEthBlocks[0] as any; // block containing an eth transfer to 0x3Ec3dA6E14BE9518A9a6e92DdCC6ACfF2CEFf4ef
await EthTransactionStorage.batchImport({...block});
const walletTxs = await EthTransactionStorage.collection.find({ chain, network, wallets: wallet }).toArray();
expect(walletTxs.length).eq(1);
});

it('should update erc20 transactions with related wallet id correctly (incoming)', async () => {
const block = unprocessedEthBlocks[1] as any; // block containing an ERC20 transfer to 0x3Ec3dA6E14BE9518A9a6e92DdCC6ACfF2CEFf4ef
await EthTransactionStorage.batchImport({...block});
const walletTxs = await EthTransactionStorage.collection.find({ chain, network, wallets: wallet }).toArray();
expect(walletTxs.length).eq(1);
});
});

});

0 comments on commit 9ea5a36

Please sign in to comment.