-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests with fake controller addresses. Get method for request window.
- Loading branch information
1ixi1
committed
Jun 9, 2023
1 parent
a92dc3e
commit 34ecb08
Showing
9 changed files
with
455 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Address, Tuple, TupleItem, TupleItemInt, TupleReader, toNano } from "ton"; | ||
import { Cell, Slice, Sender, SenderArguments, ContractProvider, Message, beginCell, Dictionary, MessageRelaxed, Transaction } from "ton-core"; | ||
import { Blockchain } from "@ton-community/sandbox"; | ||
import { computeMessageForwardFees, MsgPrices } from "./fees"; | ||
|
||
|
||
const randomAddress = (wc: number = 0) => { | ||
const buf = Buffer.alloc(32); | ||
for (let i = 0; i < buf.length; i++) { | ||
buf[i] = Math.floor(Math.random() * 256); | ||
} | ||
return new Address(wc, buf); | ||
}; | ||
|
||
const differentAddress = (oldAddr:Address) => { | ||
|
||
let newAddr = oldAddr; | ||
|
||
do { | ||
newAddr = randomAddress(newAddr.workChain); | ||
} while(newAddr.equals(oldAddr)); | ||
|
||
return newAddr; | ||
} | ||
|
||
export const getRandom = (min:number, max:number) => { | ||
return Math.random() * (max - min) + min; | ||
} | ||
|
||
enum roundMode {floor, ceil, round}; | ||
|
||
export const getRandomInt = (min:number, max:number, mode: roundMode = roundMode.floor) => { | ||
let res = getRandom(min, max); | ||
|
||
if(mode == roundMode.floor) { | ||
res = Math.floor(res); | ||
} | ||
else if(mode == roundMode.ceil) { | ||
res = Math.ceil(res); | ||
} | ||
else { | ||
res = Math.round(res); | ||
} | ||
|
||
return res; | ||
} | ||
|
||
export const getRandomTon = (min:number, max:number): bigint => { | ||
return toNano(getRandom(min, max).toFixed(9)); | ||
} | ||
|
||
export const buff2bigint = (buff: Buffer) : bigint => { | ||
return BigInt("0x" + buff.toString("hex")); | ||
} | ||
|
||
export const bigint2buff = (num:bigint) : Buffer => { | ||
return Buffer.from(num.toString(16), 'hex') | ||
} | ||
|
||
export const computedGeneric = (trans:Transaction) => { | ||
if(trans.description.type !== "generic") | ||
throw("Expected generic transaction"); | ||
if(trans.description.computePhase.type !== "vm") | ||
throw("Compute phase expected") | ||
return trans.description.computePhase; | ||
}; | ||
|
||
export const getMsgExcess = (trans:Transaction, msg:Message, value:bigint, msgConf:MsgPrices) => { | ||
const fwdFees = computeMessageForwardFees(msgConf, msg); | ||
return value - computedGeneric(trans).gasFees - fwdFees.remaining - fwdFees.fees; | ||
} | ||
|
||
|
||
export { | ||
differentAddress, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.