git.delta.rocks / unique-network / refs/commits / 0a3544788f57

difftreelog

test(identity) force set subs

Fahrrader2023-01-18parent: #e385c32.patch.diff
in: master

1 file changed

modifiedtests/src/identity.seqtest.tsdiffbeforeafterboth
29 return (await getIdentities(helper)).flatMap(([key, _value]) => key);29 return (await getIdentities(helper)).flatMap(([key, _value]) => key);
30}30}
31
32async function getSubIdentityAccounts(helper: UniqueHelper, address: string) {
33 return ((await helper.getApi().query.identity.subsOf(address)).toHuman() as any)[1];
34}
35
36async function getSubIdentityName(helper: UniqueHelper, address: string) {
37 return ((await helper.getApi().query.identity.superOf(address)).toHuman() as any);
38}
3139
32describe('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 });
4755
56 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;
5059
89 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 });
102
103 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()!];
108
109 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 ];
116
117 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]);
126
127 for (let i = 0; i < supers.length; i++) {
128 // check deposit
129 expect(((await helper.getApi().query.identity.subsOf(supers[i].address)).toJSON() as any)[0]).to.be.equal(1000001 + i);
130
131 const subsAccounts = await getSubIdentityAccounts(helper, supers[i].address);
132 // check sub-identities as account ids
133 expect(subsAccounts).to.include.members(subs[i].map(x => x.address));
134
135 for (let j = 0; j < subsAccounts.length; j++) {
136 // check sub-identities' names
137 expect((await getSubIdentityName(helper, subsAccounts[j]))[1]).to.be.deep.equal({Raw: `accounter #${j}`});
138 }
139 }
140 });
141
142 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()!];
146
147 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 ];
154
155 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]);
164
165 // change some sub-identities...
166 subs[2].pop(); subs[2].pop(); subs[2].push(...await helper.arrange.createAccounts([0n], superuser));
167
168 // ...and set them
169 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]);
178
179 // make sure everything else is the same
180 for (let i = 0; i < supers.length - 1; i++) {
181 // check deposit
182 expect(((await helper.getApi().query.identity.subsOf(supers[i].address)).toJSON() as any)[0]).to.be.equal(1000001 + i);
183
184 const subsAccounts = await getSubIdentityAccounts(helper, supers[i].address);
185 // check sub-identities as account ids
186 expect(subsAccounts).to.include.members(subs[i].map(x => x.address));
187
188 for (let j = 0; j < subsAccounts; j++) {
189 // check sub-identities' names
190 expect((await getSubIdentityName(helper, subsAccounts[j]))[1]).to.be.deep.equal({Raw: `accounter #${j}`});
191 }
192 }
193
194 // check deposit
195 expect(((await helper.getApi().query.identity.subsOf(supers[2].address)).toJSON() as any)[0]).to.be.equal(999999);
196
197 const subsAccounts = await getSubIdentityAccounts(helper, supers[2].address);
198 // check sub-identities as account ids
199 expect(subsAccounts).to.include.members(subs[2].map(x => x.address));
200
201 for (let j = 0; j < subsAccounts.length; j++) {
202 // check sub-identities' names
203 expect((await getSubIdentityName(helper, subsAccounts[j]))[1]).to.be.deep.equal({Raw: `discounter #${j}`});
204 }
205 });
206
207 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()!;
211
212 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]);
221
222 // empty sub-identities should delete the records
223 const subsInfo2 = [[
224 sup.address, [
225 1000000n,
226 [],
227 ],
228 ]];
229 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo2]);
230
231 // check deposit
232 expect((await helper.getApi().query.identity.subsOf(sup.address)).toHuman()).to.be.deep.equal(['0', []]);
233
234 for (let j = 0; j < crowd.length; j++) {
235 // check sub-identities' names
236 expect((await getSubIdentityName(helper, crowd[j].address))).to.be.null;
237 }
238 });
239
240 itSub('Removing identities deletes associated sub-identities', async ({helper}) => {
241 const crowd = await helper.arrange.createCrowd(3, 0n, superuser);
242 const sup = crowd.pop()!;
243
244 // insert identity
245 const identities = [[sup.address, {info: {display: {Raw: 'mental'}}}]];
246 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);
247
248 // and its sub-identities
249 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]);
258
259 // delete top identity
260 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [[sup.address]]);
261
262 // check that sub-identities are deleted
263 expect((await helper.getApi().query.identity.subsOf(sup.address)).toHuman()).to.be.deep.equal(['0', []]);
264
265 for (let j = 0; j < crowd.length; j++) {
266 // check sub-identities' names
267 expect((await getSubIdentityName(helper, crowd[j].address))).to.be.null;
268 }
269 });
270 });
92271
93 after(async function() {272 after(async function() {
94 await usingPlaygrounds(async helper => {273 await usingPlaygrounds(async helper => {