You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Access to the endpoint or genesis file of the parachain you wish to fork
27848
27848
- Set up your TypeScript project with the essential tools
27849
27849
27850
27850
If you haven't replayed or dry-run XCMs before, see the [Replay and Dry Run XCMs Using Chopsticks](/tutorials/interoperability/replay-and-dry-run-xcms/){target=\_blank} tutorial for step-by-step guidance.
27851
27851
27852
-
### Launch a Fork for Local Testing
27852
+
### Set Up Your Project
27853
+
27854
+
Let's start by creating a dedicated workspace for your XCM observability demo.
27855
+
27856
+
1. Create a new directory and navigate into it:
27857
+
27858
+
```bash
27859
+
mkdir -p xcm-obs-demo
27860
+
cd xcm-obs-demo
27861
+
```
27862
+
27863
+
2. Initialise a new Node project:
27864
+
27865
+
```bash
27866
+
npm init -y
27867
+
```
27868
+
27869
+
3. Install Chopsticks globally (recommended to avoid conflicts with local installs):
27870
+
27871
+
```bash
27872
+
npm install -g @acala-network/chopsticks@latest
27873
+
```
27874
+
27875
+
4. Install TypeScript and related tooling for local development:
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/hardhat.config.js
40500
40505
```
40501
40506
40502
40507
Ensure that `INSERT_PATH_TO_SUBSTRATE_NODE` and `INSERT_PATH_TO_ETH_RPC_ADAPTER` are replaced with the proper paths to the compiled binaries.
@@ -40526,27 +40531,7 @@ module.exports = {
40526
40531
1. Create a new folder called `contracts` and create a `Storage.sol` file. Add the contract code from the previous tutorial:
40527
40532
40528
40533
```solidity title="Storage.sol"
40529
-
// SPDX-License-Identifier: MIT
40530
-
pragma solidity ^0.8.28;
40531
-
40532
-
contract Storage {
40533
-
// State variable to store our number
40534
-
uint256 private number;
40535
-
40536
-
// Event to notify when the number changes
40537
-
event NumberChanged(uint256 newNumber);
40538
-
40539
-
// Function to store a new number
40540
-
function store(uint256 newNumber) public {
40541
-
number = newNumber;
40542
-
emit NumberChanged(newNumber);
40543
-
}
40544
-
40545
-
// Function to retrieve the stored number
40546
-
function retrieve() public view returns (uint256) {
40547
-
return number;
40548
-
}
40549
-
}
40534
+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/contracts/Storage.sol
40550
40535
```
40551
40536
40552
40537
2. Compile the contract:
@@ -40572,28 +40557,9 @@ Testing is a critical part of smart contract development. Hardhat makes it easy
40572
40557
1. Create a folder for testing called `test`. Inside that directory, create a file named `Storage.js` and add the following code:
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
40594
40561
// Add your logic here
40595
-
});
40596
-
});
40562
+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
40597
40563
```
40598
40564
40599
40565
The `beforeEach` hook ensures stateless contract execution by redeploying a fresh instance of the Storage contract before each test case. This approach guarantees that each test starts with a clean and independent contract state by using `ethers.getSigners()` to obtain test accounts and `ethers.getContractFactory('Storage').deploy()` to create a new contract instance.
@@ -40603,9 +40569,7 @@ describe('Storage', function () {
40603
40569
a. **Initial state verification** - ensures that the contract starts with a default value of zero, which is a fundamental expectation for the `Storage.sol` contract
40604
40570
40605
40571
```javascript title="Storage.js"
40606
-
it('Should return 0 initially', async function () {
40607
-
expect(await storage.retrieve()).to.equal(0);
40608
-
});
40572
+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
40609
40573
```
40610
40574
40611
40575
Explanation:
@@ -40617,13 +40581,7 @@ describe('Storage', function () {
40617
40581
b. **Value storage test** - validate the core functionality of storing and retrieving a value in the contract
40618
40582
40619
40583
```javascript title="Storage.js"
40620
-
it('Should update when store is called', async function () {
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
40627
40585
```
40628
40586
40629
40587
Explanation:
@@ -40635,13 +40593,7 @@ describe('Storage', function () {
40635
40593
c. **Event emission verification** - confirm that the contract emits the correct event when storing a value, which is crucial for off-chain tracking
40636
40594
40637
40595
```javascript title="Storage.js"
40638
-
it('Should emit an event when storing a value', async function () {
40639
-
const testValue = 100;
40640
-
// Check if the NumberChanged event is emitted with the correct value
40641
-
await expect(storage.store(testValue))
40642
-
.to.emit(storage, 'NumberChanged')
40643
-
.withArgs(testValue);
40644
-
});
40596
+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
40645
40597
```
40646
40598
40647
40599
Explanation:
@@ -40653,14 +40605,7 @@ describe('Storage', function () {
40653
40605
d. **Sequential value storage test** - check the contract's ability to store multiple values sequentially and maintain the most recent value
40654
40606
40655
40607
```javascript title="Storage.js"
40656
-
it('Should allow storing sequentially increasing values', async function () {
40657
-
const values = [10, 20, 30, 40];
40658
-
40659
-
for (const value of values) {
40660
-
await storage.store(value);
40661
-
expect(await storage.retrieve()).to.equal(value);
40662
-
}
40663
-
});
40608
+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
40664
40609
```
40665
40610
40666
40611
Explanation:
@@ -40673,55 +40618,7 @@ describe('Storage', function () {
it('Should emit an event when storing a value', async function () {
40708
-
const testValue = 100;
40709
-
// Check if the NumberChanged event is emitted with the correct value
40710
-
await expect(storage.store(testValue))
40711
-
.to.emit(storage, 'NumberChanged')
40712
-
.withArgs(testValue);
40713
-
});
40714
-
40715
-
it('Should allow storing sequentially increasing values', async function () {
40716
-
const values = [10, 20, 30, 40];
40717
-
40718
-
for (const value of values) {
40719
-
await storage.store(value);
40720
-
expect(await storage.retrieve()).to.equal(value);
40721
-
}
40722
-
});
40723
-
});
40724
-
});
40621
+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
40725
40622
```
40726
40623
40727
40624
2. Run the tests:
@@ -40750,13 +40647,7 @@ describe('Storage', function () {
40750
40647
1. Create a new folder called`ignition/modules`. Add a new file named `StorageModule.js` with the following logic:
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/ignition/modules/StorageModule.js
40760
40651
```
40761
40652
40762
40653
2. Deploy to the local network:
@@ -40828,40 +40719,7 @@ To interact with your deployed contract:
40828
40719
1. Create a new folder named `scripts` and add the `interact.js` with the following content:
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/scripts/interact.js
40865
40723
```
40866
40724
40867
40725
Ensure that `INSERT_DEPLOYED_CONTRACT_ADDRESS` is replaced with the value obtained in the previous step.
- Access to the endpoint or genesis file of the parachain you wish to fork
28
28
- Set up your TypeScript project with the essential tools
29
29
30
30
If you haven't replayed or dry-run XCMs before, see the [Replay and Dry Run XCMs Using Chopsticks](/tutorials/interoperability/replay-and-dry-run-xcms/){target=\_blank} tutorial for step-by-step guidance.
31
31
32
-
### Launch a Fork for Local Testing
32
+
### Set Up Your Project
33
+
34
+
Let's start by creating a dedicated workspace for your XCM observability demo.
35
+
36
+
1. Create a new directory and navigate into it:
37
+
38
+
```bash
39
+
mkdir -p xcm-obs-demo
40
+
cd xcm-obs-demo
41
+
```
42
+
43
+
2. Initialise a new Node project:
44
+
45
+
```bash
46
+
npm init -y
47
+
```
48
+
49
+
3. Install Chopsticks globally (recommended to avoid conflicts with local installs):
50
+
51
+
```bash
52
+
npm install -g @acala-network/chopsticks@latest
53
+
```
54
+
55
+
4. Install TypeScript and related tooling forlocal development:
0 commit comments