As a new dev in web3, here are some quick notes about 0xTitans 2023 challenge.
Lot's of information are given in the official notion.
-
Foundry installation Once foundry is installed, when running the test, the
logsdirectory must be created to have a correct output runningforge test. For this,cdto the root of the project, and runmkdir logs.Then all generated
logs, including the full gamegameLog.json, can be accessed. -
To run the
gameLog.jsonfile, the generated JSON must be escaped and pasted into the developer tools console of the web browser of the race viewer. To quickly generate in one step the escaped JSON and copy to clipboard, one can:- install
jqandxclip, which are respectively a command-line JSON processor and command-line interface to X selections. - run the one liner:
forge test && cat ./logs/gameLog.json | jq -Rsa | xclip -sel clip. - go to the console of the web browser, and start typing
setGameData(, then paste, then);.
- install
The strategy is a solidity code where we must follow the rules. The rules define which action we can do, and how the costs change.
There are several examples of strategies in the zip downloaded from the official notion. There are located in src/cars/samples.
To implement your strategy and test it, you can:
- Copy the
src/cars/ExampleCar.solfile intosrc/cars/MySuperCar.sol. - Register your car into the
test/Monaco.t.solfile. For this, you have to:- import the car.
- Declare the car for the race.
// test/Monaco.t.sol
...
import { MySuperCar } from "../src/cars/MySuperCar.sol";
...
// PermaShield and Sauce are already declared in the samples.
ICar w1 = new PermaShield();
ICar w2 = new Sauce();
ICar w3 = new MySuperCar();
...- Compile the code with
forge test. - Escape and copy paste the
logs/gameLog.jsoncontent into the race viewer.
Enjoy! :)