Skip to content

Commit

Permalink
Add wrapper and test cases for Sending Messages topic
Browse files Browse the repository at this point in the history
  • Loading branch information
Swafox committed Jul 26, 2024
1 parent c4c76db commit fca07a2
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
6 changes: 6 additions & 0 deletions SendingMessages/contracts/sending_messages.fc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
;; How to send a simple message
;; Cookbook link: https://docs.ton.org/develop/func/cookbook#how-to-send-a-simple-message
send_raw_message(msg, 3); ;; mode 3 - pay fees separately and ignore errors
return();
}

;; How to send a message with an incoming account
Expand All @@ -45,6 +46,7 @@
.store_slice(body)
.end_cell();
send_raw_message(msg, 3);
return();
}

;; How to send a message with the entire balance
Expand All @@ -59,6 +61,7 @@
.store_slice("Hello from FunC!") ;; comment
.end_cell();
send_raw_message(msg, 128); ;; mode = 128 is used for messages that are to carry all the remaining balance of the current smart contract
return();
}

;; How to send a message with a long text comment
Expand Down Expand Up @@ -90,6 +93,7 @@
.store_ref(body)
.end_cell();
send_raw_message(msg, 3); ;; mode 3 - pay fees separately, ignore errors
return();
}

;; How to contain a body as slice to an internal message cell
Expand All @@ -110,6 +114,7 @@
.end_cell();

send_raw_message(msg, 3);
return();
}

;; How to contain a body as ref to an internal message cell
Expand All @@ -133,6 +138,7 @@
.end_cell();

send_raw_message(msg, 3);
return();
}

throw(111);
Expand Down
61 changes: 60 additions & 1 deletion SendingMessages/tests/SendingMessages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,66 @@ describe('SendingMessages', () => {
});

it('should deploy', async () => {
// the check is done inside beforeEach
// blockchain and sendingMessages are ready to use
});

it('should send a simple message', async () => {
const result = await sendingMessages.sendSimpleMessage(deployer.getSender(), toNano('0.05'));

expect(result.transactions).toHaveTransaction({
from: deployer.address,
to: sendingMessages.address,
success: true,
});
});

it('should send a message with an incoming account', async () => {
const result = await sendingMessages.sendIncomingAccount(deployer.getSender(), toNano('0.05'));

expect(result.transactions).toHaveTransaction({
from: deployer.address,
to: sendingMessages.address,
success: true,
});
});

it('should send a message with the entire balance', async () => {
const result = await sendingMessages.sendEntireBalance(deployer.getSender(), toNano('0.05'));

expect(result.transactions).toHaveTransaction({
from: deployer.address,
to: sendingMessages.address,
success: true,
});
});

it('should send a message with long text', async () => {
const result = await sendingMessages.sendLongText(deployer.getSender(), toNano('0.05'));

expect(result.transactions).toHaveTransaction({
from: deployer.address,
to: sendingMessages.address,
success: true,
});
});

it('should send a message with body as slice', async () => {
const result = await sendingMessages.sendBodyAsSlice(deployer.getSender(), toNano('0.05'));

expect(result.transactions).toHaveTransaction({
from: deployer.address,
to: sendingMessages.address,
success: true,
});
});

it('should send a message with body as ref', async () => {
const result = await sendingMessages.sendBodyAsRef(deployer.getSender(), toNano('0.05'));

expect(result.transactions).toHaveTransaction({
from: deployer.address,
to: sendingMessages.address,
success: true,
});
});
});
18 changes: 17 additions & 1 deletion SendingMessages/wrappers/SendingMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider,

export type SendingMessagesConfig = {};

export function sendingMessagesConfigToCell(config: SendingMessagesConfig): Cell {
export function sendingMessagesConfigToCell(_config: SendingMessagesConfig): Cell {
return beginCell().endCell();
}

Expand Down Expand Up @@ -61,4 +61,20 @@ export class SendingMessages implements Contract {
body: beginCell().storeUint(4, 32).endCell(),
});
}

async sendBodyAsSlice(provider: ContractProvider, via: Sender, value: bigint) {
await provider.internal(via, {
value,
sendMode: SendMode.PAY_GAS_SEPARATELY,
body: beginCell().storeUint(5, 32).endCell(),
});
}

async sendBodyAsRef(provider: ContractProvider, via: Sender, value: bigint) {
await provider.internal(via, {
value,
sendMode: SendMode.PAY_GAS_SEPARATELY,
body: beginCell().storeUint(6, 32).endCell(),
});
}
}

0 comments on commit fca07a2

Please sign in to comment.