fix(e2e):move transaction from fixture to txn_rpc

dev
neeboo 5 years ago
parent 481a38d17b
commit a1ce128afc
  1. 2
      e2e/src/blockchain.e2e.ts
  2. 183
      e2e/src/transaction.e2e.ts
  3. 196
      e2e/src/txn_rpc.e2e.ts

@ -35,7 +35,7 @@ describe('e2e test blockchain', () => {
expect(res.responseType).toEqual('raw'); expect(res.responseType).toEqual('raw');
expect(harmony.utils.isHex(size)).toEqual(true); expect(harmony.utils.isHex(size)).toEqual(true);
expect(checkBlockData(res.result)).toEqual(true); expect(checkBlockData(res.result)).toEqual(true);
const res2 = await bc.getBlockByNumber({ blockNumber: '0x1' }); const res2 = await bc.getBlockByNumber({ blockNumber: res.result.number });
expect(res2.responseType).toEqual('raw'); expect(res2.responseType).toEqual('raw');
expect(harmony.utils.isHex(res2.result.size)).toEqual(true); expect(harmony.utils.isHex(res2.result.size)).toEqual(true);
expect(checkBlockData(res2.result)).toEqual(true); expect(checkBlockData(res2.result)).toEqual(true);

@ -1,166 +1,51 @@
import { harmony } from './harmony'; import { harmony } from './harmony';
import txnJsons from '../fixtures/transactions.json'; // tslint:disable-next-line: no-implicit-dependencies
import { Transaction, TxStatus } from '@harmony-js/transaction';
const messenger = harmony.messenger; import demoAccounts from '../fixtures/testAccount.json';
interface TransactionInfo { const receiver = demoAccounts.Accounts[3];
blockHash: string; jest.useRealTimers();
index: string;
blockNumber: string;
}
describe('e2e test transactions', () => {
const txnHashesFixtures: any = [];
const transactionInfoList: any = [];
// net_*
it('should test hmy_sendRawTransaction from fixtures', async () => {
const { transactions } = txnJsons;
for (const txn of transactions) { describe('test Transaction using SDK', () => {
const sent = await messenger.send( let signed: Transaction;
'hmy_sendRawTransaction', let sent: Transaction;
txn.rawTransaction, let txId: string;
); it('should test signTransaction', async () => {
expect(harmony.utils.isHash(sent.result)).toEqual(true); const txnObject = {
txnHashesFixtures.push(sent.result); to: harmony.crypto.getAddress(receiver.Address).bech32,
} value: new harmony.utils.Unit('100').asGwei().toWei(),
}); gasLimit: new harmony.utils.Unit('210000').asWei().toWei(),
it('should test hmy_getTransactionByHash', async () => { gasPrice: new harmony.utils.Unit('100').asGwei().toWei(),
for (const txnHash of txnHashesFixtures) { };
const txnDetail = await harmony.blockchain.getTransactionByHash({
txnHash,
});
expect(checkTransactionDetail(txnDetail.result)).toEqual(true);
expect(txnDetail.result.hash).toEqual(txnHash);
const transactionInfo = { const txn = harmony.transactions.newTx(txnObject);
blockHash: txnDetail.result.blockHash, signed = await harmony.wallet.signTransaction(txn);
blockNumber: txnDetail.result.blockNumber, expect(signed.isSigned()).toEqual(true);
index: txnDetail.result.transactionIndex,
};
transactionInfoList.push(transactionInfo);
}
});
it('should test hmy_getTransactionByBlockHashAndIndex', async () => {
for (const some of transactionInfoList) {
const transactionInfo: TransactionInfo = some;
const txnDetail: any = await harmony.blockchain.getTransactionByBlockHashAndIndex(
{
blockHash: transactionInfo.blockHash,
index: transactionInfo.index,
},
);
expect(checkTransactionDetail(txnDetail.result)).toEqual(true);
expect(txnDetail.result.blockHash).toEqual(transactionInfo.blockHash);
expect(txnDetail.result.transactionIndex).toEqual(transactionInfo.index);
}
}); });
it('should test hmy_getTransactionByBlockNumberAndIndex', async () => { it('should send transaction', async () => {
for (const some of transactionInfoList) { const [sentTxn, id] = await signed.sendTransaction();
const transactionInfo: TransactionInfo = some; expect(sentTxn.isPending()).toEqual(true);
const txnDetail: any = await harmony.blockchain.getTransactionByBlockNumberAndIndex( expect(harmony.utils.isHash(id)).toEqual(true);
{ txId = id;
blockNumber: transactionInfo.blockNumber, sent = sentTxn;
index: transactionInfo.index,
},
);
expect(checkTransactionDetail(txnDetail.result)).toEqual(true);
expect(txnDetail.result.blockNumber).toEqual(transactionInfo.blockNumber);
expect(txnDetail.result.transactionIndex).toEqual(transactionInfo.index);
}
});
it('should test hmy_getTransactionCountByHash', async () => {
for (const some of transactionInfoList) {
const transactionInfo: TransactionInfo = some;
const txnCount: any = await harmony.blockchain.getBlockTransactionCountByHash(
{
blockHash: transactionInfo.blockHash,
},
);
expect(harmony.utils.isHex(txnCount.result)).toEqual(true);
}
}); });
it('should test hmy_getTransactionCountByNumber', async () => { it('should confirm a transaction', async () => {
for (const some of transactionInfoList) { const toConfirm = await sent.confirm(txId, 20, 1000);
const transactionInfo: TransactionInfo = some; expect(toConfirm.receipt !== undefined).toEqual(true);
const txnCount: any = await harmony.blockchain.getBlockTransactionCountByNumber( expect(checkTransactionReceipt(toConfirm.receipt)).toEqual(true);
{ if (toConfirm.isConfirmed()) {
blockNumber: transactionInfo.blockNumber, expect(toConfirm.txStatus).toEqual(TxStatus.CONFIRMED);
}, } else if (toConfirm.isRejected()) {
); expect(toConfirm.txStatus).toEqual(TxStatus.REJECTED);
expect(harmony.utils.isHex(txnCount.result)).toEqual(true);
}
});
it('should test hmy_getTransactionReceipt', async () => {
const { transactions } = txnJsons;
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < txnHashesFixtures.length; i += 1) {
const txnHash = txnHashesFixtures[i];
const receipt: any = await harmony.blockchain.getTransactionReceipt({
txnHash,
});
expect(checkTransactionReceipt(receipt.result)).toEqual(true);
expect(harmony.crypto.getAddress(receipt.result.from).checksum).toEqual(
transactions[i].senderAddress,
);
expect(harmony.crypto.getAddress(receipt.result.to).checksum).toEqual(
transactions[i].receiverAddress,
);
expect(receipt.result.blockHash).toEqual(
transactionInfoList[i].blockHash,
);
expect(receipt.result.blockNumber).toEqual(
transactionInfoList[i].blockNumber,
);
expect(receipt.result.transactionIndex).toEqual(
transactionInfoList[i].index,
);
}
});
it('should test hmy_getTransactionCount', async () => {
const { transactions } = txnJsons;
for (let i = 0; i < transactionInfoList; i += 1) {
const transactionInfo: TransactionInfo = transactionInfoList[i];
const nonce: any = await harmony.blockchain.getTransactionCount({
address: transactions[i].senderAddressBech32,
blockNumber: transactionInfo.blockNumber,
});
expect(nonce.result).toEqual(transactions[i].nonce);
} }
}); });
}); });
function checkTransactionDetail(data: any) {
return harmony.utils.validateArgs(
data,
{
blockHash: [harmony.utils.isHash],
blockNumber: [harmony.utils.isHex],
from: [harmony.utils.isAddress],
gas: [harmony.utils.isHex],
gasPrice: [harmony.utils.isHex],
hash: [harmony.utils.isHash],
// tslint:disable-next-line: no-shadowed-variable
input: [(data: any) => data === '0x' || harmony.utils.isHex(data)],
nonce: [harmony.utils.isHex],
// tslint:disable-next-line: no-shadowed-variable
to: [(data: any) => data === '0x' || harmony.utils.isAddress(data)],
transactionIndex: [harmony.utils.isHex],
value: [harmony.utils.isHex],
v: [harmony.utils.isHex],
r: [harmony.utils.isHex],
s: [harmony.utils.isHex],
},
{},
);
}
function checkTransactionReceipt(data: any) { function checkTransactionReceipt(data: any) {
return harmony.utils.validateArgs( return harmony.utils.validateArgs(
data, data,
{ {
blockHash: [harmony.utils.isHash],
blockNumber: [harmony.utils.isHex], blockNumber: [harmony.utils.isHex],
contractAddress: [ contractAddress: [
// tslint:disable-next-line: no-shadowed-variable // tslint:disable-next-line: no-shadowed-variable
@ -178,6 +63,6 @@ function checkTransactionReceipt(data: any) {
transactionHash: [harmony.utils.isHash], transactionHash: [harmony.utils.isHash],
transactionIndex: [harmony.utils.isHex], transactionIndex: [harmony.utils.isHex],
}, },
{}, { blockHash: [harmony.utils.isHash] },
); );
} }

@ -0,0 +1,196 @@
import { harmony } from './harmony';
import txnJsons from '../fixtures/transactions.json';
const messenger = harmony.messenger;
interface TransactionInfo {
blockHash: string;
index: string;
blockNumber: string;
}
describe('e2e test transactions by RPC Method', () => {
const txnHashesFixtures: any = [];
const transactionInfoList: any = [];
// net_*
it('should test hmy_sendRawTransaction', async () => {
const { transactions } = txnJsons;
for (const txn of transactions) {
const sent = await messenger.send(
'hmy_sendRawTransaction',
txn.rawTransaction,
);
expect(harmony.utils.isHash(sent.result)).toEqual(true);
txnHashesFixtures.push(sent.result);
}
});
it('should test hmy_getTransactionByHash', async () => {
for (const txnHash of txnHashesFixtures) {
const txnDetail = await harmony.blockchain.getTransactionByHash({
txnHash,
});
if (txnDetail.result !== null) {
expect(checkTransactionDetail(txnDetail.result)).toEqual(true);
expect(txnDetail.result.hash).toEqual(txnHash);
const transactionInfo = {
blockHash: txnDetail.result.blockHash,
blockNumber: txnDetail.result.blockNumber,
index: txnDetail.result.transactionIndex,
};
transactionInfoList.push(transactionInfo);
}
}
});
it('should test hmy_getTransactionByBlockHashAndIndex', async () => {
for (const some of transactionInfoList) {
const transactionInfo: TransactionInfo = some;
const txnDetail: any = await harmony.blockchain.getTransactionByBlockHashAndIndex(
{
blockHash: transactionInfo.blockHash,
index: transactionInfo.index,
},
);
if (txnDetail.result !== null) {
expect(checkTransactionDetail(txnDetail.result)).toEqual(true);
expect(txnDetail.result.blockHash).toEqual(transactionInfo.blockHash);
expect(txnDetail.result.transactionIndex).toEqual(
transactionInfo.index,
);
}
}
});
it('should test hmy_getTransactionByBlockNumberAndIndex', async () => {
for (const some of transactionInfoList) {
const transactionInfo: TransactionInfo = some;
const txnDetail: any = await harmony.blockchain.getTransactionByBlockNumberAndIndex(
{
blockNumber: transactionInfo.blockNumber,
index: transactionInfo.index,
},
);
if (txnDetail.result !== null) {
expect(checkTransactionDetail(txnDetail.result)).toEqual(true);
expect(txnDetail.result.blockNumber).toEqual(
transactionInfo.blockNumber,
);
expect(txnDetail.result.transactionIndex).toEqual(
transactionInfo.index,
);
}
}
});
it('should test hmy_getTransactionCountByHash', async () => {
for (const some of transactionInfoList) {
const transactionInfo: TransactionInfo = some;
const txnCount: any = await harmony.blockchain.getBlockTransactionCountByHash(
{
blockHash: transactionInfo.blockHash,
},
);
expect(harmony.utils.isHex(txnCount.result)).toEqual(true);
}
});
it('should test hmy_getTransactionCountByNumber', async () => {
for (const some of transactionInfoList) {
const transactionInfo: TransactionInfo = some;
const txnCount: any = await harmony.blockchain.getBlockTransactionCountByNumber(
{
blockNumber: transactionInfo.blockNumber,
},
);
expect(harmony.utils.isHex(txnCount.result)).toEqual(true);
}
});
it('should test hmy_getTransactionReceipt', async () => {
const { transactions } = txnJsons;
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < txnHashesFixtures.length; i += 1) {
const txnHash = txnHashesFixtures[i];
const receipt: any = await harmony.blockchain.getTransactionReceipt({
txnHash,
});
if (receipt.result !== null) {
expect(checkTransactionReceipt(receipt.result)).toEqual(true);
expect(harmony.crypto.getAddress(receipt.result.from).checksum).toEqual(
transactions[i].senderAddress,
);
expect(harmony.crypto.getAddress(receipt.result.to).checksum).toEqual(
transactions[i].receiverAddress,
);
expect(receipt.result.blockHash).toEqual(
transactionInfoList[i].blockHash,
);
expect(receipt.result.blockNumber).toEqual(
transactionInfoList[i].blockNumber,
);
expect(receipt.result.transactionIndex).toEqual(
transactionInfoList[i].index,
);
}
}
});
it('should test hmy_getTransactionCount', async () => {
const { transactions } = txnJsons;
for (let i = 0; i < transactionInfoList; i += 1) {
const transactionInfo: TransactionInfo = transactionInfoList[i];
const nonce: any = await harmony.blockchain.getTransactionCount({
address: transactions[i].senderAddressBech32,
blockNumber: transactionInfo.blockNumber,
});
expect(nonce.result).toEqual(transactions[i].nonce);
}
});
});
function checkTransactionDetail(data: any) {
return harmony.utils.validateArgs(
data,
{
blockHash: [harmony.utils.isHash],
blockNumber: [harmony.utils.isHex],
from: [harmony.utils.isAddress],
gas: [harmony.utils.isHex],
gasPrice: [harmony.utils.isHex],
hash: [harmony.utils.isHash],
// tslint:disable-next-line: no-shadowed-variable
input: [(data: any) => data === '0x' || harmony.utils.isHex(data)],
nonce: [harmony.utils.isHex],
// tslint:disable-next-line: no-shadowed-variable
to: [(data: any) => data === '0x' || harmony.utils.isAddress(data)],
transactionIndex: [harmony.utils.isHex],
value: [harmony.utils.isHex],
v: [harmony.utils.isHex],
r: [harmony.utils.isHex],
s: [harmony.utils.isHex],
},
{},
);
}
function checkTransactionReceipt(data: any) {
return harmony.utils.validateArgs(
data,
{
blockNumber: [harmony.utils.isHex],
contractAddress: [
// tslint:disable-next-line: no-shadowed-variable
(data: any) => data === null || harmony.utils.isAddress,
],
cumulativeGasUsed: [harmony.utils.isHex],
from: [harmony.utils.isAddress],
gasUsed: [harmony.utils.isHex],
logs: [harmony.utils.isArray],
logsBloom: [harmony.utils.isHex],
root: [harmony.utils.isHash],
shardID: [harmony.utils.isNumber],
// tslint:disable-next-line: no-shadowed-variable
to: [(data: any) => data === '0x' || harmony.utils.isAddress],
transactionHash: [harmony.utils.isHash],
transactionIndex: [harmony.utils.isHex],
},
{ blockHash: [harmony.utils.isHash] },
);
}
Loading…
Cancel
Save