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

demo-statement: Update func-tests with transfer of funds and disable … #257

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
91 changes: 52 additions & 39 deletions demo/src/func-test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import * as Cord from '@cord.network/sdk'
// import { UUID, Crypto } from '@cord.network/utils'
import { createDidName } from './utils/generateDidName'
import { getDidDocFromName } from './utils/queryDidName'
import { randomUUID } from 'crypto'
import { addNetworkMember } from './utils/createAuthorities'
import { createAccount } from './utils/createAccount'

function getChallenge(): string {
return Cord.Utils.UUID.generate()
}
import BN from 'bn.js';

async function main() {
const networkAddress = process.env.NETWORK_ADDRESS
? process.env.NETWORK_ADDRESS
: 'ws://127.0.0.1:9944'
// const networkAddress = 'ws://127.0.0.1:9944'

Cord.ConfigService.set({ submitTxResolveOn: Cord.Chain.IS_IN_BLOCK })
await Cord.connect(networkAddress)

const api = Cord.ConfigService.get('api');

// Retrieve the runtime version & the type of the runtime.
const runtimeVersion = api.runtimeVersion;

const runtimeType = runtimeVersion.specName.toString();

console.log("\n❄️ Connected to CORD runtime type:", runtimeType);

// Step 1: Setup Membership
// Setup transaction author account - CORD Account.
console.log(`\n❄️ New Network Member`)
Expand All @@ -39,6 +45,10 @@ async function main() {
await addNetworkMember(authorityAuthorIdentity, authorIdentity.address)
console.log('✅ Network Member added!')

// Transfer funds for the identity.
let tx = await api.tx.balances.transferAllowDeath(authorIdentity.address, new BN('1000000000000000'));
await Cord.Chain.signAndSubmitTx(tx, authorityAuthorIdentity);

// Step 2: Setup Identities
console.log(`\n❄️ Demo Identities (KeyRing)`)

Expand Down Expand Up @@ -163,42 +173,45 @@ async function main() {
)
console.log(`✅ Chain Space Approved`)

// Step 3.5: Subspace
const subSpaceProperties = await Cord.ChainSpace.buildFromProperties(
issuerDid.uri
)
console.dir(subSpaceProperties, {
depth: null,
colors: true,
})
const subSpace = await Cord.ChainSpace.dispatchSubspaceCreateToChain(
subSpaceProperties,
issuerDid.uri,
authorIdentity,
200,
space.uri,
async ({ data }) => ({
signature: issuerKeys.authentication.sign(data),
keyType: issuerKeys.authentication.type,
/* Disable subspace for permissionless chain */
if (runtimeType != "weave") {
// Step 3.5: Subspace
const subSpaceProperties = await Cord.ChainSpace.buildFromProperties(
issuerDid.uri
)
console.dir(subSpaceProperties, {
depth: null,
colors: true,
})
)
console.dir(subSpace, {
depth: null,
colors: true,
})
console.log(`\n❄️ SubSpace is created`)

const subSpaceTx = await Cord.ChainSpace.dispatchUpdateTxCapacityToChain(
subSpace.uri,
issuerDid.uri,
authorIdentity,
300,
async ({ data }) => ({
signature: issuerKeys.authentication.sign(data),
keyType: issuerKeys.authentication.type,
const subSpace = await Cord.ChainSpace.dispatchSubspaceCreateToChain(
subSpaceProperties,
issuerDid.uri,
authorIdentity,
200,
space.uri,
async ({ data }) => ({
signature: issuerKeys.authentication.sign(data),
keyType: issuerKeys.authentication.type,
})
)
console.dir(subSpace, {
depth: null,
colors: true,
})
)
console.log(`\n❄️ SubSpace limit is updated`)
console.log(`\n❄️ SubSpace is created`)

const subSpaceTx = await Cord.ChainSpace.dispatchUpdateTxCapacityToChain(
subSpace.uri,
issuerDid.uri,
authorIdentity,
300,
async ({ data }) => ({
signature: issuerKeys.authentication.sign(data),
keyType: issuerKeys.authentication.type,
})
)
console.log(`\n❄️ SubSpace limit is updated`)
}

// Step 4: Add Delelegate Two as Registry Delegate
console.log(`\n❄️ Space Delegate Authorization `)
Expand Down