diff --git a/src/client/v2/algod/simulateTransaction.ts b/src/client/v2/algod/simulateTransaction.ts index 0d7a0ace7..1bfcd49c7 100644 --- a/src/client/v2/algod/simulateTransaction.ts +++ b/src/client/v2/algod/simulateTransaction.ts @@ -59,16 +59,16 @@ export default class SimulateRawTransactions extends JSONRequest< const res = await this.c.post( this.path(), Buffer.from(this.txnBytesToPost), - txHeaders + txHeaders, + this.query, + false ); - return res.body; + return this.prepare(res.body); } // eslint-disable-next-line class-methods-use-this - prepare(body: Uint8Array) { - if (body && body.byteLength > 0) { - return encoding.decode(body) as SimulateResponse; - } - return undefined; + prepare(body: Uint8Array): SimulateResponse { + const decoded = encoding.decode(body); + return SimulateResponse.from_obj_for_encoding(decoded); } } diff --git a/src/composer.ts b/src/composer.ts index a938d7639..99dd2b590 100644 --- a/src/composer.ts +++ b/src/composer.ts @@ -635,9 +635,7 @@ export class AtomicTransactionComposer { for (const [txnIndex, method] of this.methodCalls) { const txID = this.txIDs[txnIndex]; const pendingInfo = - simulateResponse['txn-groups'][0]['txn-results'][txnIndex][ - 'txn-result' - ]; + simulateResponse.txnGroups[0].txnResults[txnIndex].txnResult; const methodResult: ABIResult = { txID, @@ -649,7 +647,7 @@ export class AtomicTransactionComposer { AtomicTransactionComposer.parseMethodResponse( method, methodResult, - pendingInfo + pendingInfo.get_obj_for_encoding() ) ); } @@ -710,24 +708,29 @@ export class AtomicTransactionComposer { for (const [txnIndex, method] of this.methodCalls) { const txID = txIDs[txnIndex]; - const methodResult: ABIResult = { + let methodResult: ABIResult = { txID, rawReturnValue: new Uint8Array(), method, }; - const pendingInfo = - txnIndex === firstMethodCallIndex - ? confirmedTxnInfo - : // eslint-disable-next-line no-await-in-loop - await client.pendingTransactionInformation(txID).do(); - methodResults.push( - AtomicTransactionComposer.parseMethodResponse( + try { + const pendingInfo = + txnIndex === firstMethodCallIndex + ? confirmedTxnInfo + : // eslint-disable-next-line no-await-in-loop + await client.pendingTransactionInformation(txID).do(); + + methodResult = AtomicTransactionComposer.parseMethodResponse( method, methodResult, pendingInfo - ) - ); + ); + } catch (err) { + methodResult.decodeError = err; + } + + methodResults.push(methodResult); } return { diff --git a/tests/cucumber/steps/steps.js b/tests/cucumber/steps/steps.js index ea1230ee5..90e09b13e 100644 --- a/tests/cucumber/steps/steps.js +++ b/tests/cucumber/steps/steps.js @@ -4644,7 +4644,7 @@ module.exports = function getSteps(options) { Then( 'the simulation should succeed without any failure message', async function () { - assert.deepStrictEqual(true, this.simulateResponse['would-succeed']); + assert.deepStrictEqual(true, this.simulateResponse.wouldSucceed); } ); @@ -4656,14 +4656,13 @@ module.exports = function getSteps(options) { const txnIndexes = stringPath.map((n) => parseInt(n, 10)); const groupNum = parseInt(txnGroupIndex, 10); - assert.deepStrictEqual(false, this.simulateResponse['would-succeed']); + assert.deepStrictEqual(false, this.simulateResponse.wouldSucceed); // Check for missing signature flag for (const txnIndex of txnIndexes) { assert.deepStrictEqual( true, - this.simulateResponse['txn-groups'][groupNum]['txn-results'][ - txnIndex - ]['missing-signature'] + this.simulateResponse.txnGroups[groupNum].txnResults[txnIndex] + .missingSignature ); } } @@ -4679,18 +4678,15 @@ module.exports = function getSteps(options) { const stringPath = failAt.split(','); const failPath = stringPath.map((n) => parseInt(n, 10)); - const failedMessage = this.simulateResponse['txn-groups'][groupNum][ - 'failure-message' - ]; - assert.deepStrictEqual(false, this.simulateResponse['would-succeed']); + const failedMessage = this.simulateResponse.txnGroups[groupNum] + .failureMessage; + assert.deepStrictEqual(false, this.simulateResponse.wouldSucceed); const errorContainsString = failedMessage.includes(errorMsg); assert.deepStrictEqual(true, errorContainsString); // Check path array // deepStrictEqual fails for firefox tests, so compare array manually. - const failedAt = this.simulateResponse['txn-groups'][groupNum][ - 'failed-at' - ]; + const { failedAt } = this.simulateResponse.txnGroups[groupNum]; assert.strictEqual(failPath.length, failedAt.length); for (let i = 0; i < failPath.length; i++) { assert.strictEqual(failPath[i], failedAt[i]);