Skip to content

Commit

Permalink
test: messages as getter and init() parameters (#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-trunov authored Sep 4, 2024
1 parent 69ed55b commit e132278
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@tact-lang/compiler-reviewers
* @tact-lang/compiler-reviewers

8 changes: 8 additions & 0 deletions src/test/e2e-emulated/__snapshots__/getters.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ exports[`getters should implement getters correctly 2`] = `
`;

exports[`getters should implement getters correctly 3`] = `
{
"$$type": "SetIdAndData",
"data": x{},
"id": 42n,
}
`;

exports[`getters should implement getters correctly 4`] = `
{
"$$type": "Test$Data",
"anotherData": x{000000000000007B},
Expand Down
8 changes: 8 additions & 0 deletions src/test/e2e-emulated/contracts/getters.tact
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ contract Test with Deployable {
return s;
}

get fun messageAsInput1(m: SetIdAndData): Int {
return m.id;
}

get fun messageAsInput2(m: SetIdAndData): SetIdAndData {
return m;
}

get fun contractAsInput(test: Test): Test {
return test;
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/e2e-emulated/contracts/init-of-message.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
message InitData {
seller: Address;
nonce: Int as uint64;
}

contract Test {
seller: Address;

init(i: InitData) {
self.seller = i.seller;
}

receive() {
// deploy
}
}

16 changes: 16 additions & 0 deletions src/test/e2e-emulated/getters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ describe("getters", () => {
// Returning `self` from getter
expect(await contract.getContractData()).toMatchSnapshot();

// Passing `SetIdAndData` message to getter
expect(
await contract.getMessageAsInput1({
$$type: "SetIdAndData",
id: 42n,
data: beginCell().endCell(),
}),
).toBe(42n);
expect(
await contract.getMessageAsInput2({
$$type: "SetIdAndData",
id: 42n,
data: beginCell().endCell(),
}),
).toMatchSnapshot();

// Passing `Test` contract data to getter
expect(
await contract.getContractAsInput({
Expand Down
37 changes: 37 additions & 0 deletions src/test/e2e-emulated/init-of-message.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { toNano } from "@ton/core";
import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox";
import { InitData, Test } from "./contracts/output/init-of-message_Test";
import "@ton/test-utils";

describe("init-of-message", () => {
let blockchain: Blockchain;
let treasure: SandboxContract<TreasuryContract>;
let contract: SandboxContract<Test>;

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

const msg: InitData = {
$$type: "InitData",
seller: treasure.address,
nonce: 0n,
};
contract = blockchain.openContract(await Test.fromInit(msg));

const deployResult = await contract.send(
treasure.getSender(),
{ value: toNano("10") },
null,
);

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

it("should deploy when given a message as init", async () => {});
});
5 changes: 5 additions & 0 deletions tact.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@
"name": "receiver-empty",
"path": "./src/test/e2e-emulated/contracts/receiver-empty.tact",
"output": "./src/test/e2e-emulated/contracts/output"
},
{
"name": "init-of-message",
"path": "./src/test/e2e-emulated/contracts/init-of-message.tact",
"output": "./src/test/e2e-emulated/contracts/output"
}
]
}

0 comments on commit e132278

Please sign in to comment.