Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readme improvements #45

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Astar
85 changes: 43 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

# Simulated Coretime Environment

The purpose of this directory is to consolidate all the necessary components for testing RegionX functionality in one place. This repository offers scrits, simplifying the process of spinning up the required chains for testing.

The primary purpose of this repository is to provide all the necessary components for testing the [RegionX contracts](https://github.com/RegionX-Labs/RegionX), as well as the [RegionX CoreHub UI](https://github.com/RegionX-Labs/CoreHub).

## Topology

Expand All @@ -15,10 +16,13 @@ The local environment consists of three chains:
<img src="./docs/topology.png" />
</p>

The two parachains are connected through HRMP channels in both directions. In our mock environment, the Shibuya parachain treats the Coretime chain as a reserve chain for Coretime regions, thus supporting reserve transfers.

The Shibuya chain will represent the derivatives of Coretime regions as standard NFTs. This means that regions are presented as a single NFT collection, where the `ItemId` of each region corresponds to the encoded [`RegionId`](https://github.com/paritytech/polkadot-sdk/blob/2aa006e094e248110af14a742d4e2f56b7931959/substrate/frame/broker/src/types.rs#L55).

## Getting started with Zombienet

NOTE: Before proceeding make sure to have zombienet setup on your machine and accessible from your PATH.
You can find linux and macOS executables of the Zombienet CLI [here](https://github.com/paritytech/zombienet/releases)
Before proceeding, ensure that Zombienet is set up on the machine and accessible from the PATH. Linux and macOS executables for the Zombienet CLI are available [here](https://github.com/paritytech/zombienet/releases).

```sh
# Clone the repo:
Expand All @@ -28,63 +32,58 @@ git clone https://github.com/RegionX-Labs/Coretime-Mock.git
git submodule update --init
```

To run the local environment, we will first need to get all the necessary binaries.

If we only want to test functionality that is not related to any of the contracts, we can simply run the `minimal_network.toml` zombienet script:
To initiate the local environment, it is essential to get all the necessary binaries.

```sh
# This script compiles all the necessary binaries for running a Rococo relay chain,
# Coretime chain.
./scripts/minimal_init.sh
# This script compiles all the necessary binaries for running the Rococo relay chain,
# Coretime chain, and the Shibuya parachain.
./scripts/full_init.sh
```

In case we want to run the full local network, which will allow us to test the contracts as well, we need to get the binary from the contracts parachain as well:

```sh
# This script compiles all the necessary binaries for running a Rococo relay chain,
# Coretime chain, and a smart contract chain.
./scripts/full_init.sh
After successful compilation, the local network can be initiated:
```
npm run zombienet:full
```

After waiting a few minutes for the network initialization and once both parachains begin block production, we can proceed to initialize the environment.
After waiting a few minutes for the network initialization and once **both** parachains **start producing blocks**, we can proceed with setting up the environment.

This repo provides an init program which will based on the selected options set up the local network appropriately. The program exposes the following options:
This repo provides an initialization program which will based on the selected options set up the local network accordingly. The program provides the following options:

1. `--relayInit`:

- Description: Initializes the relay chain. The only thing this actually does is open an HRMP channel between the two parachains.
- Opens two HRMP channels: Coretime Chain <--> Contracts chain

2. `--coretimeInit`:

- Description: Initializes the coretime chain by setting the initial configuration, starting the bulk sale and buying a region.

3. `--contractsInit`:

- Description: Initializes the contracts parachain by creating a collection to represent regions, and mints a mock region. Also, deploys both the `xc-regions` and the `coretime-market` contracts.
- Initializes the Coretime chain by setting the initial configuration, starting the bulk sale, and purchasing a region.

4. `--contractsAccount <string>`:
3. `--coretimeAccount <string>`:

- Description: Specify an account on the contracts chain. When specified the program will transfer a mock region to this account.
- When specified the program will transfer the purchased region to this account.

5. `--contractsPath <string>`:
4. `--contractsInit`:

- Description: The path to the compiled contracts.
- Initializes the contracts parachain by creating a collection that represents Coretime regions. Also, deploys both the `xc-regions` and the `coretime-market` contracts.

5. `--mintXcRegions`:

6. `--coretimeAccount <string>`:
- Mints a couple of mock xc-regions. Convenient for testing the market functionality.

6. `--contractsAccount <string>`:

- Description: Specify an account on the coretime chain. When specified the program will transfer a mock region to this account.
- When specified the program will transfer the mock xc-regions to this account.

7. `--mintXcRegions`:
7. `--contractsPath <string>`:

- Description: Mints a couple of mock xc-regions. Convenient for testing the market functionality.
- The path to the compiled contracts.

### Example: Testing contracts related stuff only:
### Example: Testing contracts only:

> NOTE: For the following to work, it is expected that the `astar-collator` node is running in the background in `--dev` mode at port `9920`.
> NOTE: In this case, we don't need to run the zombienet network, instead it is expected that the `astar-collator` node is running in the background in `--dev` mode at port `9920`.
>
> Command for running the node: `astar-collator --dev --rpc-port 9920`

1. Compile the contracts in the RegionX directory. Before compilation ensure the uniques pallet index is configured correctly. In this case it should be set to 30: https://github.com/RegionX-Labs/RegionX?tab=readme-ov-file#4-deploy
1. Compile the contracts within the RegionX directory
```sh
cd RegionX/contracts/xc-regions
cargo contract build
Expand All @@ -93,44 +92,46 @@ This repo provides an init program which will based on the selected options set
cargo contract build
```

2. After successful compilation, you can initialize the contracts chain with the command below.
2. After successful compilation, setup the environment using the command below:
```sh
npm run zombienet-init -- \
--contractsInit \
--contractsPath ../RegionX/target/ink/ \
--contractsAccount "X2pK59cdJrdw4Ca7cNywKFtCc9bPMRGVefbeYWXa1GJJJsk" \
--contractsAccount "<ADDRESS PLACEHOLDER>" \
--mintXcRegions
```

### Example: Testing with full environment
> NOTE: For the following to work, it is expected that you run `npm run zombienet:full` in the background.
> NOTE: For the following steps to function, it is required to execute `npm run zombienet:full` in the background.

1. Compile the contracts in the RegionX directory. Before compilation ensure the uniques pallet index is configured correctly. In this case it should be set to 37: https://github.com/RegionX-Labs/RegionX?tab=readme-ov-file#4-deploy
1. Compile the contracts in the RegionX directory
```sh
cd RegionX/contracts/xc-regions
cargo contract build

cd ../coretime_market
cargo contract build
```
2. After successful compilation and once all the parachains **started producing blocks**, you can initialize the full network setup using the command below.
2. After successful compilation and once all the parachains **started producing blocks**, setup the environment using the command below:
```sh
npm run zombienet-init -- \
--contractsInit \
--coretimeInit \
--relayInit \
--contractsPath ../RegionX/target/ink/ \
--contractsAccount "X2pK59cdJrdw4Ca7cNywKFtCc9bPMRGVefbeYWXa1GJJJsk" \
--coretimeAccount "5DADsnBXr5DXiEAjdJvruf6c7ZSUR8iXUTATQqJfheGLiEVm"
--contractsAccount "<ADDRESS PLACEHOLDER>" \
--coretimeAccount "<ADDRESS PLACEHOLDER>"
```

## Getting started with Chopsticks

The Coretime chain is already deployed on Rococo (🥳), allowing us to use Chopsticks for aspects of local frontend testing that do not require the xc-regions contract.
Since the Coretime chain is deployed on Rococo, we can use Chopsticks for parts of local frontend testing that do not require the contracts.

The steps to run a Coretime chain locally and setup the mock environment:

```sh
cd Coretime-Mock

npm i

# This will run a parallel copy of the Coretime chain
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/uniques.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
const createCollectionCall = contractsApi.tx.uniques.create(REGION_COLLECTION_ID, alice.address);

const callTx = async (resolve: () => void) => {
const unsub = await createCollectionCall.signAndSend(alice, (result: any) => {

Check warning on line 16 in src/contracts/uniques.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Unexpected any. Specify a different type
if (result.status.isInBlock) {
unsub();
resolve();
Expand All @@ -25,7 +25,7 @@
}

export async function registerXcRegionAsset(contractsApi: ApiPromise): Promise<void> {
if(!contractsApi.tx.xcAssetConfig) return;
if (!contractsApi.tx.xcAssetConfig) return;

log(`Registering xc-region asset`);

Expand All @@ -52,7 +52,7 @@
const mintCall = contractsApi.tx.uniques.mint(REGION_COLLECTION_ID, rawRegionId, alice.address);

const callTx = async (resolve: () => void) => {
const unsub = await mintCall.signAndSend(alice, (result: any) => {

Check warning on line 55 in src/contracts/uniques.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Unexpected any. Specify a different type
if (result.status.isInBlock) {
unsub();
resolve();
Expand All @@ -71,7 +71,7 @@
const approveCall = contractsApi.tx.uniques.approveTransfer(REGION_COLLECTION_ID, rawRegionId, delegate);

const callTx = async (resolve: () => void) => {
const unsub = await approveCall.signAndSend(alice, (result: any) => {

Check warning on line 74 in src/contracts/uniques.ts

View workflow job for this annotation

GitHub Actions / build-and-test

Unexpected any. Specify a different type
if (result.status.isInBlock) {
unsub();
resolve();
Expand Down
Loading