Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

feat: throw GrpcError if state transaction was broadcasted twice #328

Merged
merged 1 commit into from
Dec 28, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {
server: {
error: {
InvalidArgumentGrpcError,
FailedPreconditionGrpcError,
},
},
} = require('@dashevo/grpc-common');
Expand Down Expand Up @@ -41,6 +42,10 @@ function broadcastStateTransitionHandlerFactory(rpcClient, handleAbciResponseErr
const { result, error: jsonRpcError } = await rpcClient.request('broadcast_tx_commit', { tx });

if (jsonRpcError) {
if (jsonRpcError.data === 'error on broadcastTxCommit: tx already exists in cache') {
throw new FailedPreconditionGrpcError(jsonRpcError.data, jsonRpcError);
}

const error = new Error();
Object.assign(error, jsonRpcError);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {
server: {
error: {
InvalidArgumentGrpcError,
FailedPreconditionGrpcError,
},
},
} = require('@dashevo/grpc-common');
Expand Down Expand Up @@ -156,4 +157,21 @@ describe('broadcastStateTransitionHandlerFactory', () => {
expect(e.code).to.equal(error.code);
}
});

it('should throw FailedPreconditionGrpcError if transaction was broadcasted twice', async () => {
const error = {
code: -32603,
message: 'Internal error',
data: 'error on broadcastTxCommit: tx already exists in cache',
};

response.error = error;

try {
await broadcastStateTransitionHandler(call);
} catch (e) {
expect(e).to.be.an.instanceOf(FailedPreconditionGrpcError);
expect(e.getMessage()).to.equal(`Failed precondition: ${error.data}`);
}
});
});