|
@@ -1,3 +1,5 @@
|
|
|
+const assert = require('assert')
|
|
|
+
|
|
|
function aliceKeyPair (api) {
|
|
|
return api.identities.keyring.addFromUri('//Alice', null, 'sr25519')
|
|
|
}
|
|
@@ -22,25 +24,25 @@ const init = async (api) => {
|
|
|
throw new Error('Setup requires Alice to be sudo. Are you sure you are running a devchain?')
|
|
|
}
|
|
|
|
|
|
- // register alice as a member if not already registered
|
|
|
+ // register alice as a member
|
|
|
console.log(`Registering Alice as a member`)
|
|
|
- const aliceMemberId = 0 // first assignable id
|
|
|
- api.identities.registerMember(alice, {
|
|
|
+ const aliceMemberId = await api.identities.registerMember(alice, {
|
|
|
handle: 'alice'
|
|
|
})
|
|
|
|
|
|
// Make alice the storage lead
|
|
|
+ console.log('Setting Alice as Lead')
|
|
|
// prepare set storage lead tx
|
|
|
const setLeadTx = api.api.tx.storageWorkingGroup.setLead(aliceMemberId, alice)
|
|
|
// make sudo call
|
|
|
- console.log('Setting Alice as Lead')
|
|
|
api.signAndSend(
|
|
|
alice,
|
|
|
api.api.tx.sudo.sudo(setLeadTx)
|
|
|
)
|
|
|
|
|
|
// create an openinging, apply, start review, fill opening
|
|
|
- // Assumption opening id and applicant id, provider id will all be the first ids == 0
|
|
|
+ // Assumption opening id and applicant id, provider id will all be the
|
|
|
+ // first assignable id == 0
|
|
|
// so we don't await each tx to finalize to get the ids. this allows us to
|
|
|
// batch all the transactions into a single block.
|
|
|
console.log('Making Alice a storage provider')
|
|
@@ -52,12 +54,12 @@ const init = async (api) => {
|
|
|
// default values for everything else..
|
|
|
}, 'opening0')
|
|
|
api.signAndSend(alice, openTx)
|
|
|
- const openingId = 0 // first id
|
|
|
+ const openingId = 0 // first assignable opening id
|
|
|
const applyTx = api.api.tx.storageWorkingGroup.applyOnWorkerOpening(
|
|
|
aliceMemberId, openingId, alice, null, null, 'alice'
|
|
|
)
|
|
|
api.signAndSend(alice, applyTx)
|
|
|
- const applicantId = 0 // first applicant id
|
|
|
+ const applicantId = 0 // first assignable applicant id
|
|
|
|
|
|
const reviewTx = api.api.tx.storageWorkingGroup.beginWorkerApplicantReview(openingId)
|
|
|
api.signAndSend(alice, reviewTx)
|
|
@@ -68,16 +70,15 @@ const init = async (api) => {
|
|
|
|
|
|
// const worker = await api.workers.storageWorkerByProviderId(providerId)
|
|
|
if (await api.workers.isRoleAccountOfStorageProvider(providerId, alice)) {
|
|
|
- console.log('Setup Successful')
|
|
|
+ console.log('Setup Alice successfully as storage provider')
|
|
|
} else { throw new Error('Setup Failed') }
|
|
|
|
|
|
// set localhost colossus as discovery provider on default port
|
|
|
- const bootstrapTx = api.discovery.setBootstrapEndpoints(['http://localhost:3000/'])
|
|
|
- await api.signAndSend(alice, bootstrapTx)
|
|
|
+ await api.discovery.setBootstrapEndpoints(alice, ['http://localhost:3000/'])
|
|
|
}
|
|
|
|
|
|
const check = async (api) => {
|
|
|
- const providerId = 0
|
|
|
+ const providerId = 0 // the first provider id which would have been assigned in dev-init
|
|
|
const roleAccountId = aliceKeyPair(api).address
|
|
|
|
|
|
if (await api.workers.isRoleAccountOfStorageProvider(providerId, roleAccountId)) {
|