You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

31 lines
1.3 KiB

import { Address, Cell, CellMessage, InternalMessage, CommonMessageInfo, WalletContract, SendMode, Wallet } from "ton";
import BN from "bn.js";
// helper for end-to-end on-chain tests (normally post deploy) to allow sending InternalMessages to contracts using a wallet
export async function sendInternalMessageWithWallet(params: { walletContract: WalletContract; secretKey: Buffer; to: Address; value: BN; bounce?: boolean; body?: Cell }) {
const message = params.body ? new CellMessage(params.body) : undefined;
const seqno = await params.walletContract.getSeqNo();
const transfer = params.walletContract.createTransfer({
secretKey: params.secretKey,
seqno: seqno,
sendMode: SendMode.PAY_GAS_SEPARATLY + SendMode.IGNORE_ERRORS,
order: new InternalMessage({
to: params.to,
value: params.value,
bounce: params.bounce ?? false,
body: new CommonMessageInfo({
body: message,
}),
}),
});
await params.walletContract.client.sendExternalMessage(params.walletContract, transfer);
for (let attempt = 0; attempt < 10; attempt++) {
await sleep(2000);
const seqnoAfter = await params.walletContract.getSeqNo();
if (seqnoAfter > seqno) return;
}
}
function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}