Skip to content

Commit 6359174

Browse files
Update script name
1 parent 86fe278 commit 6359174

File tree

4 files changed

+200
-17
lines changed

4 files changed

+200
-17
lines changed

.snippets/code/tutorials/interoperability/xcm-observability/multi-hop-with-set-topic-result.html renamed to .snippets/code/tutorials/interoperability/xcm-observability/deposit-reserve-asset-with-set-topic-result.html

File renamed without changes.

.snippets/code/tutorials/interoperability/xcm-observability/multi-hop-with-set-topic.ts renamed to .snippets/code/tutorials/interoperability/xcm-observability/deposit-reserve-asset-with-set-topic.ts

File renamed without changes.

llms.txt

Lines changed: 196 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28208,7 +28208,7 @@ In complex XCM flows, such as multi-hop transfers that span multiple parachains,
2820828208
- **Topic assignment**: Manually set via `SetTopic` instruction
2820928209
- **Goal**: Transfer DOT and trace the XCM using the manually assigned `message_id`
2821028210

28211-
Create a new script, `multi-hop-with-set-topic.ts`
28211+
Create a new script, `deposit-reserve-asset-with-set-topic.ts`
2821228212

2821328213
```ts
2821428214
import {Binary, createClient, Enum} from "polkadot-api";
@@ -28441,7 +28441,7 @@ main().catch(console.error);
2844128441
Run it locally:
2844228442

2844328443
```bash
28444-
npx tsx multi-hop-with-set-topic.ts
28444+
npx tsx deposit-reserve-asset-with-set-topic.ts
2844528445
```
2844628446

2844728447
#### Forwarded XCM (Destination Chain: Hydration)
@@ -40501,7 +40501,43 @@ Let's start by setting up Hardhat for your Storage contract project:
4050140501
6. Configure Hardhat by updating the `hardhat.config.js` file:
4050240502

4050340503
```javascript title="hardhat.config.js"
40504-
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/hardhat.config.js
40504+
require("@nomicfoundation/hardhat-toolbox");
40505+
40506+
require("@parity/hardhat-polkadot");
40507+
40508+
const { vars } = require("hardhat/config");
40509+
40510+
/** @type import('hardhat/config').HardhatUserConfig */
40511+
module.exports = {
40512+
solidity: "0.8.28",
40513+
resolc: {
40514+
version: "1.5.2",
40515+
compilerSource: "npm",
40516+
},
40517+
networks: {
40518+
hardhat: {
40519+
polkavm: true,
40520+
nodeConfig: {
40521+
nodeBinaryPath: 'INSERT_PATH_TO_SUBSTRATE_NODE',
40522+
rpcPort: 8000,
40523+
dev: true,
40524+
},
40525+
adapterConfig: {
40526+
adapterBinaryPath: 'INSERT_PATH_TO_ETH_RPC_ADAPTER',
40527+
dev: true,
40528+
},
40529+
},
40530+
localNode: {
40531+
polkavm: true,
40532+
url: `http://127.0.0.1:8545`,
40533+
},
40534+
passetHub: {
40535+
polkavm: true,
40536+
url: 'https://testnet-passet-hub-eth-rpc.polkadot.io',
40537+
accounts: [vars.get("PRIVATE_KEY")],
40538+
},
40539+
},
40540+
};
4050540541
```
4050640542

4050740543
Ensure that `INSERT_PATH_TO_SUBSTRATE_NODE` and `INSERT_PATH_TO_ETH_RPC_ADAPTER` are replaced with the proper paths to the compiled binaries.
@@ -40531,7 +40567,27 @@ Let's start by setting up Hardhat for your Storage contract project:
4053140567
1. Create a new folder called `contracts` and create a `Storage.sol` file. Add the contract code from the previous tutorial:
4053240568

4053340569
```solidity title="Storage.sol"
40534-
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/contracts/Storage.sol
40570+
// SPDX-License-Identifier: MIT
40571+
pragma solidity ^0.8.28;
40572+
40573+
contract Storage {
40574+
// State variable to store our number
40575+
uint256 private number;
40576+
40577+
// Event to notify when the number changes
40578+
event NumberChanged(uint256 newNumber);
40579+
40580+
// Function to store a new number
40581+
function store(uint256 newNumber) public {
40582+
number = newNumber;
40583+
emit NumberChanged(newNumber);
40584+
}
40585+
40586+
// Function to retrieve the stored number
40587+
function retrieve() public view returns (uint256) {
40588+
return number;
40589+
}
40590+
}
4053540591
```
4053640592

4053740593
2. Compile the contract:
@@ -40557,9 +40613,28 @@ Testing is a critical part of smart contract development. Hardhat makes it easy
4055740613
1. Create a folder for testing called `test`. Inside that directory, create a file named `Storage.js` and add the following code:
4055840614

4055940615
```javascript title="Storage.js"
40560-
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
40616+
const { expect } = require('chai');
40617+
const { ethers } = require('hardhat');
40618+
40619+
describe('Storage', function () {
40620+
let storage;
40621+
let owner;
40622+
let addr1;
40623+
40624+
beforeEach(async function () {
40625+
// Get signers
40626+
[owner, addr1] = await ethers.getSigners();
40627+
40628+
// Deploy the Storage contract
40629+
const Storage = await ethers.getContractFactory('Storage');
40630+
storage = await Storage.deploy();
40631+
await storage.waitForDeployment();
40632+
});
40633+
40634+
describe('Basic functionality', function () {
4056140635
// Add your logic here
40562-
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
40636+
});
40637+
});
4056340638
```
4056440639

4056540640
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.
@@ -40569,7 +40644,9 @@ Testing is a critical part of smart contract development. Hardhat makes it easy
4056940644
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
4057040645

4057140646
```javascript title="Storage.js"
40572-
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
40647+
it('Should return 0 initially', async function () {
40648+
expect(await storage.retrieve()).to.equal(0);
40649+
});
4057340650
```
4057440651

4057540652
Explanation:
@@ -40581,7 +40658,13 @@ Testing is a critical part of smart contract development. Hardhat makes it easy
4058140658
b. **Value storage test** - validate the core functionality of storing and retrieving a value in the contract
4058240659

4058340660
```javascript title="Storage.js"
40584-
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
40661+
it('Should update when store is called', async function () {
40662+
const testValue = 42;
40663+
// Store a value
40664+
await storage.store(testValue);
40665+
// Check if the value was updated
40666+
expect(await storage.retrieve()).to.equal(testValue);
40667+
});
4058540668
```
4058640669

4058740670
Explanation:
@@ -40593,7 +40676,13 @@ Testing is a critical part of smart contract development. Hardhat makes it easy
4059340676
c. **Event emission verification** - confirm that the contract emits the correct event when storing a value, which is crucial for off-chain tracking
4059440677

4059540678
```javascript title="Storage.js"
40596-
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
40679+
it('Should emit an event when storing a value', async function () {
40680+
const testValue = 100;
40681+
// Check if the NumberChanged event is emitted with the correct value
40682+
await expect(storage.store(testValue))
40683+
.to.emit(storage, 'NumberChanged')
40684+
.withArgs(testValue);
40685+
});
4059740686
```
4059840687

4059940688
Explanation:
@@ -40605,7 +40694,14 @@ Testing is a critical part of smart contract development. Hardhat makes it easy
4060540694
d. **Sequential value storage test** - check the contract's ability to store multiple values sequentially and maintain the most recent value
4060640695

4060740696
```javascript title="Storage.js"
40608-
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
40697+
it('Should allow storing sequentially increasing values', async function () {
40698+
const values = [10, 20, 30, 40];
40699+
40700+
for (const value of values) {
40701+
await storage.store(value);
40702+
expect(await storage.retrieve()).to.equal(value);
40703+
}
40704+
});
4060940705
```
4061040706

4061140707
Explanation:
@@ -40618,7 +40714,55 @@ Testing is a critical part of smart contract development. Hardhat makes it easy
4061840714

4061940715
???--- code "View complete script"
4062040716
```javascript title="Storage.js"
40621-
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
40717+
const { expect } = require('chai');
40718+
const { ethers } = require('hardhat');
40719+
40720+
describe('Storage', function () {
40721+
let storage;
40722+
let owner;
40723+
let addr1;
40724+
40725+
beforeEach(async function () {
40726+
// Get signers
40727+
[owner, addr1] = await ethers.getSigners();
40728+
40729+
// Deploy the Storage contract
40730+
const Storage = await ethers.getContractFactory('Storage');
40731+
storage = await Storage.deploy();
40732+
await storage.waitForDeployment();
40733+
});
40734+
40735+
describe('Basic functionality', function () {
40736+
it('Should return 0 initially', async function () {
40737+
expect(await storage.retrieve()).to.equal(0);
40738+
});
40739+
40740+
it('Should update when store is called', async function () {
40741+
const testValue = 42;
40742+
// Store a value
40743+
await storage.store(testValue);
40744+
// Check if the value was updated
40745+
expect(await storage.retrieve()).to.equal(testValue);
40746+
});
40747+
40748+
it('Should emit an event when storing a value', async function () {
40749+
const testValue = 100;
40750+
// Check if the NumberChanged event is emitted with the correct value
40751+
await expect(storage.store(testValue))
40752+
.to.emit(storage, 'NumberChanged')
40753+
.withArgs(testValue);
40754+
});
40755+
40756+
it('Should allow storing sequentially increasing values', async function () {
40757+
const values = [10, 20, 30, 40];
40758+
40759+
for (const value of values) {
40760+
await storage.store(value);
40761+
expect(await storage.retrieve()).to.equal(value);
40762+
}
40763+
});
40764+
});
40765+
});
4062240766
```
4062340767

4062440768
2. Run the tests:
@@ -40647,7 +40791,13 @@ Testing is a critical part of smart contract development. Hardhat makes it easy
4064740791
1. Create a new folder called`ignition/modules`. Add a new file named `StorageModule.js` with the following logic:
4064840792

4064940793
```javascript title="StorageModule.js"
40650-
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/ignition/modules/StorageModule.js
40794+
const { buildModule } = require('@nomicfoundation/hardhat-ignition/modules');
40795+
40796+
module.exports = buildModule('StorageModule', (m) => {
40797+
const storage = m.contract('Storage');
40798+
40799+
return { storage };
40800+
});
4065140801
```
4065240802

4065340803
2. Deploy to the local network:
@@ -40719,7 +40869,40 @@ To interact with your deployed contract:
4071940869
1. Create a new folder named `scripts` and add the `interact.js` with the following content:
4072040870

4072140871
```javascript title="interact.js"
40722-
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/scripts/interact.js
40872+
const hre = require('hardhat');
40873+
40874+
async function main() {
40875+
// Replace with your deployed contract address
40876+
const contractAddress = 'INSERT_DEPLOYED_CONTRACT_ADDRESS';
40877+
40878+
// Get the contract instance
40879+
const Storage = await hre.ethers.getContractFactory('Storage');
40880+
const storage = await Storage.attach(contractAddress);
40881+
40882+
// Get current value
40883+
const currentValue = await storage.retrieve();
40884+
console.log('Current stored value:', currentValue.toString());
40885+
40886+
// Store a new value
40887+
const newValue = 42;
40888+
console.log(`Storing new value: ${newValue}...`);
40889+
const tx = await storage.store(newValue);
40890+
40891+
// Wait for transaction to be mined
40892+
await tx.wait();
40893+
console.log('Transaction confirmed');
40894+
40895+
// Get updated value
40896+
const updatedValue = await storage.retrieve();
40897+
console.log('Updated stored value:', updatedValue.toString());
40898+
}
40899+
40900+
main()
40901+
.then(() => process.exit(0))
40902+
.catch((error) => {
40903+
console.error(error);
40904+
process.exit(1);
40905+
});
4072340906
```
4072440907

4072540908
Ensure that `INSERT_DEPLOYED_CONTRACT_ADDRESS` is replaced with the value obtained in the previous step.

tutorials/interoperability/xcm-observability.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,16 @@ In complex XCM flows, such as multi-hop transfers that span multiple parachains,
180180
- **Topic assignment**: Manually set via `SetTopic` instruction
181181
- **Goal**: Transfer DOT and trace the XCM using the manually assigned `message_id`
182182

183-
Create a new script, `multi-hop-with-set-topic.ts`
183+
Create a new script, `deposit-reserve-asset-with-set-topic.ts`
184184

185185
```ts
186-
--8<-- 'code/tutorials/interoperability/xcm-observability/multi-hop-with-set-topic.ts'
186+
--8<-- 'code/tutorials/interoperability/xcm-observability/deposit-reserve-asset-with-set-topic.ts'
187187
```
188188

189189
Run it locally:
190190

191191
```bash
192-
npx tsx multi-hop-with-set-topic.ts
192+
npx tsx deposit-reserve-asset-with-set-topic.ts
193193
```
194194

195195
#### Forwarded XCM (Destination Chain: Hydration)
@@ -200,7 +200,7 @@ During execution, the runtime includes a `SetTopic` instruction with the customi
200200

201201
#### Example: Message Trace Output
202202

203-
--8<-- 'code/tutorials/interoperability/xcm-observability/multi-hop-with-set-topic-result.html'
203+
--8<-- 'code/tutorials/interoperability/xcm-observability/deposit-reserve-asset-with-set-topic-result.html'
204204

205205
## Workaround for Older Runtimes
206206

0 commit comments

Comments
 (0)