Skip to content

Commit

Permalink
feat: use proper transaction status
Browse files Browse the repository at this point in the history
  • Loading branch information
monitz87 committed Apr 8, 2020
1 parent 25df5e0 commit d567b92
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
7 changes: 3 additions & 4 deletions src/base/PolymeshTransaction.ts
Expand Up @@ -215,21 +215,20 @@ export class PolymeshTransaction<Args extends unknown[], Values extends unknown[

if (receipt.isCompleted) {
/*
* isCompleted === isFinalized || isError, which means
* isCompleted === isInBlock || isError, which means
* no further updates, so we unsubscribe
*
* TODO @monitz87: change logic to use isInBlock when mesh starts using the latest substrate
*/
gettingUnsub.then(unsub => {
unsub();
});

if (receipt.isFinalized) {
if (receipt.isInBlock) {
// tx included in a block and finalized
// TODO @monitz87: replace with event object when it is auto-generated by the polkadot fork
const failed = receipt.findRecord('system', 'ExtrinsicFailed');

this.blockHash = status.asFinalized.toString();
this.blockHash = status.asInBlock.toString();

if (failed) {
// get revert message from event
Expand Down
2 changes: 1 addition & 1 deletion src/base/__tests__/PolymeshTransaction.ts
Expand Up @@ -108,7 +108,7 @@ describe('Polymesh Transaction class', () => {

expect(transaction.status).toBe(TransactionStatus.Running);

polkadotMockUtils.updateTxStatus(tx, polkadotMockUtils.MockTxStatus.InBlock);
polkadotMockUtils.updateTxStatus(tx, polkadotMockUtils.MockTxStatus.Intermediate);

await delay(0);

Expand Down
16 changes: 8 additions & 8 deletions src/testUtils/mocks/polkadot.ts
Expand Up @@ -130,7 +130,7 @@ export enum MockTxStatus {
Failed = 'Failed',
Aborted = 'Aborted',
Rejected = 'Rejected',
InBlock = 'InBlock',
Intermediate = 'Intermediate',
}

export enum TxFailReason {
Expand All @@ -153,16 +153,16 @@ const defaultReceipt: ISubmittableResult = {
toHuman: () => ({}),
};

const inBlockReceipt: ISubmittableResult = merge({}, defaultReceipt, {
status: { isReady: false, isInBlock: false, asInBlock: 'blockHash' },
const intermediateReceipt: ISubmittableResult = merge({}, defaultReceipt, {
status: { isReady: false, isInBlock: false },
isCompleted: true,
isInBlock: true,
isInBlock: false,
});

const successReceipt: ISubmittableResult = merge({}, defaultReceipt, {
status: { isReady: false, isFinalized: true, asFinalized: 'blockHash' },
status: { isReady: false, isInBlock: true, asInBlock: 'blockHash' },
isCompleted: true,
isFinalized: true,
isInBlock: true,
});

/**
Expand Down Expand Up @@ -230,8 +230,8 @@ const statusToReceipt = (status: MockTxStatus, failReason?: TxFailReason): ISubm
if (status === MockTxStatus.Ready) {
return defaultReceipt;
}
if (status === MockTxStatus.InBlock) {
return inBlockReceipt;
if (status === MockTxStatus.Intermediate) {
return intermediateReceipt;
}

throw new Error(`There is no receipt associated with status ${status}`);
Expand Down

0 comments on commit d567b92

Please sign in to comment.