|
8 | 8 | RosettaConstructionPreprocessRequest,
|
9 | 9 | RosettaConstructionPreprocessResponse,
|
10 | 10 | RosettaConstructionMetadataRequest,
|
| 11 | + RosettaConstructionHashRequest, |
| 12 | + RosettaConstructionHashResponse, |
11 | 13 | } from '@blockstack/stacks-blockchain-api-types';
|
12 | 14 |
|
13 | 15 | import { startEventServer } from '../event-stream/event-server';
|
@@ -472,6 +474,85 @@ describe('Rosetta API', () => {
|
472 | 474 | });
|
473 | 475 | /** end */
|
474 | 476 |
|
| 477 | + /**hash api test cases */ |
| 478 | + test('construction hash api success', async () => { |
| 479 | + const request: RosettaConstructionHashRequest = { |
| 480 | + network_identifier: { |
| 481 | + blockchain: RosettaConstants.blockchain, |
| 482 | + network: RosettaConstants.network, |
| 483 | + }, |
| 484 | + signed_transaction: |
| 485 | + '0x80800000000400539886f96611ba3ba6cef9618f8c78118b37c5be000000000000000000000000000000b400017a33a91515ef48608a99c6adecd2eb258e11534a1acf66348f5678c8e2c8f83d243555ed67a0019d3500df98563ca31321c1a675b43ef79f146e322fe08df75103020000000000051a1ae3f911d8f1d46d7416bfbe4b593fd41eac19cb000000000007a12000000000000000000000000000000000000000000000000000000000000000000000', |
| 486 | + }; |
| 487 | + |
| 488 | + const result = await supertest(api.server).post(`/rosetta/v1/construction/hash`).send(request); |
| 489 | + expect(result.status).toBe(200); |
| 490 | + |
| 491 | + const expectedResponse: RosettaConstructionHashResponse = { |
| 492 | + transaction_identifier: { |
| 493 | + hash: '0xf3b054a5fbae98f7f35e5e917b65759fc365a3e073f8af1c3b8d211b286fa74a', |
| 494 | + }, |
| 495 | + }; |
| 496 | + |
| 497 | + expect(JSON.parse(result.text)).toEqual(expectedResponse); |
| 498 | + }); |
| 499 | + |
| 500 | + test('construction hash api no `0x` prefix', async () => { |
| 501 | + const request: RosettaConstructionHashRequest = { |
| 502 | + network_identifier: { |
| 503 | + blockchain: RosettaConstants.blockchain, |
| 504 | + network: RosettaConstants.network, |
| 505 | + }, |
| 506 | + signed_transaction: |
| 507 | + '80800000000400d429e0b599f9cba40ecc9f219df60f9d0a02212d000000000000000100000000000000000101cc0235071690bc762d0013f6d3e4be32aa8f8d01d0db9d845595589edba47e7425bd655f20398e3d931cbe60eea59bb66f44d3f28443078fe9d10082dccef80c010200000000040000000000000000000000000000000000000000000000000000000000000000', |
| 508 | + }; |
| 509 | + |
| 510 | + const result = await supertest(api.server).post(`/rosetta/v1/construction/hash`).send(request); |
| 511 | + expect(result.status).toBe(400); |
| 512 | + |
| 513 | + const expectedResponse = RosettaErrors.invalidTransactionString; |
| 514 | + |
| 515 | + expect(JSON.parse(result.text)).toEqual(expectedResponse); |
| 516 | + }); |
| 517 | + |
| 518 | + test('construction hash api odd number of hex digits ', async () => { |
| 519 | + const request: RosettaConstructionHashRequest = { |
| 520 | + network_identifier: { |
| 521 | + blockchain: RosettaConstants.blockchain, |
| 522 | + network: RosettaConstants.network, |
| 523 | + }, |
| 524 | + signed_transaction: |
| 525 | + '80800000000400d429e0b599f9cba40ecc9f219df60f9d0a02212d000000000000000100000000000000000101cc0235071690bc762d0013f6d3e4be32aa8f8d01d0db9d845595589edba47e7425bd655f20398e3d931cbe60eea59bb66f44d3f28443078fe9d10082dccef80c01020000000004000000000000000000000000000000000000000000000000000000000000000', |
| 526 | + }; |
| 527 | + |
| 528 | + const result = await supertest(api.server).post(`/rosetta/v1/construction/hash`).send(request); |
| 529 | + expect(result.status).toBe(400); |
| 530 | + |
| 531 | + const expectedResponse = RosettaErrors.invalidTransactionString; |
| 532 | + |
| 533 | + expect(JSON.parse(result.text)).toEqual(expectedResponse); |
| 534 | + }); |
| 535 | + |
| 536 | + test('construction hash api an unsigned transaction ', async () => { |
| 537 | + const request: RosettaConstructionHashRequest = { |
| 538 | + network_identifier: { |
| 539 | + blockchain: RosettaConstants.blockchain, |
| 540 | + network: RosettaConstants.network, |
| 541 | + }, |
| 542 | + //unsigned transaction bytes |
| 543 | + signed_transaction: |
| 544 | + '0x80800000000400539886f96611ba3ba6cef9618f8c78118b37c5be000000000000000000000000000000b400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003020000000000051a1ae3f911d8f1d46d7416bfbe4b593fd41eac19cb000000000007a12000000000000000000000000000000000000000000000000000000000000000000000', |
| 545 | + }; |
| 546 | + |
| 547 | + const result = await supertest(api.server).post(`/rosetta/v1/construction/hash`).send(request); |
| 548 | + expect(result.status).toBe(400); |
| 549 | + |
| 550 | + const expectedResponse = RosettaErrors.transactionNotSigned; |
| 551 | + |
| 552 | + expect(JSON.parse(result.text)).toEqual(expectedResponse); |
| 553 | + }); |
| 554 | + /** end */ |
| 555 | + |
475 | 556 | afterAll(async () => {
|
476 | 557 | await new Promise(resolve => eventServer.close(() => resolve()));
|
477 | 558 | await api.terminate();
|
|
0 commit comments