difftreelog
test(identity) force set subs
in: master
1 file changed
tests/src/identity.seqtest.tsdiffbeforeafterboth29 return (await getIdentities(helper)).flatMap(([key, _value]) => key);29 return (await getIdentities(helper)).flatMap(([key, _value]) => key);30}30}3132async function getSubIdentityAccounts(helper: UniqueHelper, address: string) {33 return ((await helper.getApi().query.identity.subsOf(address)).toHuman() as any)[1];34}3536async function getSubIdentityName(helper: UniqueHelper, address: string) {37 return ((await helper.getApi().query.identity.superOf(address)).toHuman() as any);38}313932describe('Integration Test: Identities Manipulation', () => {40describe('Integration Test: Identities Manipulation', () => {33 let superuser: IKeyringPair;41 let superuser: IKeyringPair;45 .to.be.rejectedWith(/Transaction call is not expected/);53 .to.be.rejectedWith(/Transaction call is not expected/);46 });54 });475556 describe('Identities', () => {48 itSub('Sets identities', async ({helper}) => {57 itSub('Sets identities', async ({helper}) => {49 const oldIdentitiesCount = (await getIdentityAccounts(helper)).length;58 const oldIdentitiesCount = (await getIdentityAccounts(helper)).length;505989 const newIdentities = await getIdentityAccounts(helper);98 const newIdentities = await getIdentityAccounts(helper);90 expect(newIdentities.concat(scapegoats)).to.be.have.members(oldIdentities);99 expect(newIdentities.concat(scapegoats)).to.be.have.members(oldIdentities);91 });100 });101 });102103 describe('Sub-identities', () => {104 itSub('Sets subs', async ({helper}) => {105 const crowdSize = 18;106 const crowd = await helper.arrange.createCrowd(crowdSize, 0n, superuser);107 const supers = [crowd.pop()!, crowd.pop()!, crowd.pop()!];108109 const subsPerSup = crowd.length / supers.length;110 let subCount = 0;111 const subs = [112 crowd.slice(subCount, subCount += subsPerSup + 1),113 crowd.slice(subCount, subCount += subsPerSup),114 crowd.slice(subCount, subCount += subsPerSup - 1),115 ];116117 const subsInfo = supers.map((acc, i) => [118 acc.address, [119 1000000n + BigInt(i + 1),120 subs[i].map((sub, j) => [121 sub.address, {Raw: `accounter #${j}`},122 ]),123 ],124 ]);125 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo]);126127 for (let i = 0; i < supers.length; i++) {128 // check deposit129 expect(((await helper.getApi().query.identity.subsOf(supers[i].address)).toJSON() as any)[0]).to.be.equal(1000001 + i);130131 const subsAccounts = await getSubIdentityAccounts(helper, supers[i].address);132 // check sub-identities as account ids133 expect(subsAccounts).to.include.members(subs[i].map(x => x.address));134135 for (let j = 0; j < subsAccounts.length; j++) {136 // check sub-identities' names137 expect((await getSubIdentityName(helper, subsAccounts[j]))[1]).to.be.deep.equal({Raw: `accounter #${j}`});138 }139 }140 });141142 itSub('Setting sub-identities does not delete other existing but does overwrite own', async ({helper}) => {143 const crowdSize = 18;144 const crowd = await helper.arrange.createCrowd(crowdSize, 0n, superuser);145 const supers = [crowd.pop()!, crowd.pop()!, crowd.pop()!];146147 const subsPerSup = crowd.length / supers.length;148 let subCount = 0;149 const subs = [150 crowd.slice(subCount, subCount += subsPerSup + 1),151 crowd.slice(subCount, subCount += subsPerSup),152 crowd.slice(subCount, subCount += subsPerSup - 1),153 ];154155 const subsInfo1 = supers.map((acc, i) => [156 acc.address, [157 1000000n + BigInt(i + 1),158 subs[i].map((sub, j) => [159 sub.address, {Raw: `accounter #${j}`},160 ]),161 ],162 ]);163 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo1]);164165 // change some sub-identities...166 subs[2].pop(); subs[2].pop(); subs[2].push(...await helper.arrange.createAccounts([0n], superuser));167168 // ...and set them169 const subsInfo2 = [[170 supers[2].address, [171 999999n,172 subs[2].map((sub, j) => [173 sub.address, {Raw: `discounter #${j}`},174 ]),175 ],176 ]];177 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo2]);178179 // make sure everything else is the same180 for (let i = 0; i < supers.length - 1; i++) {181 // check deposit182 expect(((await helper.getApi().query.identity.subsOf(supers[i].address)).toJSON() as any)[0]).to.be.equal(1000001 + i);183184 const subsAccounts = await getSubIdentityAccounts(helper, supers[i].address);185 // check sub-identities as account ids186 expect(subsAccounts).to.include.members(subs[i].map(x => x.address));187188 for (let j = 0; j < subsAccounts; j++) {189 // check sub-identities' names190 expect((await getSubIdentityName(helper, subsAccounts[j]))[1]).to.be.deep.equal({Raw: `accounter #${j}`});191 }192 }193194 // check deposit195 expect(((await helper.getApi().query.identity.subsOf(supers[2].address)).toJSON() as any)[0]).to.be.equal(999999);196197 const subsAccounts = await getSubIdentityAccounts(helper, supers[2].address);198 // check sub-identities as account ids199 expect(subsAccounts).to.include.members(subs[2].map(x => x.address));200201 for (let j = 0; j < subsAccounts.length; j++) {202 // check sub-identities' names203 expect((await getSubIdentityName(helper, subsAccounts[j]))[1]).to.be.deep.equal({Raw: `discounter #${j}`});204 }205 });206207 itSub('Removes sub-identities', async ({helper}) => {208 const crowdSize = 3;209 const crowd = await helper.arrange.createCrowd(crowdSize, 0n, superuser);210 const sup = crowd.pop()!;211212 const subsInfo1 = [[213 sup.address, [214 1000000n,215 crowd.map((sub, j) => [216 sub.address, {Raw: `accounter #${j}`},217 ]),218 ],219 ]];220 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo1]);221222 // empty sub-identities should delete the records223 const subsInfo2 = [[224 sup.address, [225 1000000n,226 [],227 ],228 ]];229 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo2]);230231 // check deposit232 expect((await helper.getApi().query.identity.subsOf(sup.address)).toHuman()).to.be.deep.equal(['0', []]);233234 for (let j = 0; j < crowd.length; j++) {235 // check sub-identities' names236 expect((await getSubIdentityName(helper, crowd[j].address))).to.be.null;237 }238 });239240 itSub('Removing identities deletes associated sub-identities', async ({helper}) => {241 const crowd = await helper.arrange.createCrowd(3, 0n, superuser);242 const sup = crowd.pop()!;243244 // insert identity245 const identities = [[sup.address, {info: {display: {Raw: 'mental'}}}]];246 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);247248 // and its sub-identities249 const subsInfo = [[250 sup.address, [251 1000000n,252 crowd.map((sub, j) => [253 sub.address, {Raw: `accounter #${j}`},254 ]),255 ],256 ]];257 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo]);258259 // delete top identity260 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [[sup.address]]);261262 // check that sub-identities are deleted263 expect((await helper.getApi().query.identity.subsOf(sup.address)).toHuman()).to.be.deep.equal(['0', []]);264265 for (let j = 0; j < crowd.length; j++) {266 // check sub-identities' names267 expect((await getSubIdentityName(helper, crowd[j].address))).to.be.null;268 }269 });270 });9227193 after(async function() {272 after(async function() {94 await usingPlaygrounds(async helper => {273 await usingPlaygrounds(async helper => {