diff --git a/e2e/src/transaction.e2e.ts b/e2e/src/transaction.e2e.ts index 1a17ce5..edb411c 100644 --- a/e2e/src/transaction.e2e.ts +++ b/e2e/src/transaction.e2e.ts @@ -1,6 +1,8 @@ import { harmony } from './harmony'; // tslint:disable-next-line: no-implicit-dependencies import { Transaction, TxStatus } from '@harmony-js/transaction'; +// tslint:disable-next-line: no-implicit-dependencies +import { isHash } from '@harmony-js/utils'; import demoAccounts from '../fixtures/testAccount.json'; @@ -40,6 +42,37 @@ describe('test Transaction using SDK', () => { expect(toConfirm.txStatus).toEqual(TxStatus.REJECTED); } }); + it('should test transaction observed events', async () => { + const txnObject = { + to: harmony.crypto.getAddress(receiver.Address).bech32, + value: new harmony.utils.Unit('100').asGwei().toWei(), + gasLimit: new harmony.utils.Unit('210000').asWei().toWei(), + gasPrice: new harmony.utils.Unit('100').asGwei().toWei(), + }; + + const txn = harmony.transactions.newTx(txnObject); + txn + .observed() + .on('transactionHash', (transactionHash) => { + expect(isHash(transactionHash)).toEqual(true); + }) + .on('receipt', (receipt) => { + expect(checkTransactionReceipt(receipt)).toEqual(true); + }) + .on('confirmation', (confirmation) => { + expect( + confirmation === TxStatus.REJECTED || + confirmation === TxStatus.CONFIRMED, + ).toBe(true); + }) + .on('error', (error) => { + expect(error).toBeTruthy(); + }); + const txnSigned = await harmony.wallet.signTransaction(txn); + const [txnSent, id] = await txnSigned.sendTransaction(); + expect(txnSent.txStatus).toEqual(TxStatus.PENDING); + await txnSigned.confirm(id); + }); }); function checkTransactionReceipt(data: any) { diff --git a/packages/harmony-core/src/blockchain.ts b/packages/harmony-core/src/blockchain.ts index b249382..30f6aeb 100644 --- a/packages/harmony-core/src/blockchain.ts +++ b/packages/harmony-core/src/blockchain.ts @@ -322,7 +322,7 @@ class Blockchain extends HarmonyCore { signed.emitter.resolve(signed); }); }); - return signed.emitter; + return signed.observed(); } catch (err) { throw err; }