Skip to content

Commit 3b12c70

Browse files
authored
fix(magistrate): entity name only unique by type (#4008)
1 parent 06261f9 commit 3b12c70

File tree

6 files changed

+62
-387
lines changed

6 files changed

+62
-387
lines changed

__tests__/unit/core-magistrate/handlers/entity.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { EntityAction, EntityType } from "@arkecosystem/core-magistrate-crypto/s
66
import {
77
EntityAlreadyRegisteredError,
88
EntityAlreadyResignedError,
9+
EntityNameAlreadyRegisteredError,
910
EntityNameDoesNotMatchDelegateError,
1011
EntityNotRegisteredError,
1112
EntitySenderIsNotDelegateError,
@@ -178,6 +179,62 @@ describe("Entity handler", () => {
178179
).rejects.toBeInstanceOf(StaticFeeMismatchError);
179180
});
180181

182+
it.each([validRegisters])(
183+
"should throw when entity name is already registered for same type",
184+
async asset => {
185+
const transaction = entityBuilder
186+
.asset(asset)
187+
.sign(senderPassphrase)
188+
.build();
189+
190+
const randomPassphrase = "this is another passphrase";
191+
const randomWallet = new Wallets.Wallet(Identities.Address.fromPassphrase(randomPassphrase));
192+
randomWallet.balance = Utils.BigNumber.make(452765431200000);
193+
randomWallet.publicKey = Identities.PublicKey.fromPassphrase(randomPassphrase);
194+
// entity name already registered with different wallet and different tx id
195+
randomWallet.setAttribute("entities", {
196+
"7950c6a0d096eeb4883237feec12b9f37f36ab9343ff3640904befc75ce32ec2": {
197+
type: asset.type,
198+
subType: (asset.subType + 1) % 255, // different subType but still in the range [0, 255]
199+
data: asset.data,
200+
},
201+
});
202+
walletManager.reindex(randomWallet);
203+
204+
await expect(
205+
entityHandler.throwIfCannotBeApplied(transaction, senderWallet, walletManager),
206+
).rejects.toBeInstanceOf(EntityNameAlreadyRegisteredError);
207+
},
208+
);
209+
210+
it.each([validRegisters])(
211+
"should not throw when entity name is registered for a different type",
212+
async asset => {
213+
const transaction = entityBuilder
214+
.asset(asset)
215+
.sign(senderPassphrase)
216+
.build();
217+
218+
const randomPassphrase = "this is another passphrase";
219+
const randomWallet = new Wallets.Wallet(Identities.Address.fromPassphrase(randomPassphrase));
220+
randomWallet.balance = Utils.BigNumber.make(452765431200000);
221+
randomWallet.publicKey = Identities.PublicKey.fromPassphrase(randomPassphrase);
222+
// entity name already registered with different wallet and different tx id
223+
randomWallet.setAttribute("entities", {
224+
"7950c6a0d096eeb4883237feec12b9f37f36ab9343ff3640904befc75ce32ec2": {
225+
type: (asset.type + 1) % 255, // different subType but still in the range [0, 255]
226+
subType: asset.subType,
227+
data: asset.data,
228+
},
229+
});
230+
walletManager.reindex(randomWallet);
231+
232+
await expect(
233+
entityHandler.throwIfCannotBeApplied(transaction, senderWallet, walletManager),
234+
).toResolve();
235+
},
236+
);
237+
181238
describe("Entity delegate", () => {
182239
const createEntityDelegateTx = name =>
183240
entityBuilder

packages/core-magistrate-transactions/src/handlers/entity-subhandlers/register.ts

Lines changed: 0 additions & 106 deletions
This file was deleted.

packages/core-magistrate-transactions/src/handlers/entity-subhandlers/resign.ts

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)