Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reducing cache-control for scheduled transactions. #9327

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b25938d
Reducing cache-control for scheduled transactions.
mgoelswirlds Sep 11, 2024
8700740
Missed files.
mgoelswirlds Sep 11, 2024
26aecf7
Merge remote-tracking branch 'origin/main' into 9174-reduce-cache-sch…
mgoelswirlds Sep 11, 2024
5f4fb3b
Merge remote-tracking branch 'origin/main' into 9174-reduce-cache-sch…
mgoelswirlds Sep 11, 2024
81d263e
Fixing middleware test.
mgoelswirlds Sep 11, 2024
7c388a9
Addressing PR comments.
mgoelswirlds Sep 12, 2024
2e0840e
Adding corner cases and tests.
mgoelswirlds Sep 14, 2024
7aece37
Merge remote-tracking branch 'origin/main' into 9174-reduce-cache-sch…
mgoelswirlds Sep 16, 2024
4e737c4
Addressing PR comments.
mgoelswirlds Sep 16, 2024
26d48ec
Addressing PR comments.
mgoelswirlds Sep 17, 2024
b97bbe7
Addressing PR comments.
mgoelswirlds Sep 17, 2024
03e720a
Addressing PR comments.
mgoelswirlds Sep 17, 2024
d2d727a
Changing network supply to use response headers.
mgoelswirlds Sep 17, 2024
1a60a79
fix test
mgoelswirlds Sep 17, 2024
6736a2c
fix test
mgoelswirlds Sep 17, 2024
72470f2
Addressing PR comments.
mgoelswirlds Sep 17, 2024
e7b1761
Modifying tests to match the object format.
mgoelswirlds Sep 18, 2024
08ebb62
Merge remote-tracking branch 'origin/main' into 9174-reduce-cache-sch…
mgoelswirlds Sep 18, 2024
faa145e
Addressing PR comments.
mgoelswirlds Sep 19, 2024
840f1fb
Addressing PR comments.
mgoelswirlds Sep 19, 2024
e0661c6
Adding missing test coverage.
mgoelswirlds Sep 19, 2024
1e11fc0
Adding missing test coverage.
mgoelswirlds Sep 20, 2024
4507742
Adding spec tests for shorter max age.
mgoelswirlds Sep 20, 2024
45ab8c3
Moving content type to constants.
mgoelswirlds Sep 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hedera-mirror-rest/__tests__/integration/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ const getResponseHeadersFromFileOrDefault = (specPath) => {

const getResponseHeaders = (spec, specPath) => {
spec.responseHeaders = {
...(spec.responseHeaders ?? {}),
...getResponseHeadersFromFileOrDefault(specPath),
...(spec.responseHeaders ?? {}),
};
};

Expand Down
15 changes: 6 additions & 9 deletions hedera-mirror-rest/__tests__/middleware/responseHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,16 @@ describe('Response middleware', () => {
await responseHandler(mockRequest, mockResponse, null);
expect(mockResponse.send).toBeCalledWith(JSONStringify(responseData));
expect(mockResponse.set).toHaveBeenNthCalledWith(1, headers.default);
expect(mockResponse.set).toHaveBeenNthCalledWith(2, headers.path[mockRequest.route.path]);
expect(mockResponse.set).toHaveBeenNthCalledWith(3, 'Content-Type', 'application/json; charset=utf-8');
expect(mockResponse.set).toHaveBeenNthCalledWith(2, 'Content-Type', 'application/json; charset=utf-8');
expect(mockResponse.status).toBeCalledWith(mockResponse.locals.statusCode);
});

test('Default headers', async () => {
mockRequest.route.path = '/api/v1/accounts';
await responseHandler(mockRequest, mockResponse, null);
expect(mockResponse.send).toBeCalledWith(JSONStringify(responseData));
expect(mockResponse.set).toHaveBeenNthCalledWith(1, headers.default);
expect(mockResponse.set).toHaveBeenNthCalledWith(2, headers.path[mockRequest.route.path]);
expect(mockResponse.set).toHaveBeenNthCalledWith(3, 'Content-Type', 'application/json; charset=utf-8');
expect(mockResponse.set).toHaveBeenNthCalledWith(1, headers.path[mockRequest.route.path]);
expect(mockResponse.set).toHaveBeenNthCalledWith(2, 'Content-Type', 'application/json; charset=utf-8');
expect(mockResponse.status).toBeCalledWith(mockResponse.locals.statusCode);
});

Expand All @@ -80,8 +78,7 @@ describe('Response middleware', () => {
await responseHandler(mockRequest, mockResponse, null);
expect(mockResponse.send).toBeCalledWith(mockResponse.locals.responseData);
expect(mockResponse.set).toHaveBeenNthCalledWith(1, headers.default);
expect(mockResponse.set).toHaveBeenNthCalledWith(2, headers.path[mockRequest.route.path]);
expect(mockResponse.set).toHaveBeenNthCalledWith(3, 'Content-Type', mockResponse.locals.responseContentType);
expect(mockResponse.set).toHaveBeenNthCalledWith(2, 'Content-Type', mockResponse.locals.responseContentType);
expect(mockResponse.status).toBeCalledWith(mockResponse.locals.statusCode);
});

Expand All @@ -90,11 +87,11 @@ describe('Response middleware', () => {
mockResponse.locals.responseData.links.next = MOCK_URL;
const assertNextValue = `<${MOCK_URL}>; rel=\"next\"`;
await responseHandler(mockRequest, mockResponse, null);
expect(mockResponse.set).toHaveBeenNthCalledWith(4, 'Link', assertNextValue);
expect(mockResponse.set).toHaveBeenNthCalledWith(3, 'Link', assertNextValue);
});

test('should NOT set the Link next header and confirm it exists', async () => {
await responseHandler(mockRequest, mockResponse, null);
expect(mockResponse.set).toHaveBeenCalledTimes(3);
expect(mockResponse.set).toHaveBeenCalledTimes(2);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
{
"description": "Transaction api calls for a specific transaction using transaction id with scheduled transaction but scheduled flag is not provided",
"setup": {
"accounts": [
{
"num": 3
},
{
"num": 9
},
{
"num": 10
},
{
"num": 98
}
],
"balances": [],
"transactions": [
{
"charged_tx_fee": 7,
"payerAccountId": "0.0.10",
"nodeAccountId": "0.0.3",
"consensus_timestamp": "1234567890000000002",
"valid_start_timestamp": "1234567890000000001",
"name": "SCHEDULECREATE",
"result": 11,
"type": 42,
"transfers": [
{
"account": "0.0.9",
"amount": 10
},
{
"account": "0.0.98",
"amount": 1,
"is_approval": true
}
],
"entity_id": "0.0.1000"
},
{
"charged_tx_fee": 7,
"payerAccountId": "0.0.10",
"nodeAccountId": "0.0.3",
"consensus_timestamp": "1234567890000000004",
"valid_start_timestamp": "1234567890000000001",
"name": "SCHEDULECREATE",
"result": 11,
"type": 42,
"transfers": [
{
"account": "0.0.9",
"amount": 10
},
{
"account": "0.0.98",
"amount": 1,
"is_approval": true
}
],
"entity_id": "0.0.1000"
}
],
"cryptotransfers": [
{
"consensus_timestamp": "1234567890000000003",
"valid_start_timestamp": "1234567890000000001",
"payerAccountId": "0.0.10",
"recipientAccountId": "0.0.9",
"amount": 10,
"nodeAccountId": "0.0.3",
"treasuryAccountId": "0.0.98",
"scheduled": false
}
]
},
"url": "/api/v1/transactions/0.0.10-1234567890-000000001",
"responseStatus": 200,
"responseJson": {
"transactions": [
{
"bytes": "Ynl0ZXM=",
"consensus_timestamp": "1234567890.000000002",
"entity_id": "0.0.1000",
"charged_tx_fee": 7,
"max_fee": "33",
"memo_base64": null,
"name": "SCHEDULECREATE",
"nft_transfers": [],
"node": "0.0.3",
"nonce": 0,
"parent_consensus_timestamp": null,
"result": "DUPLICATE_TRANSACTION",
"scheduled": false,
"staking_reward_transfers": [],
"token_transfers": [],
"transaction_hash": "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8w",
"transaction_id": "0.0.10-1234567890-000000001",
"transfers": [
{
"account": "0.0.9",
"amount": 10,
"is_approval": false
},
{
"account": "0.0.98",
"amount": 1,
"is_approval": true
}
],
"valid_duration_seconds": "11",
"valid_start_timestamp": "1234567890.000000001"
},
{
"bytes": "Ynl0ZXM=",
"charged_tx_fee": 7,
"consensus_timestamp": "1234567890.000000003",
"entity_id": null,
"max_fee": "33",
"memo_base64": null,
"name": "CRYPTOTRANSFER",
"nft_transfers": [],
"node": "0.0.3",
"nonce": 0,
"parent_consensus_timestamp": null,
"result": "SUCCESS",
"scheduled": false,
"staking_reward_transfers": [],
"token_transfers": [],
"transaction_hash": "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8w",
"transaction_id": "0.0.10-1234567890-000000001",
"transfers": [
{
"account": "0.0.9",
"amount": 10,
"is_approval": false
},
{
"account": "0.0.10",
"amount": -11,
"is_approval": false
},
{
"account": "0.0.98",
"amount": 1,
"is_approval": false
}
],
"valid_duration_seconds": "11",
"valid_start_timestamp": "1234567890.000000001"
},
{
"bytes": "Ynl0ZXM=",
"consensus_timestamp": "1234567890.000000004",
"entity_id": "0.0.1000",
"charged_tx_fee": 7,
"max_fee": "33",
"memo_base64": null,
"name": "SCHEDULECREATE",
"nft_transfers": [],
"node": "0.0.3",
"nonce": 0,
"parent_consensus_timestamp": null,
"result": "DUPLICATE_TRANSACTION",
"scheduled": false,
"staking_reward_transfers": [],
"token_transfers": [],
"transaction_hash": "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8w",
"transaction_id": "0.0.10-1234567890-000000001",
"transfers": [
{
"account": "0.0.9",
"amount": 10,
"is_approval": false
},
{
"account": "0.0.98",
"amount": 1,
"is_approval": true
}
],
"valid_duration_seconds": "11",
"valid_start_timestamp": "1234567890.000000001"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"description": "Transaction api calls for a specific transaction using transaction id but scheduled flag is not provided",
"setup": {
"accounts": [
{
"num": 3
},
{
"num": 9
},
{
"num": 10
},
{
"num": 98
}
],
"balances": [],
"transactions": [
{
"charged_tx_fee": 7,
"payerAccountId": "0.0.10",
"nodeAccountId": "0.0.3",
"consensus_timestamp": "1896279200000000002",
"valid_start_timestamp": "1896279200000000001",
"name": "SCHEDULECREATE",
"type": 42,
"transfers": [
{
"account": "0.0.9",
"amount": 10
},
{
"account": "0.0.98",
"amount": 1,
"is_approval": true
}
],
"entity_id": "0.0.1000"
}
],
"cryptotransfers": [
{
"consensus_timestamp": "1896279200000000003",
"valid_start_timestamp": "1896279200000000001",
xin-hedera marked this conversation as resolved.
Show resolved Hide resolved
"payerAccountId": "0.0.10",
"recipientAccountId": "0.0.9",
"amount": 10,
"nodeAccountId": "0.0.3",
"treasuryAccountId": "0.0.98",
"scheduled": false
}
]
},
"url": "/api/v1/transactions/0.0.10-1896279200-000000001",
"responseStatus": 200,
"responseHeaders": {
"cache-control": "public, max-age=5"
},
"responseJson": {
"transactions": [
{
"bytes": "Ynl0ZXM=",
"consensus_timestamp": "1896279200.000000002",
"entity_id": "0.0.1000",
"charged_tx_fee": 7,
"max_fee": "33",
"memo_base64": null,
"name": "SCHEDULECREATE",
"nft_transfers": [],
"node": "0.0.3",
"nonce": 0,
"parent_consensus_timestamp": null,
"result": "SUCCESS",
"scheduled": false,
"staking_reward_transfers": [],
"token_transfers": [],
"transaction_hash": "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8w",
"transaction_id": "0.0.10-1896279200-000000001",
"transfers": [
{
"account": "0.0.9",
"amount": 10,
"is_approval": false
},
{
"account": "0.0.98",
"amount": 1,
"is_approval": true
}
],
"valid_duration_seconds": "11",
"valid_start_timestamp": "1896279200.000000001"
},
{
"bytes": "Ynl0ZXM=",
"charged_tx_fee": 7,
"consensus_timestamp": "1896279200.000000003",
"entity_id": null,
"max_fee": "33",
"memo_base64": null,
"name": "CRYPTOTRANSFER",
"nft_transfers": [],
"node": "0.0.3",
"nonce": 0,
"parent_consensus_timestamp": null,
"result": "SUCCESS",
"scheduled": false,
"staking_reward_transfers": [],
"token_transfers": [],
"transaction_hash": "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8w",
"transaction_id": "0.0.10-1896279200-000000001",
"transfers": [
{
"account": "0.0.9",
"amount": 10,
"is_approval": false
},
{
"account": "0.0.10",
"amount": -11,
"is_approval": false
},
{
"account": "0.0.98",
"amount": 1,
"is_approval": false
}
],
"valid_duration_seconds": "11",
"valid_start_timestamp": "1896279200.000000001"
}
]
}
}
Loading