tact icon indicating copy to clipboard operation
tact copied to clipboard

Returning `self` from getters

Open anton-trunov opened this issue 7 months ago • 1 comments

The following contract compiles, but produces a TS error:

import "@stdlib/deploy";

contract Test with Deployable {
    id: Int as uint32 = 0;
    anotherData: Cell;

    init() {
        self.anotherData = beginCell().endCell();
    }

    get fun contractData(): Test {
        return self;
    }
}

Test:

import { Blockchain, SandboxContract, TreasuryContract } from '@ton/sandbox';
import { toNano } from '@ton/core';
import { Test } from '../wrappers/Test';
import '@ton/test-utils';

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

    beforeEach(async () => {
        blockchain = await Blockchain.create();

        test = blockchain.openContract(await Test.fromInit());

        deployer = await blockchain.treasury('deployer');

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

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

    it('should get data', async () => {
        const data = await test.getContractData();
        console.log(data);
    });
});

anton-trunov avatar Jul 15 '24 15:07 anton-trunov