Skip to content

Commit

Permalink
Fix v2 tests and add extra spec tests
Browse files Browse the repository at this point in the history
Signed-off-by: Nana-EC <nana.essilfie-conduah@hedera.com>
  • Loading branch information
Nana-EC committed Jan 24, 2022
1 parent b9682cc commit 488d150
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ create table if not exists contract_result
function_parameters bytea not null,
function_result bytea null,
gas_limit bigint not null,
gas_used bigint not null,
gas_used bigint null,
payer_account_id bigint not null
);
comment on table contract_result is 'Crypto contract execution results';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"description": "Contract results api call for a specific contract using contract id and timestamp with no transaction match",
"description": "Contract results api call for a specific contract using contract id and timestamp with no result match",
"setup": {
"contractresults": [
{
"amount": 30,
"bloom": [5, 5],
"call_result": [6, 6],
"consensus_timestamp": "167654000123456",
"consensus_timestamp": "167654000123457",
"contract_id": 5001,
"created_contract_ids": [7001],
"error_message": "",
Expand All @@ -20,7 +20,7 @@
"recordFiles": [],
"transactions": [
{
"consensus_timestamp": 167654000123457,
"consensus_timestamp": 167654000123456,
"payerAccountId": "5",
"transaction_hash": "519a008fabde4d",
"valid_start_timestamp": 167654000123400
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"description": "Contract results api call for a specific contract using contract id and timestamp with no transaction match",
"setup": {
"contractresults": [
{
"amount": 30,
"bloom": [5, 5],
"call_result": [6, 6],
"consensus_timestamp": "167654000123456",
"contract_id": 5001,
"created_contract_ids": [7001],
"error_message": "",
"function_parameters": [7, 7],
"function_result": [8, 8],
"gas_limit": 987654,
"gas_used": 123,
"payer_account_id": 8001
}
],
"recordFiles": [],
"transactions": []
},
"urls": [
"/api/v1/contracts/0.0.5001/results/167654.000123456",
"/api/v1/contracts/0.5001/results/167654.000123456",
"/api/v1/contracts/5001/results/167654.000123456"
],
"responseStatus": 404,
"responseJson": {
"_status": {
"messages": [
{
"message": "No correlating transaction"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"description": "Contract results api call for a specific contract using transactionId with no result match",
"setup": {
"contractresults": [
{
"amount": 30,
"consensus_timestamp": "167654000123457",
"contract_id": 5001,
"payer_account_id": 8001
}
],
"recordFiles": [
{
"index": 17,
"consensus_start": 167654000123450,
"consensus_end": 167654000123460,
"hash": "6ceecd8bb224da491"
}
],
"transactions": [
{
"consensus_timestamp": 167654000123456,
"entity_id": 5001,
"payerAccountId": "8001",
"result": 33,
"transaction_hash": "519a008fabde4d",
"valid_start_timestamp": 167654000123455
}
]
},
"url": "/api/v1/contracts/results/0.0.8001-167654-000123455",
"responseStatus": 404,
"responseJson": {
"_status": {
"messages": [
{
"message": "Not found"
}
]
}
}
}
15 changes: 10 additions & 5 deletions hedera-mirror-rest/controllers/contractController.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ const getContractResultsById = async (req, res) => {
* @returns {Promise<void>}
*/
const getContractResultsByTimestamp = async (req, res) => {
const {timestamp, contractId} = getAndValidateContractIdAndConsensusTimestampPathParams(req);
const {timestamp} = getAndValidateContractIdAndConsensusTimestampPathParams(req);

// retrieve contract result, recordFile and transaction models concurrently
const [contractResults, recordFile, transaction, contractLogs] = await Promise.all([
Expand All @@ -568,14 +568,15 @@ const getContractResultsByTimestamp = async (req, res) => {
ContractService.getContractLogsByTimestamps(timestamp),
]);
if (_.isNil(transaction)) {
throw new NotFoundError();
throw new NotFoundError('No correlating transaction');
}

const contractResult = contractResults.length === 0 ? null : contractResults[0];
if (_.isNil(contractResult.callResult)) {
// set contractId as it would be missing in empty contractResult case
transaction.entityId = contractId;
if (_.isNil(contractResult)) {
throw new NotFoundError();
}

if (_.isNil(contractResult.callResult)) {
// set 206 partial response
res.locals.statusCode = httpStatusCodes.PARTIAL_CONTENT.code;
logger.debug(`getContractResultsByTimestamp returning partial content`);
Expand Down Expand Up @@ -643,6 +644,10 @@ const getContractResultsByTransactionId = async (req, res) => {
]);

const contractResult = contractResults.length === 0 ? null : contractResults[0];
if (_.isNil(contractResult)) {
throw new NotFoundError();
}

res.locals[constants.responseDataLabel] = new ContractResultDetailsViewModel(
contractResult,
recordFile,
Expand Down

0 comments on commit 488d150

Please sign in to comment.