vocdoni / vocdoni-sdk

Vocdoni SDK for API
GNU Affero General Public License v3.0
13 stars 6 forks source link

Fix tx and proof types #399

Open selankon opened 4 months ago

selankon commented 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);
github-actions[bot] commented 4 months ago

size-limit report 📦

Path Size
dist/index.js 1.54 MB (0%)
dist/index.mjs 1.54 MB (0%)
dist/index.umd.js 1.55 MB (0%)