-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit test for fee bump pipeline (#113)
- Loading branch information
1 parent
ec59df0
commit d8924db
Showing
4 changed files
with
122 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/stellar-plus/core/pipelines/build-transaction/index.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/stellar-plus/core/pipelines/fee-bump/index.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { FeeBumpTransaction, Transaction, TransactionBuilder } from '@stellar/stellar-sdk' | ||
|
||
import { | ||
FeeBumpPipelineInput as FBInput, | ||
FeeBumpPipelineOutput as FBOutput, | ||
} from 'stellar-plus/core/pipelines/fee-bump/types' | ||
|
||
import { FeeBumpPipeline } from '.' | ||
|
||
jest.mock('@stellar/stellar-sdk', () => ({ | ||
Horizon: { | ||
Server: jest.fn(), | ||
}, | ||
Transaction: jest.fn(() => { | ||
return { | ||
networkPassphrase: 'networkPassphrase', | ||
toXDR: jest.fn(() => { | ||
return 'toXDR' | ||
}), | ||
} | ||
}), | ||
TransactionBuilder: { | ||
fromXDR: jest.fn(() => { | ||
return {} | ||
}), | ||
buildFeeBumpTransaction: jest.fn(() => { | ||
return {} | ||
}), | ||
}, | ||
})) | ||
|
||
const MOCKED_BUMP_FEE = '101' | ||
|
||
const MOCKED_TRANSACTION = { | ||
networkPassphrase: 'networkPassphrase', | ||
toXDR: jest.fn(() => 'toXDR'), | ||
} as unknown as Transaction | ||
const MOCKED_FEE_BUMPED_TRANSACTION: FeeBumpTransaction = {} as FeeBumpTransaction | ||
const MOCKED_BT_INPUT: FBInput = { | ||
innerTransaction: MOCKED_TRANSACTION, | ||
feeBumpHeader: { | ||
header: { | ||
source: 'source', | ||
fee: MOCKED_BUMP_FEE, | ||
timeout: 2, | ||
}, | ||
signers: [], | ||
}, | ||
} | ||
const MOCKED_BT_OUTPUT: FBOutput = MOCKED_FEE_BUMPED_TRANSACTION | ||
|
||
describe('FeeBumpPipeline', () => { | ||
let feeBumpPipeline: FeeBumpPipeline | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
describe('Wrap Transaction', () => { | ||
beforeEach(() => { | ||
feeBumpPipeline = new FeeBumpPipeline() | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('should wrap transaction successfully', async () => { | ||
await expect(feeBumpPipeline.execute(MOCKED_BT_INPUT)).resolves.toEqual(MOCKED_BT_OUTPUT) | ||
expect(TransactionBuilder.fromXDR).toHaveBeenCalledTimes(1) | ||
expect(TransactionBuilder.buildFeeBumpTransaction).toHaveBeenCalledTimes(1) | ||
expect(TransactionBuilder.buildFeeBumpTransaction).toHaveBeenCalledWith( | ||
MOCKED_BT_INPUT.feeBumpHeader.header.source, | ||
MOCKED_BT_INPUT.feeBumpHeader.header.fee, | ||
{}, | ||
'networkPassphrase' | ||
) | ||
}) | ||
|
||
it('should throw error', async () => { | ||
const mockedInput = { | ||
...MOCKED_BT_INPUT, | ||
feeBumpHeader: { | ||
...MOCKED_BT_INPUT.feeBumpHeader, | ||
header: { | ||
...MOCKED_BT_INPUT.feeBumpHeader.header, | ||
fee: '0', | ||
}, | ||
}, | ||
} | ||
;(TransactionBuilder.buildFeeBumpTransaction as unknown as jest.Mock).mockImplementationOnce(() => { | ||
throw new Error('Error building fee bump transaction!') | ||
}) | ||
|
||
await expect(feeBumpPipeline.execute(mockedInput)).rejects.toThrow('Unexpected error!') | ||
expect(TransactionBuilder.fromXDR).toHaveBeenCalledTimes(1) | ||
expect(TransactionBuilder.buildFeeBumpTransaction).toHaveBeenCalledTimes(1) | ||
expect(TransactionBuilder.buildFeeBumpTransaction).toHaveBeenCalledWith( | ||
MOCKED_BT_INPUT.feeBumpHeader.header.source, | ||
'0', | ||
{}, | ||
'networkPassphrase' | ||
) | ||
}) | ||
}) | ||
}) |