Skip to content

Commit

Permalink
[node-api/e2e] minor registering refactoring and fix ordering of regi…
Browse files Browse the repository at this point in the history
…strations
  • Loading branch information
clangenb committed May 13, 2024
1 parent 2aa13b8 commit c1fc410
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions packages/node-api/src/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,34 +307,9 @@ async function registerAliceBobCharlieAndGoToAttesting(api: ApiPromise, cid: Com
const bob = keyring.addFromUri('//Bob', {name: 'Bob default'});
const charlie = keyring.addFromUri('//Charlie', {name: 'Charlie default'});

// Even though they are identical, we need to have three different objects because they are passed by reference in JS.
const tx1 = api.tx['encointerCeremonies']['registerParticipant'](cid, null)
const tx2 = api.tx['encointerCeremonies']['registerParticipant'](cid, null)
const tx3 = api.tx['encointerCeremonies']['registerParticipant'](cid, null)

// Charlie does not have funds
const transfer_tx = api.tx['balances']['transfer'](charlie.address, 10000000000000);
await submitAndWatchTx(api, alice, transfer_tx)
.then((result) => {
if (result.error !== undefined) {
console.log(`failed fund Charlie: ${JSON.stringify(result)}`);
}
})

let results = await Promise.all([
submitAndWatchTx(api, alice, tx1),
submitAndWatchTx(api, bob, tx2),
submitAndWatchTx(api, charlie, tx3),
])

const signers = [alice, bob, charlie];
results.forEach((result, index) => {
if (result.error !== undefined) {
console.log(`failed register ${signers[index].address}: ${JSON.stringify(result)}`);
} else {
console.log(`registered ${signers[index].address}: result: ${JSON.stringify(result)}`);
}
})
await registerParticipant(api, alice, cid);
await registerParticipant(api, bob, cid);
await registerParticipant(api, charlie, cid);

// go to assigning phase
await nextPhase(api, alice);
Expand All @@ -343,6 +318,18 @@ async function registerAliceBobCharlieAndGoToAttesting(api: ApiPromise, cid: Com
await nextPhase(api, alice);
}

async function registerParticipant(api: ApiPromise, signer: KeyringPair, cid: CommunityIdentifier): Promise<void> {
const tx = api.tx['encointerCeremonies']['registerParticipant'](cid, null)

const result = await submitAndWatchTx(api, signer, tx)

if (result.error !== undefined) {
console.log(`failed register ${signer.address}: ${JSON.stringify(result)}`);
} else {
console.log(`registered ${signer.address}: result: ${JSON.stringify(result)}`);
}
}

async function nextPhase(api: ApiPromise, signer: KeyringPair): Promise<void> {
const tx = api.tx['sudo']['sudo'](
api.tx['encointerScheduler']['nextPhase']()
Expand Down

0 comments on commit c1fc410

Please sign in to comment.