Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Asset Registry (#63)
Browse files Browse the repository at this point in the history
* bootstrap pallet_asset_registry

* rm change_foreign_asset fn

* fix AsAssetMultiLocation implementation

* avoid creating/destroying assets for registry

* use loose coupling with Assets pallet

* split unit tests

* bootstrap xcm-simulator unit tests

* rustfmt

* rm change_foreign_asset extrinsic

* rename Foreign Asset -> Reserve Asset

* rm xcm-simulator from unit tests

* rename ForeignFungiblesTransactor->ReservedFungiblesTransactor

* add comments to asset-registry pallet errors

* bootstrap integration-tests

* asset-registry pallet README

* zombienet with 2 collators per para

* bootstrap benchmarks

* upgrade zombienet config camel_case

* update weights with GCP c2d-highcpu-8

* integration test: rm XcmV1MultiLocation attribute from ReserveAssetRegistered event

* rm unused StatemineAssetIdInfoB

* add WeightInfo to asset-registry mock

* Run cargo fmt & clippy

* More clippy smartness

* lint pallets/asset-registry/README.md

Co-authored-by: Adam Wierzbicki <[email protected]>

* lint pallets/asset-registry/README.md

Co-authored-by: Adam Wierzbicki <[email protected]>

* lint pallets/asset-registry/README.md

Co-authored-by: Adam Wierzbicki <[email protected]>

* lint pallets/asset-registry/README.md

Co-authored-by: Adam Wierzbicki <[email protected]>

* lint pallets/asset-registry/src/benchmarking.rs

Co-authored-by: Adam Wierzbicki <[email protected]>

* lint pallets/asset-registry/src/tests.rs

Co-authored-by: Adam Wierzbicki <[email protected]>

* lint pallets/asset-registry/src/tests.rs

Co-authored-by: Adam Wierzbicki <[email protected]>

* lint primitives/xcm/Cargo.toml

Co-authored-by: Adam Wierzbicki <[email protected]>

* lint primitives/xcm/src/lib.rs

Co-authored-by: Adam Wierzbicki <[email protected]>

* lint primitives/xcm/src/lib.rs

Co-authored-by: Adam Wierzbicki <[email protected]>

* lint pallets/asset-registry/src/benchmarking.rs

Co-authored-by: Adam Wierzbicki <[email protected]>

* lint pallets/asset-registry/src/lib.rs

Co-authored-by: Adam Wierzbicki <[email protected]>

* lint pallets/asset-registry/src/lib.rs

Co-authored-by: Adam Wierzbicki <[email protected]>

* lint pallets/asset-registry/src/tests.rs

Co-authored-by: Adam Wierzbicki <[email protected]>

* fix ReserveAssetRegistered field

* add comment explaining fn asset_exists

* fix asset-registry pallet README

* set LOCAL_ASSET_ID to 10

* change &trappist_asset_id on integration test

Co-authored-by: Steve Degosserie <[email protected]>
Co-authored-by: Adam Wierzbicki <[email protected]>
  • Loading branch information
3 people authored Oct 10, 2022
1 parent 8725dba commit 9b092be
Show file tree
Hide file tree
Showing 19 changed files with 1,371 additions and 217 deletions.
399 changes: 229 additions & 170 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"node",
"runtime",
"primitives/xcm",
]
exclude = [
"contracts"
Expand Down
19 changes: 19 additions & 0 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[`parachains-integration-tests`](https://github.com/paritytech/parachains-integration-tests) is a tool designed to test interactions between Substrate blockchains.

Trappist uses it to ensure the correctness of some of its features.

# Setup

Install `parachains-integration-tests` into your system:
```
$ yarn global add @parity/parachains-integration-tests
```

# Usage

Please refer to the [project's `README.md`](https://github.com/paritytech/parachains-integration-tests#how-to-use) for an extensive description of how to write YAML test files and how to execute tests.

For example, to use zombienet and perform a reserve transfer that tests the functionality of `asset-registry` pallet:
```
$ parachains-integration-tests -m zombienet-test -c xcm-playground.toml -t integration-tests/asset-registry/0_reserve_transfer.yml
```
249 changes: 249 additions & 0 deletions integration-tests/asset-registry/0_reserve_transfer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
---
settings:
chains:
relay_chain: &relay_chain
wsPort: 9900
reserve_parachain: &reserve_parachain
wsPort: 9910
paraId: &rp_id 1000
trappist_parachain: &trappist_parachain
wsPort: 9920
paraId: &tp_id 2000
variables:
common:
amount_to_mint: &amount_to_mint 100000000000000
amount_to_send: &amount_to_send 10000000000000
require_weight_at_most: &weight_at_most 1000000000
chains:
relay_chain:
signer: &rc_signer //Alice
trappist_parachain_dest_routed: &tp_dest_routed { v1: { parents: 1, interior: { x1: { parachain: *tp_id } }}}
reserve_parachain:
signer: &rp_signer //Alice
wallet: &rp_wallet HNZata7iMYWmk5RvZRTiAsSDhV8366zq2YGb3tLH5Upf74F
bob_signer: &rp_bob_signer //Bob
bob_wallet: &rp_bob_wallet FoQJpPyadYccjavVdTWxpxU7rUEaYhfLCPwXgkfD6Zat9QP
asset_id: &reserve_asset_id 1
asset_pallet_id: &reserve_asset_pallet_id 50
asset_min_balance: &reserve_assets_min_balance 1
asset_multi_location: &reserve_asset_multi_location {
parents: 1,
interior: {
X3: [
{
Parachain: *rp_id
},
{
PalletInstance: *reserve_asset_pallet_id
},
{
GeneralIndex: *reserve_asset_id
}
]
}
}
trappist_parachain:
signer: &tp_signer //Alice
wallet: &tp_wallet 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
bob_wallet: &tp_bob_wallet 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty
asset_id: &trappist_asset_id 100 # different from reserve_asset_id, so we can test pallet-assets-registry
asset_min_balance: &trappist_assets_min_balance 1
sovereign_account: &tp_sovereign_sibl FBeL7EAeUroLWXW1yfKboiqTqVfbRBcsUKd6QqVf4kGBySS
bob_account: &tp_bob_acc '0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48'
decodedCalls:
force_create_asset:
chain: *reserve_parachain
pallet: assets
call: forceCreate
args: [
*reserve_asset_id,
{ id: *rp_wallet }, # owner
true, # isSufficient
*reserve_assets_min_balance # minBalance
]

tests:
- name: HRMP
describes:
- name: polkadotXcm.limitedReserveTransferAssets (Asset) | Reserve Parachain -> Trappist Parachain
before:
- name: DEPENDENCY | Create a sufficient Asset on Reserve Parachain
actions:
- extrinsics:
- chain: *relay_chain
signer: *rc_signer
sudo: true
pallet: parasSudoWrapper
call: sudoQueueDownwardXcm
args: [
*rp_id, # id
{
v2: [ # message
{
Transact: {
originType: Superuser,
requireWeightAtMost: *weight_at_most,
call: $force_create_asset
}
}
]
}
]
events:
- name: sudo.Sudid
attributes:
- type: Result<Null, SpRuntimeDispatchError>
value: Ok
- queries:
forced_created_asset:
chain: *reserve_parachain
pallet: assets
call: asset
args: [ *reserve_asset_id ]
- asserts:
isSome:
args: [ $forced_created_asset ]

- name: DEPENDENCY | Mint assets on Reserve Parachain
actions:
- extrinsics:
- chain: *reserve_parachain
signer: *rp_signer
pallet: assets
call: mint
args: [
*reserve_asset_id,
*rp_bob_wallet,
*amount_to_mint
]
events:
- name: assets.Issued

- name: DEPENDENCY | Create asset on Trappist Parachain
actions:
- extrinsics:
- chain: *trappist_parachain
signer: *tp_signer
pallet: assets
call: forceCreate
sudo: true
args: [
*trappist_asset_id,
{ id: *tp_wallet }, # owner
false, # isSufficient
*trappist_assets_min_balance #minBalance
]
events:
- name: sudo.Sudid
attributes:
- type: Result<Null, SpRuntimeDispatchError>
value: Ok
- name: assets.ForceCreated
- queries:
forced_created_asset:
chain: *trappist_parachain
pallet: assets
call: asset
args: [ *trappist_asset_id ]
- asserts:
isSome:
args: [ $forced_created_asset ]

its:
- name: Trappist Parachain has AssetId registered to Reserve Asset
actions:
- extrinsics:
- chain: *trappist_parachain
signer: *tp_signer
sudo: true
pallet: assetRegistry
call: registerReserveAsset
args: [
*trappist_asset_id,
*reserve_asset_multi_location
]
events:
- name: sudo.Sudid
attributes:
- type: Result<Null, SpRuntimeDispatchError>
value: Ok
- name: assetRegistry.ReserveAssetRegistered
attributes:
- type: u32
value: *trappist_asset_id

- name: Assets Parachain should be able to reserve transfer an asset to Trappist Parachain
actions:
- extrinsics:
- chain: *reserve_parachain
signer: *rp_bob_signer
pallet: polkadotXcm
call: limitedReserveTransferAssets
args: [
*tp_dest_routed, # destination
{ # beneficiary
v1: {
parents: 0,
interior: {
x1: {
AccountId32: {
network: null,
id: *tp_bob_acc
}
}
}
}
},
{ # assets
v1: [
{
id: {
Concrete: {
parents: 0,
interior: {
x2: [
{
PalletInstance: *reserve_asset_pallet_id
},
{
GeneralIndex: *reserve_asset_id
}
]
}
}
},
fun: {
Fungible: *amount_to_send
}
}
]
},
0, # feeAssetItem
Unlimited # weightLimit
]
events:
- name: polkadotXcm.Attempted
attributes:
- type: XcmV2TraitsOutcome
xcmOutcome: Complete
value: 1,000,000,000
- name: assets.Transferred
attributes:
- type: AccountId32
value: *tp_sovereign_sibl
- type: u128
value: *amount_to_send
- name: assets.Issued
chain: *trappist_parachain
- queries:
bob_received_asset:
chain: *trappist_parachain
pallet: assets
call: account
args: [
*trappist_asset_id,
*tp_bob_wallet
]
- asserts:
isSome:
args: [ $bob_received_asset ]
21 changes: 18 additions & 3 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use serde::{Deserialize, Serialize};
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
use trappist_runtime::{
constants::currency::EXISTENTIAL_DEPOSIT, AccountId, AuraId, BalancesConfig, CouncilConfig,
GenesisConfig, SessionConfig, SessionKeys, Signature, SudoConfig, SystemConfig,
constants::currency::EXISTENTIAL_DEPOSIT, AccountId, AssetsConfig, AuraId, BalancesConfig,
CouncilConfig, GenesisConfig, SessionConfig, SessionKeys, Signature, SudoConfig, SystemConfig,
};

const DEFAULT_PROTOCOL_ID: &str = "hop";
Expand Down Expand Up @@ -176,6 +176,8 @@ pub fn local_testnet_config() -> ChainSpec {
)
}

pub const LOCAL_ASSET_ID: u32 = 10;

/// Configure initial storage state for FRAME modules.
fn testnet_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
Expand Down Expand Up @@ -223,7 +225,20 @@ fn testnet_genesis(
// Assign network admin rights.
key: Some(root_key),
},
assets: Default::default(),
assets: AssetsConfig {
assets: vec![
// id, owner, is_sufficient, min_balance
(LOCAL_ASSET_ID, get_account_id_from_seed::<sr25519::Public>("Alice"), true, 1),
],
metadata: vec![
// id, name, symbol, decimals
(LOCAL_ASSET_ID, "txUSD".into(), "txUSD".into(), 10),
],
accounts: vec![
// id, account_id, balance
(LOCAL_ASSET_ID, get_account_id_from_seed::<sr25519::Public>("Alice"), 100),
],
},
council: CouncilConfig {
members: invulnerables.iter().map(|x| x.0.clone()).collect::<Vec<_>>(),
phantom: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface, RelayC
use cumulus_relay_chain_rpc_interface::{create_client_and_start_worker, RelayChainRpcInterface};

use sc_executor::NativeElseWasmExecutor;
use sc_network::{NetworkService, NetworkBlock};
use sc_network::{NetworkBlock, NetworkService};
use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager};
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
use sp_api::ConstructRuntimeApi;
Expand Down
Loading

0 comments on commit 9b092be

Please sign in to comment.