Open selankon opened 4 months ago
The actual typing is not really working (it was an inheritance from generated TS code from protobuff and is simply wrong on this case).
This refactor fixes Transactions and Proof types and add typeguards for this types.
Some fast tests done:
it('should throw when asking for a non existent transaction by index', async () => { // await expect(async () => { const tx = await ChainAPI.txInfoByBlock(URL, 197870, 0); if (isVoteEnvelopeType(tx.tx)) { const voteEnvelope = tx.tx.vote; console.log('VoteEnvelopeType:', voteEnvelope.votePackage); } if (isNewProcessTxType(tx.tx)) { throw new Error('Should not enter here'); } // }).rejects.toThrow(ErrTransactionNotFound); }, 5000); it('test type infering for proofs', async () => { // await expect(async () => { const tx = await ChainAPI.txInfoByBlock(URL, 39018, 121); // Es podrien fer servir funcions de typeguard if (isVoteEnvelopeType(tx.tx)) { const voteEnvelope = tx.tx.vote; if (isArboType(voteEnvelope.proof)) { console.log('proof:', voteEnvelope.proof.arbo.siblings); } if (isMinimeStorageType(voteEnvelope.proof)) { throw new Error('Should not enter here'); } } // }).rejects.toThrow(ErrTransactionNotFound); }, 5000);
The actual typing is not really working (it was an inheritance from generated TS code from protobuff and is simply wrong on this case).
This refactor fixes Transactions and Proof types and add typeguards for this types.
Some fast tests done: