Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WETH from assethub support
Browse files Browse the repository at this point in the history
JuaniRios committed Nov 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 663d2eb commit 35e2967
Showing 21 changed files with 616 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

175 changes: 175 additions & 0 deletions integration-tests/chopsticks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches

.cache

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
6 changes: 6 additions & 0 deletions integration-tests/chopsticks/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5"
}
15 changes: 15 additions & 0 deletions integration-tests/chopsticks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# polimec-chopstick-tests

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run index.ts
```

This project was created using `bun init` in bun v1.1.30. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
Binary file added integration-tests/chopsticks/bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions integration-tests/chopsticks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello via Bun!');
23 changes: 23 additions & 0 deletions integration-tests/chopsticks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "polimec-chopstick-tests",
"module": "index.ts",
"type": "module",
"devDependencies": {
"@acala-network/chopsticks": "0.12.2",
"@acala-network/chopsticks-testing": "0.12.2",
"@types/bun": "latest",
"prettier": "^3.3.3"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"@polkadot/keyring": "^13.2.2",
"@polkadot/types-augment": "^14.2.2",
"@polkadot/util": "^13.2.2",
"@polkadot/util-crypto": "^13.2.2"
},
"scripts": {
"fmt": "bun prettier --write ."
}
}
149 changes: 149 additions & 0 deletions integration-tests/chopsticks/src/networks/assetHub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import {
setupContext,
type SetupOption,
} from '@acala-network/chopsticks-testing';

import type { Config } from './types.js';
import { initialBalanceDOT, toNumber } from '../utils.js';
import {type StagingXcmV4Location} from '@polkadot/types/lookup';

/// Options used to create the Spiritnet context
export const getSetupOptions = ({
blockNumber = undefined,
wasmOverride = undefined,
}: {
blockNumber?: number;
wasmOverride?: string;
}) =>
({
endpoint:
process.env.ASSETHUB_WSS || 'wss://asset-hub-polkadot-rpc.dwellir.com',
db: './db/assethub.db.sqlite',
port: toNumber(process.env.ASSETHUB_PORT) || 9003,
wasmOverride,
blockNumber,
}) as SetupOption;

/// AssetHub has no own coin. Teleported dots are used as the native token.
export function assignDotTokensToAccountsAsStorage(
addr: string[],
balance: bigint = initialBalanceDOT
) {
return {
System: {
Account: addr.map((address) => [
[address],
{ providers: 1, data: { free: balance.toString() } },
]),
},
};
}

export function createForeignAsset(manager: string, assetId: StagingXcmV4Location) {
return {
foreignAssets: {
asset: [
[
[assetId],
{
owner: manager,
issuer: manager,
admin: manager,
freezer: manager,
// Just make it big enough
supply: '10000000000000000000000000000',
deposit: 0,
minBalance: 0,
isSufficient: false,
accounts: 0,
sufficients: 0,
approvals: 0,
status: 'Live',
},
],
],
},
};
}

/// Assigns KSM to an account
export function assignKSMtoAccounts(
addr: string[],
balance: bigint = initialBalanceDOT
) {
return {
foreignAssets: {
account: addr.map((addr) => [
[KSMAssetLocation, addr],
{
balance: balance,
status: 'Liquid',
reason: 'Consumer',
extra: null,
},
]),
},
};
}

/// Assigns the foreign asset to the accounts.
/// Does not check if supply is matching the sum of the account balances.
export function assignForeignAssetToAccounts(
accountInfo: [string, bigint][],
assetId = eKiltLocation
) {
return {
foreignAssets: {
account: accountInfo.map(([account, balance]) => [
[assetId, account],
{
balance: balance,
status: 'Liquid',
reason: 'Consumer',
extra: null,
},
]),
},
};
}

/// AssetHub ParaId
export const paraId = 1000;

export const KSMAssetLocation = {
parents: 2,
interior: {
X1: {
GlobalConsensus: 'Kusama',
},
},
};

// Sibling Sovereign Account
export const sovereignAccountOnSiblingChains =
'4qXPdpimHh8TR24RSk994yVzxx4TLfvKj5i1qH5puvWmfAqy';

/// Native token in AssetHub
export const nativeTokenLocation = { parents: 1, interior: 'Here' };

export const eKiltLocation = {
parents: 2,
interior: {
X2: [
{
GlobalConsensus: { Ethereum: { chainId: 11155111 } },
},
{
AccountKey20: {
network: null,
key: '0x06012c8cf97bead5deae237070f9587f8e7a266d',
},
},
],
},
};

export async function getContext(): Promise<Config> {
const options = getSetupOptions({});
return setupContext(options);
}
3 changes: 3 additions & 0 deletions integration-tests/chopsticks/src/networks/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { setupContext } from '@acala-network/chopsticks-testing';

export type Config = Awaited<ReturnType<typeof setupContext>>;
Loading

0 comments on commit 35e2967

Please sign in to comment.