Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tx and proof types #399

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Fix tx and proof types #399

wants to merge 3 commits into from

Conversation

selankon
Copy link
Collaborator

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);

@selankon selankon force-pushed the f/fix-tx-and-proof-types branch from 2999c8c to f5fbd47 Compare July 18, 2024 09:38
@selankon selankon force-pushed the f/fix-tx-and-proof-types branch from f5fbd47 to ac06141 Compare July 18, 2024 09:38
Copy link

github-actions bot commented Jul 18, 2024

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%)

@selankon selankon marked this pull request as ready for review July 23, 2024 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant