Skip to content

Commit 8da9c6d

Browse files
fariedtzone117x
authored andcommitted
style: rosetta test code cleanup
- use GetStacksTestnetNetwork from debug route instead of a local copy - change test names to print out the API endpoint being tested
1 parent 0eda451 commit 8da9c6d

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

src/tests-rosetta/api.ts

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from '@blockstack/stacks-transactions';
1919
import * as BN from 'bn.js';
2020
import { getCoreNodeEndpoint, StacksCoreRpcClient } from '../core-rpc/client';
21-
import { timeout, bufferToHexPrefixString } from '../helpers';
21+
import { bufferToHexPrefixString } from '../helpers';
2222
import {
2323
RosettaConstructionDeriveRequest,
2424
RosettaConstructionDeriveResponse,
@@ -39,12 +39,6 @@ describe('Rosetta API', () => {
3939
let eventServer: Server;
4040
let api: ApiServer;
4141

42-
function getStacksTestnetNetwork() {
43-
const stacksNetwork = new StacksTestnet();
44-
stacksNetwork.coreApiUrl = `http://${getCoreNodeEndpoint()}`;
45-
return stacksNetwork;
46-
}
47-
4842
beforeAll(async () => {
4943
process.env.PG_DATABASE = 'postgres';
5044
await cycleMigrations();
@@ -340,7 +334,7 @@ describe('Rosetta API', () => {
340334
recipient: 'STRYYQQ9M8KAF4NS7WNZQYY59X93XEKR31JP64CP',
341335
amount: new BN(3852),
342336
senderKey: 'c71700b07d520a8c9731e4d0f095aa6efb91e16e25fb27ce2b72e7b698f8127a01',
343-
network: getStacksTestnetNetwork(),
337+
network: GetStacksTestnetNetwork(),
344338
memo: 'test1234',
345339
});
346340
expectedTxId = '0x' + transferTx.txid();
@@ -418,9 +412,9 @@ describe('Rosetta API', () => {
418412
});
419413
});
420414

421-
/** rosetta construction tests */
422-
/**derive api tests */
423-
test('derive api', async () => {
415+
/* rosetta construction api tests below */
416+
417+
test('construction/derive', async () => {
424418
const request: RosettaConstructionDeriveRequest = {
425419
network_identifier: {
426420
blockchain: RosettaConstants.blockchain,
@@ -485,10 +479,8 @@ describe('Rosetta API', () => {
485479

486480
expect(JSON.parse(result3.text)).toEqual(expectedResponse3);
487481
});
488-
/**end */
489482

490-
/**preprocess api tests */
491-
test('construction preprocess api success', async () => {
483+
test('construction/preprocess', async () => {
492484
const request: RosettaConstructionPreprocessRequest = {
493485
network_identifier: {
494486
blockchain: RosettaConstants.blockchain,
@@ -597,7 +589,7 @@ describe('Rosetta API', () => {
597589
expect(JSON.parse(result.text)).toEqual(expectResponse);
598590
});
599591

600-
test('construction preprocess api failure', async () => {
592+
test('construction/preprocess - failure', async () => {
601593
const request2 = {
602594
network_identifier: {
603595
blockchain: RosettaConstants.blockchain,
@@ -691,10 +683,8 @@ describe('Rosetta API', () => {
691683

692684
expect(JSON.parse(result2.text)).toEqual(expectedResponse2);
693685
});
694-
/**end */
695686

696-
/**metadata api test cases */
697-
test('metadata api', async () => {
687+
test('construction/metadata - success', async () => {
698688
const request: RosettaConstructionMetadataRequest = {
699689
network_identifier: {
700690
blockchain: 'stacks',
@@ -722,7 +712,7 @@ describe('Rosetta API', () => {
722712
expect(JSON.parse(result.text)).toHaveProperty('metadata');
723713
});
724714

725-
test('metadata api empty network identifier', async () => {
715+
test('construction/metadata - empty network identifier', async () => {
726716
const request = {
727717
options: {
728718
sender_address: 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6',
@@ -756,7 +746,7 @@ describe('Rosetta API', () => {
756746
expect(JSON.parse(result.text)).toEqual(expectResponse);
757747
});
758748

759-
test('metadata invalid transfer type', async () => {
749+
test('construction/metadata - invalid transfer type', async () => {
760750
const request: RosettaConstructionMetadataRequest = {
761751
network_identifier: {
762752
blockchain: 'stacks',
@@ -791,7 +781,7 @@ describe('Rosetta API', () => {
791781
expect(JSON.parse(result.text)).toEqual(expectResponse);
792782
});
793783

794-
test('metadata invalid sender address', async () => {
784+
test('construction/metadata - invalid sender address', async () => {
795785
const request: RosettaConstructionMetadataRequest = {
796786
network_identifier: {
797787
blockchain: 'stacks',
@@ -826,7 +816,7 @@ describe('Rosetta API', () => {
826816
expect(JSON.parse(result.text)).toEqual(expectResponse);
827817
});
828818

829-
test('metadata invalid recipient address', async () => {
819+
test('construction/metadata - invalid recipient address', async () => {
830820
const request: RosettaConstructionMetadataRequest = {
831821
network_identifier: {
832822
blockchain: 'stacks',
@@ -860,10 +850,8 @@ describe('Rosetta API', () => {
860850

861851
expect(JSON.parse(result.text)).toEqual(expectResponse);
862852
});
863-
/** end */
864853

865-
/**hash api test cases */
866-
test('construction hash api success', async () => {
854+
test('construction/hash', async () => {
867855
const request: RosettaConstructionHashRequest = {
868856
network_identifier: {
869857
blockchain: RosettaConstants.blockchain,
@@ -885,7 +873,7 @@ describe('Rosetta API', () => {
885873
expect(JSON.parse(result.text)).toEqual(expectedResponse);
886874
});
887875

888-
test('construction hash api no `0x` prefix', async () => {
876+
test('construction/hash - no `0x` prefix', async () => {
889877
const request: RosettaConstructionHashRequest = {
890878
network_identifier: {
891879
blockchain: RosettaConstants.blockchain,
@@ -903,7 +891,7 @@ describe('Rosetta API', () => {
903891
expect(JSON.parse(result.text)).toEqual(expectedResponse);
904892
});
905893

906-
test('construction hash api odd number of hex digits ', async () => {
894+
test('construction/hash - odd number of hex digits', async () => {
907895
const request: RosettaConstructionHashRequest = {
908896
network_identifier: {
909897
blockchain: RosettaConstants.blockchain,
@@ -921,7 +909,7 @@ describe('Rosetta API', () => {
921909
expect(JSON.parse(result.text)).toEqual(expectedResponse);
922910
});
923911

924-
test('construction hash api an unsigned transaction ', async () => {
912+
test('construction/hash - unsigned transaction', async () => {
925913
const request: RosettaConstructionHashRequest = {
926914
network_identifier: {
927915
blockchain: RosettaConstants.blockchain,
@@ -940,7 +928,7 @@ describe('Rosetta API', () => {
940928
expect(JSON.parse(result.text)).toEqual(expectedResponse);
941929
});
942930

943-
test('parse api signed', async () => {
931+
test('construction/parse - signed', async () => {
944932
const publicKey = publicKeyToString(
945933
getPublicKey(createStacksPrivateKey(testnetKeys[0].secretKey))
946934
);
@@ -981,7 +969,7 @@ describe('Rosetta API', () => {
981969
expect(actual.operations[2].amount?.value).toEqual(amount.toString());
982970
});
983971

984-
test('parse api unsigned', async () => {
972+
test('construction/parse - unsigned', async () => {
985973
const publicKey = publicKeyToString(
986974
getPublicKey(createStacksPrivateKey(testnetKeys[0].secretKey))
987975
);
@@ -1022,7 +1010,7 @@ describe('Rosetta API', () => {
10221010
expect(actual.operations[2].amount?.value).toEqual(amount.toString());
10231011
});
10241012

1025-
/** end */
1013+
/* rosetta construction end */
10261014

10271015
afterAll(async () => {
10281016
await new Promise(resolve => eventServer.close(() => resolve()));

0 commit comments

Comments
 (0)