This repository has been archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle errors in
getTransaction
endpoints
Co-authored-by: Konstantin Shuplenkov <konstantin.shuplenkov@dash.org> Co-authored-by: Ivan Shumkov <ivan@shumkov.ru>
- Loading branch information
1 parent
434d91b
commit e0d36ae
Showing
4 changed files
with
88 additions
and
5 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
74 changes: 74 additions & 0 deletions
74
test/functional/grpcServer/handlers/core/getTransactionHandlerFactory.js
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,74 @@ | ||
const startDapi = require('@dashevo/dp-services-ctl/lib/services/startDapi'); | ||
|
||
const { | ||
Transaction, | ||
PrivateKey, | ||
} = require('@dashevo/dashcore-lib'); | ||
|
||
describe('getTransactionHandlerFactor', function main() { | ||
this.timeout(260000); | ||
|
||
let removeDapi; | ||
let dapiClient; | ||
let transaction; | ||
let transactionId; | ||
|
||
beforeEach(async () => { | ||
const { | ||
dapiCore, | ||
dashCore, | ||
remove, | ||
} = await startDapi(); | ||
|
||
removeDapi = remove; | ||
|
||
dapiClient = dapiCore.getApi(); | ||
|
||
const coreAPI = dashCore.getApi(); | ||
|
||
await coreAPI.generate(1000); | ||
|
||
const { result: fromAddress } = await coreAPI.getNewAddress(); | ||
const { result: privateKeyString } = await coreAPI.dumpPrivKey(fromAddress); | ||
const { result: toAddress } = await coreAPI.getNewAddress(); | ||
|
||
const privateKey = new PrivateKey(privateKeyString); | ||
await coreAPI.generate(500); | ||
await coreAPI.sendToAddress(fromAddress, 10); | ||
await coreAPI.generate(10); | ||
|
||
const { items: unspent } = await dapiClient.getUTXO(fromAddress); | ||
|
||
const amount = 10000; | ||
|
||
transaction = new Transaction(); | ||
|
||
transaction.from(unspent) | ||
.to(toAddress, amount) | ||
.change(fromAddress) | ||
.fee(668) | ||
.sign(privateKey); | ||
|
||
({ result: transactionId } = await coreAPI.sendRawTransaction(transaction.serialize())); | ||
}); | ||
|
||
afterEach(async () => { | ||
await removeDapi(); | ||
}); | ||
|
||
it('should respond with a transaction by it\'s ID', async () => { | ||
const result = await dapiClient.getTransaction(transactionId); | ||
const receivedTx = new Transaction(Buffer.from(result)); | ||
expect(receivedTx.toString('hex')).to.deep.equal(transaction.serialize()); | ||
}); | ||
|
||
it('should respond with an invalid argument error if no transaction were found', async () => { | ||
const nonExistentId = Buffer.alloc(32).toString('hex'); | ||
try { | ||
await dapiClient.getTransaction(nonExistentId); | ||
expect.fail('Error was not thrown'); | ||
} catch (e) { | ||
expect(e.message).to.equal('3 INVALID_ARGUMENT: Invalid argument: Transaction not found'); | ||
} | ||
}); | ||
}); |