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

In cases of Cell underflow/overflow or other similar exit codes, contract's debug output doesn't show anything #129

Open
novusnota opened this issue Jun 28, 2024 · 1 comment

Comments

@novusnota
Copy link
Contributor

novusnota commented Jun 28, 2024

See the following Tact snippet and comments in it:

import "@stdlib/deploy";

struct Coin {
    first: Int as coins;
    second: Int as uint32;
}

fun directParse(payload: Cell): Coin {
    return Coin.fromCell(payload);
}

contract Example with Deployable {
    receive("example") {
        let coin = directParse(
            beginCell()
            .storeCoins(42)
            .storeUint(35, 31) // here, I only specified 31 bit for storing the Uint, but could've specified 33 bits and get the same issue
            .endCell()
        );
        dump(coin.first); // would display nothing!
        dump(coin.second); // neither would this!
    }
}

And the Example.spec.ts file, which simply sends a message to the "example" receiver:

import { Blockchain, SandboxContract, TreasuryContract, printTransactionFees, prettyLogTransaction, prettyLogTransactions } from '@ton/sandbox';
import { Dictionary, Transaction, beginCell, toNano } from '@ton/core';
import { Example } from '../wrappers/Example';
import '@ton/test-utils';

describe('Example', () => {
  let blockchain: Blockchain;
  let deployer: SandboxContract<TreasuryContract>;
  let example: SandboxContract<Example>;

  beforeEach(async () => {
    blockchain = await Blockchain.create();
    example = blockchain.openContract(await Example.fromInit());
    deployer = await blockchain.treasury('deployer');

    const deployResult = await example.send(
      deployer.getSender(),
      { value: toNano('0.05') },
      { $$type: 'Deploy', queryId: 0n },
    );

    expect(deployResult.transactions).toHaveTransaction({
      from: deployer.address,
      to: example.address,
      deploy: true,
      success: true,
    });

    blockchain.now = deployResult.transactions[2].now;
  });

  it('plays', async () => {
    await example.send(
      deployer.getSender(),
      { value: toNano('0.5') },
      'example',
    );
  });
});

Test suite of Jest just goes through and there's nothing in #DEBUG# output, as if those calls to dump() didn't happen. This may be a @ton/sandbox issue, but an expected outcome is to see error with an exit code 9, Cell underflow for the given example above.

@anton-trunov
Copy link
Collaborator

@novusnota Could you also add the .spec.ts file you used for testing here. It will be useful to come up fix a fix and a test for that fix

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

No branches or pull requests

2 participants