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.
 
 

37 lines
1.4 KiB

import BN from "bn.js";
import { Address, Cell, CellMessage, InternalMessage, CommonMessageInfo, WalletContract, SendMode, Wallet } from "ton";
import { SmartContract } from "ton-contract-executor";
import Prando from "prando";
import { sendInternalMessageWithWallet} from "../contracts/utils";
export const zeroAddress = new Address(0, Buffer.alloc(32, 0));
export function randomAddress(seed: string, workchain?: number) {
const random = new Prando(seed);
const hash = Buffer.alloc(32);
for (let i = 0; i < hash.length; i++) {
hash[i] = random.nextInt(0, 255);
}
return new Address(workchain ?? 0, hash);
}
// used with ton-contract-executor (unit tests) to sendInternalMessage easily
export function internalMessage(params: { from?: Address; to?: Address; value?: BN; bounce?: boolean; body?: Cell }) {
const message = params.body ? new CellMessage(params.body) : undefined;
return new InternalMessage({
from: params.from ?? randomAddress("sender"),
to: params.to ?? zeroAddress,
value: params.value ?? 0,
bounce: params.bounce ?? true,
body: new CommonMessageInfo({ body: message }),
});
}
// temp fix until ton-contract-executor (unit tests) remembers c7 value between calls
export function setBalance(contract: SmartContract, balance: BN) {
contract.setC7Config({
balance: balance.toNumber(),
});
}
export { sendInternalMessageWithWallet };