Skip to content

Commit

Permalink
update to required body fields
Browse files Browse the repository at this point in the history
  • Loading branch information
filvecchiato committed Oct 17, 2024
1 parent 2ae138f commit 96425ed
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
8 changes: 2 additions & 6 deletions src/controllers/transaction/TransactionDryRunController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,12 @@ export default class TransactionDryRunController extends AbstractController<Tran
throw new BadRequest('Missing field `tx` on request body.');
}

if (!at) {
throw new BadRequest('Missing field `at` on request body.');
}

if (!senderAddress) {
throw new BadRequest('Missing field `senderAddress` on request body.');
}

const hash = await this.getHashFromAt(at);
const hash = at ? await this.getHashFromAt(at) : undefined;

TransactionDryRunController.sanitizedSend(res, await this.service.dryRuntExtrinsic(hash, senderAddress, tx));
TransactionDryRunController.sanitizedSend(res, await this.service.dryRuntExtrinsic(senderAddress, tx, hash));
};
}
13 changes: 3 additions & 10 deletions src/services/transaction/TransactionDryRunService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ describe('TransactionDryRunService', () => {
const sendersAddress = '5HBuLJz9LdkUNseUEL6DLeVkx2bqEi6pQr8Ea7fS4bzx7i7E';
it('Should correctly execute a dry run for a submittable executable', async () => {
const executionResult = await new TransactionDryRunService(mockAssetHubWestendApi).dryRuntExtrinsic(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
blockHash22887036,
sendersAddress,
'0xfc041f0801010100411f0100010100c224aad9c6f3bbd784120e9fceee5bfd22a62c69144ee673f76d6a34d280de160104000002043205040091010000000000',
blockHash22887036,
);

expect(executionResult?.at.hash).toEqual(blockHash22887036);
Expand All @@ -42,32 +41,26 @@ describe('TransactionDryRunService', () => {
'0xf81f0801010100411f0100010100c224aad9c6f3bbd784120e9fceee5bfd22a62c69144ee673f76d6a34d280de16010400000204320504009101000000000045022800010000e0510f00040000000000000000000000000000000000000000000000000000000000000000000000be2554aa8a0151eb4d706308c47d16996af391e4c5e499c7cbef24259b7d4503';

const executionResult = await new TransactionDryRunService(mockAssetHubWestendApi).dryRuntExtrinsic(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
blockHash22887036,
sendersAddress,
payloadTx,
blockHash22887036,
);

const resData = executionResult?.result as PostDispatchInfo;

// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
expect(resData.paysFee.toString()).toEqual(mockDryRunCallResult.Ok.executionResult.Ok.paysFee);
});

it('should correctly execute a dry run for a call', async () => {
const callTx =
'0x1f0801010100411f0100010100c224aad9c6f3bbd784120e9fceee5bfd22a62c69144ee673f76d6a34d280de160104000002043205040091010000000000' as `0x${string}`;

// expect(callTxResult.localXcmFees![1]).toEqual({ xcmFee: '3500000000000000' });

const executionResult = await new TransactionDryRunService(mockAssetHubWestendApi).dryRuntExtrinsic(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
blockHash22887036,
sendersAddress,
callTx,
);

expect(executionResult?.at.hash).toEqual(blockHash22887036);
expect(executionResult?.at.hash).toEqual('');
const resData = executionResult?.result as PostDispatchInfo;
expect(resData.paysFee.toString()).toEqual(mockDryRunCallResult.Ok.executionResult.Ok.paysFee);
});
Expand Down
10 changes: 5 additions & 5 deletions src/services/transaction/TransactionDryRunService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export type SignedOriginCaller = {

export class TransactionDryRunService extends AbstractService {
async dryRuntExtrinsic(
hash: BlockHash,
senderAddress: string,
transaction: `0x${string}`,
hash?: BlockHash,
): Promise<ITransactionDryRun> {
const { api } = this;

Expand All @@ -42,17 +42,17 @@ export class TransactionDryRunService extends AbstractService {
},
};

const [dryRunResponse, header] = await Promise.all([
const [dryRunResponse, { number }] = await Promise.all([
api.call.dryRunApi.dryRunCall(originCaller, transaction),
api.rpc.chain.getHeader(hash),
hash ? api.rpc.chain.getHeader(hash) : { number: null },
]);

const response = dryRunResponse as Result<CallDryRunEffects, XcmDryRunApiError>;

return {
at: {
hash,
height: header.number.unwrap().toString(10),
hash: hash ? hash : '',
height: number ? number.unwrap().toString(10) : '0',
},
result: response.isOk ? response.asOk.executionResult.asOk : response.asErr,
};
Expand Down

0 comments on commit 96425ed

Please sign in to comment.