Skip to content

Commit 675ceee

Browse files
authored
Example and test for contract call in /rosetta/v1/construction/preprocess (#1093)
* docs: added example for contract call * style: updated doc styles
1 parent 6fe829c commit 675ceee

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"options": {
3+
"sender_address": "STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6",
4+
"type": "stack_stx",
5+
"number_of_cycles": 5,
6+
"amount": "5000",
7+
"symbol": "STX",
8+
"decimals": 6,
9+
"pox_addr": "1Xik14zRm29UsyS6DjhYg4iZeZqsDa8D3",
10+
"suggested_fee_multiplier": 1,
11+
"max_fee": "12380898",
12+
"size": 260,
13+
"memo": "SAMPLE MEMO"
14+
},
15+
"required_public_keys": [
16+
{
17+
"address": "STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6"
18+
}
19+
]
20+
}

docs/openapi.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -2202,6 +2202,9 @@ paths:
22022202
application/json:
22032203
schema:
22042204
$ref: ./api/rosetta/rosetta-construction-preprocess-response.schema.json
2205+
example:
2206+
$ref: ./api/rosetta/rosetta-construction-preprocess-response.example.json
2207+
22052208
400:
22062209
description: Error
22072210
content:

src/tests-rosetta/api.ts

+78-1
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,84 @@ describe('Rosetta API', () => {
10001000
expect(JSON.parse(result3.text)).toEqual(expectedResponse3);
10011001
});
10021002

1003-
test('construction/preprocess', async () => {
1003+
test('construction/preprocess - Stack STX', async () => {
1004+
const sender = testnetKeys[0].stacksAddress;
1005+
const stacking_amount = 5000;
1006+
const number_of_cycles = 5;
1007+
1008+
const request: RosettaConstructionPayloadsRequest = {
1009+
network_identifier: {
1010+
blockchain: RosettaConstants.blockchain,
1011+
network: getRosettaNetworkName(ChainID.Testnet),
1012+
},
1013+
operations: [
1014+
{
1015+
operation_identifier: {
1016+
index: 1,
1017+
network_index: 0,
1018+
},
1019+
related_operations: [],
1020+
type: 'stack_stx',
1021+
account: {
1022+
address: sender,
1023+
metadata: {},
1024+
},
1025+
amount: {
1026+
value: '-' + stacking_amount,
1027+
currency: {
1028+
symbol: 'STX',
1029+
decimals: 6,
1030+
},
1031+
},
1032+
metadata: {
1033+
number_of_cycles: number_of_cycles,
1034+
pox_addr : '1Xik14zRm29UsyS6DjhYg4iZeZqsDa8D3',
1035+
}
1036+
},
1037+
],
1038+
metadata: {
1039+
memo: 'SAMPLE MEMO',
1040+
},
1041+
max_fee: [
1042+
{
1043+
value: '12380898',
1044+
currency: {
1045+
symbol: 'STX',
1046+
decimals: 6,
1047+
},
1048+
metadata: {},
1049+
},
1050+
],
1051+
suggested_fee_multiplier: 1,
1052+
};
1053+
1054+
const result = await supertest(api.server)
1055+
.post(`/rosetta/v1/construction/preprocess`)
1056+
.send(request);
1057+
1058+
expect(result.status).toBe(200);
1059+
expect(result.type).toBe('application/json');
1060+
1061+
const expectResponse: RosettaConstructionPreprocessResponse = {
1062+
options: {
1063+
sender_address: 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6',
1064+
type: 'stack_stx',
1065+
number_of_cycles: 5,
1066+
amount: '5000',
1067+
symbol: 'STX',
1068+
decimals: 6,
1069+
pox_addr: '1Xik14zRm29UsyS6DjhYg4iZeZqsDa8D3',
1070+
suggested_fee_multiplier: 1,
1071+
max_fee: '12380898',
1072+
size: 260,
1073+
memo: 'SAMPLE MEMO'
1074+
},
1075+
required_public_keys: [ { address: 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6' } ]
1076+
}
1077+
expect(JSON.parse(result.text)).toEqual(expectResponse);
1078+
});
1079+
1080+
test('construction/preprocess - token transfer', async () => {
10041081
const request: RosettaConstructionPreprocessRequest = {
10051082
network_identifier: {
10061083
blockchain: RosettaConstants.blockchain,

0 commit comments

Comments
 (0)