Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Adds skipVerify flag to dryRunTransaction endpoint - Closes #7568 #7684

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 12 additions & 10 deletions framework/src/engine/endpoint/txpool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,18 @@ export class TxpoolEndpoint {
const transaction = Transaction.fromBytes(Buffer.from(req.transaction, 'hex'));
const header = this._chain.lastBlock.header.toObject();

const { result } = await this._abi.verifyTransaction({
contextID: Buffer.alloc(0),
transaction: transaction.toObject(),
header,
});
if (result === TransactionVerifyResult.INVALID) {
return {
success: false,
events: [],
};
if (!req.skipVerify) {
const { result } = await this._abi.verifyTransaction({
contextID: Buffer.alloc(0),
transaction: transaction.toObject(),
header,
});
if (result === TransactionVerifyResult.INVALID) {
return {
success: false,
events: [],
};
}
}

const stateStore = new StateStore(this._blockchainDB);
Expand Down
5 changes: 5 additions & 0 deletions framework/src/engine/generator/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export const previouslyGeneratedInfoSchema = {

export interface DryRunTransactionRequest {
transaction: string;
skipVerify: boolean;
}

export interface DryRunTransactionResponse {
Expand All @@ -269,6 +270,10 @@ export const dryRunTransactionRequestSchema = {
type: 'string',
format: 'hex',
},
skipVerify: {
type: 'boolean',
default: false,
},
},
};

Expand Down
39 changes: 38 additions & 1 deletion framework/test/unit/engine/endpoint/txpool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ describe('generator endpoint', () => {
},
chainID,
}),
).rejects.toThrow(LiskValidationError);
).rejects.toThrow("must have required property 'transaction'");
});

it('should reject with error when transaction bytes is invalid', async () => {
Expand All @@ -226,6 +226,19 @@ describe('generator endpoint', () => {
}),
).rejects.toThrow();
});

it('should reject with error when skipVerify is not boolean', async () => {
await expect(
endpoint.dryRunTransaction({
logger,
params: {
transaction: 'xxxx',
skipVerify: 'test',
},
chainID,
}),
).rejects.toThrow("'.skipVerify' should be of type 'boolean'");
});
});

describe('when verify transaction fails', () => {
Expand Down Expand Up @@ -290,6 +303,30 @@ describe('generator endpoint', () => {
});
});

it('should not verify transaction when skipVerify', async () => {
(abi.verifyTransaction as jest.Mock).mockResolvedValue({
result: TransactionVerifyResult.OK,
});

(abi.executeTransaction as jest.Mock).mockResolvedValue({
result: TransactionExecutionResult.OK,
events,
});

await expect(
endpoint.dryRunTransaction({
logger,
params: {
transaction: tx.getBytes().toString('hex'),
skipVerify: true,
},
chainID,
}),
).toResolve();

expect(abi.verifyTransaction).toBeCalledTimes(0);
});

describe('when both verification is success & execution returns OK', () => {
it('should return true with corresponding events', async () => {
(abi.executeTransaction as jest.Mock).mockResolvedValue({
Expand Down