Block: 41

Timestamp: 01:36:42

AuditProfile

Security blog

prompt(): a new way to rock your tests

A new Foundry feature allows you to test your contracts in a more interactive and efficient way.

In some cases, you no longer need to store rpc links or private keys in users' .env files.Instead, you can type different values directly into your terminal line. Let's take a look

Recently a new prompt() cheatcode was introduced in a forge-std library. It allows a user to enter a string values directly into the terminal.

Here is a super simple test contract with implementing WETH interface to interact with.

Take a look on the line 15

That special cheatcode will ask for your rpc endpoint as a string as soon as you run your test!

So, instead of creating an .env file and writing the necessary rpc, a user simply needs to copy and paste a link, such as https://mainnet.infura.io/v3/blablabla, into the terminal.

Moreover you can use prompt() with different other data types. For example, you can let users to specify an amount for the test.

Or specify the admin address for the next test to come:

And it's not over yet! Foundry is awesome!

It allows you to enter your private keys in the terminal in a hidden way with: promptSecret()!

This way the information you enter is not stored in the terminal and you can run your tests safely!

That was just a super simple example to show the cheatcode! There are many more cases where you can use it!

#foundry

#prompt

#testing

Connent with me:

Регистрация прошла успешно! Спасибо за внимание!

loader