chore(e2e):update e2e test with transaction events

dev
neeboo 5 years ago
parent bdb233fe4f
commit d32157ffbc
  1. 33
      e2e/src/transaction.e2e.ts
  2. 2
      packages/harmony-core/src/blockchain.ts

@ -1,6 +1,8 @@
import { harmony } from './harmony'; import { harmony } from './harmony';
// tslint:disable-next-line: no-implicit-dependencies // tslint:disable-next-line: no-implicit-dependencies
import { Transaction, TxStatus } from '@harmony-js/transaction'; 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'; import demoAccounts from '../fixtures/testAccount.json';
@ -40,6 +42,37 @@ describe('test Transaction using SDK', () => {
expect(toConfirm.txStatus).toEqual(TxStatus.REJECTED); 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) { function checkTransactionReceipt(data: any) {

@ -322,7 +322,7 @@ class Blockchain extends HarmonyCore {
signed.emitter.resolve(signed); signed.emitter.resolve(signed);
}); });
}); });
return signed.emitter; return signed.observed();
} catch (err) { } catch (err) {
throw err; throw err;
} }

Loading…
Cancel
Save