Skip to content

Commit af2d8dc

Browse files
authored
refactor(core-state): merge index and reindex into one function inside WalletRepository (#3563)
1 parent 64403cd commit af2d8dc

37 files changed

+149
-147
lines changed

__tests__/functional/transaction-forging/delegate-resignation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ describe("Transaction Forging - Delegate Resignation", () => {
167167
await expect(transactionsResign.id).not.toBeForged();
168168

169169
for (const delegate of takenDelegates) {
170-
walletRepository.reindex(delegate);
170+
walletRepository.index(delegate);
171171
}
172172
});
173173
});

__tests__/integration/core-api/__support__/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,6 @@ export const calculateRanks = async () => {
124124
const wallet = walletRepository.findByPublicKey(delegate.publicKey!);
125125
wallet.setAttribute("delegate.rank", i + 1);
126126

127-
walletRepository.reindex(wallet);
127+
walletRepository.index(wallet);
128128
});
129129
};

__tests__/integration/core-api/handlers/delegates.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ beforeEach(() => {
4949
wallet.setAttribute("delegate.producedBlocks", 75);
5050
wallet.setAttribute("delegate.voteBalance", AppUtils.BigNumber.make(delegate.voteBalance));
5151

52-
walletRepository.reindex(wallet);
52+
walletRepository.index(wallet);
5353
});
5454

5555
const createWallet = (address: string): Contracts.State.Wallet =>
@@ -89,7 +89,7 @@ describe("API 2.0 - Delegates", () => {
8989
const delegate = reverseDelegates[i];
9090
delegate.setAttribute("delegate.voteBalance", AppUtils.BigNumber.make(i * 1e8));
9191

92-
walletRepository.reindex(delegate);
92+
walletRepository.index(delegate);
9393
}
9494

9595
const response = await api.request("GET", "delegates", { orderBy: "votes:asc" });
@@ -104,7 +104,7 @@ describe("API 2.0 - Delegates", () => {
104104
const delegate = originalDelegates[i];
105105
delegate.setAttribute("delegate.voteBalance", AppUtils.BigNumber.ZERO);
106106

107-
walletRepository.reindex(delegate);
107+
walletRepository.index(delegate);
108108
}
109109
});
110110

@@ -116,7 +116,7 @@ describe("API 2.0 - Delegates", () => {
116116
);
117117
const wallet: Contracts.State.Wallet = walletRepository.findByUsername("genesis_1");
118118
wallet.setAttribute("delegate.voteBalance", AppUtils.BigNumber.make(12500000000000000));
119-
walletRepository.reindex(wallet);
119+
walletRepository.index(wallet);
120120

121121
const response = await api.request("GET", "delegates", { orderBy: "votes:desc" });
122122
expect(response).toBeSuccessfulResponse();
@@ -274,17 +274,17 @@ describe("API 2.0 - Delegates", () => {
274274
for (let i = 0; i < delegates.length; i++) {
275275
const delegate = delegates[i];
276276
delegate.setAttribute("delegate.voteBalance", AppUtils.BigNumber.ZERO);
277-
walletRepository.reindex(delegate);
277+
walletRepository.index(delegate);
278278
}
279279

280280
// Give 2 delegates a vote weight
281281
const delegate1 = walletRepository.findByUsername("genesis_1");
282282
delegate1.setAttribute("delegate.voteBalance", AppUtils.BigNumber.make(10000000 * 1e8));
283-
walletRepository.reindex(delegate1);
283+
walletRepository.index(delegate1);
284284

285285
const delegate2 = walletRepository.findByUsername("genesis_2");
286286
delegate2.setAttribute("delegate.voteBalance", AppUtils.BigNumber.make(10000000 * 1e8));
287-
walletRepository.reindex(delegate2);
287+
walletRepository.index(delegate2);
288288

289289
const response = await api.request("POST", "delegates/search", {
290290
approval: {
@@ -305,7 +305,7 @@ describe("API 2.0 - Delegates", () => {
305305
// Make sure all vote balances are at 0
306306
for (const delegate of walletRepository.allByUsername()) {
307307
delegate.setAttribute("delegate.voteBalance", AppUtils.BigNumber.ZERO);
308-
walletRepository.reindex(delegate);
308+
walletRepository.index(delegate);
309309
}
310310
});
311311

@@ -321,17 +321,17 @@ describe("API 2.0 - Delegates", () => {
321321
for (let i = 0; i < delegates.length; i++) {
322322
const delegate = delegates[i];
323323
delegate.setAttribute("delegate.voteBalance", AppUtils.BigNumber.ZERO);
324-
walletRepository.reindex(delegate);
324+
walletRepository.index(delegate);
325325
}
326326

327327
// Give 2 delegates a vote weight
328328
const delegate1 = walletRepository.findByUsername("genesis_1");
329329
delegate1.setAttribute("delegate.voteBalance", AppUtils.BigNumber.make(10000000 * 1e8));
330-
walletRepository.reindex(delegate1);
330+
walletRepository.index(delegate1);
331331

332332
const delegate2 = walletRepository.findByUsername("genesis_2");
333333
delegate2.setAttribute("delegate.voteBalance", AppUtils.BigNumber.make(5000000 * 1e8));
334-
walletRepository.reindex(delegate2);
334+
walletRepository.index(delegate2);
335335

336336
const response = await api.request("POST", "delegates/search", {
337337
approval: {
@@ -492,13 +492,13 @@ describe("API 2.0 - Delegates", () => {
492492
for (let i = 0; i < delegates.length; i++) {
493493
const delegate = delegates[i];
494494
delegate.setAttribute("delegate.producedBlocks", 0);
495-
walletRepository.reindex(delegate);
495+
walletRepository.index(delegate);
496496
}
497497

498498
// Give 2 delegates a vote weight
499499
const delegate1 = walletRepository.findByUsername("genesis_1");
500500
delegate1.setAttribute("delegate.producedBlocks", delegate.producedBlocks);
501-
walletRepository.reindex(delegate1);
501+
walletRepository.index(delegate1);
502502

503503
const response = await api.request("POST", "delegates/search", {
504504
producedBlocks: {
@@ -548,13 +548,13 @@ describe("API 2.0 - Delegates", () => {
548548
for (let i = 0; i < delegates.length; i++) {
549549
const delegate = delegates[i];
550550
delegate.setAttribute("delegate.voteBalance", 0);
551-
walletRepository.reindex(delegate);
551+
walletRepository.index(delegate);
552552
}
553553

554554
// Give 2 delegates a vote weight
555555
const delegate1 = walletRepository.findByUsername("genesis_1");
556556
delegate1.setAttribute("delegate.voteBalance", AppUtils.BigNumber.make(delegate.voteBalance));
557-
walletRepository.reindex(delegate1);
557+
walletRepository.index(delegate1);
558558

559559
const response = await api.request("POST", "delegates/search", {
560560
voteBalance: {

__tests__/integration/core-api/handlers/locks.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe("API 2.0 - Locks", () => {
5656

5757
wallet.setAttribute("htlc.locks", locks);
5858

59-
walletRepository.reindex(wallet);
59+
walletRepository.index(wallet);
6060
}
6161
});
6262

@@ -201,7 +201,7 @@ describe("API 2.0 - Locks", () => {
201201

202202
it("should POST a search for locks with the exact vendorField", async () => {
203203
const wallet = createWallet("secret", { vendorField: "HTLC" });
204-
walletRepository.reindex(wallet);
204+
walletRepository.index(wallet);
205205

206206
const response = await api.request("POST", "locks/search", {
207207
vendorField: "HTLC",
@@ -219,7 +219,7 @@ describe("API 2.0 - Locks", () => {
219219

220220
it("should POST a search for locks within the timestamp range", async () => {
221221
const wallet = createWallet("secret", { timestamp: 5000 });
222-
walletRepository.reindex(wallet);
222+
walletRepository.index(wallet);
223223

224224
const response = await api.request("POST", "locks/search", {
225225
timestamp: {

__tests__/integration/core-api/handlers/wallets.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,13 @@ describe("API 2.0 - Wallets", () => {
389389
for (let i = 0; i < delegates.length; i++) {
390390
const delegate = delegates[i];
391391
delegate.setAttribute("delegate.voteBalance", Utils.BigNumber.ZERO);
392-
walletRepository.reindex(delegate);
392+
walletRepository.index(delegate);
393393
}
394394

395395
// Give 2 delegates a vote weight
396396
const delegate1 = walletRepository.findByUsername("genesis_1");
397397
delegate1.setAttribute("delegate.voteBalance", Utils.BigNumber.make(balance));
398-
walletRepository.reindex(delegate1);
398+
walletRepository.index(delegate1);
399399

400400
const response = await api.request("POST", "wallets/search", {
401401
address,

__tests__/unit/core-transactions/handlers/one/multi-signature-registration.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ beforeEach(() => {
6363
multiSignatureWallet = buildMultiSignatureWallet();
6464
recipientWallet = buildRecipientWallet(factoryBuilder);
6565

66-
walletRepository.reindex(senderWallet);
67-
walletRepository.reindex(secondSignatureWallet);
68-
walletRepository.reindex(multiSignatureWallet);
69-
walletRepository.reindex(recipientWallet);
66+
walletRepository.index(senderWallet);
67+
walletRepository.index(secondSignatureWallet);
68+
walletRepository.index(multiSignatureWallet);
69+
walletRepository.index(recipientWallet);
7070
});
7171

7272
describe("MultiSignatureRegistrationTransaction", () => {
@@ -92,7 +92,7 @@ describe("MultiSignatureRegistrationTransaction", () => {
9292

9393
recipientWallet = new Wallets.Wallet(Identities.Address.fromMultiSignatureAsset(multiSignatureAsset), new Services.Attributes.AttributeMap(getWalletAttributeSet()));
9494

95-
walletRepository.reindex(recipientWallet);
95+
walletRepository.index(recipientWallet);
9696

9797
multiSignatureTransaction = BuilderFactory.multiSignature()
9898
.version(1)

__tests__/unit/core-transactions/handlers/two/delegate-registration.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ beforeEach(() => {
6464
multiSignatureWallet = buildMultiSignatureWallet();
6565
recipientWallet = buildRecipientWallet(factoryBuilder);
6666

67-
walletRepository.reindex(senderWallet);
68-
walletRepository.reindex(secondSignatureWallet);
69-
walletRepository.reindex(multiSignatureWallet);
70-
walletRepository.reindex(recipientWallet);
67+
walletRepository.index(senderWallet);
68+
walletRepository.index(secondSignatureWallet);
69+
walletRepository.index(multiSignatureWallet);
70+
walletRepository.index(recipientWallet);
7171
});
7272

7373
describe("DelegateRegistrationTransaction", () => {
@@ -199,7 +199,7 @@ describe("DelegateRegistrationTransaction", () => {
199199

200200
delegateWallet.setAttribute("delegate", { username: "dummy" });
201201

202-
walletRepository.reindex(delegateWallet);
202+
walletRepository.index(delegateWallet);
203203

204204
await expect(handler.throwIfCannotBeApplied(delegateRegistrationTransaction, senderWallet, walletRepository)).rejects.toThrow(
205205
WalletUsernameAlreadyRegisteredError,
@@ -237,7 +237,7 @@ describe("DelegateRegistrationTransaction", () => {
237237

238238
anotherWallet.balance = Utils.BigNumber.make(7527654310);
239239

240-
walletRepository.reindex(anotherWallet);
240+
walletRepository.index(anotherWallet);
241241

242242
let anotherDelegateRegistrationTransaction = BuilderFactory.delegateRegistration()
243243
.usernameAsset("dummy")

__tests__/unit/core-transactions/handlers/two/delegate-resignation.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ beforeEach(() => {
6464
multiSignatureWallet = buildMultiSignatureWallet();
6565
recipientWallet = buildRecipientWallet(factoryBuilder);
6666

67-
walletRepository.reindex(senderWallet);
68-
walletRepository.reindex(secondSignatureWallet);
69-
walletRepository.reindex(multiSignatureWallet);
70-
walletRepository.reindex(recipientWallet);
67+
walletRepository.index(senderWallet);
68+
walletRepository.index(secondSignatureWallet);
69+
walletRepository.index(multiSignatureWallet);
70+
walletRepository.index(recipientWallet);
7171
});
7272

7373
describe("DelegateResignationTransaction", () => {
@@ -97,7 +97,7 @@ describe("DelegateResignationTransaction", () => {
9797

9898
delegateWallet.setAttribute("delegate", { username: "username" + i } );
9999

100-
walletRepository.reindex(delegateWallet);
100+
walletRepository.index(delegateWallet);
101101
allDelegates.push(delegateWallet);
102102
}
103103

@@ -111,7 +111,7 @@ describe("DelegateResignationTransaction", () => {
111111

112112
delegateWallet.balance = Utils.BigNumber.make(66 * 1e8);
113113
delegateWallet.setAttribute("delegate", {username: "dummy"});
114-
walletRepository.reindex(delegateWallet);
114+
walletRepository.index(delegateWallet);
115115

116116
delegateResignationTransaction = BuilderFactory.delegateResignation()
117117
.nonce("1")
@@ -134,7 +134,7 @@ describe("DelegateResignationTransaction", () => {
134134
it("should resolve - simulate genesis wallet", async () => {
135135
allDelegates[0].forgetAttribute("delegate");
136136

137-
walletRepository.reindex(allDelegates[0]);
137+
walletRepository.index(allDelegates[0]);
138138

139139
setMockTransaction(delegateResignationTransaction);
140140
await expect(handler.bootstrap()).toResolve();
@@ -160,7 +160,7 @@ describe("DelegateResignationTransaction", () => {
160160

161161
it("should not throw if wallet is a delegate - second sign", async () => {
162162
secondSignatureWallet.setAttribute("delegate", {username: "dummy"});
163-
walletRepository.reindex(secondSignatureWallet);
163+
walletRepository.index(secondSignatureWallet);
164164
await expect(handler.throwIfCannotBeApplied(secondSignatureDelegateResignationTransaction, secondSignatureWallet, walletRepository)).toResolve();
165165
});
166166

@@ -174,7 +174,7 @@ describe("DelegateResignationTransaction", () => {
174174
.make();
175175

176176
anotherDelegate.setAttribute("delegate", {username: "another"});
177-
walletRepository.reindex(anotherDelegate);
177+
walletRepository.index(anotherDelegate);
178178

179179
await expect(handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository)).toResolve();
180180
});

__tests__/unit/core-transactions/handlers/two/general.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ beforeEach(() => {
6262
multiSignatureWallet = buildMultiSignatureWallet();
6363
recipientWallet = buildRecipientWallet(factoryBuilder);
6464

65-
walletRepository.reindex(senderWallet);
66-
walletRepository.reindex(secondSignatureWallet);
67-
walletRepository.reindex(multiSignatureWallet);
68-
walletRepository.reindex(recipientWallet);
65+
walletRepository.index(senderWallet);
66+
walletRepository.index(secondSignatureWallet);
67+
walletRepository.index(multiSignatureWallet);
68+
walletRepository.index(recipientWallet);
6969
});
7070

7171
describe("General Tests", () => {

__tests__/unit/core-transactions/handlers/two/htlc-claim.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ beforeEach(() => {
7171
multiSignatureWallet = buildMultiSignatureWallet();
7272
recipientWallet = buildRecipientWallet(factoryBuilder);
7373

74-
walletRepository.reindex(senderWallet);
75-
walletRepository.reindex(secondSignatureWallet);
76-
walletRepository.reindex(multiSignatureWallet);
77-
walletRepository.reindex(recipientWallet);
74+
walletRepository.index(senderWallet);
75+
walletRepository.index(secondSignatureWallet);
76+
walletRepository.index(multiSignatureWallet);
77+
walletRepository.index(recipientWallet);
7878
});
7979

8080
describe("Htlc claim", () => {
@@ -116,8 +116,8 @@ describe("Htlc claim", () => {
116116
})
117117
.make();
118118

119-
walletRepository.reindex(lockWallet);
120-
walletRepository.reindex(claimWallet);
119+
walletRepository.index(lockWallet);
120+
walletRepository.index(claimWallet);
121121

122122
let expiration = {
123123
type: expirationType,
@@ -145,7 +145,7 @@ describe("Htlc claim", () => {
145145
},
146146
});
147147

148-
walletRepository.reindex(lockWallet);
148+
walletRepository.index(lockWallet);
149149

150150
htlcClaimTransaction = BuilderFactory.htlcClaim()
151151
.htlcClaimAsset({
@@ -238,7 +238,7 @@ describe("Htlc claim", () => {
238238
})
239239
.make();
240240

241-
walletRepository.reindex(dummyWallet);
241+
walletRepository.index(dummyWallet);
242242

243243
htlcClaimTransaction = BuilderFactory.htlcClaim()
244244
.htlcClaimAsset({
@@ -282,7 +282,7 @@ describe("Htlc claim", () => {
282282
},
283283
});
284284

285-
walletRepository.reindex(lockWallet);
285+
walletRepository.index(lockWallet);
286286

287287
htlcClaimTransaction = BuilderFactory.htlcClaim()
288288
.htlcClaimAsset({
@@ -390,7 +390,7 @@ describe("Htlc claim", () => {
390390
})
391391
.make();
392392

393-
walletRepository.reindex(dummyWallet);
393+
walletRepository.index(dummyWallet);
394394

395395
htlcClaimTransaction = BuilderFactory.htlcClaim()
396396
.htlcClaimAsset({

__tests__/unit/core-transactions/handlers/two/htlc-lock.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ beforeEach(() => {
6464
multiSignatureWallet = buildMultiSignatureWallet();
6565
recipientWallet = buildRecipientWallet(factoryBuilder);
6666

67-
walletRepository.reindex(senderWallet);
68-
walletRepository.reindex(secondSignatureWallet);
69-
walletRepository.reindex(multiSignatureWallet);
70-
walletRepository.reindex(recipientWallet);
67+
walletRepository.index(senderWallet);
68+
walletRepository.index(secondSignatureWallet);
69+
walletRepository.index(multiSignatureWallet);
70+
walletRepository.index(recipientWallet);
7171
});
7272

7373
describe("Htlc lock", () => {

0 commit comments

Comments
 (0)