본문으로 건너뛰기

Utils

a

( (contract || signer || string || number ): {address: string} ) => string

return an address as a string, from the contract or signer or type that has an address property.

a(MyContract); // is same with MyContract.address
a(User(1)); // is same with User(1).address
a(0); // zero address: '0x0000000000000000000000000000000000000000'

a("0x7907ca011864321868f397516ce37c959f25f8dd");
// => 0x7907ca011864321868f397516ce37c959f25f8dd

n

( number ) => Big Numberish

It is generally used to upload data from off-chain to on-chain. When entering a number, it will be parsed to a Big number with 18 decimals. (e.g. 1000 => 1000000000000000000000)

await ETH.connect(User(1).signer).transfer(a(User(1)), n(1000));

u

( Big Numberish ) => number

It is generally used to download data from on-chain to off-chain. When entering a Big number, it will be parsed to a number without 18 decimals. (e.g. 1000000000000000000000 => 1000)

u(await ETH.totalSupply());

t

( n: number | 'now', u?: 'm' | 'h' | 'd' | 'w' | 'y' ) => number

Converts the entered numeric value to convert as a duration and makes time pass in the code.

t("now"); // 1697258409 = current time.
t(86400); // 86400 = 24 hours
t(1, "d"); // 86400 = 1 day = 24 hours
t(3, "h"); // 10800 = 3 hours
t(3); // 3 = 3 seconds

ft

( number ) => string

Abbreviation for 'format time'. If you enter a numeric value such as duration, the converted value of the period is returned in human-readable string format.

ft(21646); // 6h 00m 46s
ft(88_632); // 1d 37m 12s

duration

( number ) => void

If you enter the UnixTimeStamp value as the starting point, the number of seconds that have elapsed based on the current time is returned in numeric format.

duration(1697258409); // now - 1697258409

repeat

( fn: Function, times: number ) => void

A specific function or transaction is repeated the number of times entered.

await repeat(
async (i: number) => await User(1).send(Tokens.METH, User(2), 1), // transaction to repeat
5 // repeat times
);

revert

( fn: Function, message?: string, value?: any) => void

Check whether the intended revert and error occur properly. If revert and error do not occur, it is treated as an error. The results are displayed in a terminal window.

await revert(MyContract.use(User("Receiver")).claim(history[0].key));
await revert(
MyContract.use(User("Receiver")).claim(history[0].key),
"NO_REWARD_YET" // If it same with your custome error function name on solidity, it could be more helpful.
);
await revert(
MyContract.use(User("Receiver")).claim(history[0].key),
"NO_REWARD_YET", // If it same with your custome error function name on solidity, it could be more helpful.
`key: ${history[0].key}`
);