Skip to main content

Compiling and Testing Contracts

The three Solidity contracts that form the RealEstateToken project are set out in full here:
  1. Whitelist - manages the Whitelist of approved investors.
  2. RealEstateFactory - deploys RealEstateToken contracts.
  3. RealEstateToken - Tokenization of a real estate development project.
Compiling and testing these contracts is simple. Foundry with it’s Solidity centric test scripts, and builtin helpers and assertions, make it straightforward to write unit tests for our contracts. The example project has a basic suite of tests for each contract.

Building

To build the Solidity contracts are built simply with:

Testing

Foundry unit tests are found in the test directory. There are a number of ways in which you can structure your tests. For simplicity, we’ve written one test script per contract. Test scripts are written in Solidity and the filename must have the form FileName.t.sol. You can read more about testing with Foundry here: https://getfoundry.sh/forge/tests/overview You can run your unit tests in Foundry with a simple:
This will run all test scripts int the test directory. The sample project includes the following tests scripts:

Whitelist.t.sol

RealEstateFactory.t.sol

RealEstateToken.t.sol

Whitelist Contract

The Whitelist contract is responsible for managing the account addressed of approved investors. This is intended to represent a basic KYC/AML process. Only the dApp owner can approve, and revoke an investor’s account address. The ‘Whitelistcontract is the first to be deployed as its contract address is needed by theRealEstateFactory` constructor.

Whitelist

RealEstateFactory Contract

The RealEstateFactory contract is responsible for deploying new RealEstateToken contracts with the deployProject() function. It keeps a record of deployed RealEstateToken contracts deployed in the allProjects state variable which can be accessed by the getAllProjects() function. The Whitelist contract must be deployed before the RealEstateFactory contract. RealEstateFactory requires the address of the deployed Whitelist contract that manages approved investor addresses.

RealEstateFactory

RealEstateToken Contract

The RealEstateToken contract represents a Real World Asset (RWA). Real estate, in this instance. It is a basic example of RWA tokenization. It allows the owner/adminstrator of the project to mint tokens that represent a share in a real estate devlopment project. The RealEstateToken is a modified ERC20 token. It overrides some of the standard behaviours of an ERC20 token. In particular, your attention is directed to the mint(), adminBurn, decimals(), and _update() functions. Essentially, the changes mean 1 token is a 1% share of the project. There are no fractional shares. Only the owner/admin of the project can mint tokens to an approved investor’s account address. And, a token holder is restricted to transferring their tokens to other approved investors. Finally, given the nature of the tokens and what they are intended to represent, only the owner/admin can burn tokens. They cannot be burned by the token holder.

RealEstateToken