Skip to content

Commit

Permalink
refactor!: return empty array instead of throwing UnsignedTxError
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Feb 16, 2022
1 parent da83bcc commit c6bacdf
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 26 deletions.
1 change: 0 additions & 1 deletion docs/guides/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ BaseError
│ │ TagNotFoundError
│ │ TxNotInChainError
│ │ UnknownTxError
│ │ UnsignedTxError
│ │ UnsupportedABIversionError
│ │ UnsupportedVMversionError
Expand Down
9 changes: 1 addition & 8 deletions src/tx/tx-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ import { buildTx, calculateFee, unpackTx } from './builder'
import { TX_TYPE } from './builder/schema'
import { encode } from './builder/helpers'
import { isHex } from '../utils/string'
import {
InvalidTxError,
TypeError,
UnknownTxError,
InvalidSignatureError,
UnsignedTxError
} from '../utils/errors'
import { InvalidTxError, TypeError, UnknownTxError, InvalidSignatureError } from '../utils/errors'

/**
* Build transaction from object
Expand Down Expand Up @@ -152,7 +146,6 @@ export const TxObject = stampit({
* @return {Array} Array of signatures
*/
getSignatures () {
if (!this.isSigned) throw new UnsignedTxError()
return this.signatures
},
/**
Expand Down
9 changes: 1 addition & 8 deletions src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ export class IllegalBidFeeError extends TransactionError {
export class InvalidSignatureError extends TransactionError {
constructor (message: string) {
super(message)
this.name = 'UnsignedTxError'
this.name = 'InvalidSignatureError'
}
}

Expand Down Expand Up @@ -639,13 +639,6 @@ export class UnknownTxError extends TransactionError {
}
}

export class UnsignedTxError extends TransactionError {
constructor () {
super('Signature not found, transaction is not signed')
this.name = 'UnsignedTxError'
}
}

export class UnsupportedABIversionError extends TransactionError {
constructor (message: string) {
super(message)
Expand Down
11 changes: 2 additions & 9 deletions test/unit/tx-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ import { TX_TYPE } from '../../src/tx/builder/schema'
import { generateKeyPair } from '../../src/utils/crypto'
import MemoryAccount from '../../src/account/memory'
import {
InvalidSignatureError,
InvalidTxError,
TypeError,
UnknownTxError,
UnsignedTxError
InvalidSignatureError, InvalidTxError, TypeError, UnknownTxError
} from '../../src/utils/errors'

describe('TxObject', () => {
Expand Down Expand Up @@ -87,10 +83,7 @@ describe('TxObject', () => {
tx.isSigned.should.be.equal(true)
})

it('Get signature on unsigned tx', () => {
expect(() => txObject.getSignatures())
.to.throw(UnsignedTxError, 'Signature not found, transaction is not signed')
})
it('Get signature on unsigned tx', () => expect(txObject.getSignatures()).to.eql([]))

it('Invalid props', () => {
expect(() => txObject.setProp(true)).to.throw(TypeError, 'Props should be an object')
Expand Down

0 comments on commit c6bacdf

Please sign in to comment.